diff --git a/httpd-client/index.ts b/httpd-client/index.ts index 91ac98b45..6a4f561af 100644 --- a/httpd-client/index.ts +++ b/httpd-client/index.ts @@ -17,9 +17,12 @@ import type { } from "./lib/project/commit.js"; import type { Issue, IssueState } from "./lib/project/issue.js"; import type { + CodeLocation, + LifecycleState, Merge, Patch, PatchState, + Range, Review, Revision, } from "./lib/project/patch.js"; @@ -35,6 +38,7 @@ import { Fetcher } from "./lib/fetcher.js"; export type { BaseUrl, Blob, + CodeLocation, Comment, Commit, CommitHeader, @@ -45,10 +49,12 @@ export type { HunkLine, Issue, IssueState, + LifecycleState, Merge, Patch, PatchState, Project, + Range, Remote, Review, Revision, diff --git a/httpd-client/lib/project.ts b/httpd-client/lib/project.ts index 840f6f50f..563c4f564 100644 --- a/httpd-client/lib/project.ts +++ b/httpd-client/lib/project.ts @@ -407,7 +407,7 @@ export class Client { title: string; description: string; assignees: string[]; - tags: string[]; + labels: string[]; }, authToken: string, options?: RequestOptions, diff --git a/httpd-client/lib/project/comment.ts b/httpd-client/lib/project/comment.ts index cea926e28..078cbc202 100644 --- a/httpd-client/lib/project/comment.ts +++ b/httpd-client/lib/project/comment.ts @@ -1,17 +1,6 @@ import type { ZodSchema } from "zod"; import { array, number, object, string, tuple } from "zod"; -export type ThreadUpdateAction = - | { type: "comment"; body: string; replyTo?: string } - | { type: "edit"; id: string; body: string } - | { type: "redact"; id: string } - | { - type: "react"; - to: string; - reaction: { emoji: string }; - active: boolean; - }; - export interface Comment { id: string; author: { id: string; alias?: string }; diff --git a/httpd-client/lib/project/issue.ts b/httpd-client/lib/project/issue.ts index a0cf42a77..1b49a7d6f 100644 --- a/httpd-client/lib/project/issue.ts +++ b/httpd-client/lib/project/issue.ts @@ -1,4 +1,4 @@ -import type { Comment, ThreadUpdateAction } from "./comment.js"; +import type { Comment } from "./comment.js"; import type { ZodSchema } from "zod"; import { array, boolean, literal, object, string, union } from "zod"; @@ -22,7 +22,7 @@ export interface Issue { title: string; state: IssueState; discussion: Comment[]; - tags: string[]; + labels: string[]; assignees: string[]; } @@ -32,7 +32,7 @@ export const issueSchema = object({ title: string(), state: issueStateSchema, discussion: array(commentSchema), - tags: array(string()), + labels: array(string()), assignees: array(string()), }) satisfies ZodSchema; @@ -49,12 +49,19 @@ export const issueCreatedSchema = object({ export const issuesSchema = array(issueSchema) satisfies ZodSchema; export type IssueUpdateAction = + | { type: "edit"; title: string } + | { type: "label"; labels: string[] } | { type: "assign"; - add: string[]; - remove: string[]; + assignees: string[]; } - | { type: "edit"; title: string } | { type: "lifecycle"; state: IssueState } - | { type: "tag"; add: string[]; remove: string[] } - | { type: "thread"; action: ThreadUpdateAction }; + | { type: "comment"; body: string; replyTo: string } + | { type: "comment.edit"; id: string; body: string } + | { type: "comment.redact"; id: string } + | { + type: "comment.react"; + id: string; + reaction: string; + active: boolean; + }; diff --git a/httpd-client/lib/project/patch.ts b/httpd-client/lib/project/patch.ts index e3bbe4a45..d40a995bf 100644 --- a/httpd-client/lib/project/patch.ts +++ b/httpd-client/lib/project/patch.ts @@ -1,4 +1,4 @@ -import type { Comment, ThreadUpdateAction } from "./comment.js"; +import type { Comment } from "./comment.js"; import type { ZodSchema, z } from "zod"; import { commentSchema } from "./comment.js"; @@ -101,9 +101,9 @@ export interface Patch { title: string; state: PatchState; target: string; - tags: string[]; + labels: string[]; merges: Merge[]; - reviewers: string[]; + assignees: string[]; revisions: Revision[]; } @@ -113,37 +113,108 @@ export const patchSchema = object({ title: string(), state: patchStateSchema, target: string(), - tags: array(string()), + labels: array(string()), merges: array(mergeSchema), - reviewers: array(string()), + assignees: array(string()), revisions: array(revisionSchema), }) satisfies ZodSchema; export const patchesSchema = array(patchSchema) satisfies ZodSchema; +export type LifecycleState = + | { status: "draft" } + | { status: "open" } + | { status: "archived" }; + +export type Range = + | { + type: "lines"; + range: { start: number; end: number }; + } + | { + type: "chars"; + line: number; + range: { start: number; end: number }; + }; + +export type CodeLocation = { + path: string; + old?: Range; + new?: Range; +}; + export type PatchUpdateAction = - | { type: "edit"; title: string; target: string } - | { type: "editRevision"; revision: string; description: string } - | { type: "editReview"; review: string; summary?: string } - | { type: "tag"; add: string[]; remove: string[] } - | { type: "revision"; description: string; base: string; oid: string } - | { type: "lifecycle"; state: PatchState } - | { type: "redact"; revision: string } + | { type: "edit"; title: string; target: "delegates" } + | { type: "label"; labels: string[] } + | { type: "assign"; assignees: string[] } + | { type: "merge"; revision: string; commit: string } + | { type: "lifecycle"; state: LifecycleState } | { type: "review"; revision: string; summary?: string; verdict?: Verdict | null; } - | { type: "merge"; revision: string; commit: string } - | { type: "thread"; revision: string; action: ThreadUpdateAction }; + | { type: "review.edit"; review: string; summary?: string } + | { type: "review.redact"; review: string } + | { + type: "review.comment"; + review: string; + body: string; + location: CodeLocation; + } + | { + type: "review.comment.edit"; + review: string; + comment: string; + body: string; + } + | { + type: "review.comment.redact"; + review: string; + comment: string; + } + | { + type: "review.comment.react"; + review: string; + comment: string; + reaction: string; + active: boolean; + } + | { type: "revision"; description: string; base: string; oid: string } + | { type: "revision.edit"; revision: string; description: string } + | { type: "revision.redact"; revision: string } + | { + type: "revision.comment"; + revision: string; + body: string; + replyTo: string; + } + | { + type: "revision.comment.edit"; + revision: string; + comment: string; + body: string; + } + | { + type: "revision.comment.redact"; + revision: string; + comment: string; + } + | { + type: "revision.comment.react"; + revision: string; + comment: string; + reaction: string; + active: boolean; + }; export const patchCreateSchema = object({ title: string(), description: string(), target: string(), oid: string(), - tags: array(string()), + labels: array(string()), }); export type PatchCreate = z.infer; diff --git a/httpd-client/tests/project.test.ts b/httpd-client/tests/project.test.ts index c540df5bd..9cba55c04 100644 --- a/httpd-client/tests/project.test.ts +++ b/httpd-client/tests/project.test.ts @@ -98,7 +98,7 @@ describe("project", () => { test("#getIssueById(id, issueId)", async () => { await api.project.getIssueById( cobRid, - "4fc727e722d3979fd2073d9b56b2751658a4ae79", + "9cedac832f0791bea5c9cf8fa32db8a68c592166", ); }); @@ -111,7 +111,7 @@ describe("project", () => { }); testWithAPI( - "#createIssue(id, { title, description, assignees, tags })", + "#createIssue(id, { title, description, assignees, labels })", async ({ httpd: { api, peer } }) => { const sessionId = await authenticate(api, peer); const { id: issueId } = await api.project.createIssue( @@ -120,7 +120,7 @@ describe("project", () => { title: "aaa", description: "bbb", assignees: [], - tags: ["bug", "documentation"], + labels: ["bug", "documentation"], }, sessionId, ); @@ -130,7 +130,7 @@ describe("project", () => { title: "aaa", discussion: [{ body: "bbb" }], assignees: [], - tags: ["bug", "documentation"], + labels: ["bug", "documentation"], }, api, ); @@ -153,17 +153,17 @@ describe("project", () => { ); testWithAPI( - "#updateIssue(id, issueId, { type: 'tag' }, authToken)", + "#updateIssue(id, issueId, { type: 'label' }, authToken)", async ({ httpd: { api, peer } }) => { const sessionId = await authenticate(api, peer); const issueId = await createIssueToBeModified(api, sessionId); await api.project.updateIssue( cobRid, issueId, - { type: "tag", add: ["bug"], remove: [] }, + { type: "label", labels: ["bug"] }, sessionId, ); - await assertIssue(issueId, { tags: ["bug"] }, api); + await assertIssue(issueId, { labels: ["bug"] }, api); }, ); @@ -172,18 +172,16 @@ describe("project", () => { async ({ httpd: { api, peer } }) => { const sessionId = await authenticate(api, peer); const issueId = await createIssueToBeModified(api, sessionId); - const assignee = bobRemote.replace("did:key:", ""); await api.project.updateIssue( cobRid, issueId, { type: "assign", - add: [assignee], - remove: [], + assignees: [bobRemote], }, sessionId, ); - await assertIssue(issueId, { assignees: [`did:key:${assignee}`] }, api); + await assertIssue(issueId, { assignees: [bobRemote] }, api); }, ); @@ -211,7 +209,7 @@ describe("project", () => { test("#getPatchById(id, patchId)", async () => { await api.project.getPatchById( cobRid, - "013f8b2734df1840b2e33d52ff5632c8d66b199a", + "687c3268119d23c5da32055c0b44c03e0e4088b8", ); }); @@ -230,7 +228,7 @@ describe("project", () => { description: "qqq", target: "d7dd8cecae16b1108234e09dbdb5d64ae394bc25", oid: "38c225e2a0b47ba59def211f4e4825c31d9463ec", - tags: [], + labels: [], }, sessionId, ); @@ -240,7 +238,7 @@ describe("project", () => { title: "ppp", state: { status: "open" }, target: "delegates", - tags: [], + labels: [], revisions: [ { description: "qqq", @@ -262,13 +260,13 @@ describe("project", () => { await api.project.updatePatch( cobRid, patchId, - { type: "tag", add: ["bug"], remove: [] }, + { type: "label", labels: ["bug"] }, sessionId, ); await assertPatch( patchId, { - tags: ["bug"], + labels: ["bug"], }, api, ); diff --git a/httpd-client/tests/support/support.ts b/httpd-client/tests/support/support.ts index dbb87e89e..fca619636 100644 --- a/httpd-client/tests/support/support.ts +++ b/httpd-client/tests/support/support.ts @@ -11,7 +11,7 @@ export async function createIssueToBeModified( ) { const { id } = await api.project.createIssue( cobRid, - { title: "aaa", description: "bbb", assignees: [], tags: [] }, + { title: "aaa", description: "bbb", assignees: [], labels: [] }, sessionId, ); @@ -29,7 +29,7 @@ export async function createPatchToBeModified( description: "ttt", target: "d7dd8cecae16b1108234e09dbdb5d64ae394bc25", oid: "38c225e2a0b47ba59def211f4e4825c31d9463ec", - tags: [], + labels: [], }, sessionId, ); diff --git a/src/config.json b/src/config.json index 97893ad98..59bffd95d 100644 --- a/src/config.json +++ b/src/config.json @@ -1,5 +1,4 @@ { - "reactions": ["👍", "👎", "😄", "🎉", "🙁", "🚀", "👀"], "nodes": { "defaultHttpdPort": 443, "defaultLocalHttpdPort": 8080, diff --git a/src/lib/config.ts b/src/lib/config.ts index 110d5fb81..d2815317c 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -3,7 +3,6 @@ import type { BaseUrl } from "@httpd-client"; import configJson from "@app/config.json"; export interface Config { - reactions: string[]; nodes: { defaultHttpdPort: number; defaultLocalHttpdPort: number; @@ -23,7 +22,6 @@ export interface Config { function getConfig(): Config { if (window.VITEST) { return { - reactions: [], nodes: { defaultHttpdPort: 8081, defaultLocalHttpdPort: 8081, diff --git a/src/lib/utils.ts b/src/lib/utils.ts index f7b8eb888..e7e42443f 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -243,21 +243,7 @@ export function twemoji( }); } -export function createAddRemoveArrays( - currentArray: string[], - newArray: string[], -): { add: string[]; remove: string[] } { - return { - add: newArray.filter(item => !currentArray.includes(item)), - remove: currentArray.filter(item => !newArray.includes(item)), - }; -} - // Formats COBs Object Ids export function formatObjectId(id: string): string { return id.substring(0, 7); } - -export function stripDidPrefix(array: string[]): string[] { - return array.map(id => id.replace("did:key:", "")); -} diff --git a/src/views/projects/Cob/AssigneeInput.svelte b/src/views/projects/Cob/AssigneeInput.svelte index 50dd64750..e272be4e4 100644 --- a/src/views/projects/Cob/AssigneeInput.svelte +++ b/src/views/projects/Cob/AssigneeInput.svelte @@ -22,10 +22,11 @@ function addAssignee() { if (parsedNodeId) { - if (updatedAssignees.includes(parsedNodeId.pubkey)) { + const assignee = `${parsedNodeId.prefix}${parsedNodeId.pubkey}`; + if (updatedAssignees.includes(assignee)) { validationMessage = "This assignee is already added"; } else { - updatedAssignees = [...updatedAssignees, parsedNodeId.pubkey]; + updatedAssignees = [...updatedAssignees, assignee]; inputValue = ""; if (action === "create") { dispatch("save", updatedAssignees); diff --git a/src/views/projects/Cob/TagInput.svelte b/src/views/projects/Cob/LabelInput.svelte similarity index 71% rename from src/views/projects/Cob/TagInput.svelte rename to src/views/projects/Cob/LabelInput.svelte index 8e018bbcd..dd63515a3 100644 --- a/src/views/projects/Cob/TagInput.svelte +++ b/src/views/projects/Cob/LabelInput.svelte @@ -9,34 +9,34 @@ export let action: "create" | "edit" | "view" = "view"; export let editInProgress: boolean = false; - export let tags: string[] = []; + export let labels: string[] = []; - let updatedTags: string[] = tags; + let updatedLabels: string[] = labels; let inputValue = ""; let validationMessage: string | undefined = undefined; $: sanitizedValue = inputValue.trim(); - function addTag() { + function addLabel() { if (sanitizedValue.length > 0) { - if (updatedTags.includes(sanitizedValue)) { - validationMessage = "This tag is already added"; + if (updatedLabels.includes(sanitizedValue)) { + validationMessage = "This label is already added"; } else { - updatedTags = [...updatedTags, sanitizedValue]; + updatedLabels = [...updatedLabels, sanitizedValue]; inputValue = ""; if (action === "create") { - dispatch("save", updatedTags); + dispatch("save", updatedLabels); } } } else { - validationMessage = "This tag is not valid"; + validationMessage = "This label is not valid"; } } - function removeTag({ detail: key }: { detail: number }) { - updatedTags = updatedTags.filter((_, i) => i !== key); + function removeLabel({ detail: key }: { detail: number }) { + updatedLabels = updatedLabels.filter((_, i) => i !== key); if (action === "create") { - dispatch("save", updatedTags); + dispatch("save", updatedLabels); } } @@ -57,7 +57,7 @@ gap: 0.5rem; margin-bottom: 1.25rem; } - .tag { + .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; @@ -66,14 +66,14 @@
{#if editInProgress || action === "create"} @@ -107,10 +107,10 @@ 0} - placeholder="Add tag" + placeholder="Add label" variant="form" {validationMessage} - on:submit={addTag} + on:submit={addLabel} on:input={() => (validationMessage = undefined)} />
{/if} diff --git a/src/views/projects/Issue.svelte b/src/views/projects/Issue.svelte index 7735c6ce7..6e2a1fb38 100644 --- a/src/views/projects/Issue.svelte +++ b/src/views/projects/Issue.svelte @@ -21,7 +21,7 @@ import ErrorModal from "@app/views/projects/Cob/ErrorModal.svelte"; import Icon from "@app/components/Icon.svelte"; import Markdown from "@app/components/Markdown.svelte"; - import TagInput from "./Cob/TagInput.svelte"; + import LabelInput from "./Cob/LabelInput.svelte"; import Textarea from "@app/components/Textarea.svelte"; import ThreadComponent from "@app/components/Thread.svelte"; @@ -56,8 +56,9 @@ project.id, issue.id, { - type: "thread", - action: { type: "comment", body: reply.body, replyTo: reply.id }, + type: "comment", + body: reply.body, + replyTo: reply.id, }, $httpdStore.session, api, @@ -73,7 +74,7 @@ const status = await updateIssue( project.id, issue.id, - { type: "thread", action: { type: "comment", body } }, + { type: "comment", body, replyTo: issue.id }, $httpdStore.session, api, ); @@ -106,19 +107,17 @@ } } - async function saveTags({ detail: tags }: CustomEvent) { + async function saveLabels({ detail: labels }: CustomEvent) { if ($httpdStore.state === "authenticated") { - const { add, remove } = utils.createAddRemoveArrays(issue.tags, tags); - if (add.length === 0 && remove.length === 0) { + if (isEqual(issue.labels, labels)) { return; } const status = await updateIssue( project.id, issue.id, { - type: "tag", - add, - remove, + type: "label", + labels: labels, }, $httpdStore.session, api, @@ -131,11 +130,7 @@ async function saveAssignees({ detail: assignees }: CustomEvent) { if ($httpdStore.state === "authenticated") { - const { add, remove } = utils.createAddRemoveArrays( - issue.assignees, - assignees, - ); - if (add.length === 0 && remove.length === 0) { + if (isEqual(issue.assignees, assignees)) { return; } const status = await updateIssue( @@ -143,8 +138,7 @@ issue.id, { type: "assign", - add: utils.stripDidPrefix(add), - remove: utils.stripDidPrefix(remove), + assignees: assignees, }, $httpdStore.session, api, @@ -405,6 +399,6 @@ {action} assignees={issue.assignees} on:save={saveAssignees} /> - + diff --git a/src/views/projects/Issue/IssueTeaser.svelte b/src/views/projects/Issue/IssueTeaser.svelte index 7c1e2aef8..01d73d9a7 100644 --- a/src/views/projects/Issue/IssueTeaser.svelte +++ b/src/views/projects/Issue/IssueTeaser.svelte @@ -60,12 +60,12 @@ gap: 0.5rem; color: var(--color-foreground-5); } - .tags { + .labels { display: flex; flex-direction: row; gap: 0.5rem; } - .tag { + .label { overflow: hidden; text-overflow: ellipsis; } @@ -88,7 +88,7 @@ } @media (max-width: 960px) { - .tags { + .labels { display: none; } } @@ -114,15 +114,15 @@ - - {#each issue.tags.slice(0, 4) as tag} + + {#each issue.labels.slice(0, 4) as label} - {tag} + {label} {/each} - {#if issue.tags.length > 4} + {#if issue.labels.length > 4} - +{issue.tags.length - 4} more tags + +{issue.labels.length - 4} more labels {/if} diff --git a/src/views/projects/Issue/New.svelte b/src/views/projects/Issue/New.svelte index 5acd66559..07c80ce63 100644 --- a/src/views/projects/Issue/New.svelte +++ b/src/views/projects/Issue/New.svelte @@ -14,7 +14,7 @@ import Button from "@app/components/Button.svelte"; import CobHeader from "@app/views/projects/Cob/CobHeader.svelte"; import Markdown from "@app/components/Markdown.svelte"; - import TagInput from "@app/views/projects/Cob/TagInput.svelte"; + import LabelInput from "@app/views/projects/Cob/LabelInput.svelte"; import Textarea from "@app/components/Textarea.svelte"; import ErrorMessage from "@app/components/ErrorMessage.svelte"; @@ -33,7 +33,7 @@ let issueTitle = ""; let issueText: string | undefined = undefined; let assignees: string[] = []; - let tags: string[] = []; + let labels: string[] = []; const api = new HttpdClient(baseUrl); @@ -44,8 +44,8 @@ { title: issueTitle, description: issueText ?? "", - assignees: utils.stripDidPrefix(assignees), - tags: tags, + assignees: assignees, + labels: labels, }, sessionId, ); @@ -174,7 +174,7 @@ {/if}