Make Operation generic, and handle patch operations

So far we only supported issue operations on the `activity_by_id`
command.

With this commit we separate the commands into a `activity_by_issue` and
`activity_by_patch` command that calls a generic `activity_by_id` trait
implementation.

`Operation` now takes as a generic either `cob/issue/Action.ts` or
`cob/patch/Action.ts`.

Also `Operation` now stores the array of all `Action` that happened on
said operation. I'm not entirely sure if this will help us in the
future, but it represents more closely the state of the relation between
an `Operation` and the cob `Actions`.
This commit is contained in:
Sebastian Martinez
2025-01-10 10:33:32 -06:00
committed by Rūdolfs Ošiņš
parent 63d1c87c7f
commit 432db1ce5b
16 changed files with 218 additions and 134 deletions
@@ -1,5 +1,6 @@
<script lang="ts">
import type { Operation } from "@bindings/cob/issue/Operation";
import type { Operation } from "@bindings/cob/Operation";
import type { Action } from "@bindings/cob/issue/Action";
import { authorForNodeId, formatTimestamp } from "@app/lib/utils";
@@ -8,19 +9,20 @@
import NodeId from "@app/components/NodeId.svelte";
interface Props {
operation: Extract<Operation, { type: "lifecycle" }>;
action: Extract<Action, { type: "lifecycle" }>;
op: Operation<Action>;
}
const { operation }: Props = $props();
const { op, action }: Props = $props();
</script>
<Border variant="float" stylePadding="1rem">
<div class="txt-small">
<div class="global-flex txt-small">
<NodeId {...authorForNodeId(operation.author)} />
<NodeId {...authorForNodeId(op.author)} />
changed status to
<IssueStateBadge state={operation.state} />
{formatTimestamp(operation.timestamp)}
<IssueStateBadge state={action.state} />
{formatTimestamp(op.timestamp)}
</div>
</div>
</Border>
@@ -0,0 +1,28 @@
<script lang="ts">
import type { Operation } from "@bindings/cob/Operation";
import type { Action } from "@bindings/cob/patch/Action";
import { authorForNodeId, formatTimestamp } from "@app/lib/utils";
import Border from "@app/components/Border.svelte";
import NodeId from "@app/components/NodeId.svelte";
import PatchStateBadge from "./PatchStateBadge.svelte";
interface Props {
action: Extract<Action, { type: "lifecycle" }>;
op: Operation<Action>;
}
const { op, action }: Props = $props();
</script>
<Border variant="float" stylePadding="1rem">
<div class="txt-small">
<div class="global-flex txt-small">
<NodeId {...authorForNodeId(op.author)} />
changed status to
<PatchStateBadge state={action.state} />
{formatTimestamp(op.timestamp)}
</div>
</div>
</Border>
+24 -22
View File
@@ -1,9 +1,10 @@
<script lang="ts">
import type { Action } from "@bindings/cob/issue/Action";
import type { Author } from "@bindings/cob/Author";
import type { Config } from "@bindings/config/Config";
import type { Embed } from "@bindings/cob/thread/Embed";
import type { Issue } from "@bindings/cob/issue/Issue";
import type { Operation } from "@bindings/cob/issue/Operation";
import type { Operation } from "@bindings/cob/Operation";
import type { RepoInfo } from "@bindings/repo/RepoInfo";
import type { Thread } from "@bindings/cob/thread/Thread";
import type { IssueStatus } from "./router";
@@ -45,7 +46,7 @@
repo: RepoInfo;
issue: Issue;
issues: Issue[];
activity: Operation[];
activity: Operation<Action>[];
config: Config;
threads: Thread[];
status: IssueStatus;
@@ -149,9 +150,8 @@
rid: repo.rid,
id: issue.id,
}),
invoke<Operation[]>("activity_by_id", {
invoke<Operation<Action>[]>("activity_by_issue", {
rid: repo.rid,
typeName: "xyz.radicle.issue",
id: issue.id,
}),
invoke<Thread[]>("comment_threads_by_issue_id", {
@@ -524,26 +524,28 @@
<div>
{#each activity as op}
{#if op.type === "lifecycle"}
<IssueTimelineLifecycleAction operation={op} />
<div class="connector"></div>
{:else if op.type === "comment"}
{@const thread = threads.find(t => t.root.id === op.entryId)}
{#if thread}
<ThreadComponent
{thread}
rid={repo.rid}
canEditComment={partial(
roles.isDelegateOrAuthor,
config.publicKey,
repo.delegates.map(delegate => delegate.did),
)}
{editComment}
createReply={partial(createReply)}
reactOnComment={partial(reactOnComment, config.publicKey)} />
{#each op.actions as action}
{#if action.type === "lifecycle"}
<IssueTimelineLifecycleAction {op} {action} />
<div class="connector"></div>
{:else if action.type === "comment"}
{@const thread = threads.find(t => t.root.id === op.id)}
{#if thread}
<ThreadComponent
{thread}
rid={repo.rid}
canEditComment={partial(
roles.isDelegateOrAuthor,
config.publicKey,
repo.delegates.map(delegate => delegate.did),
)}
{editComment}
createReply={partial(createReply)}
reactOnComment={partial(reactOnComment, config.publicKey)} />
<div class="connector"></div>
{/if}
{/if}
{/if}
{/each}
{/each}
</div>
+15
View File
@@ -1,4 +1,6 @@
<script lang="ts">
import type { Operation } from "@bindings/cob/Operation";
import type { Action } from "@bindings/cob/patch/Action";
import type { Author } from "@bindings/cob/Author";
import type { Config } from "@bindings/config/Config";
import type { Diff } from "@bindings/diff/Diff";
@@ -45,6 +47,7 @@
patches: PaginatedQuery<Patch[]>;
revisions: Revision[];
config: Config;
activity: Operation<Action>[];
status: PatchStatus | undefined;
}
@@ -56,6 +59,7 @@
revisions,
config,
status: initialStatus,
activity,
}: Props = $props();
/* eslint-enable prefer-const */
@@ -535,6 +539,17 @@
) && partial(editRevision, revisions[0].id)}>
</CommentComponent>
</div>
<div class="connector"></div>
<div>
{#each activity as op}
{#each op.actions as action}
{#if action.type === "revision"}
<div>New revision created {action.oid}</div>
<div class="connector"></div>
{/if}
{/each}
{/each}
</div>
{:else}
{@const revision = revisions.slice(-1)[0]}
{#await loadHighlightedDiff(repo.rid, revision.base, revision.head) then diff}
+39 -23
View File
@@ -1,7 +1,9 @@
import type { Action as IssueAction } from "@bindings/cob/issue/Action";
import type { Action as PatchAction } from "@bindings/cob/patch/Action";
import type { Config } from "@bindings/config/Config";
import type { Thread } from "@bindings/cob/thread/Thread";
import type { Issue } from "@bindings/cob/issue/Issue";
import type { Operation } from "@bindings/cob/issue/Operation";
import type { Operation } from "@bindings/cob/Operation";
import type { PaginatedQuery } from "@bindings/cob/PaginatedQuery";
import type { Patch } from "@bindings/cob/patch/Patch";
import type { RepoInfo } from "@bindings/repo/RepoInfo";
@@ -33,7 +35,7 @@ export interface LoadedRepoIssueRoute {
issue: Issue;
issues: Issue[];
status: IssueStatus;
activity: Operation[];
activity: Operation<IssueAction>[];
threads: Thread[];
};
}
@@ -82,6 +84,7 @@ export interface LoadedRepoPatchRoute {
patches: PaginatedQuery<Patch[]>;
status: PatchStatus | undefined;
revisions: Revision[];
activity: Operation<PatchAction>[];
};
}
@@ -117,28 +120,42 @@ export type LoadedRepoRoute =
export async function loadPatch(
route: RepoPatchRoute,
): Promise<LoadedRepoPatchRoute> {
const [config, repo, patches, patch, revisions] = await Promise.all([
invoke<Config>("config"),
invoke<RepoInfo>("repo_by_id", {
rid: route.rid,
}),
invoke<PaginatedQuery<Patch[]>>("list_patches", {
rid: route.rid,
status: route.status,
}),
invoke<Patch>("patch_by_id", {
rid: route.rid,
id: route.patch,
}),
invoke<Revision[]>("revisions_by_patch", {
rid: route.rid,
id: route.patch,
}),
]);
const [config, repo, patches, patch, revisions, activity] = await Promise.all(
[
invoke<Config>("config"),
invoke<RepoInfo>("repo_by_id", {
rid: route.rid,
}),
invoke<PaginatedQuery<Patch[]>>("list_patches", {
rid: route.rid,
status: route.status,
}),
invoke<Patch>("patch_by_id", {
rid: route.rid,
id: route.patch,
}),
invoke<Revision[]>("revisions_by_patch", {
rid: route.rid,
id: route.patch,
}),
invoke<Operation<PatchAction>[]>("activity_by_patch", {
rid: route.rid,
id: route.patch,
}),
],
);
return {
resource: "repo.patch",
params: { repo, config, patch, patches, revisions, status: route.status },
params: {
repo,
config,
patch,
patches,
revisions,
status: route.status,
activity,
},
};
}
@@ -194,9 +211,8 @@ export async function loadIssue(
rid: route.rid,
id: route.issue,
}),
invoke<Operation[]>("activity_by_id", {
invoke<Operation<IssueAction>[]>("activity_by_issue", {
rid: route.rid,
typeName: "xyz.radicle.issue",
id: route.issue,
}),
invoke<Issue[]>("list_issues", {