From ec1fccfb6205c330e3445655ceaecf18503eadca Mon Sep 17 00:00:00 2001 From: nichenqin Date: Thu, 5 Dec 2024 12:04:21 +0800 Subject: [PATCH] chore: view widget readonly --- .../blocks/aggregate/aggregate.svelte | 3 +- .../calendar-view-toolbar.svelte | 2 +- .../dashboard/dashboard-widget-table.gql | 33 ---------- .../blocks/dashboard/dashboard-widget.svelte | 24 ++++++-- .../blocks/dashboard/dashboard-widgets.svelte | 3 + .../blocks/share/share-calendar-view.svelte | 2 +- .../blocks/share/share-gallery-view.svelte | 2 +- .../blocks/share/share-grid-view.svelte | 2 +- .../blocks/share/share-kanban-view.svelte | 2 +- .../blocks/share/share-list-view.svelte | 2 +- .../blocks/share/share-pivot-view.svelte | 2 +- .../table-tools/share-table-tools.svelte | 2 +- .../blocks/table-tools/table-tools.svelte | 2 +- .../blocks/template/template-preview.svelte | 46 ++++++++++++++ .../view-widget/view-widget-button.svelte | 2 + .../view-widget/view-widget-sheet.svelte | 3 +- .../lib/components/blocks/view/view.svelte | 2 +- .../components/blocks/widget/widget.svelte | 60 ++++++++++--------- .../dashboards/[dashboardId]/+page.svelte | 48 +++++++-------- packages/dashboard/src/dashboard.factory.ts | 5 +- .../dashboard-layout.specification.ts | 12 +++- .../src/value-objects/dashboard-layout.vo.ts | 57 ++++++++++++++++++ .../src/value-objects/dashboard-widgets.vo.ts | 16 +++++ .../src/data-service.registery.ts | 3 + .../src/dashboard/dashboard.mutate-visitor.ts | 14 +++-- .../src/dashboard/dashboard.repository.ts | 1 + packages/table/package.json | 1 + packages/template/src/templates/hr.base.json | 16 +++++ 28 files changed, 254 insertions(+), 113 deletions(-) delete mode 100644 apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget-table.gql diff --git a/apps/frontend/src/lib/components/blocks/aggregate/aggregate.svelte b/apps/frontend/src/lib/components/blocks/aggregate/aggregate.svelte index 9c0a3f918..d4d78ec88 100644 --- a/apps/frontend/src/lib/components/blocks/aggregate/aggregate.svelte +++ b/apps/frontend/src/lib/components/blocks/aggregate/aggregate.svelte @@ -7,13 +7,14 @@ import { TriangleAlertIcon } from "lucide-svelte" import * as Tooltip from "$lib/components/ui/tooltip" import type { TableDo } from "@undb/table" - import { getDataService, getIsLocal } from "$lib/store/data-service.store" + import { getDataService, getIsLocal } from "$lib/store/data-service.store" export let tableId: string | undefined export let table: TableDo | undefined export let viewId: string | undefined export let shareId: string | undefined export let ignoreView: boolean = false + export let readonly = false export let widget: IWidgetDTO export let aggregate: IAggregate diff --git a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-toolbar.svelte b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-toolbar.svelte index 979cd5ac6..04be521f3 100644 --- a/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-toolbar.svelte +++ b/apps/frontend/src/lib/components/blocks/calendar-view/calendar-view-toolbar.svelte @@ -41,6 +41,6 @@ {/if} - + diff --git a/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget-table.gql b/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget-table.gql deleted file mode 100644 index 6e264a57b..000000000 --- a/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget-table.gql +++ /dev/null @@ -1,33 +0,0 @@ -query GetDashboardWidgetTable($tableId: ID!) { - table(id: $tableId) { - id - name - - base { - id - name - } - - schema { - id - name - type - defaultValue - display - constraint - option - metadata - } - - views { - id - name - type - filter - color - sort - aggregate - fields - } - } -} diff --git a/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget.svelte b/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget.svelte index c12a69a54..ac3e26e9c 100644 --- a/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget.svelte +++ b/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget.svelte @@ -1,28 +1,40 @@ - + diff --git a/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widgets.svelte b/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widgets.svelte index 258e5a0da..ceb64ee6d 100644 --- a/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widgets.svelte +++ b/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widgets.svelte @@ -10,6 +10,7 @@ import type { IDashboardLayouts } from "@undb/dashboard" export let shareId: string | undefined = undefined + export let readonly = false const dashboard = getDashboard() @@ -20,6 +21,7 @@ }) const onPointeup = () => { + if (readonly) return const widgets = $widgetItems .map((item) => { const { x, y, h, w } = item[COLS] @@ -54,6 +56,7 @@ {#await import("$lib/components/blocks/view-widget/view-widget-sheet.svelte") then { default: ViewWidgetSheet }} - + {/await} diff --git a/apps/frontend/src/lib/components/blocks/share/share-gallery-view.svelte b/apps/frontend/src/lib/components/blocks/share/share-gallery-view.svelte index db73255cf..11c893794 100644 --- a/apps/frontend/src/lib/components/blocks/share/share-gallery-view.svelte +++ b/apps/frontend/src/lib/components/blocks/share/share-gallery-view.svelte @@ -10,5 +10,5 @@ {#await import("$lib/components/blocks/view-widget/view-widget-sheet.svelte") then { default: ViewWidgetSheet }} - + {/await} diff --git a/apps/frontend/src/lib/components/blocks/share/share-grid-view.svelte b/apps/frontend/src/lib/components/blocks/share/share-grid-view.svelte index f7e998630..665fb6021 100644 --- a/apps/frontend/src/lib/components/blocks/share/share-grid-view.svelte +++ b/apps/frontend/src/lib/components/blocks/share/share-grid-view.svelte @@ -76,5 +76,5 @@ {/if} {#await import("$lib/components/blocks/view-widget/view-widget-sheet.svelte") then { default: ViewWidgetSheet }} - + {/await} diff --git a/apps/frontend/src/lib/components/blocks/share/share-kanban-view.svelte b/apps/frontend/src/lib/components/blocks/share/share-kanban-view.svelte index 6f77a8a04..ab2e1b4d1 100644 --- a/apps/frontend/src/lib/components/blocks/share/share-kanban-view.svelte +++ b/apps/frontend/src/lib/components/blocks/share/share-kanban-view.svelte @@ -10,5 +10,5 @@ {#await import("$lib/components/blocks/view-widget/view-widget-sheet.svelte") then { default: ViewWidgetSheet }} - + {/await} diff --git a/apps/frontend/src/lib/components/blocks/share/share-list-view.svelte b/apps/frontend/src/lib/components/blocks/share/share-list-view.svelte index 5dc81b6de..e7af735de 100644 --- a/apps/frontend/src/lib/components/blocks/share/share-list-view.svelte +++ b/apps/frontend/src/lib/components/blocks/share/share-list-view.svelte @@ -10,5 +10,5 @@ {#await import("$lib/components/blocks/view-widget/view-widget-sheet.svelte") then { default: ViewWidgetSheet }} - + {/await} diff --git a/apps/frontend/src/lib/components/blocks/share/share-pivot-view.svelte b/apps/frontend/src/lib/components/blocks/share/share-pivot-view.svelte index fa79513a2..bfd293ab7 100644 --- a/apps/frontend/src/lib/components/blocks/share/share-pivot-view.svelte +++ b/apps/frontend/src/lib/components/blocks/share/share-pivot-view.svelte @@ -10,5 +10,5 @@ {#await import("$lib/components/blocks/view-widget/view-widget-sheet.svelte") then { default: ViewWidgetSheet }} - + {/await} diff --git a/apps/frontend/src/lib/components/blocks/table-tools/share-table-tools.svelte b/apps/frontend/src/lib/components/blocks/table-tools/share-table-tools.svelte index 65d4ea87d..f1760dd60 100644 --- a/apps/frontend/src/lib/components/blocks/table-tools/share-table-tools.svelte +++ b/apps/frontend/src/lib/components/blocks/table-tools/share-table-tools.svelte @@ -21,6 +21,6 @@
- +
diff --git a/apps/frontend/src/lib/components/blocks/table-tools/table-tools.svelte b/apps/frontend/src/lib/components/blocks/table-tools/table-tools.svelte index df835e9fe..60419b5e8 100644 --- a/apps/frontend/src/lib/components/blocks/table-tools/table-tools.svelte +++ b/apps/frontend/src/lib/components/blocks/table-tools/table-tools.svelte @@ -33,6 +33,6 @@ {/if} - + diff --git a/apps/frontend/src/lib/components/blocks/template/template-preview.svelte b/apps/frontend/src/lib/components/blocks/template/template-preview.svelte index bd3c5f784..d0b02b5bc 100644 --- a/apps/frontend/src/lib/components/blocks/template/template-preview.svelte +++ b/apps/frontend/src/lib/components/blocks/template/template-preview.svelte @@ -17,6 +17,8 @@ import { preferences } from "$lib/store/persisted.store" import { RecordDO } from "@undb/table" import { templateStore } from "$lib/store/template.store.svelte" + import { setDashboard } from "$lib/store/dashboard.store" + import DashboardWidgets from "$lib/components/blocks/dashboard/dashboard-widgets.svelte" export let template: ITemplateDTO @@ -25,13 +27,18 @@ let t = templateStore.mustGetTemplate(template) let tables = t.flatMap((base) => base.tables.map(({ table }) => table)) + let dashboards = t.flatMap((base) => base.dashboards) let bases = t.map((base) => base.base) let currentTableId = writable(tables.at(0)?.id.value) let currentViewId = writable(undefined) + let currentDashboardId = writable(undefined) let currentTable = derived(currentTableId, ($currentTableId) => { return tables.find((table) => table.id.value === $currentTableId) }) + let currentDashboard = derived(currentDashboardId, ($currentDashboardId) => { + return dashboards.find((dashboard) => dashboard.id.value === $currentDashboardId) + }) let r = writable(null) @@ -56,6 +63,10 @@ setTable(writable($currentTable)) } + $: if ($currentDashboard) { + setDashboard(writable($currentDashboard)) + } + let open: Record = tables.length > 0 ? { @@ -91,6 +102,7 @@ {#if base} {@const active = base.id.value === $currentTable?.baseId && !$currentTableId && !$currentViewId} {@const baseTables = tables.filter((t) => t?.baseId === base.id.value)} + {@const baseDashboards = dashboards.filter((d) => d.baseId === base.id.value)}
+ {#each baseDashboards as dashboard} + {@const active = dashboard.id.value === $currentDashboardId} +
+ +
+ {/each} {#each baseTables as table} {#if table} {@const active = table.id.value === $currentTableId && !$currentViewId} @@ -142,6 +181,7 @@