Set special flags when configuring db-only fields (#15640)

Co-authored-by: ian <licitdev@gmail.com>
This commit is contained in:
Azri Kahar
2022-10-15 12:15:27 +08:00
committed by GitHub
parent 372d042a48
commit 18bf1344e1
4 changed files with 51 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
import { HelperFunctions, State, StateUpdates } from '../types';
import { getInterface } from '@/interfaces';
import { set } from 'lodash';
import { getSpecialForType } from '@/utils/get-special-for-type';
export function applyChanges(updates: StateUpdates, _state: State, helperFn: HelperFunctions) {
const { hasChanged } = helperFn;
@@ -13,22 +14,9 @@ export function applyChanges(updates: StateUpdates, _state: State, helperFn: Hel
function setSpecialForType(updates: StateUpdates) {
const type = updates.field?.type;
switch (type) {
case 'json':
case 'csv':
case 'boolean':
set(updates, 'field.meta.special', ['cast-' + type]);
break;
case 'uuid':
case 'hash':
case 'geometry':
set(updates, 'field.meta.special', [type]);
break;
case undefined:
break;
default:
set(updates, 'field.meta.special', null);
}
if (type === undefined) return;
const special = getSpecialForType(type);
set(updates, 'field.meta.special', special);
}
function updateInterface(updates: StateUpdates, fn: HelperFunctions) {

View File

@@ -152,6 +152,7 @@ import { getInterface } from '@/interfaces';
import { useRouter } from 'vue-router';
import { cloneDeep } from 'lodash';
import { getLocalTypeForField } from '@/utils/get-local-type';
import { getSpecialForType } from '@/utils/get-special-for-type';
import { notify } from '@/utils/notify';
import { unexpectedError } from '@/utils/unexpected-error';
import { Field } from '@directus/shared/types';
@@ -309,7 +310,8 @@ export default defineComponent({
async function openFieldDetail() {
if (!props.field.meta) {
await fieldsStore.updateField(props.field.collection, props.field.field, { meta: {} });
const special = getSpecialForType(props.field.type);
await fieldsStore.updateField(props.field.collection, props.field.field, { meta: { special } });
}
router.push(`/settings/data-model/${props.field.collection}/${props.field.field}`);