From 740c5003899dfe40e076602924f1862c971edda9 Mon Sep 17 00:00:00 2001 From: nichenqin Date: Sat, 24 Aug 2024 11:59:24 +0800 Subject: [PATCH] feat: readonly form ui --- apps/frontend/schema.graphql | 1 + .../blocks/base/share-base-nav.svelte | 142 ++++++++++-------- .../blocks/forms/form-display.svelte | 10 +- .../table-header/share-table-header.svelte | 95 ++++++++++++ .../blocks/view-sort/view-sort.svelte | 24 +-- .../routes/(share)/s/b/[shareId]/+layout.gql | 10 ++ .../t/[tableId]/[[viewId]]/+page.svelte | 24 ++- packages/graphql/src/index.ts | 1 + packages/trpc/src/router.ts | 2 + 9 files changed, 222 insertions(+), 87 deletions(-) create mode 100644 apps/frontend/src/lib/components/blocks/table-header/share-table-header.svelte diff --git a/apps/frontend/schema.graphql b/apps/frontend/schema.graphql index 5168392f7..2dc2737b0 100644 --- a/apps/frontend/schema.graphql +++ b/apps/frontend/schema.graphql @@ -135,6 +135,7 @@ type ShareTarget { } enum ShareTargetType { + base form view } diff --git a/apps/frontend/src/lib/components/blocks/base/share-base-nav.svelte b/apps/frontend/src/lib/components/blocks/base/share-base-nav.svelte index 5f3f84247..f4709553d 100644 --- a/apps/frontend/src/lib/components/blocks/base/share-base-nav.svelte +++ b/apps/frontend/src/lib/components/blocks/base/share-base-nav.svelte @@ -25,79 +25,91 @@ $: viewId = $page.params.viewId $: baseTables = base.tables.filter((t) => t !== null) ?? [] + $: active = !tableId && !viewId let open: Record = {} - -
- - {base.name} -
-
-{#each baseTables as table} - {#if table} - {@const active = table.id === tableId} - {@const views = table.views.filter((view) => !view.isDefault)} - -
- + +
+ + {base.name} +
+
+ {#each baseTables as table} + {#if table} + {@const active = table.id === tableId} + {@const views = table.views.filter((view) => !view.isDefault)} + +
- - {table.name} - -
- {#if views.length > 0} - { - e.preventDefault() - e.stopPropagation() - open[table.id] = !open[table.id] - }} + + + {table.name} + +
+ {#if views.length > 0} + { + e.preventDefault() + e.stopPropagation() + open[table.id] = !open[table.id] + }} + class={cn( + "flex h-5 w-5 items-center justify-center rounded-md hover:bg-gray-200", + active && !viewId && "hover:bg-primary", + )} + > + + + {/if} +
+
+ + {#each views as view} + {@const active = view.id === viewId} +
- - - {/if} -
-
- - {#each views as view} - {@const active = view.id === viewId} - - {/each} - -
- {/if} -{/each} + href={`/s/b/${shareId}/t/${table.id}/${view.id}`} + > + + {view.name} + +
+ {/each} + +
+ {/if} + {/each} + diff --git a/apps/frontend/src/lib/components/blocks/forms/form-display.svelte b/apps/frontend/src/lib/components/blocks/forms/form-display.svelte index fb9a3885e..120cae2de 100644 --- a/apps/frontend/src/lib/components/blocks/forms/form-display.svelte +++ b/apps/frontend/src/lib/components/blocks/forms/form-display.svelte @@ -149,15 +149,19 @@ }} class={cn( "bg-background relative -mx-4 space-y-2 rounded-md border-2 border-transparent p-0 px-4 transition-all", - isSelected ? "border-primary shadow-lg" : "hover:bg-muted/50", + isSelected ? "border-primary shadow-lg" : !readonly && "hover:bg-muted/50", )} > {#if isSelected} - {/if} -
+
diff --git a/apps/frontend/src/lib/components/blocks/table-header/share-table-header.svelte b/apps/frontend/src/lib/components/blocks/table-header/share-table-header.svelte new file mode 100644 index 000000000..712971b0c --- /dev/null +++ b/apps/frontend/src/lib/components/blocks/table-header/share-table-header.svelte @@ -0,0 +1,95 @@ + + +
+
+
+ + + {#if base} + + + + {base.name} + + + + {/if} + + + + {$table.name.value} + + + + {#if $isFormTab} + {#if forms.length} + + + Forms + + + + {currentForm?.name} + + {/if} + {:else} + + + {view.name.value} + + + {/if} + + + + +
+ + {#if forms.length} + { + if (!$tab && value === "data") { + return + } + + tab.set(value === "data" ? "" : (value ?? "")) + }} + class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 transform" + > + + + + Data + + + + Forms + + + + {/if} +
+
diff --git a/apps/frontend/src/lib/components/blocks/view-sort/view-sort.svelte b/apps/frontend/src/lib/components/blocks/view-sort/view-sort.svelte index 3574b34a1..daefb9aba 100644 --- a/apps/frontend/src/lib/components/blocks/view-sort/view-sort.svelte +++ b/apps/frontend/src/lib/components/blocks/view-sort/view-sort.svelte @@ -93,7 +93,7 @@ variant={count || open ? "secondary" : "ghost"} builders={[builder]} size="sm" - disabled={!readonly && (!$hasPermission("table:update") && (!sort || sort.isEmpty))} + disabled={!readonly && !$hasPermission("table:update") && (!sort || sort.isEmpty)} > Sorts @@ -176,19 +176,21 @@
{:else if readonly}
- +

There's no sorts

{/if} -
- {#if $hasPermission("table:update")} - - - {/if} -
+ {#if !readonly} +
+ {#if $hasPermission("table:update")} + + + {/if} +
+ {/if}
diff --git a/apps/frontend/src/routes/(share)/s/b/[shareId]/+layout.gql b/apps/frontend/src/routes/(share)/s/b/[shareId]/+layout.gql index bcbf79cc0..a4f55e009 100644 --- a/apps/frontend/src/routes/(share)/s/b/[shareId]/+layout.gql +++ b/apps/frontend/src/routes/(share)/s/b/[shareId]/+layout.gql @@ -16,6 +16,16 @@ query GetShareBaseData($shareId: ID!) { id name + forms { + id + name + fields + description + option { + backgroundColor + } + } + views { id name diff --git a/apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/[[viewId]]/+page.svelte b/apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/[[viewId]]/+page.svelte index 9cb8a01d9..c59ce41d4 100644 --- a/apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/[[viewId]]/+page.svelte +++ b/apps/frontend/src/routes/(share)/s/b/[shareId]/t/[tableId]/[[viewId]]/+page.svelte @@ -10,6 +10,9 @@ import { onMount, type ComponentType } from "svelte" import { derived, writable } from "svelte/store" import { queryParam } from "sveltekit-search-params" + import { isDataTab, isFormTab } from "$lib/store/tab.store" + import ShareTableHeader from "$lib/components/blocks/table-header/share-table-header.svelte" + import FormsReadonly from "$lib/components/blocks/forms/forms-readonly.svelte" let RecordDetailSheet: ComponentType @@ -48,16 +51,21 @@
+ - + {#if $isDataTab} + + {:else if $isFormTab} + + {/if} {#if RecordDetailSheet} diff --git a/packages/graphql/src/index.ts b/packages/graphql/src/index.ts index b3a4b7064..80469cf4a 100644 --- a/packages/graphql/src/index.ts +++ b/packages/graphql/src/index.ts @@ -63,6 +63,7 @@ export class Graphql { enum ShareTargetType { view + base form } diff --git a/packages/trpc/src/router.ts b/packages/trpc/src/router.ts index f102453a3..2692830ed 100644 --- a/packages/trpc/src/router.ts +++ b/packages/trpc/src/router.ts @@ -129,9 +129,11 @@ const queryBus = container.resolve(QueryBus) const formRouter = t.router({ create: privateProcedure + .use(authz("form:create")) .input(createTableFormCommand) .mutation(({ input }) => commandBus.execute(new CreateTableFormCommand(input))), set: privateProcedure + .use(authz("form:update")) .input(setTableFormCommand) .mutation(({ input }) => commandBus.execute(new SetTableFormCommand(input))), })