Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
djbarnwal committed Jan 3, 2025
1 parent 9242858 commit 68673a2
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 90 deletions.
2 changes: 1 addition & 1 deletion web-common/src/features/canvas/components/charts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface ChartConfig {
export type ChartType = "line_chart" | "bar_chart" | "stacked_bar";

export interface ChartMetadata {
id: ChartType;
type: ChartType;
icon: ComponentType<SvelteComponent>;
title: string;
}
6 changes: 3 additions & 3 deletions web-common/src/features/canvas/components/charts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function generateSpec(
}

export const chartMetadata: ChartMetadata[] = [
{ id: "line_chart", title: "Line", icon: LineChart },
{ id: "bar_chart", title: "Bar", icon: BarChart },
{ id: "stacked_bar", title: "Stacked Bar", icon: StackedBar },
{ type: "line_chart", title: "Line", icon: LineChart },
{ type: "bar_chart", title: "Bar", icon: BarChart },
{ type: "stacked_bar", title: "Stacked Bar", icon: StackedBar },
];
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
export let component: CanvasComponentObj;
async function selectChartType(chartType: ChartMetadata) {
component.updateChartType(chartType.id);
component.updateChartType(chartType.type);
}
</script>

Expand All @@ -26,7 +26,7 @@
square
small
type="secondary"
selected={componentType === chart.id}
selected={componentType === chart.type}
on:click={() => selectChartType(chart)}
>
<svelte:component this={chart.icon} size="20px" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script lang="ts">
import { createCanvasStateSync } from "@rilldata/web-common/features/canvas/stores/syncCanvasState";
import DelayedSpinner from "@rilldata/web-common/features/entity-management/DelayedSpinner.svelte";
import { useQueryClient } from "@tanstack/svelte-query";
import { setContext } from "svelte";
import { createStateManagers, DEFAULT_STORE_KEY } from "./state-managers";
Expand All @@ -11,7 +13,15 @@
canvasName,
});
const canvasStoreReady = createCanvasStateSync(canvasName);
setContext(DEFAULT_STORE_KEY, stateManagers);
</script>

