From 550256db6bb939b41d05ea4ccd97f09f48893d5b Mon Sep 17 00:00:00 2001 From: nichenqin Date: Thu, 26 Sep 2024 16:44:13 +0800 Subject: [PATCH] feat: template preview --- .../blocks/field-control/date-control.svelte | 2 +- .../editable-cell/checkbox-cell.svelte | 4 +- .../grid-view/grid-view-data-table.svelte | 2 +- .../kanban-view/kanban-option-button.svelte | 11 +- .../blocks/kanban-view/kanban-view.svelte | 18 +- .../select-kanban-field-form.svelte | 16 +- .../kanban-view/select-kanban-lane.svelte | 16 +- .../kanban-view/select-kanban-view.svelte | 29 ++- .../blocks/share/share-grid-view.svelte | 6 +- .../blocks/table-tools/table-tools.svelte | 22 +- .../blocks/tables-nav/tables-nav.svelte | 1 - .../blocks/template/template-card.svelte | 76 +++++-- .../blocks/template/template-grid-view.svelte | 26 +++ .../blocks/template/template-preview.svelte | 191 +++++++++++++++++- .../view-color-editor.svelte | 14 +- .../blocks/view-fields/view-fields.svelte | 16 +- .../view-filter-editor.svelte | 2 +- .../blocks/view-sort/view-sort.svelte | 2 +- .../create-from-template.command-handler.ts | 3 - .../src/create-from-template.command.ts | 2 + .../space/src/value-objects/space-id.vo.ts | 2 +- packages/template/src/index.ts | 1 + .../src/templates/projectManagement.base.json | 6 +- 23 files changed, 398 insertions(+), 70 deletions(-) create mode 100644 apps/frontend/src/lib/components/blocks/template/template-grid-view.svelte diff --git a/apps/frontend/src/lib/components/blocks/field-control/date-control.svelte b/apps/frontend/src/lib/components/blocks/field-control/date-control.svelte index fd84299bc..0b7ce02e1 100644 --- a/apps/frontend/src/lib/components/blocks/field-control/date-control.svelte +++ b/apps/frontend/src/lib/components/blocks/field-control/date-control.svelte @@ -25,7 +25,7 @@ let open = false - + - Update kanban view - + + {#if !readonly} + Update kanban view + {:else} + Kanban view + {/if} + + diff --git a/apps/frontend/src/lib/components/blocks/kanban-view/kanban-view.svelte b/apps/frontend/src/lib/components/blocks/kanban-view/kanban-view.svelte index a16dccd57..d3e549c0f 100644 --- a/apps/frontend/src/lib/components/blocks/kanban-view/kanban-view.svelte +++ b/apps/frontend/src/lib/components/blocks/kanban-view/kanban-view.svelte @@ -1,18 +1,21 @@ {#key $table.id.value} - + {#if !shareId} - + {/if} {#if view.type === "kanban"} {#if field?.type === "select"} {#if field.isSingle} - + {:else}
diff --git a/apps/frontend/src/lib/components/blocks/kanban-view/select-kanban-field-form.svelte b/apps/frontend/src/lib/components/blocks/kanban-view/select-kanban-field-form.svelte index 86c2292bd..147569f5f 100644 --- a/apps/frontend/src/lib/components/blocks/kanban-view/select-kanban-field-form.svelte +++ b/apps/frontend/src/lib/components/blocks/kanban-view/select-kanban-field-form.svelte @@ -10,6 +10,9 @@ import { createMutation } from "@tanstack/svelte-query" import { toast } from "svelte-sonner" import { invalidate } from "$app/navigation" + import { hasPermission } from "$lib/store/space-member.store" + + export let readonly = false const table = getTable() @@ -59,6 +62,7 @@
{ @@ -74,9 +78,13 @@
- + {#if !readonly && $hasPermission("field:update")} + + {/if} -
- -
+ {#if !readonly} +
+ +
+ {/if}
diff --git a/apps/frontend/src/lib/components/blocks/kanban-view/select-kanban-lane.svelte b/apps/frontend/src/lib/components/blocks/kanban-view/select-kanban-lane.svelte index e0c216315..3c0a5ae02 100644 --- a/apps/frontend/src/lib/components/blocks/kanban-view/select-kanban-lane.svelte +++ b/apps/frontend/src/lib/components/blocks/kanban-view/select-kanban-lane.svelte @@ -50,19 +50,20 @@ export let tableId: string export let view: KanbanView - export let viewId: Readable + export let viewId: Readable export let fieldId: string export let field: SelectField export let option: IOption | null export let readonly = false export let shareId: string | undefined = undefined + export let disableRecordQuery = false $: color = view.color.into(undefined) const q = queryParam("q") let getIsLaneCollapsed = kanbanStore.getIsLaneCollapsed - $: isLaneCollapsed = $getIsLaneCollapsed($viewId, option?.id ?? "") ?? false + $: isLaneCollapsed = $viewId ? ($getIsLaneCollapsed($viewId, option?.id ?? "") ?? false) : false const query = createInfiniteQuery( derived([table, viewId, q], ([$table, $viewId, $q]) => { @@ -109,7 +110,7 @@ } return pages.length + 1 }, - enabled: view?.type === "kanban", + enabled: view?.type === "kanban" && !disableRecordQuery, filters: { conjunction: "and", children: [{ field: fieldId, op: "eq", value: option ? option.id : null }], @@ -304,6 +305,9 @@ { + if (!$viewId) { + return + } kanbanStore.toggleLane($viewId, option?.id ?? "") }} > @@ -323,7 +327,7 @@ getKanbanBgColor(option?.color ?? "gray"), )} > - {#if !readonly && $hasPermission("record:create")} + {#if $hasPermission("record:create")} {#if $query.isFetchedAfterMount} {#if recordDos.length > 0} + + + + + + +
+ + + Preview template {template.name} + + + + {template.description} + +
+
+ + +
+ + +
+
+
+ +
+ +
+
+
diff --git a/apps/frontend/src/lib/components/blocks/template/template-grid-view.svelte b/apps/frontend/src/lib/components/blocks/template/template-grid-view.svelte new file mode 100644 index 000000000..68f85af25 --- /dev/null +++ b/apps/frontend/src/lib/components/blocks/template/template-grid-view.svelte @@ -0,0 +1,26 @@ + + +{#if store} + +{/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 ee2ef43f8..95938d800 100644 --- a/apps/frontend/src/lib/components/blocks/template/template-preview.svelte +++ b/apps/frontend/src/lib/components/blocks/template/template-preview.svelte @@ -1,5 +1,194 @@ + +{#if template.template.type === "base"} +
+
+ +
+ {#key $currentTableId} + {#if $currentTable} +
+ {#if $currentView?.type === "grid"} + + {:else if $currentView?.type === "kanban"} + + {/if} +
+ {/if} + {/key} +
+{/if} diff --git a/apps/frontend/src/lib/components/blocks/view-color-editor/view-color-editor.svelte b/apps/frontend/src/lib/components/blocks/view-color-editor/view-color-editor.svelte index aa084d579..aca8ba32e 100644 --- a/apps/frontend/src/lib/components/blocks/view-color-editor/view-color-editor.svelte +++ b/apps/frontend/src/lib/components/blocks/view-color-editor/view-color-editor.svelte @@ -51,10 +51,10 @@ } - + -
- -

There's no color filter

-
+
+ +

There's no color filter

+
diff --git a/apps/frontend/src/lib/components/blocks/view-fields/view-fields.svelte b/apps/frontend/src/lib/components/blocks/view-fields/view-fields.svelte index c4a24e1d8..07fd3db41 100644 --- a/apps/frontend/src/lib/components/blocks/view-fields/view-fields.svelte +++ b/apps/frontend/src/lib/components/blocks/view-fields/view-fields.svelte @@ -18,6 +18,8 @@ import FieldMenu from "../field/field-menu.svelte" import { hasPermission } from "$lib/store/space-member.store" + export let readonly = false + const table = getTable() $: fields = $table.getOrderedFields(undefined, $viewId) $: viewFieldsVo = $table.getViewFields($viewId) @@ -47,6 +49,8 @@ }) const setViewFields = async () => { + if (readonly) return + await tick() $setViewFieldsMutation.mutate({ tableId: $table.id.value, @@ -56,6 +60,7 @@ } function swapFields(oldIndex: number, newIndex: number) { + if (readonly) return const fields = [...viewFields] const [removed] = fields.splice(oldIndex, 1) fields.splice(newIndex, 0, removed) @@ -76,6 +81,8 @@ }) const setViewOption = async (value: boolean) => { + if (readonly) return + viewOption.showSystemFields = value await tick() $setViewOptionMutation.mutate({ @@ -86,7 +93,7 @@ } - + diff --git a/apps/frontend/src/lib/components/blocks/view-filter-editor/view-filter-editor.svelte b/apps/frontend/src/lib/components/blocks/view-filter-editor/view-filter-editor.svelte index 3d4612db6..a15cdfd59 100644 --- a/apps/frontend/src/lib/components/blocks/view-filter-editor/view-filter-editor.svelte +++ b/apps/frontend/src/lib/components/blocks/view-filter-editor/view-filter-editor.svelte @@ -56,7 +56,7 @@ } - +