mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 22:30:41 +08:00
Add option to view diff between revisions
Signed-off-by: xphoniex <dj.2dixx@gmail.com>
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
| "chevron-up"
|
||||
| "clipboard"
|
||||
| "clipboard-small"
|
||||
| "diff"
|
||||
| "ellipsis"
|
||||
| "exclamation"
|
||||
| "exclamation-circle"
|
||||
@@ -94,6 +95,16 @@
|
||||
10.5H8C7.72386 10.5 7.5 10.2761 7.5 10ZM7.5 13C7.5 12.7239 7.72386 12.5 8
|
||||
12.5H13C13.2761 12.5 13.5 12.7239 13.5 13C13.5 13.2761 13.2761 13.5 13
|
||||
13.5H8C7.72386 13.5 7.5 13.2761 7.5 13Z" />
|
||||
{:else if name === "diff"}
|
||||
<path d="M12.5 10.5H15V9.5H12.5V7H11.5V9.5H9V10.5H11.5V13H12.5V10.5Z" />
|
||||
<path d="M15 16.5H9V15.5H15V16.5Z" />
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
d="M16 21.5C18.4853 21.5 20.5 19.4853 20.5 17V7C20.5 4.51472 18.4853 2.5
|
||||
16 2.5H8C5.51472 2.5 3.5 4.51472 3.5 7V17C3.5 19.4853 5.51472 21.5 8
|
||||
21.5H16ZM19.5 17C19.5 18.933 17.933 20.5 16 20.5H8C6.067 20.5 4.5 18.933
|
||||
4.5 17V7C4.5 5.067 6.067 3.5 8 3.5H16C17.933 3.5 19.5 5.067 19.5 7V17Z" />
|
||||
{:else if name === "ellipsis"}
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
import Clipboard from "@app/components/Clipboard.svelte";
|
||||
import CommentComponent from "@app/components/Comment.svelte";
|
||||
import DiffStatBadge from "@app/components/DiffStatBadge.svelte";
|
||||
import Dropdown from "@app/components/Dropdown.svelte";
|
||||
import ErrorMessage from "@app/components/ErrorMessage.svelte";
|
||||
import Floating from "@app/components/Floating.svelte";
|
||||
import Icon from "@app/components/Icon.svelte";
|
||||
import InlineMarkdown from "@app/components/InlineMarkdown.svelte";
|
||||
import ProjectLink from "@app/components/ProjectLink.svelte";
|
||||
@@ -22,12 +24,15 @@
|
||||
export let expanded: boolean = true;
|
||||
export let patchId: string;
|
||||
export let projectHead: string;
|
||||
export let projectDefaultBranch: string;
|
||||
export let projectId: string;
|
||||
export let revisionBase: string;
|
||||
export let revisionId: string;
|
||||
export let revisionOid: string;
|
||||
export let revisionTimestamp: number;
|
||||
export let timelines: Timeline[];
|
||||
export let previousRevId: string | undefined = undefined;
|
||||
export let previousRevOid: string | undefined = undefined;
|
||||
|
||||
const api = new HttpdClient(baseUrl);
|
||||
|
||||
@@ -142,13 +147,67 @@
|
||||
</div>
|
||||
<div class="txt-small" />
|
||||
<div class="revision-data">
|
||||
<span class="layout-desktop txt-small">
|
||||
{utils.formatTimestamp(revisionTimestamp)}
|
||||
</span>
|
||||
{#if response?.diff.stats}
|
||||
{@const { insertions, deletions } = response.diff.stats}
|
||||
<DiffStatBadge {insertions} {deletions} />
|
||||
{/if}
|
||||
<span class="layout-desktop txt-small">
|
||||
{utils.formatTimestamp(revisionTimestamp)}
|
||||
</span>
|
||||
{#if previousRevOid}
|
||||
<ProjectLink
|
||||
projectParams={{
|
||||
search: `diff=${previousRevOid}..${revisionOid}`,
|
||||
}}>
|
||||
<Icon name="diff" />
|
||||
</ProjectLink>
|
||||
{/if}
|
||||
<Floating>
|
||||
<svelte:fragment slot="toggle">
|
||||
<Icon name="ellipsis" />
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="modal">
|
||||
<Dropdown
|
||||
items={previousRevOid && previousRevId
|
||||
? [
|
||||
{
|
||||
title: projectHead,
|
||||
value: projectHead,
|
||||
badge: null,
|
||||
},
|
||||
{
|
||||
title: previousRevOid,
|
||||
value: previousRevOid,
|
||||
badge: null,
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
title: projectHead,
|
||||
value: projectHead,
|
||||
badge: null,
|
||||
},
|
||||
]}>
|
||||
<svelte:fragment slot="item" let:item>
|
||||
<ProjectLink
|
||||
title="{item.value}..{revisionOid}"
|
||||
projectParams={{
|
||||
search: `diff=${item.value}..${revisionOid}`,
|
||||
}}>
|
||||
{#if item.value === projectHead}
|
||||
Compare to {projectDefaultBranch} ({utils.formatObjectId(
|
||||
projectHead,
|
||||
)})
|
||||
{:else if previousRevId}
|
||||
Compare to previous revision ({utils.formatObjectId(
|
||||
previousRevId,
|
||||
)})
|
||||
{/if}
|
||||
</ProjectLink>
|
||||
</svelte:fragment>
|
||||
</Dropdown>
|
||||
</svelte:fragment>
|
||||
</Floating>
|
||||
</div>
|
||||
</div>
|
||||
{#if expanded}
|
||||
|
||||
@@ -67,8 +67,10 @@
|
||||
export let baseUrl: BaseUrl;
|
||||
export let patch: Patch;
|
||||
export let projectHead: string;
|
||||
export let projectDefaultBranch: string;
|
||||
export let revision: string;
|
||||
export let currentTab: "activity" | "commits" | "files";
|
||||
export let diff: string | undefined = undefined;
|
||||
|
||||
const api = new HttpdClient(baseUrl);
|
||||
|
||||
@@ -293,7 +295,7 @@
|
||||
<SquareButton
|
||||
size="small"
|
||||
clickable={option.disabled}
|
||||
active={option.value === currentTab}
|
||||
active={option.value === currentTab && !diff}
|
||||
disabled={option.disabled}>
|
||||
{option.title}
|
||||
</SquareButton>
|
||||
@@ -308,6 +310,16 @@
|
||||
</SquareButton>
|
||||
{/if}
|
||||
{/each}
|
||||
{#if diff}
|
||||
<ProjectLink
|
||||
projectParams={{
|
||||
search: `diff=${diff}`,
|
||||
}}>
|
||||
<SquareButton size="small" active={true}>
|
||||
Diff {diff.substr(0, 6)}..{diff.split("..")[1].substr(0, 6)}
|
||||
</SquareButton>
|
||||
</ProjectLink>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if currentTab !== "activity"}
|
||||
@@ -347,23 +359,40 @@
|
||||
{/if}
|
||||
</div>
|
||||
{#if currentTab === "activity"}
|
||||
{#each timelineTuple as [revision, timelines], index}
|
||||
<RevisionComponent
|
||||
{baseUrl}
|
||||
{projectId}
|
||||
{timelines}
|
||||
{projectHead}
|
||||
{...revision}
|
||||
on:reply={createReply}
|
||||
patchId={patch.id}
|
||||
authorId={patch.author.id}
|
||||
expanded={index === patch.revisions.length - 1} />
|
||||
{#if diff}
|
||||
{#await api.project.getDiff(projectId, diff.split("..")[0], diff.split("..")[1]) then diff}
|
||||
<div style:margin-top="1rem">
|
||||
<Changeset revision={currentRevision.oid} diff={diff.diff} />
|
||||
</div>
|
||||
{:catch e}
|
||||
<ErrorMessage
|
||||
message="Not able to load revision diff."
|
||||
stackTrace={e} />
|
||||
{/await}
|
||||
{:else}
|
||||
<Placeholder emoji="🍂">
|
||||
<div slot="title">No activity</div>
|
||||
<div slot="body">No activity on this patch yet</div>
|
||||
</Placeholder>
|
||||
{/each}
|
||||
{#each timelineTuple as [revision, timelines], index}
|
||||
{@const previousRevision =
|
||||
index > 0 ? patch.revisions[index - 1] : undefined}
|
||||
<RevisionComponent
|
||||
{baseUrl}
|
||||
{projectId}
|
||||
{timelines}
|
||||
{projectDefaultBranch}
|
||||
{projectHead}
|
||||
{...revision}
|
||||
on:reply={createReply}
|
||||
patchId={patch.id}
|
||||
authorId={patch.author.id}
|
||||
expanded={index === patch.revisions.length - 1}
|
||||
previousRevId={previousRevision?.id}
|
||||
previousRevOid={previousRevision?.oid} />
|
||||
{:else}
|
||||
<Placeholder emoji="🍂">
|
||||
<div slot="title">No activity</div>
|
||||
<div slot="body">No activity on this patch yet</div>
|
||||
</Placeholder>
|
||||
{/each}
|
||||
{/if}
|
||||
{:else if currentTab === "commits"}
|
||||
{#await api.project.getDiff(projectId, currentRevision.base, currentRevision.oid) then diff}
|
||||
<div class="commit-list">
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
$: patchTabFilter =
|
||||
(searchParams.get("tab") as "activity" | "commits" | "files") || "activity";
|
||||
$: patchFilter = (searchParams.get("state") as PatchStatus) || "open";
|
||||
$: patchDiffFilter = searchParams.get("diff") || undefined;
|
||||
$: baseUrl = utils.extractBaseUrl(activeRoute.params.hostnamePort);
|
||||
$: api = new HttpdClient(baseUrl);
|
||||
|
||||
@@ -271,10 +272,12 @@
|
||||
{patch}
|
||||
{baseUrl}
|
||||
projectId={project.id}
|
||||
projectDefaultBranch={project.defaultBranch}
|
||||
projectHead={project.head}
|
||||
revision={activeRoute.params.view.params.revision ??
|
||||
latestRevision.id}
|
||||
currentTab={patchTabFilter} />
|
||||
currentTab={patchTabFilter}
|
||||
diff={patchDiffFilter} />
|
||||
{:catch e}
|
||||
<div class="message">
|
||||
<ErrorMessage message="Couldn't load patch." stackTrace={e} />
|
||||
|
||||
Reference in New Issue
Block a user