chore(CTB): remove lodash usage in FormModal

This commit is contained in:
Jamie Howard 2023-06-01 16:14:51 +01:00
parent d13b8ccdaf
commit 0d46b7ada7

View File

@ -1,5 +1,3 @@
import get from 'lodash/get';
import toLower from 'lodash/toLower';
import { attributesForm, attributeTypes, commonBaseForm } from '../attributes';
import { categoryForm, createCategorySchema } from '../category';
import { contentTypeForm, createContentTypeSchema } from '../contentType';
@ -86,7 +84,7 @@ const forms = {
extensions
) {
// Get the attributes object on the schema
const attributes = get(currentSchema, ['schema', 'attributes'], []);
const attributes = currentSchema?.schema?.attributes ?? [];
const usedAttributeNames = getUsedAttributeNames(attributes, options);
try {
@ -163,7 +161,7 @@ const forms = {
});
const pluralNames = Object.values(contentTypes).map((contentType) => {
return get(contentType, ['schema', 'pluralName'], '');
return contentType?.schema?.pluralName ?? '';
});
const takenNames = isEditing
@ -172,33 +170,30 @@ const forms = {
const takenSingularNames = isEditing
? singularNames.filter((singName) => {
const currentSingularName = get(contentTypes, [ctUid, 'schema', 'singularName'], '');
const { schema } = contentTypes[ctUid];
return currentSingularName !== singName;
return schema.singularName !== singName;
})
: singularNames;
const takenPluralNames = isEditing
? pluralNames.filter((pluralName) => {
const currentPluralName = get(contentTypes, [ctUid, 'schema', 'pluralName'], '');
const { schema } = contentTypes[ctUid];
return currentPluralName !== pluralName;
return schema.pluralName !== pluralName;
})
: pluralNames;
// return the array of collection names not all normalized
const collectionNames = Object.values(contentTypes).map((contentType) => {
return get(contentType, ['schema', 'collectionName'], '');
return contentType?.schema?.collectionName ?? '';
});
const takenCollectionNames = isEditing
? collectionNames.filter((collectionName) => {
const currentPluralName = get(contentTypes, [ctUid, 'schema', 'pluralName'], '');
const currentCollectionName = get(
contentTypes,
[ctUid, 'schema', 'collectionName'],
''
);
const { schema } = contentTypes[ctUid];
const currentPluralName = schema.pluralName;
const currentCollectionName = schema.collectionName;
return collectionName !== currentPluralName || collectionName !== currentCollectionName;
})
@ -280,7 +275,7 @@ const forms = {
return dynamiczoneForm.advanced.default();
},
base({ data }) {
const isCreatingComponent = get(data, 'createComponent', false);
const isCreatingComponent = data?.createComponent ?? false;
if (isCreatingComponent) {
return dynamiczoneForm.base.createComponent();
@ -294,7 +289,7 @@ const forms = {
schema(allCategories, initialData) {
const allowedCategories = allCategories
.filter((cat) => cat !== initialData.name)
.map((cat) => toLower(cat));
.map((cat) => cat.toLowerCase());
return createCategorySchema(allowedCategories);
},