From 3b68f20ee54f46c4d1830e5aa29beb60dc528e09 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Mon, 22 Jul 2024 07:12:55 +0000 Subject: [PATCH] fix: show bt relation of self-link under system fields --- .../smartsheet/column/FormulaOptions.vue | 2 +- .../smartsheet/toolbar/CreateGroupBy.vue | 2 +- .../smartsheet/toolbar/CreateSort.vue | 2 +- .../toolbar/FieldListAutoCompleteDropdown.vue | 4 +-- packages/nc-gui/composables/useViewColumns.ts | 2 +- packages/nocodb-sdk/src/lib/UITypes.ts | 31 ++++++++++++------- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue b/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue index 03563d389d..d7971b5a23 100644 --- a/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue +++ b/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue @@ -37,7 +37,7 @@ const supportedColumns = computed( return false } - if (isHiddenCol(col)) { + if (isHiddenCol(col, meta.value)) { return false } diff --git a/packages/nc-gui/components/smartsheet/toolbar/CreateGroupBy.vue b/packages/nc-gui/components/smartsheet/toolbar/CreateGroupBy.vue index 88de18ec18..a3016af294 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/CreateGroupBy.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/CreateGroupBy.vue @@ -32,7 +32,7 @@ const options = computed( return false } - if (isHiddenCol(c)) { + if (isHiddenCol(c, meta.value)) { /** ignore mm relation column, created by and last modified by system field */ return false } diff --git a/packages/nc-gui/components/smartsheet/toolbar/CreateSort.vue b/packages/nc-gui/components/smartsheet/toolbar/CreateSort.vue index 9cb46111cd..2595e2c750 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/CreateSort.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/CreateSort.vue @@ -27,7 +27,7 @@ const options = computed( return true } if (isSystemColumn(metaColumnById?.value?.[c.id!])) { - if (isHiddenCol(c)) { + if (isHiddenCol(c,meta.value)) { /** ignore mm relation column, created by and last modified by system field */ return false } diff --git a/packages/nc-gui/components/smartsheet/toolbar/FieldListAutoCompleteDropdown.vue b/packages/nc-gui/components/smartsheet/toolbar/FieldListAutoCompleteDropdown.vue index 54dd63e945..8ec98041f7 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/FieldListAutoCompleteDropdown.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/FieldListAutoCompleteDropdown.vue @@ -39,7 +39,7 @@ const options = computed(() => } if (isSystemColumn(metaColumnById?.value?.[c.id!])) { - if (isHiddenCol(c)) { + if (isHiddenCol(c,meta.value)) { /** ignore mm relation column, created by and last modified by system field */ return false } @@ -60,7 +60,7 @@ const options = computed(() => return true } if (isSystemColumn(metaColumnById?.value?.[c.id!])) { - if (isHiddenCol(c)) { + if (isHiddenCol(c, meta.value)) { /** ignore mm relation column, created by and last modified by system field */ return false } diff --git a/packages/nc-gui/composables/useViewColumns.ts b/packages/nc-gui/composables/useViewColumns.ts index 75c40af61f..1de81319a5 100644 --- a/packages/nc-gui/composables/useViewColumns.ts +++ b/packages/nc-gui/composables/useViewColumns.ts @@ -87,7 +87,7 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState( fields.value = meta.value?.columns ?.filter((column: ColumnType) => { // filter created by and last modified by system columns - if (isHiddenCol(column)) return false + if (isHiddenCol(column, meta.value)) return false return true }) .map((column: ColumnType) => { diff --git a/packages/nocodb-sdk/src/lib/UITypes.ts b/packages/nocodb-sdk/src/lib/UITypes.ts index f5a3c6d42b..875cf7387b 100644 --- a/packages/nocodb-sdk/src/lib/UITypes.ts +++ b/packages/nocodb-sdk/src/lib/UITypes.ts @@ -1,5 +1,6 @@ -import { ColumnReqType, ColumnType } from './Api'; +import { ColumnReqType, ColumnType, TableType } from './Api'; import { FormulaDataTypes } from './formulaHelpers'; +import { RelationTypes } from '~/lib/globals'; enum UITypes { ID = 'ID', @@ -208,17 +209,25 @@ export function isCreatedOrLastModifiedByCol( } export function isHiddenCol( - col: (ColumnReqType | ColumnType) & { system?: number | boolean } + col: (ColumnReqType | ColumnType) & { + colOptions?: any; + system?: number | boolean; + }, + tableMeta: Partial ) { - return ( - col.system && - ( - [ - UITypes.CreatedBy, - UITypes.LastModifiedBy, - UITypes.LinkToAnotherRecord, - ] as string[] - ).includes(col.uidt) + if (!col.system) return false; + + // hide belongs to column in mm tables only + if (col.uidt === UITypes.LinkToAnotherRecord) { + if (col.colOptions?.type === RelationTypes.BELONGS_TO && tableMeta?.mm) { + return true; + } + // hide system columns in other tables which are has-many used for mm + return col.colOptions?.type === RelationTypes.HAS_MANY; + } + + return ([UITypes.CreatedBy, UITypes.LastModifiedBy] as string[]).includes( + col.uidt ); }