From 39874d8d51cf61d53b6ffb2b63bb03fbdddfd88d Mon Sep 17 00:00:00 2001 From: xphoniex Date: Tue, 23 May 2023 14:38:08 +0000 Subject: [PATCH] Add `alias` to `Patch` Signed-off-by: xphoniex --- httpd-client/lib/project/patch.ts | 12 ++++---- src/components/Authorship.svelte | 13 ++++---- src/views/projects/Cob/Revision.svelte | 41 ++++++++++++++++++++++---- src/views/projects/Patch.svelte | 9 ++++-- 4 files changed, 56 insertions(+), 19 deletions(-) diff --git a/httpd-client/lib/project/patch.ts b/httpd-client/lib/project/patch.ts index b60f99c93..2d1553004 100644 --- a/httpd-client/lib/project/patch.ts +++ b/httpd-client/lib/project/patch.ts @@ -10,7 +10,6 @@ import { optional, strictObject, string, - tuple, union, } from "zod"; @@ -28,13 +27,13 @@ const patchStateSchema = union([ ]) satisfies ZodSchema; export interface Merge { - node: string; + author: { id: string; alias?: string }; commit: string; timestamp: number; } const mergeSchema = strictObject({ - node: string(), + author: strictObject({ id: string(), alias: string().optional() }), commit: string(), timestamp: number(), }) satisfies ZodSchema; @@ -72,6 +71,7 @@ const codeCommentSchema = strictObject({ type Verdict = "accept" | "reject"; export interface Review { + author: { id: string; alias?: string }; verdict?: Verdict | null; comment?: string | null; inline: CodeComment[]; @@ -79,6 +79,7 @@ export interface Review { } const reviewSchema = strictObject({ + author: strictObject({ id: string(), alias: string().optional() }), verdict: optional(union([literal("accept"), literal("reject")]).nullable()), comment: optional(string().nullable()), inline: array(codeCommentSchema), @@ -92,7 +93,7 @@ export interface Revision { oid: string; refs: string[]; discussions: Comment[]; - reviews: [string, Review][]; + reviews: Review[]; merges: Merge[]; timestamp: number; } @@ -104,7 +105,7 @@ const revisionSchema = strictObject({ oid: string(), refs: array(string()), discussions: array(commentSchema), - reviews: array(tuple([string(), reviewSchema])), + reviews: array(reviewSchema), merges: array(mergeSchema), timestamp: number(), }) satisfies ZodSchema; @@ -142,6 +143,7 @@ export type PatchUpdateAction = | { type: "redact"; revision: string } | { type: "review"; + author: { id: string; alias?: string }; revision: string; verdict?: Verdict; comment?: string; diff --git a/src/components/Authorship.svelte b/src/components/Authorship.svelte index 9421819e9..197e51e0c 100644 --- a/src/components/Authorship.svelte +++ b/src/components/Authorship.svelte @@ -4,6 +4,12 @@ export let authorId: string; export let authorAlias: string | undefined = undefined; + export let authorAliasColor: + | "--color-primary-5" + | "--color-foreground-5" + | "--color-positive-5" + | "--color-negative-5" + | undefined = "--color-foreground-5"; export let caption: string | undefined = undefined; export let noAvatar: boolean = false; export let timestamp: number | undefined = undefined; @@ -28,9 +34,6 @@ .body { white-space: nowrap; } - .alias { - color: var(--color-foreground-5); - } @@ -40,13 +43,13 @@ {formatNodeId(authorId)} {#if authorAlias} - ({authorAlias}) + ({authorAlias}) {/if} {formatNodeId(authorId).replace("did:key:", "")} {#if authorAlias} - ({authorAlias}) + ({authorAlias}) {/if} {#if !caption} diff --git a/src/views/projects/Cob/Revision.svelte b/src/views/projects/Cob/Revision.svelte index 9e45965fa..2ca46e523 100644 --- a/src/views/projects/Cob/Revision.svelte +++ b/src/views/projects/Cob/Revision.svelte @@ -21,6 +21,7 @@ import ThreadComponent from "@app/components/Thread.svelte"; export let authorId: string; + export let authorAlias: string | undefined = undefined; export let baseUrl: BaseUrl; export let expanded: boolean = true; export let patchId: string; @@ -48,6 +49,17 @@ } } + function aliasColorForVerdict(verdict?: string | null) { + switch (verdict) { + case "accept": + return "--color-positive-5"; + case "reject": + return "--color-negative-5"; + default: + return "--color-foreground-5"; + } + } + let response: DiffResponse | undefined = undefined; let error: any | undefined = undefined; @@ -228,13 +240,17 @@ {:else}
- + {caption}
@@ -275,8 +291,10 @@ class="action-padding action-background merge layout-desktop txt-tiny">
+ authorId={element.inner.author.id} + authorAlias={element.inner.author.alias} + timestamp={element.timestamp} + authorAliasColor="--color-primary-5"> merged {utils.formatCommit(element.inner.commit)} @@ -285,7 +303,10 @@
- + merged {utils.formatCommit(element.inner.commit)} @@ -301,6 +322,7 @@ @@ -311,7 +333,11 @@ class:positive-review={element.inner[2].verdict === "accept"} class:negative-review={element.inner[2].verdict === "reject"}>
- + {formatVerdict(revisionId, review.verdict)}
@@ -321,7 +347,10 @@ class:positive-review={element.inner[2].verdict === "accept"} class:negative-review={element.inner[2].verdict === "reject"}>
- + {formatVerdict(revisionId, review.verdict)}
diff --git a/src/views/projects/Patch.svelte b/src/views/projects/Patch.svelte index 1c04942c6..f2cd8d1d7 100644 --- a/src/views/projects/Patch.svelte +++ b/src/views/projects/Patch.svelte @@ -153,10 +153,10 @@ revisionOid: rev.oid, }, [ - ...rev.reviews.map(([author, review]) => ({ + ...rev.reviews.map(review => ({ timestamp: review.timestamp, type: "review", - inner: [rev.id, author, review], + inner: [rev.id, review.author.id, review], })), ...rev.merges.map(inner => ({ timestamp: inner.timestamp, @@ -279,7 +279,9 @@ {/if}
- opened by + opened by {utils.formatTimestamp(patch.revisions[0].timestamp)}
@@ -379,6 +381,7 @@ on:reply={createReply} patchId={patch.id} authorId={patch.author.id} + authorAlias={patch.author.alias} expanded={index === patch.revisions.length - 1} previousRevId={previousRevision?.id} previousRevOid={previousRevision?.oid} />