Browse Source

refactor: introduce `isHiddenCol` method to replace `isMMSystemCol` and `isCreatedOrLastModifiedByCol`

pull/7524/head
Pranav C 7 months ago
parent
commit
ae332d936b
  1. 4
      packages/nc-gui/components/smartsheet/column/FormulaOptions.vue
  2. 6
      packages/nc-gui/components/smartsheet/toolbar/CreateGroupBy.vue
  3. 6
      packages/nc-gui/components/smartsheet/toolbar/CreateSort.vue
  4. 10
      packages/nc-gui/components/smartsheet/toolbar/FieldListAutoCompleteDropdown.vue
  5. 4
      packages/nc-gui/composables/useViewColumns.ts
  6. 11
      packages/nocodb-sdk/src/lib/UITypes.ts
  7. 2
      packages/nocodb-sdk/src/lib/index.ts

4
packages/nc-gui/components/smartsheet/column/FormulaOptions.vue

@ -5,7 +5,7 @@ import jsep from 'jsep'
import { import {
FormulaError, FormulaError,
UITypes, UITypes,
isCreatedOrLastModifiedByCol, isHiddenCol,
jsepCurlyHook, jsepCurlyHook,
substituteColumnIdWithAliasInFormula, substituteColumnIdWithAliasInFormula,
validateFormulaAndExtractTreeWithType, validateFormulaAndExtractTreeWithType,
@ -58,7 +58,7 @@ const supportedColumns = computed(
return false return false
} }
if (isCreatedOrLastModifiedByCol(col) && col.system) { if (isHiddenCol(col)) {
return false return false
} }

6
packages/nc-gui/components/smartsheet/toolbar/CreateGroupBy.vue

@ -1,6 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk' import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk'
import { RelationTypes, UITypes, isCreatedOrLastModifiedByCol, isLinksOrLTAR, isSystemColumn } from 'nocodb-sdk' import { RelationTypes, UITypes, isHiddenCol, isLinksOrLTAR, isSystemColumn } from 'nocodb-sdk'
const props = defineProps<{ const props = defineProps<{
// As we need to focus search box when the parent is opened // As we need to focus search box when the parent is opened
@ -40,8 +40,8 @@ const options = computed<ColumnType[]>(
return false return false
} }
if (isCreatedOrLastModifiedByCol(c)) { if (isHiddenCol(c)) {
/** ignore created by and last modified by system field */ /** ignore mm relation column, created by and last modified by system field */
return false return false
} }

6
packages/nc-gui/components/smartsheet/toolbar/CreateSort.vue

@ -1,6 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk' import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk'
import { RelationTypes, UITypes, isCreatedOrLastModifiedByCol, isLinksOrLTAR, isSystemColumn } from 'nocodb-sdk' import { RelationTypes, UITypes, isHiddenCol, isLinksOrLTAR, isSystemColumn } from 'nocodb-sdk'
const props = defineProps<{ const props = defineProps<{
// As we need to focus search box when the parent is opened // As we need to focus search box when the parent is opened
@ -33,8 +33,8 @@ const options = computed<ColumnType[]>(
return true return true
} }
if (isSystemColumn(metaColumnById?.value?.[c.id!])) { if (isSystemColumn(metaColumnById?.value?.[c.id!])) {
if (isCreatedOrLastModifiedByCol(c)) { if (isHiddenCol(c)) {
/** ignore created by and last modified by system field */ /** ignore mm relation column, created by and last modified by system field */
return false return false
} }

10
packages/nc-gui/components/smartsheet/toolbar/FieldListAutoCompleteDropdown.vue

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import type { SelectProps } from 'ant-design-vue' import type { SelectProps } from 'ant-design-vue'
import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk' import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk'
import { RelationTypes, UITypes, isCreatedOrLastModifiedByCol, isLinksOrLTAR, isSystemColumn, isVirtualCol } from 'nocodb-sdk' import { RelationTypes, UITypes, isHiddenCol, isLinksOrLTAR, isSystemColumn, isVirtualCol } from 'nocodb-sdk'
import { MetaInj, computed, inject, ref, resolveComponent, useViewColumnsOrThrow } from '#imports' import { MetaInj, computed, inject, ref, resolveComponent, useViewColumnsOrThrow } from '#imports'
const { modelValue, isSort, allowEmpty, ...restProps } = defineProps<{ const { modelValue, isSort, allowEmpty, ...restProps } = defineProps<{
@ -28,8 +28,8 @@ const options = computed<SelectProps['options']>(() =>
( (
customColumns.value?.filter((c: ColumnType) => { customColumns.value?.filter((c: ColumnType) => {
if (isSystemColumn(metaColumnById?.value?.[c.id!])) { if (isSystemColumn(metaColumnById?.value?.[c.id!])) {
if (isCreatedOrLastModifiedByCol(c)) { if (isHiddenCol(c)) {
/** ignore created by and last modified by system field */ /** ignore mm relation column, created by and last modified by system field */
return false return false
} }
} }
@ -40,8 +40,8 @@ const options = computed<SelectProps['options']>(() =>
return true return true
} }
if (isSystemColumn(metaColumnById?.value?.[c.id!])) { if (isSystemColumn(metaColumnById?.value?.[c.id!])) {
if (isCreatedOrLastModifiedByCol(c)) { if (isHiddenCol(c)) {
/** ignore created by and last modified by system field */ /** ignore mm relation column, created by and last modified by system field */
return false return false
} }

4
packages/nc-gui/composables/useViewColumns.ts

@ -1,4 +1,4 @@
import { ViewTypes, isCreatedOrLastModifiedByCol, isMMSystemCol, isSystemColumn } from 'nocodb-sdk' import { ViewTypes, isHiddenCol, isSystemColumn } from 'nocodb-sdk'
import type { ColumnType, GridColumnReqType, GridColumnType, MapType, TableType, ViewType } from 'nocodb-sdk' import type { ColumnType, GridColumnReqType, GridColumnType, MapType, TableType, ViewType } from 'nocodb-sdk'
import type { ComputedRef, Ref } from 'vue' import type { ComputedRef, Ref } from 'vue'
import { computed, ref, storeToRefs, useBase, useNuxtApp, useRoles, useUndoRedo, watch } from '#imports' import { computed, ref, storeToRefs, useBase, useNuxtApp, useRoles, useUndoRedo, watch } from '#imports'
@ -72,7 +72,7 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(
fields.value = meta.value?.columns fields.value = meta.value?.columns
?.filter((column: ColumnType) => { ?.filter((column: ColumnType) => {
// filter created by and last modified by system columns // filter created by and last modified by system columns
if ((isCreatedOrLastModifiedByCol(column) || isMMSystemCol(column)) && column.system) return false if (isHiddenCol(column)) return false
return true return true
}) })
.map((column: ColumnType) => { .map((column: ColumnType) => {

11
packages/nocodb-sdk/src/lib/UITypes.ts

@ -162,11 +162,18 @@ export function isCreatedOrLastModifiedByCol(
); );
} }
export function isMMSystemCol( export function isHiddenCol(
col: (ColumnReqType | ColumnType) & { system?: number | boolean } col: (ColumnReqType | ColumnType) & { system?: number | boolean }
) { ) {
return ( return (
col.system && [UITypes.LinkToAnotherRecord].includes(<UITypes>col.uidt) col.system &&
(
[
UITypes.CreatedBy,
UITypes.LastModifiedBy,
UITypes.LinkToAnotherRecord,
] as string[]
).includes(col.uidt)
); );
} }

2
packages/nocodb-sdk/src/lib/index.ts

@ -16,7 +16,7 @@ export {
isLinksOrLTAR, isLinksOrLTAR,
isCreatedOrLastModifiedTimeCol, isCreatedOrLastModifiedTimeCol,
isCreatedOrLastModifiedByCol, isCreatedOrLastModifiedByCol,
isMMSystemCol, isHiddenCol,
} from '~/lib/UITypes'; } from '~/lib/UITypes';
export { default as CustomAPI, FileType } from '~/lib/CustomAPI'; export { default as CustomAPI, FileType } from '~/lib/CustomAPI';
export { default as TemplateGenerator } from '~/lib/TemplateGenerator'; export { default as TemplateGenerator } from '~/lib/TemplateGenerator';

Loading…
Cancel
Save