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