From 9d4c8c78976a136b0b73e777d3594e6b214163a0 Mon Sep 17 00:00:00 2001 From: nichenqin Date: Thu, 31 Aug 2023 14:37:32 +0800 Subject: [PATCH 1/8] feat(merge): merge data modal --- apps/frontend/src/lib/import/MergeData.svelte | 6 ++++++ apps/frontend/src/lib/store/modal.ts | 3 +++ apps/frontend/src/lib/table/TableMenu.svelte | 13 ++++++++++++- apps/frontend/src/routes/(authed)/+layout.svelte | 3 +++ packages/authz/src/rbac/permissions.ts | 5 +++++ 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 apps/frontend/src/lib/import/MergeData.svelte diff --git a/apps/frontend/src/lib/import/MergeData.svelte b/apps/frontend/src/lib/import/MergeData.svelte new file mode 100644 index 000000000..c1c312f28 --- /dev/null +++ b/apps/frontend/src/lib/import/MergeData.svelte @@ -0,0 +1,6 @@ + + +merge diff --git a/apps/frontend/src/lib/store/modal.ts b/apps/frontend/src/lib/store/modal.ts index 2125ccef5..7857787f5 100644 --- a/apps/frontend/src/lib/store/modal.ts +++ b/apps/frontend/src/lib/store/modal.ts @@ -72,6 +72,9 @@ export const createOptionModal = createModal(CREATE_OPTION) const UPDATE_OPTION = Symbol('UPDATE_OPTION') export const updateOptionModal = createModal(UPDATE_OPTION) +const MERGE_DATA_MODAL = Symbol('MERGE_DATA_MODAL') +export const mergeDataModal = createModal(MERGE_DATA_MODAL) + const IMPORT_DATA_MODAL = Symbol('IMPORT_DATA_MODAL') export const importDataModal = createModal(IMPORT_DATA_MODAL) diff --git a/apps/frontend/src/lib/table/TableMenu.svelte b/apps/frontend/src/lib/table/TableMenu.svelte index 7b0fd134e..c2a523036 100644 --- a/apps/frontend/src/lib/table/TableMenu.svelte +++ b/apps/frontend/src/lib/table/TableMenu.svelte @@ -1,7 +1,7 @@ -merge + + { + event.preventDefault() + }} + on:change={handleChange} + > + +

+ {@html $t('click to upload or dnd', { ns: 'common' })} +

