Add issue creation

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2023-03-01 15:12:03 +01:00
parent d71f47a98a
commit d1168dc6ff
33 changed files with 848 additions and 327 deletions
+16 -22
View File
@@ -123,28 +123,22 @@
<span class="txt-bold">{tree.stats.commits}</span>
commit(s)
</HeaderToggleLabel>
{#if project.issues}
<HeaderToggleLabel
ariaLabel="Issue count"
active={activeRoute.params.view.resource === "issues"}
disabled={project.issues === 0}
clickable={project.issues > 0}
on:click={() => toggleContent("issues", false)}>
<span class="txt-bold">{project.issues}</span>
issue(s)
</HeaderToggleLabel>
{/if}
{#if project.patches}
<HeaderToggleLabel
ariaLabel="Patch count"
clickable={project.patches > 0}
active={activeRoute.params.view.resource === "patches"}
disabled={project.patches === 0}
on:click={() => toggleContent("patches", false)}>
<span class="txt-bold">{project.patches}</span>
patch(es)
</HeaderToggleLabel>
{/if}
<HeaderToggleLabel
ariaLabel="Issue count"
active={activeRoute.params.view.resource === "issues"}
clickable
on:click={() => toggleContent("issues", false)}>
<span class="txt-bold">{project.issues.open ?? 0}</span>
issue(s)
</HeaderToggleLabel>
<HeaderToggleLabel
ariaLabel="Patch count"
clickable
active={activeRoute.params.view.resource === "patches"}
on:click={() => toggleContent("patches", false)}>
<span class="txt-bold">{project.patches.proposed ?? 0}</span>
patch(es)
</HeaderToggleLabel>
<HeaderToggleLabel ariaLabel="Contributor count">
<span class="txt-bold">{tree.stats.contributors}</span>
contributor(s)
+51 -28
View File
@@ -3,8 +3,10 @@
import type { Issue } from "@app/lib/issue";
import Authorship from "@app/components/Authorship.svelte";
import Avatar from "@app/components/Comment/Avatar.svelte";
import Chip from "@app/components/Chip.svelte";
import Comment from "@app/components/Comment.svelte";
import { canonicalize, capitalize } from "@app/lib/utils";
import { formatNodeId, canonicalize, capitalize } from "@app/lib/utils";
import { formatObjectId } from "@app/lib/cobs";
export let issue: Issue;
@@ -51,41 +53,35 @@
color: var(--color-foreground-5);
}
.metadata-section-body {
display: flex;
flex-wrap: wrap;
flex-direction: row;
gap: 0.5rem;
margin-bottom: 1.25rem;
}
.metadata-section-empty {
color: var(--color-foreground-6);
}
.label {
border-radius: var(--border-radius);
color: var(--color-tertiary);
background-color: var(--color-tertiary-2);
padding: 0.25rem 0.75rem;
margin-right: 0.5rem;
font-size: var(--font-size-small);
line-height: 1.6;
}
.summary {
display: flex;
justify-content: space-between;
flex-direction: row;
align-items: center;
margin-bottom: 0.5rem;
}
.summary-left {
display: flex;
align-items: center;
}
.summary-title {
display: flex;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.id {
flex: 1 0 auto;
font-size: var(--font-size-tiny);
margin-left: 0.75rem;
color: var(--color-foreground-5);
}
.summary-state {
margin-left: 2rem;
padding: 0.5rem 1rem;
border-radius: var(--border-radius);
}
@@ -100,25 +96,37 @@
.replies {
margin-left: 2rem;
}
.assignee {
display: flex;
flex-direction: row;
align-items: center;
}
.tag {
max-width: 15rem;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
@media (max-width: 960px) {
.issue {
padding-left: 2rem;
}
.summary-state {
margin-left: 0.5rem;
}
}
</style>
<div class="issue">
<header>
<div class="summary">
<div class="summary-left">
<span class="summary-title txt-medium">
{issue.title}
</span>
<span class="txt-monospace id layout-desktop">{issue.id}</span>
<span class="txt-monospace id layout-mobile">
{formatObjectId(issue.id)}
</span>
<div class="summary-title txt-medium">
{issue.title}
</div>
<div class="txt-monospace id layout-desktop">{issue.id}</div>
<div class="txt-monospace id layout-mobile">
{formatObjectId(issue.id)}
</div>
<div
class="summary-state"
@@ -130,7 +138,7 @@
<Authorship
author={issue.author}
timestamp={issue.timestamp}
caption="opened on" />
caption="opened" />
</header>
<main>
<div class="comments">
@@ -153,14 +161,29 @@
</div>
<div class="metadata layout-desktop">
<div class="metadata-section">
<div class="metadata-section-header">Assignees</div>
<div class="metadata-section-body">
{#if issue.assignees?.length}
{#each issue.assignees as assignee, key}
<Chip {key}>
<div slot="text" class="assignee">
<Avatar inline source={assignee} title={assignee} />
<span>{formatNodeId(assignee)}</span>
</div>
</Chip>
{/each}
{:else}
<div class="metadata-section-empty">No assignees</div>
{/if}
</div>
<div class="metadata-section-header">Tags</div>
<div class="metadata-section-body">
{#if issue.tags?.length}
{#each issue.tags as tag}
<span class="label">{tag}</span>
{#each issue.tags as tag, key}
<Chip {key}><span class="tag" slot="text">{tag}</span></Chip>
{/each}
{:else}
<div class="metadata-section-empty">No tags.</div>
<div class="metadata-section-empty">No tags</div>
{/if}
</div>
</div>
+25 -43
View File
@@ -2,9 +2,8 @@
import type { Issue } from "@app/lib/issue";
import { formatObjectId } from "@app/lib/cobs";
import { twemoji } from "@app/lib/utils";
import Authorship from "@app/components/Authorship.svelte";
import Icon from "@app/components/Icon.svelte";
export let issue: Issue;
@@ -13,11 +12,10 @@
<style>
.issue-teaser {
display: flex;
align-items: center;
justify-content: space-between;
background-color: var(--color-foreground-1);
display: grid;
grid-template-columns: 3rem minmax(0, 1fr) 4rem;
padding: 0.75rem 0;
background-color: var(--color-foreground-1);
}
.issue-teaser:hover {
background-color: var(--color-foreground-2);
@@ -29,27 +27,33 @@
font-family: var(--font-family-monospace);
margin-left: 0.5rem;
}
.column-left {
flex: min-content;
}
.column-right {
.summary {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-end;
margin-right: 1rem;
flex-basis: 5rem;
padding-right: 2rem;
}
.issue-title {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.comment-count {
color: var(--color-foreground-4);
font-weight: var(--font-weight-bold);
display: flex;
flex-direction: row;
align-items: center;
gap: 0.5rem;
color: var(--color-foreground-5);
}
.comment-count .emoji {
margin-right: 0.25rem;
.column-right {
align-self: center;
justify-self: center;
}
.state {
padding: 0 1rem;
justify-self: center;
align-self: center;
}
.state-icon {
width: 0.5rem;
@@ -62,27 +66,6 @@
.closed {
background-color: var(--color-negative);
}
.summary {
display: flex;
flex-direction: row;
align-items: center;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
padding-right: 1rem;
}
@media (max-width: 720px) {
.column-left {
overflow: hidden;
}
.summary {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
padding-right: 1rem;
}
}
</style>
<div class="issue-teaser">
@@ -94,8 +77,7 @@
</div>
<div class="column-left">
<div class="summary">
<!-- TODO: Truncation not working on overflow -->
{issue.title}
<span class="issue-title">{issue.title}</span>
<span class="issue-id">{formatObjectId(issue.id)}</span>
</div>
<Authorship
@@ -106,7 +88,7 @@
{#if commentCount > 0}
<div class="column-right">
<div class="comment-count">
<span class="txt-tiny emoji" use:twemoji>💬</span>
<Icon name="chat" />
<span>{commentCount}</span>
</div>
</div>
+279
View File
@@ -0,0 +1,279 @@
<script lang="ts" strictEvents>
import type { MaybeBlob, Project } from "@app/lib/project";
import type { Session } from "@app/lib/session";
import * as modal from "@app/lib/modal";
import AuthenticationErrorModal from "@app/views/session/AuthenticationErrorModal.svelte";
import Avatar from "@app/components/Comment/Avatar.svelte";
import Button from "@app/components/Button.svelte";
import Chip from "@app/components/Chip.svelte";
import Comment from "@app/components/Comment.svelte";
import TextInput from "@app/components/TextInput.svelte";
import Textarea from "@app/components/Textarea.svelte";
import { Issue } from "@app/lib/issue";
import { canonicalize, formatNodeId, parseNid } from "@app/lib/utils";
import { createEventDispatcher } from "svelte";
export let session: Session;
export let project: Project;
const dispatch = createEventDispatcher<{ create: never }>();
// Get an image blob based on a relative path.
const getImage = async (imagePath: string): Promise<MaybeBlob> => {
const finalPath = canonicalize(imagePath, "/"); // We only use the root path in issues.
const commit = project.branches[project.defaultBranch]; // We suppose that all issues are only looked at on HEAD of the default branch.
return project.getBlob(commit, finalPath);
};
let preview: boolean = false;
function handleAddAssignee() {
const nid = parseNid(assignee);
if (nid) {
if (assignees.includes(nid.pubkey)) {
assigneeCaption = "This user is already assigned";
return;
}
assignees.push(nid.pubkey);
assignees = assignees;
assignee = "";
} else {
assigneeCaption = "This user is not valid";
}
}
function handleAddTag() {
if (tags.includes(tag)) {
tagCaption = "This tag already exists";
return;
}
tags.push(tag);
tags = tags;
tag = "";
}
let issueTitle = "";
let issueText = "";
let assignees: string[] = [];
let assignee: string = "";
let assigneeCaption: string | undefined = undefined;
let tags: string[] = [];
let tag: string = "";
let tagCaption: string | undefined = undefined;
async function createIssue() {
try {
await Issue.createIssue(
project.id,
issueTitle,
issueText,
assignees,
tags,
project.seed.addr,
session.id,
);
dispatch("create");
} catch {
modal.show({
component: AuthenticationErrorModal,
props: {
title: "Authentication failed",
subtitle: [
"Could not create the issue. Make sure you're still logged in.",
],
},
});
}
}
</script>
<style>
main {
padding: 0 2rem 0 8rem;
}
.form {
display: grid;
grid-template-columns: minmax(0, 2fr) 1fr;
margin-bottom: 1rem;
}
.side-bar {
border-left: 1px solid var(--color-foreground-4);
padding-left: 1rem;
display: flex;
flex-direction: column;
flex: 1;
}
.actions {
text-align: right;
display: flex;
justify-content: flex-end;
flex-direction: row;
gap: 1rem;
margin-top: 1rem;
}
.editor {
flex: 2;
padding-right: 1rem;
}
.section {
display: flex;
flex-direction: column;
gap: 0.5rem;
margin-bottom: 3rem;
}
.section:not(:first-child) {
border-top: 1px solid var(--color-foreground-4);
padding-top: 1rem;
}
.summary {
padding: 1rem;
background: var(--color-foreground-1);
border-radius: var(--border-radius);
margin-bottom: 2rem;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.chips {
display: flex;
flex-direction: column;
align-items: flex-start;
flex-wrap: wrap;
gap: 0.5rem;
}
.tags {
flex-direction: row;
}
.tag {
max-width: 15rem;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.assignee {
display: flex;
flex-direction: row;
align-items: center;
}
@media (max-width: 960px) {
main {
padding-left: 2rem;
}
}
@media (max-width: 720px) {
.form {
grid-template-columns: minmax(0, 1fr);
}
}
</style>
<main>
<div class="form">
<div class="editor">
{#if preview}
<div class="summary txt-medium" class:txt-missing={preview}>
{#if issueTitle.trim() === ""}
No title
{:else}
{issueTitle}
{/if}
</div>
<div class="comments">
<Comment
comment={{
author: { id: session.publicKey },
body: issueText,
reactions: {},
replies: null,
replyTo: null,
timestamp: Date.now(),
}}
{getImage} />
</div>
{:else}
<Textarea bind:value={issueTitle} placeholder="Title" />
<Textarea
bind:value={issueText}
resizable
placeholder="Leave a comment" />
{/if}
<div class="actions">
<Button
size="small"
variant="text"
on:click={() => (preview = !preview)}>
{#if preview}
Resume editing
{:else}
Preview
{/if}
</Button>
<Button
disabled={!issueTitle}
size="small"
variant="secondary"
on:click={createIssue}>
Submit
</Button>
</div>
</div>
<div class="side-bar layout-desktop">
<div class="section txt-small">
<span class="txt-bold">Assignees</span>
<div class="chips">
{#each assignees as assignee, key}
<Chip
{key}
removeable
on:remove={e => {
assignees.splice(e.detail, 1);
assignees = assignees;
}}>
<div slot="text" class="assignee">
<Avatar inline source={assignee} title={assignee} />
<span>{formatNodeId(assignee)}</span>
</div>
</Chip>
{/each}
</div>
<div>
<TextInput
bind:value={assignee}
variant="form"
on:submit={handleAddAssignee}
on:input={() => (assigneeCaption = undefined)}
placeholder="Assign this issue"
validationMessage={assigneeCaption}
valid={Boolean(parseNid(assignee))} />
</div>
</div>
<div class="section txt-small">
<span class="txt-bold">Tags</span>
<div class="chips tags">
{#each tags as tag, key}
<Chip
{key}
removeable
on:remove={e => {
tags.splice(e.detail, 1);
tags = tags;
}}>
<span class="tag" slot="text">{tag}</span>
</Chip>
{/each}
</div>
<div>
<TextInput
bind:value={tag}
variant="form"
on:input={() => (tagCaption = undefined)}
on:submit={handleAddTag}
placeholder="Tag this issue"
validationMessage={tagCaption}
valid={tag !== ""} />
</div>
</div>
</div>
</div>
</main>
+36 -11
View File
@@ -3,19 +3,23 @@
</script>
<script lang="ts">
import type { Project } from "@app/lib/project";
import type { Issue } from "@app/lib/issue";
import type { Tab } from "@app/components/TabBar.svelte";
import * as router from "@app/lib/router";
import { capitalize } from "@app/lib/utils";
import { groupIssues } from "@app/lib/issue";
import * as router from "@app/lib/router";
import { sessionStore } from "@app/lib/session";
import HeaderToggleLabel from "@app/views/projects/HeaderToggleLabel.svelte";
import IssueTeaser from "@app/views/projects/Issue/IssueTeaser.svelte";
import Placeholder from "@app/components/Placeholder.svelte";
import TabBar from "@app/components/TabBar.svelte";
export let issues: Issue[];
export let state: State;
export let project: Project;
let options: Tab<State>[];
const { open, closed } = groupIssues(issues);
@@ -28,11 +32,11 @@
$: options = [
{
value: "open",
count: open.length,
count: project.issues.open,
},
{
value: "closed",
count: closed.length,
count: project.issues.closed,
},
];
</script>
@@ -49,6 +53,12 @@
.teaser:not(:last-child) {
border-bottom: 1px dashed var(--color-background);
}
.section-header {
display: flex;
flex-direction: row;
justify-content: space-between;
width: 100%;
}
@media (max-width: 960px) {
.issues {
@@ -58,14 +68,29 @@
</style>
<div class="issues">
<div style="margin-bottom: 1rem;">
<TabBar
{options}
on:select={e =>
<div class="section-header">
<div style="margin-bottom: 1rem;">
<TabBar
{options}
on:select={e =>
router.updateProjectRoute({
search: `state=${e.detail}`,
})}
active={state} />
</div>
<HeaderToggleLabel
disabled={!$sessionStore}
on:click={() => {
router.updateProjectRoute({
search: `state=${e.detail}`,
})}
active={state} />
view: {
resource: "issues",
params: { view: { resource: "new" } },
},
});
}}
clickable>
New issue
</HeaderToggleLabel>
</div>
{#if filteredIssues.length}
@@ -87,7 +112,7 @@
{/each}
</div>
{:else}
<Placeholder emoji="🍣">
<Placeholder emoji="🍂">
<div slot="title">{capitalize(state)} issues</div>
<div slot="body">No issues matched the current filter</div>
</Placeholder>
@@ -41,15 +41,11 @@
{#if element.type === TimelineType.Merge && element.inner.peer.person}
<div class="element">
<Authorship
author={{
peer: element.inner.peer.id,
id: element.inner.peer.person.id,
profile: element.inner.peer.person,
}}
author={{ id: element.inner.peer.person.id }}
caption={`merged to ${formatSeedId(element.inner.peer.id)}`}
timestamp={element.timestamp} />
</div>
{:else if element.type === TimelineType.Review && element.inner.author.profile?.ens?.name}
{:else if element.type === TimelineType.Review && element.inner.author.id}
<div class="margin-left">
<Review review={element.inner} {getImage} />
</div>
+6 -4
View File
@@ -5,6 +5,7 @@
<script lang="ts">
import type { Patch } from "@app/lib/patch";
import type { Tab } from "@app/components/TabBar.svelte";
import type { Project } from "@app/lib/project";
import PatchTeaser from "./Patch/PatchTeaser.svelte";
import Placeholder from "@app/components/Placeholder.svelte";
@@ -16,6 +17,7 @@
export let state: State;
export let patches: Patch[];
export let project: Project;
let options: Tab<State>[];
const sortedPatches = groupPatches(patches);
@@ -24,15 +26,15 @@
$: options = [
{
value: "proposed",
count: sortedPatches.proposed.length,
count: project.patches.proposed,
},
{
value: "draft",
count: sortedPatches.draft.length,
count: project.patches.draft,
},
{
value: "archived",
count: sortedPatches.archived.length,
count: project.patches.archived,
},
];
</script>
@@ -84,7 +86,7 @@
{/each}
</div>
{:else}
<Placeholder emoji="🍖">
<Placeholder emoji="🍂">
<div slot="title">{capitalize(state)} patches</div>
<div slot="body">No patches matched the current filter</div>
</Placeholder>
+8 -7
View File
@@ -1,11 +1,12 @@
<script lang="ts" strictEvents>
import { createEventDispatcher, onMount } from "svelte";
import Icon from "@app/components/Icon.svelte";
import Dropdown from "@app/components/Dropdown.svelte";
import { formatSeedId } from "@app/lib/utils";
import type { Peer } from "@app/lib/project";
import Floating from "@app/components/Floating.svelte";
import Badge from "@app/components/Badge.svelte";
import Dropdown from "@app/components/Dropdown.svelte";
import Floating from "@app/components/Floating.svelte";
import Icon from "@app/components/Icon.svelte";
import { createEventDispatcher, onMount } from "svelte";
import { formatNodeId } from "@app/lib/utils";
export let peer: string | null = null;
export let peers: Peer[];
@@ -90,7 +91,7 @@
<Icon name="fork" />
{#if meta}
<span class="peer-id">
{meta.person?.name ?? formatSeedId(meta.id)}
{meta.person?.name ?? formatNodeId(meta.id)}
</span>
{#if meta.delegate}
<Badge variant="primary">delegate</Badge>
@@ -98,7 +99,7 @@
<!-- If the delegate metadata is not found -->
{:else if peer}
<span class="peer-id">
{formatSeedId(peer)}
{formatNodeId(peer)}
</span>
{/if}
</div>
+45 -11
View File
@@ -9,19 +9,21 @@
import * as router from "@app/lib/router";
import Loading from "@app/components/Loading.svelte";
import NotFound from "@app/components/NotFound.svelte";
import { formatSeedId, unreachable } from "@app/lib/utils";
import { formatNodeId, unreachable } from "@app/lib/utils";
import { sessionStore } from "@app/lib/session";
import Header from "./Header.svelte";
import Browser from "./Browser.svelte";
import History from "./History.svelte";
import Commit from "./Commit.svelte";
import Issues from "./Issues.svelte";
import Header from "./Header.svelte";
import History from "./History.svelte";
import Issue from "./Issue.svelte";
import Patches from "./Patches.svelte";
import Patch from "./Patch.svelte";
import ProjectMeta from "./ProjectMeta.svelte";
import Issues from "./Issues.svelte";
import Message from "@app/components/Message.svelte";
import NewIssue from "./Issue/New.svelte";
import Patch from "./Patch.svelte";
import Patches from "./Patches.svelte";
import Placeholder from "@app/components/Placeholder.svelte";
import ProjectMeta from "./ProjectMeta.svelte";
export let activeRoute: ProjectRoute;
@@ -60,6 +62,24 @@
return project;
};
const handleIssueCreation = () => {
router.push({
resource: "projects",
params: {
id,
seed,
view: {
resource: "issues",
},
},
});
// This assignment allows us to have an up-to-date issue count
projectPromise = getProject(id, seed, peer);
};
// React to peer changes
$: projectPromise = getProject(id, seed, peer);
// Content can be altered in child components.
$: revision = activeRoute.params.revision || null;
</script>
@@ -92,7 +112,7 @@
}
</style>
{#await getProject(id, seed, peer)}
{#await projectPromise}
<main>
<header>
<Loading center />
@@ -128,11 +148,25 @@
<Message error>{e.message}</Message>
</div>
{/await}
{:else if activeRoute.params.view.resource === "issues" && activeRoute.params.view.params?.view.resource === "new"}
{#if $sessionStore}
<NewIssue
on:create={handleIssueCreation}
session={$sessionStore}
{project} />
{:else}
<div class="message">
<Message error>
Could not access the issue creation. Make sure you're still logged
in.
</Message>
</div>
{/if}
{:else if activeRoute.params.view.resource === "issues"}
{#await issue.Issue.getIssues(project.id, project.seed.addr)}
<Loading center />
{:then issues}
<Issues state={issueFilter} {issues} />
<Issues {project} state={issueFilter} {issues} />
{:catch e}
<div class="message">
<Message error>{e.message}</Message>
@@ -152,7 +186,7 @@
{#await patch.Patch.getPatches(project.id, project.seed.addr)}
<Loading center />
{:then patches}
<Patches state={patchFilter} {patches} />
<Patches {project} state={patchFilter} {patches} />
{:catch e}
<div class="message">
<Message error>{e.message}</Message>
@@ -176,7 +210,7 @@
{#if peer}
<Placeholder emoji="🍂">
<span slot="title">
<span class="txt-monospace">{formatSeedId(peer)}</span>
<span class="txt-monospace">{formatNodeId(peer)}</span>
</span>
<span slot="body">
<span style="display: block">