Remove header_icon from search

Signed-off-by: soupette <cyril@strapi.io>
This commit is contained in:
soupette 2021-10-14 15:47:09 +02:00
parent adff11cb99
commit 30ac998cb7
15 changed files with 88 additions and 215 deletions

View File

@ -27,7 +27,7 @@ const NoContentType = () => {
<LinkButton <LinkButton
variant="secondary" variant="secondary"
startIcon={<AddIcon />} startIcon={<AddIcon />}
to="/plugins/content-type-builder/content-types/plugin::users-permissions.user?modalType=contentType&kind=collectionType&actionType=create&settingType=base&forTarget=contentType&headerId=content-type-builder.modalForm.contentType.header-create&header_icon_isCustom_1=false&header_icon_name_1=contentType&header_label_1=null" to="/plugins/content-type-builder/content-types/create-content-type"
> >
{formatMessage({ {formatMessage({
id: 'app.components.HomePage.create', id: 'app.components.HomePage.create',

View File

@ -396,7 +396,7 @@ describe('CONTENT MANAGER | pages | NoContentType', () => {
<a <a
aria-disabled="false" aria-disabled="false"
class="c14 c15" class="c14 c15"
href="/plugins/content-type-builder/content-types/plugin::users-permissions.user?modalType=contentType&kind=collectionType&actionType=create&settingType=base&forTarget=contentType&headerId=content-type-builder.modalForm.contentType.header-create&header_icon_isCustom_1=false&header_icon_name_1=contentType&header_label_1=null" href="/plugins/content-type-builder/content-types/create-content-type"
variant="secondary" variant="secondary"
> >
<div <div

View File

@ -36,9 +36,7 @@ const HomePage = () => {
const handleClick = e => { const handleClick = e => {
e.preventDefault(); e.preventDefault();
push( push('/plugins/content-type-builder/content-types/create-content-type');
'/plugins/content-type-builder/content-types/plugins::users-permissions.user?modalType=contentType&kind=collectionType&actionType=create&settingType=base&forTarget=contentType&headerId=content-type-builder.modalForm.contentType.header-create&header_icon_isCustom_1=false&header_icon_name_1=contentType&header_label_1=null'
);
}; };
const hasAlreadyCreatedContentTypes = useMemo(() => { const hasAlreadyCreatedContentTypes = useMemo(() => {

View File

@ -23,6 +23,7 @@ import { pxToRem } from '@strapi/helper-plugin';
const iconByTypes = { const iconByTypes = {
biginteger: Numbers, biginteger: Numbers,
boolean: Boolean, boolean: Boolean,
collectionType: CT,
component: Component, component: Component,
contentType: CT, contentType: CT,
date: Date, date: Date,
@ -58,11 +59,9 @@ const IconBox = styled(Box)`
`; `;
const AttributeIcon = ({ type, ...rest }) => { const AttributeIcon = ({ type, ...rest }) => {
const iconType = type === 'collectionType' ? 'contentType' : type; const Compo = iconByTypes[type];
const Compo = iconByTypes[iconType]; if (!iconByTypes[type]) {
if (!iconByTypes[iconType]) {
return null; return null;
} }

View File

@ -31,18 +31,12 @@ const AttributeOption = ({ type }) => {
const header_info_category_1 = query.header_info_category_1 || null; const header_info_category_1 = query.header_info_category_1 || null;
const header_info_name_1 = query.header_info_name_1 || null; const header_info_name_1 = query.header_info_name_1 || null;
const header_label_2 = query.header_label_2 || null; const header_label_2 = query.header_label_2 || null;
const header_icon_name_2 = query.header_icon_name_2 || null;
const header_icon_isCustom_2 = query.header_icon_isCustom_2 || null;
const header_info_category_2 = query.header_info_category_2 || null; const header_info_category_2 = query.header_info_category_2 || null;
const header_info_name_2 = query.header_info_name_2 || null; const header_info_name_2 = query.header_info_name_2 || null;
const header_label_3 = query.header_label_3 || null; const header_label_3 = query.header_label_3 || null;
const header_icon_name_3 = query.header_icon_name_3 || null;
const header_icon_isCustom_3 = query.header_icon_isCustom_3 || null;
const header_info_category_3 = query.header_info_category_3 || null; const header_info_category_3 = query.header_info_category_3 || null;
const header_info_name_3 = query.header_info_name_3 || null; const header_info_name_3 = query.header_info_name_3 || null;
const header_label_4 = query.header_label_4 || null; const header_label_4 = query.header_label_4 || null;
const header_icon_name_4 = query.header_icon_name_4 || null;
const header_icon_isCustom_4 = query.header_icon_isCustom_4 || null;
const header_info_category_4 = query.header_info_category_4 || null; const header_info_category_4 = query.header_info_category_4 || null;
const header_info_name_4 = query.header_info_name_4 || null; const header_info_name_4 = query.header_info_name_4 || null;
@ -59,22 +53,14 @@ const AttributeOption = ({ type }) => {
header_info_name_1, header_info_name_1,
header_info_category_1, header_info_category_1,
header_label_2, header_label_2,
header_icon_name_2,
header_icon_isCustom_2,
header_info_name_2, header_info_name_2,
header_info_category_2, header_info_category_2,
header_label_3, header_label_3,
header_icon_name_3,
header_icon_isCustom_3,
header_info_name_3, header_info_name_3,
header_info_category_3, header_info_category_3,
header_label_4, header_label_4,
header_icon_name_4,
header_icon_isCustom_4,
header_info_name_4, header_info_name_4,
header_info_category_4, header_info_category_4,
header_icon_isCustom_1: false,
header_icon_name_1: type,
}); });
if (forTarget === 'contentType') { if (forTarget === 'contentType') {

View File

@ -39,13 +39,9 @@ const useContentTypeBuilderMenu = () => {
id: getTrad('modalForm.header.categories'), id: getTrad('modalForm.header.categories'),
defaultMessage: 'Categories', defaultMessage: 'Categories',
}), }),
header_icon_name_1: 'component',
header_icon_isCustom_1: false,
header_info_category_1: null, header_info_category_1: null,
header_info_name_1: null, header_info_name_1: null,
header_label_2: data.name, header_label_2: data.name,
header_icon_name_2: null,
header_icon_isCustom_2: false,
header_info_category_2: null, header_info_category_2: null,
header_info_name_2: null, header_info_name_2: null,
@ -86,8 +82,6 @@ const useContentTypeBuilderMenu = () => {
settingType: 'base', settingType: 'base',
forTarget: modalType, forTarget: modalType,
headerId: getTrad(`modalForm.${type}.header-create`), headerId: getTrad(`modalForm.${type}.header-create`),
header_icon_isCustom_1: 'false',
header_icon_name_1: type,
header_label_1: 'null', header_label_1: 'null',
}); });
push({ push({

View File

@ -130,28 +130,18 @@ const FormModal = () => {
const settingType = query.get('settingType'); const settingType = query.get('settingType');
const headerId = query.get('headerId'); const headerId = query.get('headerId');
const header_label_1 = query.get('header_label_1'); const header_label_1 = query.get('header_label_1');
const header_icon_name_1 = query.get('header_icon_name_1');
const header_icon_isCustom_1 = query.get('header_icon_isCustom_1');
const header_info_category_1 = query.get('header_info_category_1'); const header_info_category_1 = query.get('header_info_category_1');
const header_info_name_1 = query.get('header_info_name_1'); const header_info_name_1 = query.get('header_info_name_1');
const header_label_2 = query.get('header_label_2'); const header_label_2 = query.get('header_label_2');
const header_icon_name_2 = query.get('header_icon_name_2');
const header_icon_isCustom_2 = query.get('header_icon_isCustom_2');
const header_info_category_2 = query.get('header_info_category_2'); const header_info_category_2 = query.get('header_info_category_2');
const header_info_name_2 = query.get('header_info_name_2'); const header_info_name_2 = query.get('header_info_name_2');
const header_label_3 = query.get('header_label_3'); const header_label_3 = query.get('header_label_3');
const header_icon_name_3 = query.get('header_icon_name_3');
const header_icon_isCustom_3 = query.get('header_icon_isCustom_3');
const header_info_category_3 = query.get('header_info_category_3'); const header_info_category_3 = query.get('header_info_category_3');
const header_info_name_3 = query.get('header_info_name_3'); const header_info_name_3 = query.get('header_info_name_3');
const header_label_4 = query.get('header_label_4'); const header_label_4 = query.get('header_label_4');
const header_icon_name_4 = query.get('header_icon_name_4');
const header_icon_isCustom_4 = query.get('header_icon_isCustom_4');
const header_info_category_4 = query.get('header_info_category_4'); const header_info_category_4 = query.get('header_info_category_4');
const header_info_name_4 = query.get('header_info_name_4'); const header_info_name_4 = query.get('header_info_name_4');
const header_label_5 = query.get('header_label_5'); const header_label_5 = query.get('header_label_5');
const header_icon_name_5 = query.get('header_icon_name_5');
const header_icon_isCustom_5 = query.get('header_icon_isCustom_5');
const header_info_category_5 = query.get('header_info_category_5'); const header_info_category_5 = query.get('header_info_category_5');
const header_info_name_5 = query.get('header_info_name_5'); const header_info_name_5 = query.get('header_info_name_5');
const step = query.get('step'); const step = query.get('step');
@ -173,28 +163,18 @@ const FormModal = () => {
step, step,
targetUid, targetUid,
header_label_1, header_label_1,
header_icon_name_1,
header_icon_isCustom_1,
header_info_name_1, header_info_name_1,
header_info_category_1, header_info_category_1,
header_label_2, header_label_2,
header_icon_name_2,
header_icon_isCustom_2,
header_info_name_2, header_info_name_2,
header_info_category_2, header_info_category_2,
header_label_3, header_label_3,
header_icon_name_3,
header_icon_isCustom_3,
header_info_name_3, header_info_name_3,
header_info_category_3, header_info_category_3,
header_label_4, header_label_4,
header_icon_name_4,
header_icon_isCustom_4,
header_info_name_4, header_info_name_4,
header_info_category_4, header_info_category_4,
header_label_5, header_label_5,
header_icon_name_5,
header_icon_isCustom_5,
header_info_name_5, header_info_name_5,
header_info_category_5, header_info_category_5,
headerId, headerId,
@ -287,6 +267,7 @@ const FormModal = () => {
modalType, modalType,
data: { data: {
name, name,
// FIXME
collectionName, collectionName,
draftAndPublish, draftAndPublish,
kind, kind,
@ -624,17 +605,6 @@ const FormModal = () => {
await checkFormValidity(); await checkFormValidity();
sendButtonAddMoreFieldEvent(shouldContinue); sendButtonAddMoreFieldEvent(shouldContinue);
const targetUid = state.forTarget === 'components' ? state.targetUid : uid; const targetUid = state.forTarget === 'components' ? state.targetUid : uid;
let headerIcon;
if (state.forTarget === 'contentType') {
const currentKind = get(allDataSchema, ['contentType', 'schema', 'kind'], 'contentType');
headerIcon = state.kind || currentKind;
} else if (state.forTarget === 'component') {
headerIcon = 'component';
} else {
headerIcon = get(allDataSchema, ['components', state.targetUid, 'schema', 'icon'], '');
}
// Remove the last header when editing // Remove the last header when editing
if (state.actionType === 'edit') { if (state.actionType === 'edit') {
@ -649,6 +619,7 @@ const FormModal = () => {
if (isCreating) { if (isCreating) {
createSchema({ ...modifiedData, kind: state.kind }, state.modalType, uid); createSchema({ ...modifiedData, kind: state.kind }, state.modalType, uid);
} else { } else {
// TODO : add comments
if (canEditContentType(allDataSchema, modifiedData)) { if (canEditContentType(allDataSchema, modifiedData)) {
push({ search: '' }); push({ search: '' });
submitData(modifiedData); submitData(modifiedData);
@ -669,8 +640,6 @@ const FormModal = () => {
forTarget: state.forTarget, forTarget: state.forTarget,
targetUid, targetUid,
header_label_1: modifiedData.name, header_label_1: modifiedData.name,
header_icon_name_1: headerIcon,
header_icon_isCustom_1: null,
}), }),
}); });
} else if (isCreatingComponent) { } else if (isCreatingComponent) {
@ -687,8 +656,6 @@ const FormModal = () => {
forTarget: state.forTarget, forTarget: state.forTarget,
targetUid: componentUid, targetUid: componentUid,
header_label_1: modifiedData.name, header_label_1: modifiedData.name,
header_icon_name_1: 'contentType',
header_icon_isCustom_1: null,
}), }),
pathname: `/plugins/${pluginId}/component-categories/${category}/${componentUid}`, pathname: `/plugins/${pluginId}/component-categories/${category}/${componentUid}`,
}); });
@ -739,8 +706,6 @@ const FormModal = () => {
actionType: 'create', actionType: 'create',
...headersObject, ...headersObject,
header_label_2: modifiedData.name, header_label_2: modifiedData.name,
header_icon_name_2: null,
header_icon_isCustom_2: false,
}); });
const nextSearch = isDynamicZoneAttribute const nextSearch = isDynamicZoneAttribute
? dzSearch ? dzSearch
@ -750,8 +715,6 @@ const FormModal = () => {
forTarget: state.forTarget, forTarget: state.forTarget,
targetUid, targetUid,
...headersObject, ...headersObject,
header_icon_isCustom_1: !['contentType', 'component'].includes(state.forTarget),
header_icon_name_1: headerIcon,
}, },
shouldContinue shouldContinue
); );
@ -786,8 +749,6 @@ const FormModal = () => {
attributeType: 'component', attributeType: 'component',
step: '2', step: '2',
...headersObject, ...headersObject,
header_icon_isCustom_1: !['contentType', 'component'].includes(state.forTarget),
header_icon_name_1: headerIcon,
}; };
push({ push({
@ -827,8 +788,6 @@ const FormModal = () => {
forTarget: state.forTarget, forTarget: state.forTarget,
targetUid: state.targetUid, targetUid: state.targetUid,
...headersObject, ...headersObject,
header_icon_isCustom_1: !['contentType', 'component'].includes(state.forTarget),
header_icon_name_1: headerIcon,
}; };
push({ search: makeSearch(nextSearch, shouldContinue) }); push({ search: makeSearch(nextSearch, shouldContinue) });
@ -855,8 +814,6 @@ const FormModal = () => {
attributeType: 'component', attributeType: 'component',
step: '2', step: '2',
...headersObject, ...headersObject,
header_icon_isCustom_1: false,
header_icon_name_1: 'component',
}; };
trackUsage('willCreateComponentFromAttributesModal'); trackUsage('willCreateComponentFromAttributesModal');
@ -909,11 +866,7 @@ const FormModal = () => {
forTarget: 'components', forTarget: 'components',
targetUid: componentUid, targetUid: componentUid,
...headersObject, ...headersObject,
header_icon_isCustom_1: true,
header_icon_name_1: componentToCreate.icon,
[`header_label_${nextHeaderIndex}`]: modifiedData.name, [`header_label_${nextHeaderIndex}`]: modifiedData.name,
[`header_icon_name_${nextHeaderIndex}`]: 'component',
[`header_icon_isCustom_${nextHeaderIndex}`]: false,
[`header_info_category_${nextHeaderIndex}`]: category, [`header_info_category_${nextHeaderIndex}`]: category,
[`header_info_name_${nextHeaderIndex}`]: componentToCreate.name, [`header_info_name_${nextHeaderIndex}`]: componentToCreate.name,
}; };
@ -961,11 +914,7 @@ const FormModal = () => {
forTarget: 'components', forTarget: 'components',
targetUid: componentUid, targetUid: componentUid,
...headersObject, ...headersObject,
header_icon_isCustom_1: true,
header_icon_name_1: modifiedData.componentToCreate.icon,
[`header_label_${nextHeaderIndex}`]: modifiedData.name, [`header_label_${nextHeaderIndex}`]: modifiedData.name,
[`header_icon_name_${nextHeaderIndex}`]: 'component',
[`header_icon_isCustom_${nextHeaderIndex}`]: false,
[`header_info_category_${nextHeaderIndex}`]: category, [`header_info_category_${nextHeaderIndex}`]: category,
[`header_info_name_${nextHeaderIndex}`]: modifiedData.componentToCreate.name, [`header_info_name_${nextHeaderIndex}`]: modifiedData.componentToCreate.name,
}; };
@ -999,6 +948,7 @@ const FormModal = () => {
}); });
} }
}; };
const handleClosed = () => { const handleClosed = () => {
// Close the modal // Close the modal
push({ search: '' }); push({ search: '' });
@ -1065,6 +1015,11 @@ const FormModal = () => {
return null; return null;
} }
// FIXME
if (!state.modalType) {
return null;
}
const formToDisplay = get(forms, [state.modalType, 'form'], { const formToDisplay = get(forms, [state.modalType, 'form'], {
advanced: () => ({ advanced: () => ({
sections: [], sections: [],
@ -1138,7 +1093,15 @@ const FormModal = () => {
return ( return (
<> <>
<ModalLayout onClose={handleClosed} labelledBy="title"> <ModalLayout onClose={handleClosed} labelledBy="title">
<FormModalHeader headerId={state.headerId} headers={headers} /> <FormModalHeader
headerId={state.headerId}
headers={headers}
contentTypeKind={state.kind}
modalType={state.modalType}
forTarget={state.forTarget}
targetUid={state.targetUid}
attributeType={state.attributeType}
/>
{isPickingAttribute && ( {isPickingAttribute && (
<AttributeOptions <AttributeOptions
attributes={displayedAttributes} attributes={displayedAttributes}

View File

@ -1,12 +1,6 @@
import { set } from 'lodash'; import { set } from 'lodash';
const ALLOWED_KEYS = [ const ALLOWED_KEYS = ['header_label', 'header_info_category', 'header_info_name'];
'header_label',
'header_icon_name',
'header_icon_isCustom',
'header_info_category',
'header_info_name',
];
const createHeadersArray = obj => { const createHeadersArray = obj => {
const array = Object.keys(obj).reduce((acc, current) => { const array = Object.keys(obj).reduce((acc, current) => {
const splitted = current.split('_'); const splitted = current.split('_');
@ -16,11 +10,7 @@ const createHeadersArray = obj => {
const currentKeysIndex = parseInt(splitted[splitted.length - 1] - 1, 10); const currentKeysIndex = parseInt(splitted[splitted.length - 1] - 1, 10);
const path = [currentKeysIndex, ...currentKeys.filter(key => key !== 'header')]; const path = [currentKeysIndex, ...currentKeys.filter(key => key !== 'header')];
let value = obj[current]; const value = obj[current];
if (current.includes('isCustom')) {
value = obj[current] === 'true';
}
set(acc, path, value); set(acc, path, value);
} }

View File

@ -12,28 +12,18 @@ const INITIAL_STATE_DATA = {
targetUid: null, targetUid: null,
headerId: null, headerId: null,
header_label_1: null, header_label_1: null,
header_icon_name_1: null,
header_icon_isCustom_1: null,
header_info_category_1: null, header_info_category_1: null,
header_info_name_1: null, header_info_name_1: null,
header_label_2: null, header_label_2: null,
header_icon_name_2: null,
header_icon_isCustom_2: null,
header_info_category_2: null, header_info_category_2: null,
header_info_name_2: null, header_info_name_2: null,
header_label_3: null, header_label_3: null,
header_icon_name_3: null,
header_icon_isCustom_3: null,
header_info_category_3: null, header_info_category_3: null,
header_info_name_3: null, header_info_name_3: null,
header_label_4: null, header_label_4: null,
header_icon_name_4: null,
header_icon_isCustom_4: null,
header_info_category_4: null, header_info_category_4: null,
header_info_name_4: null, header_info_name_4: null,
header_label_5: null, header_label_5: null,
header_icon_name_5: null,
header_icon_isCustom_5: null,
header_info_category_5: null, header_info_category_5: null,
header_info_name_5: null, header_info_name_5: null,
}; };

View File

@ -15,18 +15,12 @@ describe('FormModal | utils | createHeadersArray', () => {
targetUid: null, targetUid: null,
headerId: null, headerId: null,
header_label_1: null, header_label_1: null,
header_icon_name_1: null,
header_icon_isCustom_1: null,
header_info_category_1: null, header_info_category_1: null,
header_info_name_1: null, header_info_name_1: null,
header_label_2: null, header_label_2: null,
header_icon_name_2: null,
header_icon_isCustom_2: null,
header_info_category_2: null, header_info_category_2: null,
header_info_name_2: null, header_info_name_2: null,
header_label_3: null, header_label_3: null,
header_icon_name_3: null,
header_icon_isCustom_3: null,
header_info_category_3: null, header_info_category_3: null,
header_info_name_3: null, header_info_name_3: null,
}; };
@ -49,28 +43,19 @@ describe('FormModal | utils | createHeadersArray', () => {
targetUid: null, targetUid: null,
headerId: null, headerId: null,
header_label_1: 'restaurant', header_label_1: 'restaurant',
header_icon_name_1: 'contentType',
header_icon_isCustom_1: 'false',
header_info_category_1: null, header_info_category_1: null,
header_info_name_1: null, header_info_name_1: null,
header_label_2: null, header_label_2: null,
header_icon_name_2: null,
header_icon_isCustom_2: null,
header_info_category_2: null, header_info_category_2: null,
header_info_name_2: null, header_info_name_2: null,
header_label_3: null, header_label_3: null,
header_icon_name_3: null,
header_icon_isCustom_3: null,
header_info_category_3: null, header_info_category_3: null,
header_info_name_3: null, header_info_name_3: null,
}; };
const expected = [ const expected = [
{ {
label: 'restaurant', label: 'restaurant',
icon: {
name: 'contentType',
isCustom: false,
},
info: { info: {
name: null, name: null,
category: null, category: null,
@ -97,18 +82,12 @@ describe('FormModal | utils | createHeadersArray', () => {
targetUid: null, targetUid: null,
headerId: null, headerId: null,
header_label_1: 'restaurant', header_label_1: 'restaurant',
header_icon_name_1: 'bool',
header_icon_isCustom_1: 'true',
header_info_category_1: null, header_info_category_1: null,
header_info_name_1: null, header_info_name_1: null,
header_label_2: 'closing period', header_label_2: 'closing period',
header_icon_name_2: null,
header_icon_isCustom_2: null,
header_info_category_2: 'default', header_info_category_2: 'default',
header_info_name_2: 'closingperiod', header_info_name_2: 'closingperiod',
header_label_3: null, header_label_3: null,
header_icon_name_3: null,
header_icon_isCustom_3: null,
header_info_category_3: null, header_info_category_3: null,
header_info_name_3: null, header_info_name_3: null,
}; };
@ -116,10 +95,7 @@ describe('FormModal | utils | createHeadersArray', () => {
const expected = [ const expected = [
{ {
label: 'restaurant', label: 'restaurant',
icon: {
name: 'bool',
isCustom: true,
},
info: { info: {
name: null, name: null,
category: null, category: null,
@ -127,10 +103,7 @@ describe('FormModal | utils | createHeadersArray', () => {
}, },
{ {
label: 'closing period', label: 'closing period',
icon: {
name: null,
isCustom: false,
},
info: { info: {
name: 'closingperiod', name: 'closingperiod',
category: 'default', category: 'default',

View File

@ -5,10 +5,7 @@ describe('FormModal | utils | createHeadersArray', () => {
const data = [ const data = [
{ {
label: 'test', label: 'test',
icon: {
name: 'contentType',
isCustom: false,
},
info: { info: {
name: null, name: null,
category: null, category: null,
@ -16,10 +13,7 @@ describe('FormModal | utils | createHeadersArray', () => {
}, },
{ {
label: 'test2', label: 'test2',
icon: {
name: 'book',
isCustom: true,
},
info: { info: {
name: 'something', name: 'something',
category: 'default', category: 'default',
@ -29,13 +23,11 @@ describe('FormModal | utils | createHeadersArray', () => {
const expected = { const expected = {
header_label_1: 'test', header_label_1: 'test',
header_icon_name_1: 'contentType',
header_icon_isCustom_1: false,
header_info_name_1: null, header_info_name_1: null,
header_info_category_1: null, header_info_category_1: null,
header_label_2: 'test2', header_label_2: 'test2',
header_icon_name_2: 'book',
header_icon_isCustom_2: true,
header_info_name_2: 'something', header_info_name_2: 'something',
header_info_category_2: 'default', header_info_category_2: 'default',
}; };

View File

@ -16,6 +16,7 @@ import { Row } from '@strapi/parts/Row';
import { Stack } from '@strapi/parts/Stack'; import { Stack } from '@strapi/parts/Stack';
import { ButtonText } from '@strapi/parts/Text'; import { ButtonText } from '@strapi/parts/Text';
import styled from 'styled-components'; import styled from 'styled-components';
import useDataManager from '../../hooks/useDataManager';
import AttributeIcon from '../AttributeIcon'; import AttributeIcon from '../AttributeIcon';
const IconBox = styled(Box)` const IconBox = styled(Box)`
@ -24,8 +25,49 @@ const IconBox = styled(Box)`
} }
`; `;
const FormModalHeader = ({ headerId, headers }) => { const FormModalHeader = ({
attributeType,
contentTypeKind,
forTarget,
headerId,
headers,
modalType,
targetUid,
}) => {
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
const { modifiedData } = useDataManager();
let icon;
let isFontAwesomeIcon = false;
if (modalType === 'chooseAttribute') {
const schema = modifiedData[forTarget][targetUid] || modifiedData[forTarget];
if (forTarget === 'components') {
icon = schema.schema.icon;
isFontAwesomeIcon = true;
} else if (forTarget === 'component') {
icon = 'component';
} else {
icon = schema.schema.kind;
}
}
if (modalType === 'contentType') {
icon = contentTypeKind;
}
if (['component', 'editCategory'].includes(modalType)) {
icon = 'component';
}
if (modalType === 'addComponentToDynamicZone') {
icon = 'dynamiczone';
}
if (modalType === 'attribute') {
icon = attributeType;
}
// TODO refacto // TODO refacto
// Editing a content type or component // Editing a content type or component
@ -34,7 +76,7 @@ const FormModalHeader = ({ headerId, headers }) => {
<ModalHeader> <ModalHeader>
<Row> <Row>
<Box> <Box>
<AttributeIcon type={headers[0].icon.name} /> <AttributeIcon type={icon} />
</Box> </Box>
<Box paddingLeft={3}> <Box paddingLeft={3}>
<ButtonText textColor="neutral800" as="h2" id="title"> <ButtonText textColor="neutral800" as="h2" id="title">
@ -47,15 +89,14 @@ const FormModalHeader = ({ headerId, headers }) => {
} }
const breadcrumbsLabel = headers.map(({ label }) => label).join(','); const breadcrumbsLabel = headers.map(({ label }) => label).join(',');
const { name, isCustom } = headers[0].icon;
return ( return (
<ModalHeader> <ModalHeader>
<Stack horizontal size={3}> <Stack horizontal size={3}>
{!isCustom && <AttributeIcon type={name} />} {!isFontAwesomeIcon && <AttributeIcon type={icon} />}
{isCustom && ( {isFontAwesomeIcon && (
<IconBox> <IconBox>
<FontAwesomeIcon icon={name} /> <FontAwesomeIcon icon={icon} />
</IconBox> </IconBox>
)} )}
@ -82,10 +123,16 @@ const FormModalHeader = ({ headerId, headers }) => {
}; };
FormModalHeader.defaultProps = { FormModalHeader.defaultProps = {
attributeType: null,
contentTypeKind: null,
headerId: null, headerId: null,
targetUid: null,
}; };
FormModalHeader.propTypes = { FormModalHeader.propTypes = {
attributeType: PropTypes.string,
contentTypeKind: PropTypes.string,
forTarget: PropTypes.oneOf(['contentType', 'component', 'components']).isRequired,
headerId: PropTypes.string, headerId: PropTypes.string,
headers: PropTypes.arrayOf( headers: PropTypes.arrayOf(
PropTypes.shape({ PropTypes.shape({
@ -93,6 +140,8 @@ FormModalHeader.propTypes = {
label: PropTypes.string.isRequired, label: PropTypes.string.isRequired,
}) })
).isRequired, ).isRequired,
modalType: PropTypes.string.isRequired,
targetUid: PropTypes.string,
}; };
export default FormModalHeader; export default FormModalHeader;

View File

@ -50,11 +50,7 @@ function List({
const { openModalAddField } = useListView(); const { openModalAddField } = useListView();
const onClickAddField = () => { const onClickAddField = () => {
trackUsage('hasClickedCTBAddFieldBanner'); trackUsage('hasClickedCTBAddFieldBanner');
const firstComponentIcon = get(
modifiedData,
['components', firstLoopComponentUid, 'schema', 'icon'],
''
);
const firstComponentCategory = get( const firstComponentCategory = get(
modifiedData, modifiedData,
['components', firstLoopComponentUid, 'category'], ['components', firstLoopComponentUid, 'category'],
@ -75,39 +71,21 @@ function List({
['components', secondLoopComponentUid, 'schema', 'name'], ['components', secondLoopComponentUid, 'schema', 'name'],
null null
); );
const secondComponentIcon = get(
modifiedData,
['components', secondLoopComponentUid, 'schema', 'icon'],
''
);
const headerIconName1 =
editTarget === 'contentType'
? get(modifiedData, ['contentType', 'schema', 'kind'], null)
: editTarget;
let firstHeaderObject = { let firstHeaderObject = {
header_label_1: mainTypeName, header_label_1: mainTypeName,
header_icon_name_1: headerIconName1,
header_icon_isCustom_1: false,
header_info_category_1: null, header_info_category_1: null,
header_info_name_1: null, header_info_name_1: null,
}; };
let secondHeaderObject = { let secondHeaderObject = {
header_label_2: firstLoopComponentName, header_label_2: firstLoopComponentName,
header_icon_name_2: 'component',
header_icon_isCustom_2: false,
header_info_category_2: firstComponentCategory, header_info_category_2: firstComponentCategory,
header_info_name_2: firstComponentFriendlyName, header_info_name_2: firstComponentFriendlyName,
}; };
let thirdHeaderObject = { let thirdHeaderObject = {
header_icon_name_3: 'component',
header_icon_isCustom_3: false,
header_info_category_3: secondComponentCategory,
header_info_name_3: secondComponentFriendlyName, header_info_name_3: secondComponentFriendlyName,
}; };
let fourthHeaderObject = { let fourthHeaderObject = {
header_icon_name_4: null,
header_icon_isCustom_4: false,
header_info_category_4: secondComponentCategory, header_info_category_4: secondComponentCategory,
header_info_name_4: secondComponentFriendlyName, header_info_name_4: secondComponentFriendlyName,
}; };
@ -115,20 +93,15 @@ function List({
if (firstLoopComponentName) { if (firstLoopComponentName) {
firstHeaderObject = { firstHeaderObject = {
...firstHeaderObject, ...firstHeaderObject,
header_icon_name_1: firstComponentIcon,
header_icon_isCustom_1: true,
}; };
} }
if (secondLoopComponentUid) { if (secondLoopComponentUid) {
firstHeaderObject = { firstHeaderObject = {
...firstHeaderObject, ...firstHeaderObject,
header_icon_name_1: secondComponentIcon,
header_icon_isCustom_1: true,
}; };
thirdHeaderObject = { thirdHeaderObject = {
...thirdHeaderObject, ...thirdHeaderObject,
header_label_3: secondLoopComponentName,
}; };
} }
@ -136,14 +109,11 @@ function List({
secondHeaderObject = { secondHeaderObject = {
...secondHeaderObject, ...secondHeaderObject,
header_label_2: dzName, header_label_2: dzName,
header_icon_name_2: 'dynamiczone',
header_icon_isCustom_2: false,
header_info_category_2: null, header_info_category_2: null,
header_info_name_2: null, header_info_name_2: null,
}; };
thirdHeaderObject = { thirdHeaderObject = {
...thirdHeaderObject, ...thirdHeaderObject,
header_icon_name_3: isNestedInDZComponent ? 'component' : null,
header_label_3: firstLoopComponentName, header_label_3: firstLoopComponentName,
header_info_category_3: firstComponentCategory, header_info_category_3: firstComponentCategory,
header_info_name_3: firstComponentFriendlyName, header_info_name_3: firstComponentFriendlyName,

View File

@ -12,7 +12,6 @@ import DeleteIcon from '@strapi/icons/DeleteIcon';
import { stopPropagation, onRowClick } from '@strapi/helper-plugin'; import { stopPropagation, onRowClick } from '@strapi/helper-plugin';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import useDataManager from '../../hooks/useDataManager'; import useDataManager from '../../hooks/useDataManager';
import getAttributeDisplayedType from '../../utils/getAttributeDisplayedType';
import getTrad from '../../utils/getTrad'; import getTrad from '../../utils/getTrad';
import Curve from '../../icons/Curve'; import Curve from '../../icons/Curve';
import UpperFist from '../UpperFirst'; import UpperFist from '../UpperFirst';
@ -74,37 +73,26 @@ function ListRow({
); );
const attrType = type; const attrType = type;
const icoType = getAttributeDisplayedType(attrType);
let firstHeaderObject = { let firstHeaderObject = {
header_label_1: mainTypeName, header_label_1: mainTypeName,
header_icon_name_1: icoType,
header_icon_isCustom_1: false,
header_info_category_1: null, header_info_category_1: null,
header_info_name_1: null, header_info_name_1: null,
}; };
let secondHeaderObject = { let secondHeaderObject = {
header_label_2: name, header_label_2: name,
header_icon_name_2: null,
header_icon_isCustom_2: false,
header_info_category_2: null, header_info_category_2: null,
header_info_name_2: null, header_info_name_2: null,
}; };
let thirdHeaderObject = { let thirdHeaderObject = {
header_icon_name_3: 'component',
header_icon_isCustom_3: false,
header_info_category_3: null, header_info_category_3: null,
header_info_name_3: null, header_info_name_3: null,
}; };
let fourthHeaderObject = { let fourthHeaderObject = {
header_icon_name_4: null,
header_icon_isCustom_4: false,
header_info_category_4: null, header_info_category_4: null,
header_info_name_4: null, header_info_name_4: null,
}; };
let fifthHeaderObject = { let fifthHeaderObject = {
header_icon_name_5: null,
header_icon_isCustom_5: false,
header_info_category_5: null, header_info_category_5: null,
header_info_name_5: null, header_info_name_5: null,
}; };
@ -112,8 +100,6 @@ function ListRow({
if (firstLoopComponentName) { if (firstLoopComponentName) {
secondHeaderObject = { secondHeaderObject = {
header_label_2: firstLoopComponentName, header_label_2: firstLoopComponentName,
header_icon_name_2: 'component',
header_icon_isCustom_2: false,
header_info_category_2: firstComponentCategory, header_info_category_2: firstComponentCategory,
header_info_name_2: firstLoopComponentName, header_info_name_2: firstLoopComponentName,
}; };
@ -121,7 +107,6 @@ function ListRow({
thirdHeaderObject = { thirdHeaderObject = {
...thirdHeaderObject, ...thirdHeaderObject,
header_label_3: name, header_label_3: name,
header_icon_name_3: null,
}; };
} }
@ -129,27 +114,22 @@ function ListRow({
thirdHeaderObject = { thirdHeaderObject = {
...thirdHeaderObject, ...thirdHeaderObject,
header_label_3: secondLoopComponentName, header_label_3: secondLoopComponentName,
header_icon_name_3: 'component',
header_info_category_3: secondComponentCategory, header_info_category_3: secondComponentCategory,
header_info_name_3: secondLoopComponentName, header_info_name_3: secondLoopComponentName,
}; };
fourthHeaderObject = { fourthHeaderObject = {
...fourthHeaderObject, ...fourthHeaderObject,
header_label_4: name, header_label_4: name,
header_icon_name_4: null,
}; };
} }
if (isFromDynamicZone || isNestedInDZComponent) { if (isFromDynamicZone || isNestedInDZComponent) {
secondHeaderObject = { secondHeaderObject = {
header_label_2: dzName, header_label_2: dzName,
header_icon_name_2: 'dynamiczone',
header_icon_isCustom_2: false,
header_info_name_2: null, header_info_name_2: null,
header_info_category_2: null, header_info_category_2: null,
}; };
thirdHeaderObject = { thirdHeaderObject = {
header_icon_name_3: 'component',
header_label_3: firstLoopComponentName, header_label_3: firstLoopComponentName,
header_info_name_3: firstComponentCategory, header_info_name_3: firstComponentCategory,
header_info_category_3: firstComponentCategory, header_info_category_3: firstComponentCategory,
@ -157,15 +137,11 @@ function ListRow({
if (!isNestedInDZComponent) { if (!isNestedInDZComponent) {
fourthHeaderObject = { fourthHeaderObject = {
header_icon_name_4: null,
header_icon_isCustom_4: false,
header_info_category_4: null, header_info_category_4: null,
header_label_4: name, header_label_4: name,
}; };
} else { } else {
fourthHeaderObject = { fourthHeaderObject = {
header_icon_name_4: 'components',
header_icon_isCustom_4: false,
header_info_category_4: secondComponentCategory, header_info_category_4: secondComponentCategory,
header_info_name_4: secondLoopComponentName, header_info_name_4: secondLoopComponentName,
header_label_4: secondLoopComponentName, header_label_4: secondLoopComponentName,

View File

@ -100,8 +100,6 @@ const ListView = () => {
const handleClickAddComponentToDZ = async dzName => { const handleClickAddComponentToDZ = async dzName => {
const firstHeaderObject = { const firstHeaderObject = {
header_label_1: currentDataName, header_label_1: currentDataName,
header_icon_name_1: 'dynamiczone',
header_icon_isCustom_1: false,
}; };
const secondHeaderObj = { const secondHeaderObj = {
header_label_2: dzName, header_label_2: dzName,
@ -217,8 +215,6 @@ const ListView = () => {
forTarget: firstMainDataPath, forTarget: firstMainDataPath,
targetUid, targetUid,
header_label_1: label, header_label_1: label,
header_icon_isCustom_1: false,
header_icon_name_1: contentType === 'singleType' ? contentType : firstMainDataPath,
headerId: getTrad('modalForm.header-edit'), headerId: getTrad('modalForm.header-edit'),
}), }),
}); });
@ -245,9 +241,6 @@ const ListView = () => {
onClick={() => { onClick={() => {
const headerDisplayObject = { const headerDisplayObject = {
header_label_1: currentDataName, header_label_1: currentDataName,
header_icon_name_1:
forTarget === 'contentType' ? contentTypeKind : forTarget,
header_icon_isCustom_1: false,
}; };
handleClickAddField(forTarget, targetUid, headerDisplayObject); handleClickAddField(forTarget, targetUid, headerDisplayObject);
}} }}