From cd56e295f397d28cb46168471840fa4f65403a95 Mon Sep 17 00:00:00 2001 From: Eric P Green Date: Tue, 16 Apr 2024 14:06:10 -0700 Subject: [PATCH] Cloud UI: Surface Custom Dashboards in navigation (#4531) * WIP commit * Fix lint * Use TanStack Query client to fetch chart data * TODO: render a "read-only" version of the dashboard * Utils to differentiate between Metrics Explorer and Custom Dashboard pages * Show both Metrics Explorers and Custom Dashboards in the breadcrumb * Remove console log * Add wrongly-detected TS error to whitelist * Small clean-up * Fix merge * Remove unused component --- scripts/tsc-with-whitelist.sh | 1 + .../dashboards/listing/DashboardsTable.svelte | 30 ++++++++--- .../DashboardsTableCompositeCell.svelte | 18 +++++-- .../dashboards/listing/NoDashboardsCTA.svelte | 4 +- .../features/dashboards/listing/selectors.ts | 11 ++-- .../embeds/TopNavigationBarEmbed.svelte | 2 +- web-admin/src/features/errors/error-utils.ts | 10 ++-- .../navigation/TopNavigationBar.svelte | 44 ++++++++------- .../src/features/navigation/nav-utils.ts | 15 +++++- web-admin/src/routes/+layout.svelte | 12 +++-- .../[project]/-/dashboards/+page.ts | 6 +++ .../-/dashboards/[dashboard]/+page.svelte | 11 ++++ .../__stories__/DropdownMenu.stories.svelte | 6 +-- .../icons/CustomDashboardIcon.svelte | 53 +++++++++++++++++++ ...Icon.svelte => MetricsExplorerIcon.svelte} | 0 .../breadcrumbs/BreadcrumbItem.svelte | 6 +-- .../features/custom-dashboards/Chart.svelte | 7 ++- .../src/features/dashboards/selectors.ts | 18 +++++++ .../resource-icon-mapping.ts | 7 +-- 19 files changed, 200 insertions(+), 61 deletions(-) mode change 100644 => 100755 scripts/tsc-with-whitelist.sh create mode 100644 web-admin/src/routes/[organization]/[project]/-/dashboards/+page.ts create mode 100644 web-admin/src/routes/[organization]/[project]/-/dashboards/[dashboard]/+page.svelte create mode 100644 web-common/src/components/icons/CustomDashboardIcon.svelte rename web-common/src/components/icons/{DashboardIcon.svelte => MetricsExplorerIcon.svelte} (100%) diff --git a/scripts/tsc-with-whitelist.sh b/scripts/tsc-with-whitelist.sh old mode 100644 new mode 100755 index 3fcbb4455d60..545d845059d1 --- a/scripts/tsc-with-whitelist.sh +++ b/scripts/tsc-with-whitelist.sh @@ -19,6 +19,7 @@ web-admin/src/features/scheduled-reports/selectors.ts: error TS2345 web-admin/src/features/view-as-user/clearViewedAsUser.ts: error TS18047 web-admin/src/features/view-as-user/clearViewedAsUser.ts: error TS2322 web-admin/src/features/view-as-user/setViewedAsUser.ts: error TS2322 +web-admin/src/routes/[organization]/[project]/-/dashboards/+page.ts: error TS2307 web-common/src/components/button-group/ButtonGroup.spec.ts: error TS2345 web-common/src/components/data-graphic/actions/mouse-position-to-domain-action-factory.ts: error TS2322 web-common/src/components/data-graphic/actions/outline.ts: error TS18047 diff --git a/web-admin/src/features/dashboards/listing/DashboardsTable.svelte b/web-admin/src/features/dashboards/listing/DashboardsTable.svelte index 6b9d3e889f45..0e23cb5f35ca 100644 --- a/web-admin/src/features/dashboards/listing/DashboardsTable.svelte +++ b/web-admin/src/features/dashboards/listing/DashboardsTable.svelte @@ -2,7 +2,7 @@ import Spinner from "@rilldata/web-common/features/entity-management/Spinner.svelte"; import { EntityStatus } from "@rilldata/web-common/features/entity-management/types"; import { runtime } from "@rilldata/web-common/runtime-client/runtime-store"; - import { type Row, flexRender } from "@tanstack/svelte-table"; + import { flexRender, type Row } from "@tanstack/svelte-table"; import { createEventDispatcher } from "svelte"; import Table from "../../../components/table/Table.svelte"; import DashboardsError from "./DashboardsError.svelte"; @@ -10,7 +10,7 @@ import DashboardsTableEmpty from "./DashboardsTableEmpty.svelte"; import DashboardsTableHeader from "./DashboardsTableHeader.svelte"; import NoDashboardsCTA from "./NoDashboardsCTA.svelte"; - import { type DashboardResource, useDashboardsV2 } from "./selectors"; + import { useDashboardsV2, type DashboardResource } from "./selectors"; export let isEmbedded = false; @@ -30,13 +30,27 @@ { id: "composite", cell: ({ row }) => { - const dashboard = row.original as DashboardResource; + const dashboardResource = row.original as DashboardResource; + const resource = dashboardResource.resource; + const refreshedOn = dashboardResource.refreshedOn; + const name = resource.meta.name.name; + + // If not a Metrics Explorer, it's a Custom Dashboard. + const isMetricsExplorer = !!resource?.metricsView; + const title = isMetricsExplorer + ? resource.metricsView.spec.title + : resource.dashboard.spec.title; + const description = isMetricsExplorer + ? resource.metricsView.spec.description + : ""; + return flexRender(DashboardsTableCompositeCell, { - name: dashboard.resource.meta.name.name, - title: dashboard.resource.metricsView.spec.title, - lastRefreshed: dashboard.refreshedOn, - description: dashboard.resource.metricsView.spec.description, - error: dashboard.resource.meta.reconcileError, + name, + title, + lastRefreshed: refreshedOn, + description, + error: resource.meta.reconcileError, + isMetricsExplorer, isEmbedded, }); }, diff --git a/web-admin/src/features/dashboards/listing/DashboardsTableCompositeCell.svelte b/web-admin/src/features/dashboards/listing/DashboardsTableCompositeCell.svelte index 4cc46c9b675d..88784891f672 100644 --- a/web-admin/src/features/dashboards/listing/DashboardsTableCompositeCell.svelte +++ b/web-admin/src/features/dashboards/listing/DashboardsTableCompositeCell.svelte @@ -1,6 +1,7 @@
- + {#if isMetricsExplorer} + + {:else} + + {/if}
diff --git a/web-admin/src/features/dashboards/listing/NoDashboardsCTA.svelte b/web-admin/src/features/dashboards/listing/NoDashboardsCTA.svelte index af8daa18cf4b..dc95282fdb0f 100644 --- a/web-admin/src/features/dashboards/listing/NoDashboardsCTA.svelte +++ b/web-admin/src/features/dashboards/listing/NoDashboardsCTA.svelte @@ -1,5 +1,5 @@
- +
{ - const dashboards = data.resources.filter((res) => res.metricsView); - return dashboards.map((db) => { - const refreshedOn = getDashboardRefreshedOn(db, data.resources); - return { resource: db, refreshedOn }; + // Filter for Metrics Explorers and Custom Dashboards + const resources = data.resources.filter( + (res) => res.metricsView || res.dashboard, + ); + return resources.map((resource) => { + const refreshedOn = getDashboardRefreshedOn(resource, data.resources); + return { resource, refreshedOn }; }); }, }, diff --git a/web-admin/src/features/embeds/TopNavigationBarEmbed.svelte b/web-admin/src/features/embeds/TopNavigationBarEmbed.svelte index 15784c52d2e8..0360d1812e5d 100644 --- a/web-admin/src/features/embeds/TopNavigationBarEmbed.svelte +++ b/web-admin/src/features/embeds/TopNavigationBarEmbed.svelte @@ -1,4 +1,5 @@ @@ -49,7 +49,9 @@ -
+
{#if !isEmbed} {/if} diff --git a/web-admin/src/routes/[organization]/[project]/-/dashboards/+page.ts b/web-admin/src/routes/[organization]/[project]/-/dashboards/+page.ts new file mode 100644 index 000000000000..882f18af5204 --- /dev/null +++ b/web-admin/src/routes/[organization]/[project]/-/dashboards/+page.ts @@ -0,0 +1,6 @@ +import { redirect } from "@sveltejs/kit"; +import type { PageLoad } from "./$types"; + +export const load: PageLoad = ({ params }) => { + throw redirect(307, `/${params.organization}/${params.project}`); +}; diff --git a/web-admin/src/routes/[organization]/[project]/-/dashboards/[dashboard]/+page.svelte b/web-admin/src/routes/[organization]/[project]/-/dashboards/[dashboard]/+page.svelte new file mode 100644 index 000000000000..f4a77f108107 --- /dev/null +++ b/web-admin/src/routes/[organization]/[project]/-/dashboards/[dashboard]/+page.svelte @@ -0,0 +1,11 @@ + + +
+ A "read-only" version of the Custom Dashboard named {customDashboardName} goes here. +
diff --git a/web-common/src/components/dropdown-menu/__stories__/DropdownMenu.stories.svelte b/web-common/src/components/dropdown-menu/__stories__/DropdownMenu.stories.svelte index c6c290391a22..da5e40ef487d 100644 --- a/web-common/src/components/dropdown-menu/__stories__/DropdownMenu.stories.svelte +++ b/web-common/src/components/dropdown-menu/__stories__/DropdownMenu.stories.svelte @@ -2,9 +2,9 @@ import { Meta, Story } from "@storybook/addon-svelte-csf"; import * as DropdownMenu from ".."; - import CopyIcon from "../../icons/CopyIcon.svelte"; - import DashboardIcon from "../../icons/DashboardIcon.svelte"; import Button from "@rilldata/web-common/components/button/Button.svelte"; + import CopyIcon from "../../icons/CopyIcon.svelte"; + import MetricsExplorerIcon from "../../icons/MetricsExplorerIcon.svelte"; let subMenuOpen = false; @@ -34,7 +34,7 @@ Option 1 - + Option 2 diff --git a/web-common/src/components/icons/CustomDashboardIcon.svelte b/web-common/src/components/icons/CustomDashboardIcon.svelte new file mode 100644 index 000000000000..86bc1c15c789 --- /dev/null +++ b/web-common/src/components/icons/CustomDashboardIcon.svelte @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + diff --git a/web-common/src/components/icons/DashboardIcon.svelte b/web-common/src/components/icons/MetricsExplorerIcon.svelte similarity index 100% rename from web-common/src/components/icons/DashboardIcon.svelte rename to web-common/src/components/icons/MetricsExplorerIcon.svelte diff --git a/web-common/src/components/navigation/breadcrumbs/BreadcrumbItem.svelte b/web-common/src/components/navigation/breadcrumbs/BreadcrumbItem.svelte index 1a515a745366..2574a205ecc2 100644 --- a/web-common/src/components/navigation/breadcrumbs/BreadcrumbItem.svelte +++ b/web-common/src/components/navigation/breadcrumbs/BreadcrumbItem.svelte @@ -1,9 +1,9 @@