Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cd: enable add chart button #5037

Merged
merged 6 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions web-common/src/features/custom-dashboards/AddChartMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";

Expand All @@ -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);
}
}
</script>

<DropdownMenu.Root bind:open typeahead={false}>
Expand All @@ -37,30 +52,30 @@
</DropdownMenu.Trigger>
<DropdownMenu.Content class="flex flex-col gap-y-1 ">
<DropdownMenu.Group>
<DropdownMenu.Item disabled>
<!-- <DropdownMenu.Item disabled>
Generate chart
{#if $ai}
with AI
<WandIcon class="w-3 h-3" />
{/if}
</DropdownMenu.Item> -->
<DropdownMenu.Item on:click={handleAddChart}>
Create new chart
</DropdownMenu.Item>
<DropdownMenu.Item disabled>Create new chart</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 CHARTS
</DropdownMenu.Label>
<DropdownMenu.Group>
{#each chartFileNames.filter( (n) => n.startsWith(value), ) as chartName (chartName)}
<DropdownMenu.Item
on:click={() => {
dispatch("add-chart", { chartName });
}}
>
<DropdownMenu.Item on:click={() => addChart(chartName)}>
{chartName}
</DropdownMenu.Item>
{/each}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -233,7 +233,7 @@
</div>
{/if}

<AddChartMenu on:add-chart={addChart} />
<AddChartMenu {addChart} />

<PreviewButton
dashboardName={customDashboardName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
$: instanceId = $runtime.instanceId;
$: initLocalUserPreferenceStore(metricViewName);
$: isModelingSupportedQuery = canModel(instanceId);
$: isModelingSupported = $isModelingSupportedQuery.data;
$: isModelingSupported = $isModelingSupportedQuery;

$: fileQuery = createRuntimeServiceGetFile(
instanceId,
Expand Down
Loading