Skip to content

Commit

Permalink
Update file artifact references
Browse files Browse the repository at this point in the history
  • Loading branch information
djbarnwal committed Dec 20, 2024
1 parent 40d5875 commit eb5bcb9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 61 deletions.
16 changes: 10 additions & 6 deletions web-common/src/features/canvas/Canvas.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
$: ({
saveLocalContent: updateComponentFile,
autoSave,
updateLocalContent,
localContent,
updateEditorContent,
editorContent,
remoteContent,
} = fileArtifact);
Expand All @@ -43,12 +43,14 @@
}
async function deleteComponent(index: number) {
const parsedDocument = parseDocument($localContent ?? $remoteContent ?? "");
const parsedDocument = parseDocument(
$editorContent ?? $remoteContent ?? "",
);
const items = parsedDocument.get("items") as any;
if (!items) return;
items.delete(index);
updateLocalContent(parsedDocument.toString(), true);
updateEditorContent(parsedDocument.toString(), true);
if ($autoSave) await updateComponentFile();
}
Expand All @@ -59,7 +61,9 @@
dimensions: Vector;
}>,
) {
const parsedDocument = parseDocument($localContent ?? $remoteContent ?? "");
const parsedDocument = parseDocument(
$editorContent ?? $remoteContent ?? "",
);
const items = parsedDocument.get("items") as any;
const node = items.get(e.detail.index);
Expand All @@ -69,7 +73,7 @@
node.set("x", e.detail.position[0]);
node.set("y", e.detail.position[1]);
updateLocalContent(parsedDocument.toString(), true);
updateEditorContent(parsedDocument.toString(), true);
if ($autoSave) await updateComponentFile();
}
Expand Down
47 changes: 2 additions & 45 deletions web-common/src/features/canvas/components/AddComponentMenu.svelte
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
<script lang="ts">
import Button from "@rilldata/web-common/components/button/Button.svelte";
import * as DropdownMenu from "@rilldata/web-common/components/dropdown-menu";
import Search from "@rilldata/web-common/components/search/Search.svelte";
import {
ResourceKind,
useClientFilteredResources,
} from "@rilldata/web-common/features/entity-management/resource-selectors";
import { ResourceKind } from "@rilldata/web-common/features/entity-management/resource-selectors";
import { ChevronDown, Plus } from "lucide-svelte";
import { runtime } from "../../../runtime-client/runtime-store";
import { getNameFromFile } from "../../entity-management/entity-mappers";
// import { featureFlags } from "../feature-flags";
import Button from "@rilldata/web-common/components/button/Button.svelte";
import { createResourceFile } from "../../file-explorer/new-files";
// const { ai } = featureFlags;
export let addComponent: (componentName: string) => void;
let open = false;
let value = "";
// We want to get only valid components here. Hence using ListResources API
$: componentsQuery = useClientFilteredResources(
$runtime.instanceId,
ResourceKind.Component,
);
$: componentFileNames =
$componentsQuery.data
?.filter((c) => !c.component?.spec?.definedInCanvas)
.map((c) => c.meta?.name?.name ?? "") ?? [];
async function handleAddComponent() {
const newFilePath = await createResourceFile(ResourceKind.Component);
Expand All @@ -54,33 +35,9 @@
</DropdownMenu.Trigger>
<DropdownMenu.Content class="flex flex-col gap-y-1 ">
<DropdownMenu.Group>
<!-- <DropdownMenu.Item disabled>
Generate chart
{#if $ai}
with AI
<WandIcon class="w-3 h-3" />
{/if}
</DropdownMenu.Item> -->
<DropdownMenu.Item on:click={handleAddComponent}>
Create new component
</DropdownMenu.Item>
</DropdownMenu.Group>

<DropdownMenu.Separator />
<div class="px-1">
<Search bind:value />
</div>
<DropdownMenu.Separator />

<DropdownMenu.Label class="text-[11px] text-gray-500 py-0">
EXISTING COMPONENTS
</DropdownMenu.Label>
<DropdownMenu.Group>
{#each componentFileNames.filter( (n) => n.startsWith(value), ) as componentName (componentName)}
<DropdownMenu.Item on:click={() => addComponent(componentName)}>
{componentName}
</DropdownMenu.Item>
{/each}
</DropdownMenu.Group>
</DropdownMenu.Content>
</DropdownMenu.Root>
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
const { validSpecStore, canvasStore } = getCanvasStateManagers();
$: ({ localContent, remoteContent, saveContent, path } = fileArtifact);
$: ({ editorContent, remoteContent, saveContent, path } = fileArtifact);
$: parsedDocument = parseDocument($localContent ?? $remoteContent ?? "");
$: parsedDocument = parseDocument($editorContent ?? $remoteContent ?? "");
$: selectedComponentIndex = $canvasStore.selectedComponentIndex;
$: selectedComponentName =
Expand Down
4 changes: 2 additions & 2 deletions web-common/src/features/canvas/inspector/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export const useAllSimpleMeasureFromMetric = (
);

export function getParsedDocument(fileArtifact: FileArtifact) {
const { localContent, remoteContent } = fileArtifact;
const { editorContent, remoteContent } = fileArtifact;
return derived(
[localContent, remoteContent],
[editorContent, remoteContent],
([$localContent, $remoteContent]) => {
return parseDocument($localContent ?? $remoteContent ?? "");
},
Expand Down
12 changes: 6 additions & 6 deletions web-common/src/features/workspaces/CanvasWorkspace.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import WorkspaceEditorContainer from "@rilldata/web-common/layout/workspace/WorkspaceEditorContainer.svelte";
import { queryClient } from "@rilldata/web-common/lib/svelte-query/globalQueryClient";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
import { setContext } from "svelte";
import { parseDocument } from "yaml";
import PreviewButton from "../explores/PreviewButton.svelte";
Expand All @@ -40,8 +39,8 @@
autoSave,
path: filePath,
fileName,
updateLocalContent,
localContent,
updateEditorContent,
editorContent,
getResource,
getAllErrors,
remoteContent,
Expand All @@ -64,7 +63,6 @@
$: canvasResource = data?.canvas;
$: canvasName = getNameFromFile(filePath);
$: setContext("rill::canvas:name", canvasName);
$: ({ instanceId } = $runtime);
Expand Down Expand Up @@ -93,7 +91,9 @@
x: 0,
y: 0,
};
const parsedDocument = parseDocument($localContent ?? $remoteContent ?? "");
const parsedDocument = parseDocument(
$editorContent ?? $remoteContent ?? "",
);
const items = parsedDocument.get("items") as any;
Expand All @@ -103,7 +103,7 @@
items.add(newComponent);
}
updateLocalContent(parsedDocument.toString(), true);
updateEditorContent(parsedDocument.toString(), true);
if ($autoSave) await updateComponentFile();
}
Expand Down

0 comments on commit eb5bcb9

Please sign in to comment.