From ae3ad3793b47462623aff2bc79035af642f14d88 Mon Sep 17 00:00:00 2001 From: soupette Date: Wed, 20 Nov 2019 18:59:25 +0100 Subject: [PATCH] Init edit fields --- .../admin/src/containers/FormModal/index.js | 9 +- .../admin/src/containers/ListPage/index.js | 93 +++++++++++++++++-- .../admin/src/translations/en.json | 3 +- 3 files changed, 97 insertions(+), 8 deletions(-) diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/index.js index f9bee9bb9e..2b30eee40a 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/index.js @@ -35,6 +35,7 @@ const NAVLINKS = [{ id: 'base' }, { id: 'advanced' }]; const FormModal = () => { const initialStateData = { + attributeName: null, actionType: null, modalType: null, settingType: null, @@ -62,11 +63,15 @@ const FormModal = () => { useEffect(() => { if (!isEmpty(search)) { // Return 'null' if there isn't any attributeType search params + //TODO need targetUID + // TODO change target by targetUID & add displayName instead of target const attributeType = query.get('attributeType'); const modalType = query.get('modalType'); + const actionType = query.get('actionType'); setState({ - actionType: query.get('actionType'), + attributeName: query.get('attributeName'), + actionType, modalType, settingType: query.get('settingType'), forTarget: query.get('forTarget'), @@ -83,6 +88,7 @@ const FormModal = () => { dispatch({ type: 'SET_ATTRIBUTE_DATA_SCHEMA', attributeType, + isEditing: actionType === 'edit', }); } } @@ -292,6 +298,7 @@ const FormModal = () => { id: getTrad(`attribute.${state.attributeType}`), }) ), + name: upperFirst(state.attributeName), }} > {msg => {upperFirst(msg)}} diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/ListPage/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/ListPage/index.js index 4cadda30d8..2a7faa4324 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/ListPage/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/ListPage/index.js @@ -8,6 +8,7 @@ import LeftMenu from '../LeftMenu'; const ListPage = () => { const { pathname } = useLocation(); const { + components, initialData, modifiedData, isInContentTypeView, @@ -22,15 +23,45 @@ const ListPage = () => { }, [pathname]); const attributes = get(modifiedData, ['schema', 'attributes'], {}); + const currentDataName = get(initialData, ['schema', 'name'], ''); const handleClick = () => { - const currentDataName = get(initialData, ['schema', 'name'], ''); const forTarget = isInContentTypeView ? 'contentType' : 'component'; - const search = `modalType=chooseAttribute&forTarget=${forTarget}&targetr=${currentDataName}`; + const search = `modalType=chooseAttribute&forTarget=${forTarget}&target=${currentDataName}`; push({ search }); }; + // TODO just a util not sure it should be kept + const getType = attrName => { + return get(modifiedData, ['schema', 'attributes', attrName, 'type'], ''); + }; + const getComponentSchema = attrName => { + const componentToGet = get( + modifiedData, + ['schema', 'attributes', attrName, 'component'], + '' + ); + const componentSchema = get( + components, + [componentToGet, 'schema', 'attributes'], + {} + ); - console.log({ allSchema: modifiedData }); + return componentSchema; + }; + const handleClickEditField = (forTarget, target, attrName, type) => { + const attributeType = [ + 'integer', + 'biginteger', + 'decimal', + 'float', + ].includes(type) + ? 'number' + : type; + + push({ + search: `modalType=attribute&actionType=edit&settingType=base&forTarget=${forTarget}&target=${target}&attributeName=${attrName}&attributeType=${attributeType}`, + }); + }; return ( @@ -41,10 +72,60 @@ const ListPage = () => { + + {/* REALLY TEMPORARY SINCE IT DOESN T SUPPORT ANY NESTING COMPONENT*/} diff --git a/packages/strapi-plugin-content-type-builder/admin/src/translations/en.json b/packages/strapi-plugin-content-type-builder/admin/src/translations/en.json index 70cf21fb0c..828c2d3b82 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/translations/en.json +++ b/packages/strapi-plugin-content-type-builder/admin/src/translations/en.json @@ -241,5 +241,6 @@ "modalForm.header-edit": "Edit {name}", "modalForm.sub-header.chooseAttribute.component": "Select a field for your component", "modalForm.sub-header.chooseAttribute.contentType": "Select a field for your content type", - "modalForm.sub-header.attribute.create": "Add new {type} field" + "modalForm.sub-header.attribute.create": "Add new {type} field", + "modalForm.sub-header.attribute.edit": "Edit {name}" }