From 38917daaf03d81a7a4f0beeb62378b06ef20d49c Mon Sep 17 00:00:00 2001 From: nichenqin Date: Tue, 22 Oct 2024 11:44:38 +0800 Subject: [PATCH] feat: share dashboard --- apps/frontend/schema.graphql | 2 ++ .../dashboard-widget-share-table.gql | 32 +++++++++++++++++ .../blocks/dashboard/dashboard-widget.svelte | 15 +++++--- .../blocks/dashboard/dashboard-widgets.svelte | 10 +++++- .../components/blocks/widget/widget.svelte | 8 +++-- .../dashboards/[dashboardId]/+page.svelte | 7 ++-- .../(share)/s/[d]/[shareId]/+layout.gql | 24 +++++++++++++ .../(share)/s/[d]/[shareId]/+layout.svelte | 35 +++++++++++++++++++ .../routes/(share)/s/[d]/[shareId]/+layout.ts | 23 ++++++++++++ .../(share)/s/[d]/[shareId]/+page.svelte | 22 ++++++++++++ packages/graphql/src/index.ts | 15 ++++++++ .../src/get-dashboard-by-share.query.ts | 18 ++++++++++ .../src/get-table-by-share-dashboard.query.ts | 22 ++++++++++++ packages/queries/src/index.ts | 2 ++ .../get-dashboard-by-share.query-handler.ts | 33 +++++++++++++++++ ... get-table-by-share-base.query-handler.ts} | 0 ...-table-by-share-dashboard.query-handler.ts | 33 +++++++++++++++++ packages/query-handlers/src/handlers/index.ts | 6 +++- packages/share/src/services/share.service.ts | 33 ++++++++++++++--- 19 files changed, 323 insertions(+), 17 deletions(-) create mode 100644 apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget-share-table.gql create mode 100644 apps/frontend/src/routes/(share)/s/[d]/[shareId]/+layout.gql create mode 100644 apps/frontend/src/routes/(share)/s/[d]/[shareId]/+layout.svelte create mode 100644 apps/frontend/src/routes/(share)/s/[d]/[shareId]/+layout.ts create mode 100644 apps/frontend/src/routes/(share)/s/[d]/[shareId]/+page.svelte create mode 100644 packages/queries/src/get-dashboard-by-share.query.ts create mode 100644 packages/queries/src/get-table-by-share-dashboard.query.ts create mode 100644 packages/query-handlers/src/handlers/get-dashboard-by-share.query-handler.ts rename packages/query-handlers/src/handlers/{get-table-by-share-table.query-handler.ts => get-table-by-share-base.query-handler.ts} (100%) create mode 100644 packages/query-handlers/src/handlers/get-table-by-share-dashboard.query-handler.ts diff --git a/apps/frontend/schema.graphql b/apps/frontend/schema.graphql index 4c7786715..ab3d90d04 100644 --- a/apps/frontend/schema.graphql +++ b/apps/frontend/schema.graphql @@ -135,6 +135,7 @@ type Query { baseByShare(shareId: ID!): Base bases: [Base] dashboard(id: ID!): Dashboard + dashboardByShare(shareId: ID!): Dashboard dashboards(baseId: ID): [Dashboard]! invitations(status: InvitationStatus): [Invitation!]! member: SpaceMember @@ -150,6 +151,7 @@ type Query { table(id: ID!): Table tableByShare(shareId: ID!): Table tableByShareBase(shareId: ID!, tableId: ID!): Table + tableByShareDashboard(shareId: ID!, tableId: ID!): Table tableForeignTables(tableId: ID!): [Table!]! tables(baseId: ID): [Table]! template(shareId: ID!): Template diff --git a/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget-share-table.gql b/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget-share-table.gql new file mode 100644 index 000000000..ea6ec5d33 --- /dev/null +++ b/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget-share-table.gql @@ -0,0 +1,32 @@ +query GetDashboardWidgetShareTable($shareId: ID!, $tableId: ID!) { + tableByShareDashboard(shareId: $shareId, tableId: $tableId) { + id + name + + base { + id + name + } + + schema { + id + name + type + defaultValue + display + constraint + option + } + + 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 f99778de7..c12a69a54 100644 --- a/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget.svelte +++ b/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widget.svelte @@ -1,23 +1,28 @@ - + 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 48e0897b2..258e5a0da 100644 --- a/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widgets.svelte +++ b/apps/frontend/src/lib/components/blocks/dashboard/dashboard-widgets.svelte @@ -9,6 +9,8 @@ import { trpc } from "$lib/trpc/client" import type { IDashboardLayouts } from "@undb/dashboard" + export let shareId: string | undefined = undefined + const dashboard = getDashboard() const widgetItems = getDashboardWidgetItemsStore() @@ -49,7 +51,13 @@ on:pointerup={onPointeup} > {#if dataItem.widget} - + {/if} diff --git a/apps/frontend/src/lib/components/blocks/widget/widget.svelte b/apps/frontend/src/lib/components/blocks/widget/widget.svelte index f498b18b6..b72b93650 100644 --- a/apps/frontend/src/lib/components/blocks/widget/widget.svelte +++ b/apps/frontend/src/lib/components/blocks/widget/widget.svelte @@ -40,6 +40,7 @@ const deleteViewWidgetMutation = createMutation({ mutationFn: trpc.table.view.widget.delete.mutate, + enabled: !shareId, onSuccess: async () => { confirmDelete = false if (table) { @@ -53,6 +54,7 @@ const deleteDashboardWidgetMutation = createMutation({ mutationFn: trpc.dashboard.widget.delete.mutate, + enabled: !shareId, onSuccess: async () => { confirmDelete = false if ($isDashboard) { @@ -69,6 +71,7 @@ let confirmDuplicate = false const duplicateDashboardWidgetMutation = createMutation({ mutationFn: trpc.dashboard.widget.duplicate.mutate, + enabled: !shareId, onSuccess: async () => { if ($isDashboard) { await invalidate(`dashboard:${$dashboard.id.value}`) @@ -81,6 +84,7 @@ const duplicateViewWidgetMutation = createMutation({ mutationFn: trpc.table.view.widget.duplicate.mutate, + enabled: !shareId, onSuccess: async () => { confirmDuplicate = false if (table) { @@ -96,7 +100,7 @@
- {#if movePointerDown} + {#if movePointerDown && !shareId}