+
+ +
+ + +
+
diff --git a/packages/trpc/src/router/record.router.ts b/packages/trpc/src/router/record.router.ts index dbeee7ac7..02b2579a3 100644 --- a/packages/trpc/src/router/record.router.ts +++ b/packages/trpc/src/router/record.router.ts @@ -4,6 +4,7 @@ import { BulkDeleteRecordsCommand, BulkDuplicateRecordsCommand, CreateRecordCommand, + CreateRecordsCommand, DeleteRecordCommand, DuplicateRecordCommand, GetForeignRecordsQuery, @@ -42,6 +43,14 @@ export const createRecordRouter = const cmd = new CreateRecordCommand(input) return commandBus.execute(cmd) }), + buldCreate: procedure + .use(authz('record:create')) + .input(z.any()) + .output(z.any()) + .mutation(({ input }) => { + const cmd = new CreateRecordsCommand(input) + return commandBus.execute(cmd) + }), duplicate: procedure .use(authz('record:create')) .input(duplicateRecordCommandInput) From 035a9023eae335a84d76d25c8d439f42268a00f1 Mon Sep 17 00:00:00 2001 From: nichenqin Date: Thu, 31 Aug 2023 16:43:25 +0800 Subject: [PATCH 3/8] fix: fix merge data modal --- apps/frontend/src/routes/(authed)/+layout.svelte | 3 --- .../src/routes/(authed)/t/[tableId]/[[viewId]]/+page.svelte | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/frontend/src/routes/(authed)/+layout.svelte b/apps/frontend/src/routes/(authed)/+layout.svelte index 0e264514b..2b21174a8 100644 --- a/apps/frontend/src/routes/(authed)/+layout.svelte +++ b/apps/frontend/src/routes/(authed)/+layout.svelte @@ -22,7 +22,6 @@ import { DARK_THEME, LIGHT_THEME } from '$lib/store/ui.type' import TablesNav from '$lib/table/TablesNav.svelte' import { hasPermission } from '$lib/store/authz' - import MergeData from '$lib/import/MergeData.svelte' $: navigation = [ { name: $t('Tables', { ns: 'common' }), href: '/', icon: 'table', current: $page.url.pathname === '/' }, @@ -407,8 +406,6 @@ {#if $importDataModal.open} {/if} - - + {#key $table} {/key} From 7aa623d5422d35faf724a5a1b30018b3ed123261 Mon Sep 17 00:00:00 2001 From: nichenqin Date: Thu, 31 Aug 2023 16:49:09 +0800 Subject: [PATCH 4/8] feat: merge data cast field value o array --- packages/core/src/table/field/field.util.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/src/table/field/field.util.ts b/packages/core/src/table/field/field.util.ts index d9decebac..3236177f4 100644 --- a/packages/core/src/table/field/field.util.ts +++ b/packages/core/src/table/field/field.util.ts @@ -1,5 +1,5 @@ import type { TFunction } from 'i18next' -import { isBoolean, isNumber, isPlainObject, isString, uniq } from 'lodash-es' +import { castArray, isBoolean, isNumber, isPlainObject, isString, uniq } from 'lodash-es' import { match } from 'ts-pattern' import { z } from 'zod' import { Options } from '../option' @@ -708,5 +708,6 @@ export const castFieldValue = (type: IFieldType, value: string | number | null | .otherwise(Boolean), ) .with('select', () => value || null) + .with('multi-select', 'reference', 'tree', 'collaborator', () => (value ? castArray(value) : null)) .otherwise(() => value) } From f27005381d7a7238b65220b9931488699dbb1091 Mon Sep 17 00:00:00 2001 From: nichenqin Date: Fri, 1 Sep 2023 11:05:21 +0800 Subject: [PATCH 5/8] fix: fix filter record values --- apps/frontend/src/lib/import/MergeData.svelte | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/frontend/src/lib/import/MergeData.svelte b/apps/frontend/src/lib/import/MergeData.svelte index 2a9886dd0..fb41cf1de 100644 --- a/apps/frontend/src/lib/import/MergeData.svelte +++ b/apps/frontend/src/lib/import/MergeData.svelte @@ -6,6 +6,7 @@ import { getTable } from '$lib/store/table' import { castFieldValue, type IMutateRecordValueSchema } from '@undb/core' import { trpc } from '$lib/trpc/client' + import { isEmpty } from 'lodash-es' const table = getTable() @@ -37,7 +38,7 @@ return prev }, {} as IMutateRecordValueSchema) }) - .filter(Boolean) + .filter((value) => !isEmpty(value)) let ext: string | undefined let file: File | undefined From 9bc0b4835f8b436cc5e6bf10831735adad9972bf Mon Sep 17 00:00:00 2001 From: nichenqin Date: Fri, 1 Sep 2023 11:41:35 +0800 Subject: [PATCH 6/8] feat: merge data add some warning message --- apps/frontend/src/lib/import/MergeData.svelte | 33 ++++++++++++++++--- packages/i18n/src/index.ts | 2 ++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/apps/frontend/src/lib/import/MergeData.svelte b/apps/frontend/src/lib/import/MergeData.svelte index fb41cf1de..6523eb8bc 100644 --- a/apps/frontend/src/lib/import/MergeData.svelte +++ b/apps/frontend/src/lib/import/MergeData.svelte @@ -1,24 +1,29 @@