Browse Source

fix(nc-gui): allow only specific column types for display value

pull/9986/head
Ramesh Mane 3 days ago
parent
commit
f0be54b0bc
  1. 7
      packages/nc-gui/components/smartsheet/header/Menu.vue
  2. 32
      packages/nocodb-sdk/src/lib/UITypes.ts
  3. 18
      packages/nocodb-sdk/src/lib/helperFunctions.ts
  4. 1
      packages/nocodb-sdk/src/lib/index.ts

7
packages/nc-gui/components/smartsheet/header/Menu.vue

@ -1,6 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import { type ColumnReqType, type ColumnType, partialUpdateAllowedTypes, readonlyMetaAllowedTypes } from 'nocodb-sdk' import { type ColumnReqType, type ColumnType, partialUpdateAllowedTypes, readonlyMetaAllowedTypes } from 'nocodb-sdk'
import { PlanLimitTypes, RelationTypes, UITypes, isLinksOrLTAR, isSystemColumn } from 'nocodb-sdk' import { PlanLimitTypes, RelationTypes, UITypes, isLinksOrLTAR, isSystemColumn, isSupportedDisplayValueColumn } from 'nocodb-sdk'
import { SmartsheetStoreEvents, isColumnInvalid } from '#imports' import { SmartsheetStoreEvents, isColumnInvalid } from '#imports'
const props = defineProps<{ virtual?: boolean; isOpen: boolean; isHiddenCol?: boolean }>() const props = defineProps<{ virtual?: boolean; isOpen: boolean; isHiddenCol?: boolean }>()
@ -578,10 +578,7 @@ const onDeleteColumn = () => {
{{ isHiddenCol ? $t('general.showField') : $t('general.hideField') }} {{ isHiddenCol ? $t('general.showField') : $t('general.hideField') }}
</div> </div>
</NcMenuItem> </NcMenuItem>
<NcMenuItem <NcMenuItem v-if="column && isSupportedDisplayValueColumn(column) && !column?.pv && !isHiddenCol" @click="setAsDisplayValue">
v-if="(!virtual || column?.uidt === UITypes.Formula) && !column?.pv && !isHiddenCol"
@click="setAsDisplayValue"
>
<div class="nc-column-set-primary nc-header-menu-item item"> <div class="nc-column-set-primary nc-header-menu-item item">
<GeneralLoader v-if="isLoading === 'setDisplay'" size="regular" /> <GeneralLoader v-if="isLoading === 'setDisplay'" size="regular" />
<GeneralIcon v-else icon="star" class="text-gray-500 !w-4.25 !h-4.25" /> <GeneralIcon v-else icon="star" class="text-gray-500 !w-4.25 !h-4.25" />

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

@ -2,6 +2,7 @@ import { ColumnReqType, ColumnType, TableType } from './Api';
import { FormulaDataTypes } from './formulaHelpers'; import { FormulaDataTypes } from './formulaHelpers';
import { LongTextAiMetaProp, RelationTypes } from '~/lib/globals'; import { LongTextAiMetaProp, RelationTypes } from '~/lib/globals';
import { parseHelper } from './helperFunctions'; import { parseHelper } from './helperFunctions';
import { ncParseProp } from './helperFunctions';
enum UITypes { enum UITypes {
ID = 'ID', ID = 'ID',
@ -331,3 +332,34 @@ export const getUITypesForFormulaDataType = (
return []; return [];
} }
}; };
export const isSupportedDisplayValueColumn = (column: ColumnType) => {
switch (column.uidt) {
case UITypes.SingleLineText:
case UITypes.Date:
case UITypes.DateTime:
case UITypes.Time:
case UITypes.Year:
case UITypes.PhoneNumber:
case UITypes.Email:
case UITypes.URL:
case UITypes.Number:
case UITypes.Currency:
case UITypes.Percent:
case UITypes.Duration:
case UITypes.Formula: {
return true;
}
case UITypes.LongText: {
if (ncParseProp(column.meta)?.richMode) {
return false;
}
//Todo: prevent AI Prompt field once it get merged in develop
return true;
}
default: {
return false;
}
}
};

18
packages/nocodb-sdk/src/lib/helperFunctions.ts

@ -228,6 +228,24 @@ export const integrationCategoryNeedDefault = (category: IntegrationsType) => {
return [IntegrationsType.Ai].includes(category); return [IntegrationsType.Ai].includes(category);
}; };
export function ncParseProp(v: any): any {
if (!v) return {};
try {
return typeof v === 'string' ? JSON.parse(v) ?? {} : v;
} catch {
return {};
}
}
export function ncStringifyProp(v: any): string {
if (!v) return '{}';
try {
return typeof v === 'string' ? v : JSON.stringify(v) ?? '{}';
} catch {
return '{}';
}
}
export function parseHelper(v: any): any { export function parseHelper(v: any): any {
try { try {
return typeof v === 'string' ? JSON.parse(v) : v; return typeof v === 'string' ? JSON.parse(v) : v;

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

@ -24,6 +24,7 @@ export {
getUITypesForFormulaDataType, getUITypesForFormulaDataType,
readonlyMetaAllowedTypes, readonlyMetaAllowedTypes,
partialUpdateAllowedTypes, partialUpdateAllowedTypes,
isSupportedDisplayValueColumn,
} 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