Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Thomas G. Lopes
commited on
Commit
·
a792a8e
1
Parent(s):
0c94929
cleanup branch tree
Browse files
src/lib/components/inference-playground/branch-tree-modal.svelte
CHANGED
|
@@ -1,14 +1,13 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
-
import { clickOutside } from "$lib/attachments/click-outside.js";
|
| 3 |
-
import { projects } from "$lib/state/projects.svelte";
|
| 4 |
import { conversations } from "$lib/state/conversations.svelte";
|
|
|
|
| 5 |
import { Popover, Tree, type TreeItem } from "melt/builders";
|
|
|
|
| 6 |
import IconBranch from "~icons/carbon/branch";
|
| 7 |
-
import IconTree from "~icons/carbon/tree-view";
|
| 8 |
-
import IconLiteralTree from "~icons/carbon/tree";
|
| 9 |
import IconChevronDown from "~icons/carbon/chevron-down";
|
| 10 |
import IconChevronRight from "~icons/carbon/chevron-right";
|
| 11 |
-
import
|
|
|
|
| 12 |
|
| 13 |
interface ProjectTreeItem extends TreeItem {
|
| 14 |
id: string;
|
|
@@ -17,23 +16,16 @@
|
|
| 17 |
children?: ProjectTreeItem[];
|
| 18 |
}
|
| 19 |
|
| 20 |
-
const popover = new Popover({
|
| 21 |
-
floatingConfig: {
|
| 22 |
-
offset: { crossAxis: -12 },
|
| 23 |
-
},
|
| 24 |
-
onOpenChange: open => {
|
| 25 |
-
if (open) dialog?.showModal();
|
| 26 |
-
else dialog?.close();
|
| 27 |
-
},
|
| 28 |
-
});
|
| 29 |
-
|
| 30 |
-
let dialog = $state<HTMLDialogElement>();
|
| 31 |
-
|
| 32 |
const treeItems = $derived.by((): ProjectTreeItem[] => {
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
const nodeMap = new SvelteMap<string, ProjectTreeItem>();
|
| 35 |
|
| 36 |
-
|
| 37 |
if (!nodeMap.has(project.id)) {
|
| 38 |
nodeMap.set(project.id, {
|
| 39 |
id: project.id,
|
|
@@ -46,7 +38,7 @@
|
|
| 46 |
|
| 47 |
const roots: ProjectTreeItem[] = [];
|
| 48 |
|
| 49 |
-
|
| 50 |
const node = nodeMap.get(project.id)!;
|
| 51 |
|
| 52 |
if (project.branchedFromId) {
|
|
@@ -86,6 +78,16 @@
|
|
| 86 |
expandOnClick: false,
|
| 87 |
});
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
function getBranchStats(projectId: string) {
|
| 90 |
const convs = conversations.for(projectId);
|
| 91 |
const totalMessages = convs.reduce((sum, c) => sum + (c.data.messages?.length || 0), 0);
|
|
@@ -100,10 +102,8 @@
|
|
| 100 |
{/if}
|
| 101 |
</button>
|
| 102 |
|
| 103 |
-
<
|
| 104 |
-
bind:this={dialog}
|
| 105 |
class="mb-2 !overflow-visible rounded-xl border border-gray-200 bg-white shadow-lg dark:border-gray-700 dark:bg-gray-800"
|
| 106 |
-
{@attach clickOutside(() => (popover.open = false))}
|
| 107 |
{...popover.content}
|
| 108 |
>
|
| 109 |
<div
|
|
@@ -128,7 +128,7 @@
|
|
| 128 |
</div>
|
| 129 |
{/if}
|
| 130 |
</div>
|
| 131 |
-
</
|
| 132 |
|
| 133 |
{#snippet treeNode(items: typeof tree.children)}
|
| 134 |
{#each items as item (item.id)}
|
|
|
|
| 1 |
<script lang="ts">
|
|
|
|
|
|
|
| 2 |
import { conversations } from "$lib/state/conversations.svelte";
|
| 3 |
+
import { projects } from "$lib/state/projects.svelte";
|
| 4 |
import { Popover, Tree, type TreeItem } from "melt/builders";
|
| 5 |
+
import { SvelteMap } from "svelte/reactivity";
|
| 6 |
import IconBranch from "~icons/carbon/branch";
|
|
|
|
|
|
|
| 7 |
import IconChevronDown from "~icons/carbon/chevron-down";
|
| 8 |
import IconChevronRight from "~icons/carbon/chevron-right";
|
| 9 |
+
import IconLiteralTree from "~icons/carbon/tree";
|
| 10 |
+
import IconTree from "~icons/carbon/tree-view";
|
| 11 |
|
| 12 |
interface ProjectTreeItem extends TreeItem {
|
| 13 |
id: string;
|
|
|
|
| 16 |
children?: ProjectTreeItem[];
|
| 17 |
}
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
const treeItems = $derived.by((): ProjectTreeItem[] => {
|
| 20 |
+
// Get the root of the current active project
|
| 21 |
+
const currentRoot = projects.getBranchRoot(projects.activeId);
|
| 22 |
+
if (!currentRoot) return [];
|
| 23 |
+
|
| 24 |
+
// Get all projects in this tree (same root)
|
| 25 |
+
const treeProjects = projects.getAllBranchesInTree(currentRoot.id);
|
| 26 |
const nodeMap = new SvelteMap<string, ProjectTreeItem>();
|
| 27 |
|
| 28 |
+
treeProjects.forEach(project => {
|
| 29 |
if (!nodeMap.has(project.id)) {
|
| 30 |
nodeMap.set(project.id, {
|
| 31 |
id: project.id,
|
|
|
|
| 38 |
|
| 39 |
const roots: ProjectTreeItem[] = [];
|
| 40 |
|
| 41 |
+
treeProjects.forEach(project => {
|
| 42 |
const node = nodeMap.get(project.id)!;
|
| 43 |
|
| 44 |
if (project.branchedFromId) {
|
|
|
|
| 78 |
expandOnClick: false,
|
| 79 |
});
|
| 80 |
|
| 81 |
+
const popover = new Popover({
|
| 82 |
+
floatingConfig: {
|
| 83 |
+
offset: { crossAxis: -12 },
|
| 84 |
+
},
|
| 85 |
+
focus: {
|
| 86 |
+
onOpen: () => `#${contentId} [data-melt-tree-item][data-selected]`,
|
| 87 |
+
},
|
| 88 |
+
});
|
| 89 |
+
const contentId: string = $derived(popover.ids.content);
|
| 90 |
+
|
| 91 |
function getBranchStats(projectId: string) {
|
| 92 |
const convs = conversations.for(projectId);
|
| 93 |
const totalMessages = convs.reduce((sum, c) => sum + (c.data.messages?.length || 0), 0);
|
|
|
|
| 102 |
{/if}
|
| 103 |
</button>
|
| 104 |
|
| 105 |
+
<div
|
|
|
|
| 106 |
class="mb-2 !overflow-visible rounded-xl border border-gray-200 bg-white shadow-lg dark:border-gray-700 dark:bg-gray-800"
|
|
|
|
| 107 |
{...popover.content}
|
| 108 |
>
|
| 109 |
<div
|
|
|
|
| 128 |
</div>
|
| 129 |
{/if}
|
| 130 |
</div>
|
| 131 |
+
</div>
|
| 132 |
|
| 133 |
{#snippet treeNode(items: typeof tree.children)}
|
| 134 |
{#each items as item (item.id)}
|