From 1ea35f1f6daf9e59e528d10cbf470c7ecd9ded40 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 16 Oct 2024 10:30:45 +0000 Subject: [PATCH 1/8] refactor: make title mandatory instead of table_name --- .../nocodb/src/services/tables.service.ts | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/nocodb/src/services/tables.service.ts b/packages/nocodb/src/services/tables.service.ts index 184a1c95da..090d9f5e89 100644 --- a/packages/nocodb/src/services/tables.service.ts +++ b/packages/nocodb/src/services/tables.service.ts @@ -558,15 +558,30 @@ export class TablesService { } } + + if ( - !tableCreatePayLoad.table_name || - (base.prefix && base.prefix === tableCreatePayLoad.table_name) + !tableCreatePayLoad.title ) { NcError.badRequest( - 'Missing table name `table_name` property in request body', + 'Missing table `title` property in request body', ); } + if(!tableCreatePayLoad.table_name) { + + } + + if ( + !(await Model.checkAliasAvailable(context, { + title: tableCreatePayLoad.title, + base_id: base.id, + source_id: source.id, + })) + ) { + NcError.badRequest('Duplicate table alias'); + } + if (source.type === 'databricks') { tableCreatePayLoad.table_name = tableCreatePayLoad.table_name .replace(/\s/g, '_') @@ -608,15 +623,7 @@ export class TablesService { ); } - if ( - !(await Model.checkAliasAvailable(context, { - title: tableCreatePayLoad.title, - base_id: base.id, - source_id: source.id, - })) - ) { - NcError.badRequest('Duplicate table alias'); - } + const sqlMgr = await ProjectMgrv2.getSqlMgr(context, base); From be95825039296f83ff61b67c1315132668b8545f Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 16 Oct 2024 10:30:45 +0000 Subject: [PATCH 2/8] refactor: allow using icon index for checkbox and rating --- packages/nc-gui/components/cell/Checkbox.vue | 8 +- .../smartsheet/column/CheckboxOptions.vue | 31 +----- .../smartsheet/column/RatingOptions.vue | 10 +- packages/nc-gui/helpers/columnDefaultMeta.ts | 23 ----- packages/nc-gui/utils/columnUtils.ts | 94 +++++++++++++++++++ 5 files changed, 103 insertions(+), 63 deletions(-) diff --git a/packages/nc-gui/components/cell/Checkbox.vue b/packages/nc-gui/components/cell/Checkbox.vue index 569ea6248e..27865a6b1f 100644 --- a/packages/nc-gui/components/cell/Checkbox.vue +++ b/packages/nc-gui/components/cell/Checkbox.vue @@ -38,13 +38,11 @@ const isSurveyForm = inject(IsSurveyFormInj, ref(false)) const isGrid = inject(IsGridInj, ref(false)) const checkboxMeta = computed(() => { + const icon = extractCheckboxIcon(column?.value?.meta); + return { - icon: { - checked: 'mdi-check-circle-outline', - unchecked: 'mdi-checkbox-blank-circle-outline', - }, + icon, color: 'primary', - ...parseProp(column?.value?.meta), } }) diff --git a/packages/nc-gui/components/smartsheet/column/CheckboxOptions.vue b/packages/nc-gui/components/smartsheet/column/CheckboxOptions.vue index 51426c4b95..4b32cc513c 100644 --- a/packages/nc-gui/components/smartsheet/column/CheckboxOptions.vue +++ b/packages/nc-gui/components/smartsheet/column/CheckboxOptions.vue @@ -10,36 +10,7 @@ const emit = defineEmits(['update:value']) const vModel = useVModel(props, 'value', emit) // cater existing v1 cases -const iconList = [ - { - checked: 'mdi-check-bold', - unchecked: 'mdi-crop-square', - }, - { - checked: 'mdi-check-circle-outline', - unchecked: 'mdi-checkbox-blank-circle-outline', - }, - { - checked: 'mdi-star', - unchecked: 'mdi-star-outline', - }, - { - checked: 'mdi-heart', - unchecked: 'mdi-heart-outline', - }, - { - checked: 'mdi-moon-full', - unchecked: 'mdi-moon-new', - }, - { - checked: 'mdi-thumb-up', - unchecked: 'mdi-thumb-up-outline', - }, - { - checked: 'mdi-flag', - unchecked: 'mdi-flag-outline', - }, -] +const iconList = checkboxIconList const picked = computed({ get: () => vModel.value.meta.color, diff --git a/packages/nc-gui/components/smartsheet/column/RatingOptions.vue b/packages/nc-gui/components/smartsheet/column/RatingOptions.vue index 42f2720bc2..041a149de4 100644 --- a/packages/nc-gui/components/smartsheet/column/RatingOptions.vue +++ b/packages/nc-gui/components/smartsheet/column/RatingOptions.vue @@ -26,7 +26,7 @@ vModel.value.meta = { // antdv doesn't support object as value // use iconIdx as value and update back in watch -const iconIdx = iconList.findIndex( +const iconIdx = ratingIconList.findIndex( (ele) => ele.full === vModel.value.meta.icon.full && ele.empty === vModel.value.meta.icon.empty, ) @@ -35,7 +35,7 @@ vModel.value.meta.iconIdx = iconIdx === -1 ? 0 : iconIdx watch( () => vModel.value.meta.iconIdx, (v) => { - vModel.value.meta.icon = iconList[v] + vModel.value.meta.icon = ratingIconList[v] }, ) @@ -49,7 +49,7 @@ watch( - +
@@ -84,13 +84,13 @@ watch( >
{ } } +// cater existing v1 cases +const checkboxIconList = [ + { + checked: 'mdi-check-bold', + unchecked: 'mdi-crop-square', + }, + { + checked: 'mdi-check-circle-outline', + unchecked: 'mdi-checkbox-blank-circle-outline', + }, + { + checked: 'mdi-star', + unchecked: 'mdi-star-outline', + }, + { + checked: 'mdi-heart', + unchecked: 'mdi-heart-outline', + }, + { + checked: 'mdi-moon-full', + unchecked: 'mdi-moon-new', + }, + { + checked: 'mdi-thumb-up', + unchecked: 'mdi-thumb-up-outline', + }, + { + checked: 'mdi-flag', + unchecked: 'mdi-flag-outline', + }, +] + +export const ratingIconList = [ + { + full: 'mdi-star', + empty: 'mdi-star-outline', + }, + { + full: 'mdi-heart', + empty: 'mdi-heart-outline', + }, + { + full: 'mdi-moon-full', + empty: 'mdi-moon-new', + }, + { + full: 'mdi-thumb-up', + empty: 'mdi-thumb-up-outline', + }, + { + full: 'mdi-flag', + empty: 'mdi-flag-outline', + }, +] + +function extractCheckboxIcon(meta: string | Record = null) { + const parsedMeta = parseProp(meta) + + const icon = { + checked: 'mdi-check-circle-outline', + unchecked: 'mdi-checkbox-blank-circle-outline', + } + + if (parsedMeta.icon) { + icon.checked = parsedMeta.icon.checked || icon.checked + icon.unchecked = parsedMeta.icon.unchecked || icon.unchecked + } else if (typeof parsedMeta.iconIndex === 'number' && checkboxIconList[parsedMeta.iconIndex]) { + icon.checked = checkboxIconList[parsedMeta.iconIndex].checked + icon.unchecked = checkboxIconList[parsedMeta.iconIndex].unchecked + } + return icon +} + +function extractRatingIcon(meta: string | Record = null) { + const parsedMeta = parseProp(meta) + + const icon = { + full: 'mdi-star', + empty: 'mdi-star-outline', + } + + if (parsedMeta.icon) { + icon.full = parsedMeta.icon.full || icon.full + icon.empty = parsedMeta.icon.empty || icon.empty + } else if (typeof parsedMeta.iconIndex === 'number' && ratingIconList[parsedMeta.iconIndex]) { + icon.full = ratingIconList[parsedMeta.iconIndex].full + icon.empty = ratingIconList[parsedMeta.iconIndex].empty + } + return icon +} + export { uiTypes, isTypableInputColumn, @@ -267,4 +358,7 @@ export { isColumnRequiredAndNull, isColumnRequired, isVirtualColRequired, + checkboxIconList, + ratingIconList, + extractCheckboxIcon, } From 9ec0baec9aa7636a38b78b7805aa9c80bce7c968 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 16 Oct 2024 10:30:45 +0000 Subject: [PATCH 3/8] refactor: make only title as required --- packages/nc-gui/utils/columnUtils.ts | 2 +- .../jobs/export-import/duplicate.controller.ts | 3 ++- packages/nocodb/src/schema/swagger-v2.json | 8 ++++++-- packages/nocodb/src/schema/swagger.json | 9 +++++++-- packages/nocodb/src/services/tables.service.ts | 16 ++++------------ 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/packages/nc-gui/utils/columnUtils.ts b/packages/nc-gui/utils/columnUtils.ts index e8f802c48e..9a4299d843 100644 --- a/packages/nc-gui/utils/columnUtils.ts +++ b/packages/nc-gui/utils/columnUtils.ts @@ -289,7 +289,7 @@ const checkboxIconList = [ }, ] -export const ratingIconList = [ +const ratingIconList = [ { full: 'mdi-star', empty: 'mdi-star-outline', diff --git a/packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.controller.ts b/packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.controller.ts index 05f4cdc987..98718cdce3 100644 --- a/packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.controller.ts +++ b/packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.controller.ts @@ -194,6 +194,7 @@ export class DuplicateController { @Param('modelId') modelId?: string, @Body() body?: { + title?: string; options?: { excludeData?: boolean; excludeViews?: boolean; @@ -226,7 +227,7 @@ export class DuplicateController { const models = await source.getModels(context); const uniqueTitle = generateUniqueName( - `${model.title} copy`, + body.title || `${model.title} copy`, models.map((p) => p.title), ); diff --git a/packages/nocodb/src/schema/swagger-v2.json b/packages/nocodb/src/schema/swagger-v2.json index 98a5b646b9..949235a7e3 100644 --- a/packages/nocodb/src/schema/swagger-v2.json +++ b/packages/nocodb/src/schema/swagger-v2.json @@ -3883,6 +3883,11 @@ "excludeHooks": { "type": "boolean", "required": false + }, + "title": { + "type": "string", + "required": false, + "description": "New table title" } } } @@ -20568,7 +20573,6 @@ } }, "required": [ - "table_name", "title" ], "x-stoplight": { @@ -20839,7 +20843,7 @@ }, "required": [ "columns", - "table_name" + "title" ], "title": "Table Request Model", "type": "object", diff --git a/packages/nocodb/src/schema/swagger.json b/packages/nocodb/src/schema/swagger.json index 4b68b1d215..d29b9feede 100644 --- a/packages/nocodb/src/schema/swagger.json +++ b/packages/nocodb/src/schema/swagger.json @@ -4489,6 +4489,11 @@ "excludeHooks": { "type": "boolean", "required": false + }, + "title": { + "type": "string", + "required": false, + "description": "New table title" } } } @@ -25625,7 +25630,7 @@ } }, "required": [ - "table_name", + "title", "title" ], "x-stoplight": { @@ -25905,7 +25910,7 @@ }, "required": [ "columns", - "table_name" + "title" ], "title": "Table Request Model", "type": "object", diff --git a/packages/nocodb/src/services/tables.service.ts b/packages/nocodb/src/services/tables.service.ts index 090d9f5e89..af54c9366c 100644 --- a/packages/nocodb/src/services/tables.service.ts +++ b/packages/nocodb/src/services/tables.service.ts @@ -558,18 +558,12 @@ export class TablesService { } } - - - if ( - !tableCreatePayLoad.title - ) { - NcError.badRequest( - 'Missing table `title` property in request body', - ); + if (!tableCreatePayLoad.title) { + NcError.badRequest('Missing table `title` property in request body'); } - if(!tableCreatePayLoad.table_name) { - + if (!tableCreatePayLoad.table_name) { + tableCreatePayLoad.table_name = tableCreatePayLoad.title; } if ( @@ -623,8 +617,6 @@ export class TablesService { ); } - - const sqlMgr = await ProjectMgrv2.getSqlMgr(context, base); const sqlClient = await NcConnectionMgrv2.getSqlClient(source); From a22e4c579fab04c80fc8c2ec3b06d1552012f7ab Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 16 Oct 2024 10:30:45 +0000 Subject: [PATCH 4/8] test: update in test --- packages/nocodb/tests/unit/rest/tests/table.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/nocodb/tests/unit/rest/tests/table.test.ts b/packages/nocodb/tests/unit/rest/tests/table.test.ts index a9cfee807d..a31d346009 100644 --- a/packages/nocodb/tests/unit/rest/tests/table.test.ts +++ b/packages/nocodb/tests/unit/rest/tests/table.test.ts @@ -48,13 +48,13 @@ function tableStaticTests() { expect(response.body.list).to.be.an('array').not.empty; }); - it('Create table with no table name', async function () { + it('Create table with no table title', async function () { const response = await request(context.app) .post(`/api/v1/db/meta/projects/${base.id}/tables`) .set('xc-auth', context.token) .send({ - table_name: undefined, - title: 'new_title', + table_name: 'new_table_name', + title: undefined, columns: defaultColumns(context), }) .expect(400); From 8e1c05090c0706d0cbdaa258e149b38ce8f160aa Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 16 Oct 2024 10:30:46 +0000 Subject: [PATCH 5/8] refactor: extract icon based on index --- packages/nc-gui/components/cell/Rating.vue | 8 ++++---- .../smartsheet/column/CheckboxOptions.vue | 1 + .../components/smartsheet/column/RatingOptions.vue | 1 + packages/nc-gui/utils/columnUtils.ts | 13 +++++++------ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/nc-gui/components/cell/Rating.vue b/packages/nc-gui/components/cell/Rating.vue index 9b97f7f37f..26cb5b5ad5 100644 --- a/packages/nc-gui/components/cell/Rating.vue +++ b/packages/nc-gui/components/cell/Rating.vue @@ -1,4 +1,6 @@