<slot />
{#if canvasStoreReady.isFetching}
<div class="grid place-items-center size-full">
<DelayedSpinner isLoading={canvasStoreReady.isFetching} size="40px" />
</div>
{:else}
<slot />
{/if}
15 changes: 0 additions & 15 deletions web-common/src/features/canvas/stores/CanvasStateProvider.svelte

This file was deleted.

5 changes: 1 addition & 4 deletions web-common/src/features/canvas/stores/syncCanvasState.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import type { StateManagers } from "@rilldata/web-common/features/canvas/state-managers/state-managers";
import { canvasEntities } from "@rilldata/web-common/features/canvas/stores/canvas-entities";
import { get } from "svelte/store";

export function createCanvasStateSync(ctx: StateManagers) {
const canvasName = get(ctx.canvasName);
export function createCanvasStateSync(canvasName: string) {
if (canvasEntities.hasCanvas(canvasName)) {
// TODO: Add sync method if required
return { isFetching: false, error: false };
Expand Down
105 changes: 51 additions & 54 deletions web-common/src/features/workspaces/CanvasWorkspace.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import VisualCanvasEditing from "@rilldata/web-common/features/canvas/inspector/VisualCanvasEditing.svelte";
import { useDefaultMetrics } from "@rilldata/web-common/features/canvas/selector";
import StateManagersProvider from "@rilldata/web-common/features/canvas/state-managers/StateManagersProvider.svelte";
import CanvasStateProvider from "@rilldata/web-common/features/canvas/stores/CanvasStateProvider.svelte";
import DelayedSpinner from "@rilldata/web-common/features/entity-management/DelayedSpinner.svelte";
import { getNameFromFile } from "@rilldata/web-common/features/entity-management/entity-mappers";
import type { FileArtifact } from "@rilldata/web-common/features/entity-management/file-artifact";
Expand Down Expand Up @@ -127,62 +126,60 @@
{#if canvasResource && fileArtifact}
{#key canvasName}
<StateManagersProvider {canvasName}>
<CanvasStateProvider>
<CanvasThemeProvider>
<WorkspaceContainer>
<WorkspaceHeader
slot="header"
{filePath}
hasUnsavedChanges={$hasUnsavedChanges}
titleInput={fileName}
onTitleChange={onChangeCallback}
resourceKind={ResourceKind.Canvas}
>
<div class="flex gap-x-2" slot="cta">
<PreviewButton
href="/canvas/{canvasName}"
disabled={allErrors.length > 0 || resourceIsReconciling}
reconciling={resourceIsReconciling}
<CanvasThemeProvider>
<WorkspaceContainer>
<WorkspaceHeader
slot="header"
{filePath}
hasUnsavedChanges={$hasUnsavedChanges}
titleInput={fileName}
onTitleChange={onChangeCallback}
resourceKind={ResourceKind.Canvas}
>
<div class="flex gap-x-2" slot="cta">
<PreviewButton
href="/canvas/{canvasName}"
disabled={allErrors.length > 0 || resourceIsReconciling}
reconciling={resourceIsReconciling}
/>

<AddComponentMenu {addComponent} />
<ViewSelector
allowSplit={false}
bind:selectedView={$selectedViewStore}
/>
</div>
</WorkspaceHeader>

<WorkspaceEditorContainer
slot="body"
error={mainError}
showError={!!$remoteContent && selectedView === "code"}
>
{#if selectedView === "code"}
<CanvasEditor
bind:autoSave={$autoSave}
{canvasName}
{fileArtifact}
{lineBasedRuntimeErrors}
/>
{:else if selectedView === "viz"}
{#if mainError}
<ErrorPage
body={mainError.message}
fatal
header="Unable to load dashboard preview"
statusCode={404}
/>

<AddComponentMenu {addComponent} />
<ViewSelector
allowSplit={false}
bind:selectedView={$selectedViewStore}
/>
</div>
</WorkspaceHeader>

<WorkspaceEditorContainer
slot="body"
error={mainError}
showError={!!$remoteContent && selectedView === "code"}
>
{#if selectedView === "code"}
<CanvasEditor
bind:autoSave={$autoSave}
{canvasName}
{fileArtifact}
{lineBasedRuntimeErrors}
/>
{:else if selectedView === "viz"}
{#if mainError}
<ErrorPage
body={mainError.message}
fatal
header="Unable to load dashboard preview"
statusCode={404}
/>
{:else if canvasResource}
<Canvas {fileArtifact} />
{/if}
{:else if canvasResource}
<Canvas {fileArtifact} />
{/if}
</WorkspaceEditorContainer>
{/if}
</WorkspaceEditorContainer>

<VisualCanvasEditing {fileArtifact} slot="inspector" />
</WorkspaceContainer>
</CanvasThemeProvider>
</CanvasStateProvider>
<VisualCanvasEditing {fileArtifact} slot="inspector" />
</WorkspaceContainer>
</CanvasThemeProvider>
</StateManagersProvider>
{/key}
{:else if allErrors.length}
Expand Down
17 changes: 7 additions & 10 deletions web-local/src/routes/(viz)/canvas/[name]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import CanvasDashboardEmbed from "@rilldata/web-common/features/canvas/CanvasDashboardEmbed.svelte";
import CanvasThemeProvider from "@rilldata/web-common/features/canvas/CanvasThemeProvider.svelte";
import StateManagersProvider from "@rilldata/web-common/features/canvas/state-managers/StateManagersProvider.svelte";
import CanvasStateProvider from "@rilldata/web-common/features/canvas/stores/CanvasStateProvider.svelte";
import type { PageData } from "./$types";
export let data: PageData;
Expand All @@ -13,13 +12,11 @@
</script>

<StateManagersProvider {canvasName}>
<CanvasStateProvider>
<CanvasThemeProvider>
<CanvasDashboardEmbed
items={data.dashboard.spec?.items || []}
{columns}
{gap}
/>
</CanvasThemeProvider>
</CanvasStateProvider>
<CanvasThemeProvider>
<CanvasDashboardEmbed
items={data.dashboard.spec?.items || []}
{columns}
{gap}
/>
</CanvasThemeProvider>
</StateManagersProvider>

0 comments on commit 68673a2

Please sign in to comment.