diff --git a/src/components/Authorship.svelte b/src/components/Authorship.svelte index 7a5774076..d42ded07d 100644 --- a/src/components/Authorship.svelte +++ b/src/components/Authorship.svelte @@ -5,16 +5,20 @@ import { formatNodeId, formatTimestamp } from "@app/lib/utils"; export let author: Author; + export let caption: string | undefined = undefined; + export let highlight: boolean = false; export let noAvatar: boolean = false; - export let timestamp: number; - export let caption: string; + export let timestamp: number | undefined = undefined; + + const relativeTimestamp = (time: number | undefined) => + time ? new Date(time).toISOString() : undefined; - + {#if !noAvatar} {/if} - {formatNodeId(author.id)} - + + {formatNodeId(author.id)} + + {formatNodeId(author.id).replace("did:key:", "")} -  {caption}  - - {formatTimestamp(timestamp)} + + {#if !caption} + + {:else} + {caption} + {/if} + {#if timestamp} + + {formatTimestamp(timestamp)} + + {/if} diff --git a/src/components/Badge.svelte b/src/components/Badge.svelte index 975ec64c9..91487cbed 100644 --- a/src/components/Badge.svelte +++ b/src/components/Badge.svelte @@ -5,7 +5,9 @@ | "negative" | "positive" | "primary" + | "secondary" | "tertiary"; + export let style: string | undefined = undefined;
- + + + {#if removeable} - -
diff --git a/src/components/Markdown.svelte b/src/components/Markdown.svelte index 39217af3c..4899f2af3 100644 --- a/src/components/Markdown.svelte +++ b/src/components/Markdown.svelte @@ -14,13 +14,13 @@ } from "@app/lib/markdown"; export let content: string; - export let doc = matter(content); export let hash: string | null = null; export let path: string = "/"; export let breaks = false; export let rawPath: string; - const frontMatter = Object.entries(doc.data).filter( + $: doc = matter(content); + $: frontMatter = Object.entries(doc.data).filter( ([, val]) => typeof val === "string" || typeof val === "number", ); marked.use({ extensions, renderer, breaks }); diff --git a/src/components/TabBar.svelte b/src/components/TabBar.svelte index 6b827340c..e4c05264b 100644 --- a/src/components/TabBar.svelte +++ b/src/components/TabBar.svelte @@ -1,7 +1,7 @@ @@ -18,7 +18,7 @@ const dispatch = createEventDispatcher<{ select: T }>(); function onSelect(option: Tab) { - if (option.count !== 0) { + if (!option.disabled) { dispatch("select", option.value); } } @@ -60,11 +60,8 @@ {/each} diff --git a/src/lib/cobs.ts b/src/lib/cobs.ts index 75d9d22c9..b985ac848 100644 --- a/src/lib/cobs.ts +++ b/src/lib/cobs.ts @@ -1,3 +1,8 @@ +import type { IssueState } from "@app/lib/issue"; +import type { PatchState } from "@app/lib/patch"; + +import { parseNodeId } from "@app/lib/utils"; + export interface Comment { id: string; author: Author; @@ -11,6 +16,11 @@ export interface Author { id: string; } +export interface Thread { + root: Comment; + replies: Comment[]; +} + export interface PeerIdentity { id: string; } @@ -28,3 +38,34 @@ export function formatObjectId(id: string): string { export function stripDidPrefix(array: string[]): string[] { return array.map(id => id.replace("did:key:", "")); } + +export type State = IssueState | PatchState; + +export function validateTag( + value: string, + items: string[], +): { success: false; error: string } | { success: true } { + if (value.trim().length > 0) { + if (items.includes(value)) { + return { success: false, error: "This tag is already added" }; + } else { + return { success: true }; + } + } + return { success: false, error: "This tag is not valid" }; +} + +export function validateAssignee( + value: string, + items: string[], +): { success: false; error: string } | { success: true } { + const nodeId = parseNodeId(value); + if (nodeId) { + if (items.includes(`${nodeId.prefix}${nodeId.pubkey}`)) { + return { success: false, error: "This assignee is already added" }; + } else { + return { success: true }; + } + } + return { success: false, error: "This assignee is not valid" }; +} diff --git a/src/lib/issue.ts b/src/lib/issue.ts index 1f2117aff..0835a4629 100644 --- a/src/lib/issue.ts +++ b/src/lib/issue.ts @@ -1,4 +1,4 @@ -import type { Author, Comment } from "@app/lib/cobs"; +import type { Author, Comment, State } from "@app/lib/cobs"; import type { Host } from "@app/lib/api"; import { stripDidPrefix } from "@app/lib/cobs"; @@ -8,21 +8,16 @@ export interface IIssue { id: string; author: Author; title: string; - state: State; + state: IssueState; discussion: Comment[]; tags: string[]; assignees: string[]; timestamp: number; } -export type State = - | { - status: "open"; - } - | { - status: "closed"; - reason: "other" | "solved"; - }; +export type IssueState = + | { status: "open" } + | { status: "closed"; reason: "other" | "solved" }; export function groupIssues(issues: Issue[]): { open: Issue[]; @@ -51,7 +46,7 @@ export class Issue { id: string; author: Author; title: string; - state: State; + state: IssueState; discussion: Comment[]; tags: string[]; assignees: string[]; diff --git a/src/lib/patch.ts b/src/lib/patch.ts new file mode 100644 index 000000000..aeec059f6 --- /dev/null +++ b/src/lib/patch.ts @@ -0,0 +1,150 @@ +import type { Author, Comment } from "@app/lib/cobs"; +import type { CommitHeader } from "@app/lib/commit"; +import type { Diff } from "@app/lib/diff"; +import type { Host } from "@app/lib/api"; + +import { Request } from "@app/lib/api"; + +interface IPatch { + id: string; + author: Author; + title: string; + description: string; + state: PatchState; + target: string; + tags: string[]; + revisions: Revision[]; +} + +export interface Revision { + id: string; + description: string; + base: string; + oid: string; + refs: string[]; + discussions: Comment[]; + reviews: [string, Review][]; + merges: Merge[]; + timestamp: number; +} + +export interface Review { + verdict?: "accept" | "reject"; + comment?: string; + inline: CodeComment[]; + timestamp: number; +} + +export interface CodeComment { + location: CodeLocation; + comment: string; + timestamp: number; +} + +interface CodeLocation { + path: string; + commit: string; + lines: { + start: number; + end: number; + }; +} + +export interface Merge { + node: string; + commit: string; + timestamp: number; +} + +export type PatchState = + | { status: "draft" } + | { status: "proposed" } + | { status: "archived" }; + +export class Patch { + id: string; + author: Author; + title: string; + description: string; + state: PatchState; + target: string; + tags: string[]; + revisions: Revision[]; + + constructor(patch: IPatch) { + this.id = patch.id; + this.author = patch.author; + this.title = patch.title; + this.description = patch.description; + this.state = patch.state; + this.target = patch.target; + this.tags = patch.tags; + this.revisions = patch.revisions; + } + + async editTags( + project: string, + add: string[], + remove: string[], + host: Host, + session: string, + ): Promise { + await new Request(`projects/${project}/patches/${this.id}`, host).patch( + { + type: "tag", + add, + remove, + }, + { Authorization: `Bearer ${session}` }, + ); + } + + static async getPatches(id: string, host: Host): Promise { + const response: IPatch[] = await new Request( + `projects/${id}/patches`, + host, + ).get(); + return response.map(patch => new Patch(patch)); + } + + async replyComment( + project: string, + revision: string, + body: string, + replyTo: string, + host: Host, + session: string, + ): Promise { + await new Request(`projects/${project}/patches/${this.id}`, host).patch( + { + type: "thread", + revision, + action: { + type: "comment", + body, + replyTo, + }, + }, + { Authorization: `Bearer ${session}` }, + ); + } + + async getPatchDiff( + project: string, + revision: Revision, + host: Host, + ): Promise<{ commits: CommitHeader[]; diff: Diff }> { + return await new Request( + `projects/${project}/diff/${revision.base}/${revision.oid}`, + host, + ).get(); + } + + static async getPatch(id: string, patch: string, host: Host): Promise { + const response: IPatch = await new Request( + `projects/${id}/patches/${patch}`, + host, + ).get(); + return new Patch(response); + } +} diff --git a/src/lib/router.ts b/src/lib/router.ts index 564ea28c2..baeffc56d 100644 --- a/src/lib/router.ts +++ b/src/lib/router.ts @@ -268,6 +268,13 @@ export function routeToPath(route: Route) { return `${hostPrefix}/${route.params.id}${peer}/issues${suffix}`; } else if (route.params.view.resource === "issue") { return `${hostPrefix}/${route.params.id}${peer}/issues/${route.params.view.params.issue}`; + } else if (route.params.view.resource === "patches") { + return `${hostPrefix}/${route.params.id}${peer}/patches${suffix}`; + } else if (route.params.view.resource === "patch") { + if (route.params.view.params.revision) { + return `${hostPrefix}/${route.params.id}${peer}/patches/${route.params.view.params.patch}/${route.params.view.params.revision}${suffix}`; + } + return `${hostPrefix}/${route.params.id}${peer}/patches/${route.params.view.params.patch}${suffix}`; } else { return `${hostPrefix}/${route.params.id}${peer}${content}`; } @@ -361,6 +368,30 @@ function resolveProjectRoute( revision: undefined, }; } + } else if (content === "patches") { + const patch = segments.shift(); + const revision = segments.shift(); + if (patch) { + return { + view: { resource: "patch", params: { patch, revision } }, + id, + seed, + peer, + path: undefined, + revision: undefined, + search: sanitizeQueryString(url.search), + }; + } else { + return { + view: { resource: "patches" }, + id, + seed, + peer, + search: sanitizeQueryString(url.search), + path: undefined, + revision: undefined, + }; + } } return null; diff --git a/src/lib/router/definitions.ts b/src/lib/router/definitions.ts index b9b0651ab..e3f7f6368 100644 --- a/src/lib/router/definitions.ts +++ b/src/lib/router/definitions.ts @@ -20,7 +20,14 @@ export interface ProjectsParams { params?: { view: { resource: "new" }; }; - }; + } + | { + resource: "patches"; + params?: { + view: { resource: "new" }; + }; + } + | { resource: "patch"; params: { patch: string; revision?: string } }; seed: string; hash?: string; line?: string; diff --git a/src/views/projects/Issue/IssueHeader.svelte b/src/views/projects/Cob/CobHeader.svelte similarity index 72% rename from src/views/projects/Issue/IssueHeader.svelte rename to src/views/projects/Cob/CobHeader.svelte index 497be82d6..12ec4df18 100644 --- a/src/views/projects/Issue/IssueHeader.svelte +++ b/src/views/projects/Cob/CobHeader.svelte @@ -1,19 +1,11 @@ + + + + diff --git a/src/views/projects/Cob/CobStateButton.svelte b/src/views/projects/Cob/CobStateButton.svelte new file mode 100644 index 000000000..b93aac51d --- /dev/null +++ b/src/views/projects/Cob/CobStateButton.svelte @@ -0,0 +1,74 @@ + + + + +
+ + + + + + + !isEqual(i.value, state))} /> + + +
diff --git a/src/views/projects/Header.svelte b/src/views/projects/Header.svelte index fc564ce6e..276c218d9 100644 --- a/src/views/projects/Header.svelte +++ b/src/views/projects/Header.svelte @@ -22,7 +22,7 @@ // Switches between project views. const toggleContent = ( - input: "issues" | "history", + input: "issues" | "patches" | "history", keepSourceInPath: boolean, ) => { router.updateProjectRoute({ @@ -130,6 +130,14 @@ {project.issues.open ?? 0} issue(s) + toggleContent("patches", false)}> + {project.patches.proposed ?? 0} + patch(es) + {tree.stats.contributors} contributor(s) diff --git a/src/views/projects/Issue.svelte b/src/views/projects/Issue.svelte index 375b9c0f2..9ec4b03a7 100644 --- a/src/views/projects/Issue.svelte +++ b/src/views/projects/Issue.svelte @@ -1,17 +1,24 @@ - - - - diff --git a/src/views/projects/Issue/IssueStateButton.svelte b/src/views/projects/Issue/IssueStateButton.svelte deleted file mode 100644 index 6b17c66db..000000000 --- a/src/views/projects/Issue/IssueStateButton.svelte +++ /dev/null @@ -1,76 +0,0 @@ - - - - -
- (showStateDropdown = !showStateDropdown)} - on:click={() => dispatch("saveStatus", selectedItem.value)}> - {selectedItem.key} - - {#if showStateDropdown} - - {/if} -
diff --git a/src/views/projects/Issue/IssueTeaser.svelte b/src/views/projects/Issue/IssueTeaser.svelte index 5ea7d36a3..78a9dd9fe 100644 --- a/src/views/projects/Issue/IssueTeaser.svelte +++ b/src/views/projects/Issue/IssueTeaser.svelte @@ -4,6 +4,8 @@ import { formatObjectId } from "@app/lib/cobs"; import Authorship from "@app/components/Authorship.svelte"; import Icon from "@app/components/Icon.svelte"; + import { formatTimestamp } from "@app/lib/utils"; + import Badge from "@app/components/Badge.svelte"; export let issue: Issue; @@ -21,17 +23,21 @@ background-color: var(--color-foreground-2); cursor: pointer; } - .issue-id { + .subtitle { color: var(--color-foreground-5); font-size: var(--font-size-tiny); font-family: var(--font-family-monospace); - margin-left: 0.5rem; + margin-right: 0.4rem; + } + .id { + margin-right: 0.5rem; } .summary { display: flex; flex-direction: row; align-items: center; - padding-right: 2rem; + gap: 0.5rem; + padding-right: 1rem; } .issue-title { overflow: hidden; @@ -46,6 +52,15 @@ gap: 0.5rem; color: var(--color-foreground-5); } + .tags { + display: flex; + flex-direction: row; + gap: 0.5rem; + } + .tag { + overflow: hidden; + text-overflow: ellipsis; + } .column-right { align-self: center; @@ -56,6 +71,9 @@ justify-self: center; align-self: center; } + .highlight { + color: var(--color-foreground-6); + } .state-icon { width: 0.5rem; height: 0.5rem; @@ -67,6 +85,12 @@ .closed { background-color: var(--color-negative); } + + @media (max-width: 960px) { + .tags { + display: none; + } + }
@@ -79,12 +103,28 @@
{issue.title} - {formatObjectId(issue.id)} + + {#each issue.tags.slice(0, 4) as tag} + + {tag} + + {/each} + {#if issue.tags.length > 4} + + +{issue.tags.length - 4} more tags + + {/if} + +
+
+ + {formatObjectId(issue.id)} + opened + {formatTimestamp(issue.timestamp)} + by + +
-
{#if commentCount > 0}
diff --git a/src/views/projects/Issue/New.svelte b/src/views/projects/Issue/New.svelte index 185a77c90..605cf8e7f 100644 --- a/src/views/projects/Issue/New.svelte +++ b/src/views/projects/Issue/New.svelte @@ -4,18 +4,25 @@ import * as modal from "@app/lib/modal"; import AuthenticationErrorModal from "@app/views/session/AuthenticationErrorModal.svelte"; + import Authorship from "@app/components/Authorship.svelte"; + import Avatar from "@app/components/Comment/Avatar.svelte"; + import Badge from "@app/components/Badge.svelte"; import Button from "@app/components/Button.svelte"; + import CobHeader from "@app/views/projects/Cob/CobHeader.svelte"; + import CobSideInput from "@app/views/projects/Cob/CobSideInput.svelte"; import Comment from "@app/components/Comment.svelte"; - import IssueSidebar from "@app/views/projects/Issue/IssueSidebar.svelte"; - import IssueHeader from "@app/views/projects/Issue/IssueHeader.svelte"; import { Issue } from "@app/lib/issue"; import { createEventDispatcher } from "svelte"; - import { stripDidPrefix } from "@app/lib/cobs"; + import { formatNodeId, isLocal, parseNodeId } from "@app/lib/utils"; + import { sessionStore } from "@app/lib/session"; + import { stripDidPrefix, validateTag } from "@app/lib/cobs"; export let session: Session; export let project: Project; const dispatch = createEventDispatcher<{ create: string }>(); + const action: "edit" | "view" = + $sessionStore && isLocal(project.seed.addr.host) ? "edit" : "view"; let preview: boolean = false; @@ -66,6 +73,12 @@ gap: 1rem; margin-top: 1rem; } + .metadata { + border-radius: var(--border-radius); + font-size: var(--font-size-small); + padding-left: 1rem; + margin-left: 1rem; + } .editor { flex: 2; padding-right: 1rem; @@ -85,12 +98,15 @@
- + + + open + + +
- (assignees = detail)} - on:saveTags={({ detail }) => (tags = detail)} - action="create" /> +
diff --git a/src/views/projects/Issues.svelte b/src/views/projects/Issues.svelte index 0ad82e635..f6c9ce3e2 100644 --- a/src/views/projects/Issues.svelte +++ b/src/views/projects/Issues.svelte @@ -1,5 +1,7 @@ + +
+
+ + + + + 1} + disabled={patch.revisions.length === 1} + title="Toggle revision"> + Revision {currentRevisionIndex} + + + + { + return { + key: `Revision ${i} (${formatObjectId(r.id)})`, + title: `Revision ${i} (${formatObjectId(r.id)})`, + value: r.id, + badge: null, + }; + })} + selected={currentRevision.toString()} + on:select={({ detail: item }) => { + router.updateProjectRoute({ + view: { + resource: "patch", + params: { patch: patch.id, revision: item.value }, + }, + }); + }} /> + + + + + {#if patch.state.status === "draft"} + + {patch.state.status} + + {:else if patch.state.status === "proposed"} + + {patch.state.status} + + {:else} + + {patch.state.status} + + {/if} +
+ +
+
+ +
+
+
+ + router.updateProjectRoute({ + search: `tab=${tab}`, + })} /> + {#if currentTab === "activity"} +
+
+ +
+ {#each timeline as element} + {#if element.type === "thread"} + + (currentRevision = index)} /> + {:else if element.type === "merge"} +
+ + merged + + {formatCommit(element.inner.commit)} + + +
+
+ + merged + + {formatCommit(element.inner.commit)} + + +
+ {:else if element.type === "review"} + + {@const [author, review] = element.inner} +
+ + {formatVerdict(review.verdict)} + +
+
+ + {formatVerdict(review.verdict)} + +
+ {#if review.comment} + + {/if} + {/if} + {/each} +
+ {:else if currentTab === "commits"} + {#await diffPromise then diff} +
+ {#each diff.commits as commit} + { + router.updateProjectRoute({ + view: { resource: "commits" }, + revision: commit.id, + search: undefined, + }); + }} + on:browseCommit={browseCommit} /> + {/each} +
+ {/await} + {:else if currentTab === "files"} + {#await diffPromise then diff} +
+ { + router.updateProjectRoute({ + view: { resource: "tree" }, + search: undefined, + revision: currentRevision.oid, + path, + }); + }} /> +
+ {/await} + {/if} +
+ +
diff --git a/src/views/projects/Patch/PatchTeaser.svelte b/src/views/projects/Patch/PatchTeaser.svelte new file mode 100644 index 000000000..a35dfc166 --- /dev/null +++ b/src/views/projects/Patch/PatchTeaser.svelte @@ -0,0 +1,154 @@ + + + + +
+
+
+
+
+
+ {patch.title} + + {#each patch.tags.slice(0, 4) as tag} + + {tag} + + {/each} + {#if patch.tags.length > 4} + + +{patch.tags.length - 4} more tags + + {/if} + +
+
+ + {formatObjectId(patch.id)} + opened + + {formatTimestamp(latestRevision.timestamp)} + + by + + +
+
+
+
+ {#await diffPromise then { diff }} + + {/await} + {#if latestRevision.discussions.length > 0} + + {latestRevision.discussions.length} + {/if} +
+
+
diff --git a/src/views/projects/Patches.svelte b/src/views/projects/Patches.svelte new file mode 100644 index 000000000..65f2cd5dd --- /dev/null +++ b/src/views/projects/Patches.svelte @@ -0,0 +1,66 @@ + + + + + + +
+ {#if patches.length} +
+ {#each patches as patch} + +
{ + router.updateProjectRoute({ + view: { + resource: "patch", + params: { patch: patch.id }, + }, + }); + }}> + +
+ {/each} +
+ {:else} + +
{utils.capitalize(status)} patches
+
No issues matched the current filter
+
+ {/if} +
diff --git a/src/views/projects/PeerSelector.svelte b/src/views/projects/PeerSelector.svelte index d274e9fe1..8102210df 100644 --- a/src/views/projects/PeerSelector.svelte +++ b/src/views/projects/PeerSelector.svelte @@ -1,5 +1,6 @@