Add default relation to standard object on custom object in manifest (#18033)
add default relation fields when creating an object from an application --------- Co-authored-by: prastoin <paul@twenty.com>
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
import { RESERVED_METADATA_NAME_KEYWORDS } from '@/metadata';
|
||||
|
||||
export const addCustomSuffixIfIsReserved = (name: string): string => {
|
||||
if (!name) return name;
|
||||
|
||||
return RESERVED_METADATA_NAME_KEYWORDS.includes(name)
|
||||
? `${name}Custom`
|
||||
: name;
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
import { addCustomSuffixIfIsReserved } from '@/metadata/utils/add-custom-suffix-if-reserved.util';
|
||||
import camelCase from 'lodash.camelcase';
|
||||
import { slugify } from 'transliteration';
|
||||
|
||||
export const computeMetadataNameFromLabel = ({
|
||||
label,
|
||||
applyCustomSuffix = true,
|
||||
}: {
|
||||
label: string;
|
||||
applyCustomSuffix?: boolean;
|
||||
}): string => {
|
||||
if (!label) return '';
|
||||
|
||||
const prefixedLabel = /^\d/.test(label) ? `n${label}` : label;
|
||||
|
||||
if (prefixedLabel === '') return '';
|
||||
|
||||
const formattedString = slugify(prefixedLabel, {
|
||||
trim: true,
|
||||
separator: '_',
|
||||
allowedChars: 'a-zA-Z0-9',
|
||||
});
|
||||
|
||||
if (formattedString === '') {
|
||||
throw new Error(`Invalid label: "${label}"`);
|
||||
}
|
||||
|
||||
const computedName = camelCase(formattedString);
|
||||
|
||||
return applyCustomSuffix
|
||||
? addCustomSuffixIfIsReserved(computedName)
|
||||
: computedName;
|
||||
};
|
||||
Reference in New Issue
Block a user