diff --git a/web-common/src/features/custom-dashboards/AddChartMenu.svelte b/web-common/src/features/custom-dashboards/AddChartMenu.svelte index d2fbcd306ab..b661d6d4f89 100644 --- a/web-common/src/features/custom-dashboards/AddChartMenu.svelte +++ b/web-common/src/features/custom-dashboards/AddChartMenu.svelte @@ -3,16 +3,19 @@ ResourceKind, useClientFilteredResources, } from "@rilldata/web-common/features/entity-management/resource-selectors"; - import { ChevronDown, Plus, WandIcon } from "lucide-svelte"; + import { ChevronDown, Plus } from "lucide-svelte"; import * as DropdownMenu from "@rilldata/web-common/components/dropdown-menu"; import { runtime } from "../../runtime-client/runtime-store"; - import { createEventDispatcher } from "svelte"; import Search from "@rilldata/web-common/components/search/Search.svelte"; - import { featureFlags } from "../feature-flags"; + import { getNameFromFile } from "../entity-management/entity-mappers"; + // import { featureFlags } from "../feature-flags"; import Button from "@rilldata/web-common/components/button/Button.svelte"; + import { handleEntityCreate } from "../file-explorer/new-files"; + + // const { ai } = featureFlags; + + export let addChart: (chartName: string) => void; - const { ai } = featureFlags; - const dispatch = createEventDispatcher(); let open = false; let value = ""; @@ -23,6 +26,18 @@ ); $: chartFileNames = $chartsQuery.data?.map((c) => c.meta?.name?.name ?? "") ?? []; + + async function handleAddChart() { + const newRoute = await handleEntityCreate(ResourceKind.Component); + + if (!newRoute) return; + + const chartName = getNameFromFile(newRoute); + + if (chartName) { + addChart(chartName); + } + } @@ -37,30 +52,30 @@ - + + + Create new chart - Create new chart +
+ EXISTING CHARTS {#each chartFileNames.filter( (n) => n.startsWith(value), ) as chartName (chartName)} - { - dispatch("add-chart", { chartName }); - }} - > + addChart(chartName)}> {chartName} {/each} diff --git a/web-local/src/routes/(application)/custom-dashboards/[name]/+page.svelte b/web-local/src/routes/(application)/custom-dashboards/[name]/+page.svelte index 746bc7f834b..936da31f5ae 100644 --- a/web-local/src/routes/(application)/custom-dashboards/[name]/+page.svelte +++ b/web-local/src/routes/(application)/custom-dashboards/[name]/+page.svelte @@ -162,9 +162,9 @@ await updateChartFile(new CustomEvent("update", { detail: yaml })); } - async function addChart(e: CustomEvent<{ chartName: string }>) { + async function addChart(chartName: string) { const newChart = { - component: e.detail.chartName, + component: chartName, height: 4, width: 4, x: 0, @@ -233,7 +233,7 @@ {/if} - +