remove commit group from the data hierarchy - its not needed

This commit is contained in:
Kiril Videlov 2023-06-14 14:19:36 +02:00 committed by Kiril Videlov
parent d0c2707cae
commit 0b394857ec
8 changed files with 886 additions and 1027 deletions

File diff suppressed because it is too large Load Diff

View File

@ -65,19 +65,19 @@ def process_pr(pr_number):
"hunks": hunks,
}
files.append(file_out)
commit = {
"id": "Commit:" + branch_name + ":" + pr_number,
"description": title,
"committedAt": updated_at,
"kind": "commit",
"files": files,
}
# commit = {
# "id": "Commit:" + branch_name + ":" + pr_number,
# "description": title,
# "committedAt": updated_at,
# "kind": "commit",
# "files": files,
# }
branch = {
"id": branch_name + ":" + pr_number,
"name": branch_name,
"active": True,
"kind": "branch",
"commits": [commit],
"files": files,
}
return branch

View File

@ -11,32 +11,26 @@ export const load: PageLoad = async () => {
);
// fix dates from the test data
test_branches.map((branch: Branch) =>
branch.commits.map((commit: any) => {
commit.committedAt = new Date(commit.committedAt);
commit.files = commit.files.map((file: File) => {
file.hunks = file.hunks.map((hunk: any) => {
hunk.modifiedAt = new Date(hunk.modifiedAt);
return hunk;
});
return file;
test_branches.map((branch: Branch) => {
branch.files = branch.files.map((file: File) => {
file.hunks = file.hunks.map((hunk: any) => {
hunk.modifiedAt = new Date(hunk.modifiedAt);
return hunk;
});
return file;
});
return commit;
})
);
return branch;
});
let branches = test_branches as Branch[];
branches = plainToInstance(
Branch,
branches.map((column) => ({
...column,
commits: column.commits.map((commit) => ({
...commit,
files: commit.files.map((file) => ({
...file,
hunks: file.hunks.sort((a, b) => b.modifiedAt.getTime() - a.modifiedAt.getTime())
}))
files: column.files.map((file) => ({
...file,
hunks: file.hunks.sort((a, b) => b.modifiedAt.getTime() - a.modifiedAt.getTime())
}))
}))
);

View File

@ -2,31 +2,26 @@
import { flip } from 'svelte/animate';
import { dndzone } from 'svelte-dnd-action';
import Lane from './BranchLane.svelte';
import { Branch, Commit, File, Hunk } from './types';
import { Branch, File, Hunk } from './types';
import type { DndEvent } from 'svelte-dnd-action/typings';
import { createBranch, createCommit, createFile } from './helpers';
import { createBranch, createFile } from './helpers';
export let branches: Branch[];
const flipDurationMs = 300;
function handleDndEvent(e: CustomEvent<DndEvent<Branch | Commit | File | Hunk>>) {
function handleDndEvent(e: CustomEvent<DndEvent<Branch | File | Hunk>>) {
const newItems = e.detail.items;
const branchItems = newItems.filter((item) => item instanceof Branch) as Branch[];
const hunkItems = newItems.filter((item) => item instanceof Hunk) as Hunk[];
for (const hunk of hunkItems) {
branchItems.push(createBranch(createCommit(createFile(hunk.filePath, hunk))));
branchItems.push(createBranch(createFile(hunk.filePath, hunk)));
}
const fileItems = newItems.filter((item) => item instanceof File) as File[];
for (const file of fileItems) {
branchItems.push(createBranch(createCommit(file)));
}
const commitItems = newItems.filter((item) => item instanceof Commit) as Commit[];
for (const commit of commitItems) {
branchItems.push(createBranch(commit));
branchItems.push(createBranch(file));
}
branches = branchItems.filter((commit) => commit.active);
@ -34,7 +29,7 @@
}
function handleEmpty() {
const emptyIndex = branches.findIndex((item) => !item.commits || item.commits.length == 0);
const emptyIndex = branches.findIndex((item) => !item.files || item.files.length == 0);
if (emptyIndex != -1) {
// TODO: Figure out what to do when a branch is empty. Just removing it is a bit jarring.
}
@ -52,12 +47,12 @@
on:consider={handleDndEvent}
on:finalize={handleDndEvent}
>
{#each branches.filter((c) => c.active) as { id, name, commits } (id)}
{#each branches.filter((c) => c.active) as { id, name, files } (id)}
<div
class="flex h-full w-96 border border-zinc-700 bg-zinc-900/50 p-4"
animate:flip={{ duration: flipDurationMs }}
>
<Lane {name} bind:commits on:empty={handleEmpty} />
<Lane {name} bind:files on:empty={handleEmpty} />
</div>
{/each}
</section>

View File

@ -2,44 +2,45 @@
import { flip } from 'svelte/animate';
import { dndzone } from 'svelte-dnd-action';
import type { DndEvent } from 'svelte-dnd-action/typings';
import { Commit, File, Hunk } from './types';
import CommitGroup from './CommitGroup.svelte';
import { File, Hunk } from './types';
import { createEventDispatcher } from 'svelte';
import { createCommit, createFile } from './helpers';
import { createFile } from './helpers';
import FileCard from './FileCard.svelte';
export let name: string;
export let commits: Commit[];
export let files: File[];
const flipDurationMs = 150;
const dispatch = createEventDispatcher();
function handleDndEvent(e: CustomEvent<DndEvent<Commit | File | Hunk>>) {
function handleDndEvent(e: CustomEvent<DndEvent<File | Hunk>>) {
const newItems = e.detail.items;
const commitItems = newItems.filter((item) => item instanceof Commit) as Commit[];
const fileItems = newItems.filter((item) => item instanceof File) as File[];
const hunkItems = newItems.filter((item) => item instanceof Hunk) as Hunk[];
for (const hunk of hunkItems) {
commitItems.push(createCommit(createFile(hunk.filePath, hunk)));
const file = fileItems.find((file) => file.path == hunk.filePath);
if (file) {
file.hunks.push(hunk);
} else {
fileItems.push(createFile(hunk.filePath, hunk));
}
}
const fileItems = newItems.filter((item) => item instanceof File) as File[];
for (const file of fileItems) {
commitItems.push(createCommit(file));
}
files = fileItems.filter((file) => file.hunks && file.hunks.length > 0);
commits = commitItems.filter((commit) => commit.files && commit.files.length > 0);
if (e.type == 'finalize' && (!commits || commits.length == 0)) {
if (e.type == 'finalize' && (!files || files.length == 0)) {
dispatch('empty');
return;
}
}
function handleEmpty() {
const emptyIndex = commits.findIndex((item) => !item.files || item.files.length == 0);
const emptyIndex = files.findIndex((item) => !item.hunks || item.hunks.length == 0);
if (emptyIndex != -1) {
commits.splice(emptyIndex, 1);
files.splice(emptyIndex, 1);
}
if (commits.length == 0) {
if (files.length == 0) {
dispatch('empty');
}
}
@ -50,20 +51,20 @@
{name}
</div>
<div
class="flex flex-grow flex-col gap-y-4 overflow-x-hidden overflow-y-scroll"
class="flex w-full flex-grow flex-col gap-y-2 overflow-x-hidden overflow-y-scroll"
use:dndzone={{
items: commits,
items: files,
flipDurationMs,
zoneTabIndex: -1,
types: ['commit'],
receives: ['commit', 'file', 'hunk']
types: ['file'],
receives: ['file', 'hunk']
}}
on:consider={handleDndEvent}
on:finalize={handleDndEvent}
>
{#each commits.filter((x) => x.files) as { id, description, files }, idx (id)}
{#each files.filter((x) => x.hunks) as file, idx (file.id)}
<div class="w-full" animate:flip={{ duration: flipDurationMs }}>
<CommitGroup {id} bind:description bind:files on:empty={handleEmpty} />
<FileCard bind:file on:empty={handleEmpty} />
</div>
{/each}
</div>

View File

@ -1,73 +0,0 @@
<script lang="ts">
import { flip } from 'svelte/animate';
import { dndzone } from 'svelte-dnd-action';
import type { DndEvent } from 'svelte-dnd-action/typings';
import { File, Hunk } from './types';
import FileCard from './FileCard.svelte';
import { createEventDispatcher } from 'svelte';
import { createFile } from './helpers';
export let description: string | undefined;
export let id: string;
export let files: File[];
const flipDurationMs = 150;
const dispatch = createEventDispatcher();
function handleDndEvent(e: CustomEvent<DndEvent<File | Hunk>>) {
const newItems = e.detail.items;
const fileItems = newItems.filter((item) => item instanceof File) as File[];
const hunkItems = newItems.filter((item) => item instanceof Hunk) as Hunk[];
for (const hunk of hunkItems) {
const file = fileItems.find((file) => file.path == hunk.filePath);
if (file) {
file.hunks.push(hunk);
} else {
fileItems.push(createFile(hunk.filePath, hunk));
}
}
files = fileItems.filter((file) => file.hunks && file.hunks.length > 0);
if (e.type == 'finalize' && (!files || files.length == 0)) {
dispatch('empty');
return;
}
}
function handleEmpty() {
const emptyIndex = files.findIndex((item) => !item.hunks || item.hunks.length == 0);
if (emptyIndex != -1) {
files.splice(emptyIndex, 1);
}
if (files.length == 0) {
dispatch('empty');
}
}
</script>
<div class="flex w-full flex-col gap-y-2 border border-zinc-700 bg-zinc-900/70 p-2">
<div
class="flex w-full flex-col gap-y-2"
id="commit-{id}"
use:dndzone={{
items: files,
flipDurationMs,
zoneTabIndex: -1,
types: ['file'],
receives: ['file', 'hunk']
}}
on:consider={handleDndEvent}
on:finalize={handleDndEvent}
>
{#each files.filter((x) => x.hunks) as file, idx (file.id)}
<div class="w-full" animate:flip={{ duration: flipDurationMs }}>
<FileCard bind:file on:empty={handleEmpty} />
</div>
{/each}
</div>
<div>
{description}
</div>
</div>

View File

@ -1,8 +1,7 @@
import { Branch, Commit, File, type Hunk } from './types';
import { Branch, File, type Hunk } from './types';
import { plainToInstance } from 'class-transformer';
let fileCounter = 0;
let commitCounter = 0;
let branchCounter = 0;
export function createFile(path: string, hunk: Hunk): File {
@ -15,23 +14,13 @@ export function createFile(path: string, hunk: Hunk): File {
});
}
export function createCommit(file: File): Commit {
commitCounter++;
return plainToInstance(Commit, {
id: `commit-${commitCounter}`,
description: `New commit # ${commitCounter}`,
kind: 'commit',
files: [file]
});
}
export function createBranch(commit: Commit): Branch {
export function createBranch(file: File): Branch {
branchCounter++;
return plainToInstance(Branch, {
id: `branch-${branchCounter}`,
name: `new branch ${branchCounter}`,
active: true,
kind: 'branch',
commits: [commit]
files: [file]
});
}

View File

@ -20,16 +20,9 @@ export class File extends DndItem {
hunks!: Hunk[];
}
export class Commit extends DndItem {
description?: string;
committedAt?: Date;
@Type(() => File)
files!: File[];
}
export class Branch extends DndItem {
name!: string;
active!: boolean;
@Type(() => Commit)
commits!: Commit[];
@Type(() => File)
files!: File[];
}