mirror of
https://github.com/directus/directus.git
synced 2026-02-11 09:55:06 -05:00
Set special flags when configuring db-only fields (#15640)
Co-authored-by: ian <licitdev@gmail.com>
This commit is contained in:
28
app/src/utils/get-special-for-type.test.ts
Normal file
28
app/src/utils/get-special-for-type.test.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { TYPES } from '@directus/shared/constants';
|
||||
import { expect, test } from 'vitest';
|
||||
import { getSpecialForType } from './get-special-for-type';
|
||||
|
||||
const castPrefixedSpecials = ['json', 'csv', 'boolean'];
|
||||
const nonPrefixedSpecials = ['uuid', 'hash', 'geometry'];
|
||||
|
||||
test('Returns cast-prefixed special array for json, csv, and boolean field types', () => {
|
||||
const types = TYPES.filter((type) => castPrefixedSpecials.includes(type));
|
||||
for (const type of types) {
|
||||
expect(getSpecialForType(type)).toStrictEqual(['cast-' + type]);
|
||||
}
|
||||
});
|
||||
|
||||
test('Returns special array for uuid, hash, and geometry field types', () => {
|
||||
const types = TYPES.filter((type) => nonPrefixedSpecials.includes(type));
|
||||
for (const type of types) {
|
||||
expect(getSpecialForType(type)).toStrictEqual([type]);
|
||||
}
|
||||
});
|
||||
|
||||
test('Returns null for other field types', () => {
|
||||
const specials = [...castPrefixedSpecials, ...nonPrefixedSpecials];
|
||||
const types = TYPES.filter((type) => !specials.includes(type));
|
||||
for (const type of types) {
|
||||
expect(getSpecialForType(type)).toStrictEqual(null);
|
||||
}
|
||||
});
|
||||
16
app/src/utils/get-special-for-type.ts
Normal file
16
app/src/utils/get-special-for-type.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Type } from '@directus/shared/types';
|
||||
|
||||
export function getSpecialForType(type: Type): string[] | null {
|
||||
switch (type) {
|
||||
case 'json':
|
||||
case 'csv':
|
||||
case 'boolean':
|
||||
return ['cast-' + type];
|
||||
case 'uuid':
|
||||
case 'hash':
|
||||
case 'geometry':
|
||||
return [type];
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user