Skip to content
This repository was archived by the owner on Aug 1, 2022. It is now read-only.

Commit 2b83393

Browse files
committed
Show file contents for created and deleted files
Signed-off-by: Rūdolfs Ošiņš <[email protected]>
1 parent 2924251 commit 2b83393

File tree

4 files changed

+71
-57
lines changed

4 files changed

+71
-57
lines changed

proxy-client/commit.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ export interface CopiedFile {
8181
oldPath: string;
8282
}
8383

84+
export interface CreatedFile {
85+
diff: FileDiff;
86+
path: string;
87+
}
88+
89+
export interface DeletedFile {
90+
diff: FileDiff;
91+
path: string;
92+
}
93+
8494
export interface ModifiedFile {
8595
diff: FileDiff;
8696
path: string;
@@ -93,8 +103,8 @@ export interface MovedFile {
93103

94104
export interface Diff {
95105
copied: CopiedFile[];
96-
created: string[];
97-
deleted: string[];
106+
created: CreatedFile[];
107+
deleted: DeletedFile[];
98108
modified: ModifiedFile[];
99109
moved: MovedFile[];
100110
}
@@ -106,8 +116,8 @@ const diffSchema: zod.Schema<Diff> = zod.object({
106116
oldPath: zod.string(),
107117
})
108118
),
109-
created: zod.array(zod.string()),
110-
deleted: zod.array(zod.string()),
119+
created: zod.array(zod.object({ path: zod.string(), diff: fileDiffSchema })),
120+
deleted: zod.array(zod.object({ path: zod.string(), diff: fileDiffSchema })),
111121
modified: zod.array(
112122
zod.object({
113123
path: zod.string(),

ui/App/ProjectScreen/Source/SourceBrowser/Changeset.svelte

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@
88
<script lang="ts">
99
import type { Diff, CommitStats } from "proxy-client/commit";
1010
11-
import FileIcon from "design-system/icons/File.svelte";
12-
1311
import FileDiff from "./FileDiff.svelte";
1412
1513
export let diff: Diff;
1614
export let stats: CommitStats;
15+
16+
const changedFileCount: number =
17+
diff.modified.length + diff.created.length + diff.deleted.length;
18+
19+
function pluralize(word: string, count: number) {
20+
if (count > 1) {
21+
return `${count} ${word}s`;
22+
} else {
23+
return `${count} ${word}`;
24+
}
25+
}
1726
</script>
1827

1928
<style>
@@ -30,62 +39,30 @@
3039
.changeset-summary .deletions {
3140
color: var(--color-negative);
3241
}
33-
34-
.file-header {
35-
height: 3rem;
36-
display: flex;
37-
align-items: center;
38-
background: none;
39-
border-bottom: 1px solid var(--color-foreground-level-3);
40-
border-radius: 0;
41-
padding: 0.75rem;
42-
}
43-
44-
.file-header:last-child {
45-
border-bottom: none;
46-
margin-bottom: 1rem;
47-
}
48-
49-
.file-header .diff-type {
50-
margin-left: 1rem;
51-
padding: 0.25rem 0.5rem;
52-
border-radius: 0.25rem;
53-
}
54-
55-
.file-header .diff-type.created {
56-
color: var(--color-positive);
57-
background-color: var(--color-positive-level-1);
58-
}
59-
60-
.file-header .diff-type.deleted {
61-
color: var(--color-negative);
62-
background-color: var(--color-negative-level-1);
63-
}
6442
</style>
6543

6644
<div class="changeset-summary">
67-
{#if diff.modified.length > 0}
68-
<span class="typo-semi-bold"> {diff.modified.length} file(s) changed </span>
45+
{#if changedFileCount > 0}
46+
<span class="typo-semi-bold">
47+
{pluralize("file", changedFileCount)}
48+
changed
49+
</span>
6950
with
70-
<span class="additions typo-semi-bold"> {stats.additions} additions </span>
51+
<span class="additions typo-semi-bold">
52+
{pluralize("addition", stats.additions)}
53+
</span>
7154
and
72-
<span class="deletions typo-semi-bold"> {stats.deletions} deletions </span>
55+
<span class="deletions typo-semi-bold">
56+
{pluralize("deletion", stats.deletions)}
57+
</span>
7358
{/if}
7459
</div>
7560
<div>
76-
{#each diff.created as path (path)}
77-
<header class="file-header">
78-
<FileIcon style="margin-right: 8px;" />
79-
<p class="typo-text-bold">{path}</p>
80-
<span class="diff-type created">created</span>
81-
</header>
61+
{#each diff.created as created (created)}
62+
<FileDiff file={created} label="created" />
8263
{/each}
83-
{#each diff.deleted as path (path)}
84-
<header class="file-header">
85-
<FileIcon style="margin-right: 8px;" />
86-
<p class="typo-text-bold">{path}</p>
87-
<span class="diff-type deleted">deleted</span>
88-
</header>
64+
{#each diff.deleted as deleted (deleted)}
65+
<FileDiff file={deleted} label="deleted" />
8966
{/each}
9067
</div>
9168

ui/App/ProjectScreen/Source/SourceBrowser/FileDiff.svelte

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@
66
LICENSE file.
77
-->
88
<script lang="ts">
9-
import type { ModifiedFile } from "ui/src/source/diff";
9+
import type {
10+
ModifiedFile,
11+
CreatedFile,
12+
DeletedFile,
13+
} from "ui/src/source/diff";
1014
import { lineNumberL, lineNumberR, lineSign } from "ui/src/source/diff";
1115
1216
import ChevronDownIcon from "design-system/icons/ChevronDown.svelte";
1317
import ChevronRightIcon from "design-system/icons/ChevronRight.svelte";
1418
import FileIcon from "design-system/icons/File.svelte";
1519
16-
export let file: ModifiedFile;
20+
export let file: ModifiedFile | CreatedFile | DeletedFile;
21+
export let label: "created" | "deleted" | undefined = undefined;
1722
1823
let collapsed: boolean = false;
1924
</script>
@@ -107,6 +112,20 @@
107112
.collapse-button:hover :global(svg) {
108113
fill: var(--color-foreground-level-6);
109114
}
115+
.created {
116+
color: var(--color-positive);
117+
background-color: var(--color-positive-level-1);
118+
}
119+
120+
.deleted {
121+
color: var(--color-negative);
122+
background-color: var(--color-negative-level-1);
123+
}
124+
.diff-type {
125+
margin-left: 1rem;
126+
padding: 0.25rem 0.5rem;
127+
border-radius: 0.25rem;
128+
}
110129
</style>
111130

112131
<article class="changeset-file">
@@ -123,6 +142,12 @@
123142
</div>
124143
<FileIcon style="margin-right: 0.5rem;" />
125144
<p class="typo-text-bold">{file.path}</p>
145+
{#if label}
146+
<span
147+
class="diff-type"
148+
class:created={label === "created"}
149+
class:deleted={label === "deleted"}>{label}</span>
150+
{/if}
126151
</header>
127152
{#if !collapsed}
128153
<main>

ui/src/source/diff.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
// LICENSE file.
66

77
import {
8+
CreatedFile,
9+
DeletedFile,
10+
Diff,
811
LineDiff,
912
LineDiffType,
1013
ModifiedFile,
11-
Diff,
1214
} from "proxy-client/commit";
1315

14-
export type { ModifiedFile, Diff };
16+
export type { CreatedFile, DeletedFile, ModifiedFile, Diff };
1517

1618
export const lineNumberR = (line: LineDiff): string | number => {
1719
switch (line.type) {

0 commit comments

Comments
 (0)