From aa62ef0bc11c72149508b6a866a650f54c0d9d67 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 3 Jun 2022 16:42:47 +0200 Subject: [PATCH] Add issue listing and detail view Signed-off-by: Sebastian Martinez --- cypress/fixtures/projectIssues.json | 1 + cypress/integration/project.spec.ts | 3 +- public/index.css | 16 +- src/ReactionSelector.svelte | 66 +++++++ src/base/projects/Commit.svelte | 7 +- src/base/projects/Commit/CommitTeaser.svelte | 2 +- src/base/projects/Header.svelte | 18 +- src/base/projects/History.svelte | 4 +- src/base/projects/Issue.svelte | 177 ++++++++++++++++++ .../projects/Issue/IssueAuthorship.svelte | 47 +++++ src/base/projects/Issue/IssueComment.svelte | 87 +++++++++ src/base/projects/Issue/IssueFilter.svelte | 71 +++++++ src/base/projects/Issue/IssueTeaser.svelte | 125 +++++++++++++ src/base/projects/Issue/Reactions.svelte | 27 +++ src/base/projects/Issues.svelte | 61 ++++++ src/base/projects/Project.svelte | 8 + src/base/projects/ProjectRoute.svelte | 3 + .../projects/SourceBrowser/Changeset.svelte | 14 +- src/base/projects/View.svelte | 7 + src/issue.ts | 86 +++++++++ src/project.ts | 35 +++- src/utils.ts | 8 + 22 files changed, 850 insertions(+), 23 deletions(-) create mode 100644 cypress/fixtures/projectIssues.json create mode 100644 src/ReactionSelector.svelte create mode 100644 src/base/projects/Issue.svelte create mode 100644 src/base/projects/Issue/IssueAuthorship.svelte create mode 100644 src/base/projects/Issue/IssueComment.svelte create mode 100644 src/base/projects/Issue/IssueFilter.svelte create mode 100644 src/base/projects/Issue/IssueTeaser.svelte create mode 100644 src/base/projects/Issue/Reactions.svelte create mode 100644 src/base/projects/Issues.svelte create mode 100644 src/issue.ts diff --git a/cypress/fixtures/projectIssues.json b/cypress/fixtures/projectIssues.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/cypress/fixtures/projectIssues.json @@ -0,0 +1 @@ +[] diff --git a/cypress/integration/project.spec.ts b/cypress/integration/project.spec.ts index c384a32d4..4571e7b92 100644 --- a/cypress/integration/project.spec.ts +++ b/cypress/integration/project.spec.ts @@ -58,6 +58,7 @@ describe("Project view", () => { cy.intercept("https://willow.radicle.garden:8777/v1/projects/bright-forest-protocol", { fixture: "projectInfo.json" }); cy.intercept("https://willow.radicle.garden:8777/v1/projects/rad:git:hnrk8mbpirp7ua7sy66o4t9soasbq4y8uwgoy", { fixture: "projectInfo.json" }); cy.intercept("https://willow.radicle.garden:8777/v1/projects/rad:git:hnrk8mbpirp7ua7sy66o4t9soasbq4y8uwgoy/remotes", { fixture: "projectRemotes.json" }); + cy.intercept("https://willow.radicle.garden:8777/v1/projects/rad:git:hnrk8mbpirp7ua7sy66o4t9soasbq4y8uwgoy/issues", { fixture: "projectIssues.json" }); cy.intercept("https://willow.radicle.garden:8777/v1/projects/rad:git:hnrk8mbpirp7ua7sy66o4t9soasbq4y8uwgoy/tree/56e4e029c294b08546386e1fb706b772c7433c49", { fixture: "projectTree56e4e02.json" }); cy.intercept("https://willow.radicle.garden:8777/v1/projects/rad:git:hnrk8mbpirp7ua7sy66o4t9soasbq4y8uwgoy/tree/cbf5df499ab4f4a908f1756fbe2c236a4530516a", { fixture: "projectTreecbf5df4.json" }); cy.intercept("https://willow.radicle.garden:8777/v1/projects/rad:git:hnrk8mbpirp7ua7sy66o4t9soasbq4y8uwgoy/remotes/hyndc7nx9keq76p1bkw9831arcndeeu3trwsc7kxt3osmpi6j9oeke", { fixture: "projectBranches.json" }); @@ -150,7 +151,7 @@ describe("Project view", () => { cy.location().should((location) => { expect(location.pathname).to.eq('/seeds/willow.radicle.garden/rad:git:hnrk8mbpirp7ua7sy66o4t9soasbq4y8uwgoy/remotes/hyndc7nx9keq76p1bkw9831arcndeeu3trwsc7kxt3osmpi6j9oeke/commits/cbf5df499ab4f4a908f1756fbe2c236a4530516a'); }); - cy.get("header .summary h3").should("have.text", "initial commit"); + cy.get("header .summary .text-medium").should("have.text", "initial commit"); cy.get("header pre.description").should("have.text", "this is the first commit of many"); cy.get("header .committer").should("have.text", "dabit3"); cy.get("div.changeset-summary").should("have.text", "1 file(s) changed\n with\n 0 addition(s)\n and\n 0 deletion(s)"); diff --git a/public/index.css b/public/index.css index e0d39812e..159bc0c7f 100644 --- a/public/index.css +++ b/public/index.css @@ -48,8 +48,9 @@ --color-negative-2: #623237; --color-negative-6: #ffd4d4; --color-foreground: #ffffff; - --color-foreground-90: #dddddd; - --color-foreground-80: #aaaaaa; + --color-foreground-90: #ddddee; + --color-foreground-80: #aaaab6; + --color-foreground-70: #9999aa; --color-foreground-faded: #777788; --color-foreground-subtle: #444455; --color-foreground-subtler: #333344; @@ -74,6 +75,7 @@ --font-weight-medium: 600; --font-weight-bold: 700; --border-radius: 50px; + --border-radius-medium: 0.25rem; --box-shadow-color: var(--color-secondary-2); --content-max-width: 1920px; --content-min-width: 480px; @@ -170,7 +172,7 @@ button { min-width: 8rem; } button:not([disabled]):hover { - color: var(--color-background) !important; + color: var(--color-background); background-color: var(--color-foreground); } button.waiting { @@ -212,6 +214,14 @@ button[disabled] { button[data-waiting] { cursor: wait !important; } +button.unstyled, button.unstyled:hover, button.unstyled:focus { + padding: 0; + margin: 0; + min-width: 0; + border: none; + color: var(--color-foreground); + background: transparent; +} button.text { color: var(--color-foreground-6); diff --git a/src/ReactionSelector.svelte b/src/ReactionSelector.svelte new file mode 100644 index 000000000..90c8ed6cc --- /dev/null +++ b/src/ReactionSelector.svelte @@ -0,0 +1,66 @@ + + + + + +
+ + {#if showReactions} + + {/if} +
diff --git a/src/base/projects/Commit.svelte b/src/base/projects/Commit.svelte index f7980852d..fd75d3f77 100644 --- a/src/base/projects/Commit.svelte +++ b/src/base/projects/Commit.svelte @@ -21,13 +21,10 @@ .commit { padding: 0 2rem 0 8rem; } - h3 { - margin: 0; - } header { padding: 1rem; background: var(--color-foreground-background-subtle); - border-radius: 0.5rem; + border-radius: var(--border-radius-medium); } .summary { display: flex; @@ -62,7 +59,7 @@
-

{commit.header.summary}

+
{commit.header.summary}
{commit.header.sha1}
diff --git a/src/base/projects/Commit/CommitTeaser.svelte b/src/base/projects/Commit/CommitTeaser.svelte index d6ba42e0c..f403316f2 100644 --- a/src/base/projects/Commit/CommitTeaser.svelte +++ b/src/base/projects/Commit/CommitTeaser.svelte @@ -23,7 +23,7 @@ } .commit-teaser { background-color: var(--color-foreground-background); - padding: 0.5rem 0rem; + padding: 0.75rem 0rem; } .commit-teaser:hover { background-color: var(--color-foreground-background-lighter); diff --git a/src/base/projects/Header.svelte b/src/base/projects/Header.svelte index 6cbe4f899..08964281e 100644 --- a/src/base/projects/Header.svelte +++ b/src/base/projects/Header.svelte @@ -8,6 +8,7 @@ import PeerSelector from '@app/base/projects/PeerSelector.svelte'; import type { Tree } from "@app/project"; import Input from "@app/Input.svelte"; + import { groupIssues, Issue } from '@app/issue'; export let project: Project; export let tree: Tree; @@ -31,7 +32,17 @@ // Switches between the browser and commit view. const toggleContent = (input: ProjectContent) => { project.navigateTo({ - content: content === input ? ProjectContent.Tree : input + content: content === input ? ProjectContent.Tree : input, + issue: null // Removing issue here from browserStore to not contaminate path on navigation. + }); + }; + + const toggleIssues = () => { + project.navigateTo({ + content: content !== ProjectContent.Issues ? ProjectContent.Issues : ProjectContent.Tree, + revision: null, + issue: null, + path: null, }); }; @@ -186,6 +197,11 @@
toggleContent(ProjectContent.History)}> {tree.stats.commits} commit(s)
+ {#await Issue.getIssues(project.urn, seed.api) then issues} +
+ {groupIssues(issues).open.length} issue(s) +
+ {/await}
{tree.stats.contributors} contributor(s)
diff --git a/src/base/projects/History.svelte b/src/base/projects/History.svelte index 95fa7ae07..293a9bea6 100644 --- a/src/base/projects/History.svelte +++ b/src/base/projects/History.svelte @@ -9,11 +9,11 @@ export let commit: string; const navigateHistory = (revision: string, content?: ProjectContent) => { - project.navigateTo({ content, revision, path: null }); + project.navigateTo({ content, revision, issue: null, path: null }); }; const browseCommit = (event: { detail: string }) => { - project.navigateTo({ content: ProjectContent.Tree, revision: event.detail, path: null }); + project.navigateTo({ content: ProjectContent.Tree, revision: event.detail, issue: null, path: null }); }; const fetchCommits = async (parentCommit: string): Promise => { diff --git a/src/base/projects/Issue.svelte b/src/base/projects/Issue.svelte new file mode 100644 index 000000000..7aaff86a6 --- /dev/null +++ b/src/base/projects/Issue.svelte @@ -0,0 +1,177 @@ + + + + +{#await Issue.getIssue(project.urn, issue, project.seed.api)} + +{:then issue} + {@const state = issue.state === "open" ? "open" : "closed"} +
+
+
+
+ + {issue.title} + + {issue.id} +
+
+ {capitalize(state)} +
+
+
+ {issue.author.name} + opened on + + {formatTimestamp(issue.timestamp)} + +
+
+
+
+ + {#each issue.discussion as comment} + + {#if comment.replies} +
+ {#each comment.replies as reply} + + {/each} +
+ {/if} + {/each} +
+ +
+
+{/await} diff --git a/src/base/projects/Issue/IssueAuthorship.svelte b/src/base/projects/Issue/IssueAuthorship.svelte new file mode 100644 index 000000000..7c3e358f6 --- /dev/null +++ b/src/base/projects/Issue/IssueAuthorship.svelte @@ -0,0 +1,47 @@ + + + + + + {#if profile} +
+ {:else} + + {author.name} + + {/if} +  {caption}  + + {formatTimestamp(timestamp)} + + diff --git a/src/base/projects/Issue/IssueComment.svelte b/src/base/projects/Issue/IssueComment.svelte new file mode 100644 index 000000000..6eecf57f5 --- /dev/null +++ b/src/base/projects/Issue/IssueComment.svelte @@ -0,0 +1,87 @@ + + + + +
+
+ +
+
+
+ + +
+
+ + {#if comment.reactions.length > 0} +
+ +
+ {/if} +
+
+
diff --git a/src/base/projects/Issue/IssueFilter.svelte b/src/base/projects/Issue/IssueFilter.svelte new file mode 100644 index 000000000..cbfd4097b --- /dev/null +++ b/src/base/projects/Issue/IssueFilter.svelte @@ -0,0 +1,71 @@ + + + + +
+ + · + +
+ +{#if filteredIssues.length} + +{:else} +
No results matched your search.
+{/if} diff --git a/src/base/projects/Issue/IssueTeaser.svelte b/src/base/projects/Issue/IssueTeaser.svelte new file mode 100644 index 000000000..66392d9c2 --- /dev/null +++ b/src/base/projects/Issue/IssueTeaser.svelte @@ -0,0 +1,125 @@ + + + + +
+
+
+
+
+
+ + {issue.title} + {formatIssueId(issue.id)} +
+ +
+ {#if commentCount > 0} +
+
+ 💬 + {commentCount} +
+
+ {/if} +
diff --git a/src/base/projects/Issue/Reactions.svelte b/src/base/projects/Issue/Reactions.svelte new file mode 100644 index 000000000..5e090f46a --- /dev/null +++ b/src/base/projects/Issue/Reactions.svelte @@ -0,0 +1,27 @@ + + + + +{#if reactions} +
+ {#each Object.entries(reactions) as [reaction, count]} + + + {/each} +
+{/if} diff --git a/src/base/projects/Issues.svelte b/src/base/projects/Issues.svelte new file mode 100644 index 000000000..ffa9c8583 --- /dev/null +++ b/src/base/projects/Issues.svelte @@ -0,0 +1,61 @@ + + + + +
+ {#await Issue.getIssues(project.urn, project.seed.api) then issues} + +
+ {#each filteredIssues as issue} +
navigate(issue.id)}> + +
+ {/each} +
+
+ {/await} +
diff --git a/src/base/projects/Project.svelte b/src/base/projects/Project.svelte index 037823807..3952761d0 100644 --- a/src/base/projects/Project.svelte +++ b/src/base/projects/Project.svelte @@ -10,6 +10,8 @@ import Browser from "./Browser.svelte"; import Commit from "./Commit.svelte"; import History from "./History.svelte"; + import Issues from './Issues.svelte'; + import Issue from './Issue.svelte'; import ProjectMeta from './ProjectMeta.svelte'; export let peer: string | null = null; @@ -75,6 +77,12 @@
{/await} + + {#if content == proj.ProjectContent.Issues} + + {:else if content == proj.ProjectContent.Issue && $browserStore.issue} + + {/if} {:else}
{#if peer} diff --git a/src/base/projects/ProjectRoute.svelte b/src/base/projects/ProjectRoute.svelte index aaf9b3b37..8e9808c20 100644 --- a/src/base/projects/ProjectRoute.svelte +++ b/src/base/projects/ProjectRoute.svelte @@ -9,6 +9,7 @@ export let browserStore: Writable = proj.browserStore; export let route: string | null = null; export let revision: string | null = null; + export let issue: string | null = null; export let peer: string | null; export let content: proj.ProjectContent = proj.ProjectContent.Tree; export let project: proj.Project; @@ -29,6 +30,8 @@ if (revision) browse.revision = revision; } else if (revision) { browse.revision = revision; + } else if (issue) { + browse.issue = issue; } else if (head) { browse.revision = head; } else { diff --git a/src/base/projects/SourceBrowser/Changeset.svelte b/src/base/projects/SourceBrowser/Changeset.svelte index ed0a81721..997b60162 100644 --- a/src/base/projects/SourceBrowser/Changeset.svelte +++ b/src/base/projects/SourceBrowser/Changeset.svelte @@ -24,7 +24,7 @@ } .file-header { border: 1px solid var(--color-foreground-3); - border-radius: 0.5rem; + border-radius: var(--border-radius-medium); height: 3rem; display: flex; flex-direction: row; @@ -40,7 +40,7 @@ .file-header .diff-type { margin-left: 1rem; padding: 0.25rem 0.5rem; - border-radius: 0.25rem; + border-radius: var(--border-radius-medium); } .file-header .diff-type.created { color: var(--color-positive); @@ -66,18 +66,18 @@
{#if diff.modified.length > 0} - {diff.modified.length} file(s) changed + {diff.modified.length} file(s) changed with - {stats.additions} addition(s) + {stats.additions} addition(s) and - {stats.deletions} deletion(s) + {stats.deletions} deletion(s) {/if}
{#each diff.created as path (path)}
-

{path}

+

{path}

created
dispatch("browse", path)}> @@ -88,7 +88,7 @@ {#each diff.deleted as path (path)}
-

{path}

+

{path}

deleted
dispatch("browse", path)}> diff --git a/src/base/projects/View.svelte b/src/base/projects/View.svelte index c1962a947..739811925 100644 --- a/src/base/projects/View.svelte +++ b/src/base/projects/View.svelte @@ -67,6 +67,13 @@ + + + + + + + {:catch} diff --git a/src/issue.ts b/src/issue.ts new file mode 100644 index 000000000..19238002a --- /dev/null +++ b/src/issue.ts @@ -0,0 +1,86 @@ +import { type Host, Request } from '@app/api'; + +export interface IIssue { + id: string; + author: Author; + title: string; + state: State; + comment: CommentWithReplies; + discussion: CommentWithReplies[]; + labels?: Label[]; // When no labels are set, this is undefined + timestamp: number; +} + +export type State = { closed: { reason: string } } | "open"; + +export interface Comment { + author: Author; + body: string; + reactions: Record; + timestamp: number; +} + +export interface Author { + urn: string; + name?: string; + ens?: { + name: string; + }; +} + +export interface CommentWithReplies extends Comment { + replies: Comment[]; +} + +export type Label = string; + +export function groupIssues(issues: Issue[]): { open: Issue[]; closed: Issue[] } { + return issues.reduce((acc, issue) => { + if (issue.state === 'open') { + acc.open.push(issue); + } else { + acc.closed.push(issue); + } + return acc; + }, { open: [] as Issue[], closed: [] as Issue[] }); +} + +export class Issue { + id: string; + author: Author; + title: string; + state: State; + comment: CommentWithReplies; + discussion: CommentWithReplies[]; + labels?: Label[]; // When no labels are set, this is undefined + timestamp: number; + + constructor(issue: IIssue) { + this.id = issue.id; + this.author = issue.author; + this.title = issue.title; + this.state = issue.state; + this.comment = issue.comment; + this.discussion = issue.discussion; + this.labels = issue.labels; + this.timestamp = issue.timestamp; + } + + // Counts the amount of comments and replies in a discussion + countComments(): number { + return this.discussion.reduce((acc, comment) => { + if (comment.replies) return acc + comment.replies.length + 1; // We add all replies and 1 forathe comment in this loop. + return acc + 1; // If there are no replies, we simply add 1 for the comment in this loop. + }, 0); + } + + static async getIssues(urn: string, host: Host): Promise { + const response: IIssue[] = await new Request(`projects/${urn}/issues`, host).get(); + return response.map(issue => new Issue(issue)); + } + + static async getIssue(urn: string, issue: string, host: Host): Promise { + const response: IIssue = await new Request(`projects/${urn}/issues/${issue}`, host).get(); + return new Issue(response); + } +} diff --git a/src/project.ts b/src/project.ts index 1e8ad8abb..a6d51c0ba 100644 --- a/src/project.ts +++ b/src/project.ts @@ -6,6 +6,7 @@ import { isOid, isRadicleId } from '@app/utils'; import { Profile, ProfileType } from '@app/profile'; import { Seed } from '@app/base/seeds/Seed'; import type { Config } from '@app/config'; +import type { Issue } from '@app/issue'; export type Urn = string; export type PeerId = string; @@ -34,6 +35,8 @@ export enum ProjectContent { Tree, History, Commit, + Issues, + Issue } export interface ProjectInfo { @@ -99,6 +102,7 @@ export interface Peer { export interface Browser { content: ProjectContent; revision: string | null; + issue: string | null; peer: string | null; path: string | null; line: number | null; @@ -108,6 +112,7 @@ export const browserStore = writable({ content: ProjectContent.Tree, branches: {}, revision: null, + issue: null, peer: null, path: null, line: null, @@ -116,6 +121,7 @@ export const browserStore = writable({ export interface BrowseTo { content?: ProjectContent; revision?: string | null; + issue?: string | null; path?: string | null; peer?: string | null; line?: number | null; @@ -133,7 +139,7 @@ export function browse(browse: BrowseTo): void { } export function path(opts: PathOptions): string { - const { urn, profile, seed, peer, content, revision, path } = opts; + const { urn, profile, seed, peer, content, revision, path, issue } = opts; const result = []; if (profile) { @@ -156,11 +162,23 @@ export function path(opts: PathOptions): string { result.push("commits"); break; + case ProjectContent.Issues: + result.push("issues"); + break; + + case ProjectContent.Issue: + result.push("issues"); + break; + default: result.push("tree"); break; } + if (issue) { + result.push(issue); + } + if (revision) { result.push(revision); } @@ -217,10 +235,11 @@ export class Project implements ProjectInfo { seed: Seed; peers: Peer[]; branches: Branches; + issues: Issue[]; profile: Profile | null; anchors: string[]; - constructor(urn: string, info: ProjectInfo, seed: Seed, peers: Peer[], branches: Branches, profile: Profile | null, anchors: string[]) { + constructor(urn: string, info: ProjectInfo, seed: Seed, peers: Peer[], branches: Branches, profile: Profile | null, anchors: string[], issues: Issue[]) { this.urn = urn; this.head = info.head; this.name = info.name; @@ -231,6 +250,7 @@ export class Project implements ProjectInfo { this.seed = seed; this.peers = peers; this.branches = branches; + this.issues = issues; this.profile = profile; this.anchors = anchors; } @@ -301,6 +321,14 @@ export class Project implements ProjectInfo { return new Request(`projects/${this.urn}/commits/${commit}`, this.seed.api).get(); } + static async getIssues(urn: string, host: Host): Promise { + return new Request(`projects/${urn}/issues`, host).get(); + } + + async getIssue(issue: string): Promise { + return new Request(`projects/${this.urn}/issues/${issue}`, this.seed.api).get(); + } + async getTree( commit: string, path: string, @@ -358,6 +386,7 @@ export class Project implements ProjectInfo { const info = await Project.getInfo(id, seed.api); const urn = isRadicleId(id) ? id : info.urn; const anchors = profile ? await profile.confirmedProjectAnchors(urn, config) : []; + const issues = await Project.getIssues(urn, seed.api); // Older versions of http-api don't include the URN. if (! info.urn) info.urn = urn; @@ -378,6 +407,6 @@ export class Project implements ProjectInfo { } } - return new Project(urn, info, seed, peers, remote.heads, profile, anchors); + return new Project(urn, info, seed, peers, remote.heads, profile, anchors, issues); } } diff --git a/src/utils.ts b/src/utils.ts index 18454d5b6..9f0c2a1a7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -100,6 +100,10 @@ export function formatLocationHash(hash: string | null): number | null { return null; } +export function formatIssueId(id: string): string { + return id.substring(0, 11); +} + export function formatSeedId(id: string): string { return id.substring(0, 6) + '…' @@ -242,6 +246,10 @@ export function unixTime(): number { return Math.floor(Date.now() / 1000); } +export const formatTimestamp = (t: number): string => { + return new Date(t * 1000).toLocaleString("en-EN", { dateStyle: "full", timeStyle: "long" }); +}; + // Check whether the input is a Radicle ID. export function isRadicleId(input: string): boolean { return /^rad:[a-z]+:[a-zA-Z0-9]+$/.test(input);