mirror of
https://github.com/strapi/strapi.git
synced 2025-09-20 14:00:48 +00:00
Remove search from components except FormModal
Signed-off-by: soupette <cyril@strapi.io>
This commit is contained in:
parent
d0f6dcad75
commit
cb2bf64a68
@ -7,43 +7,25 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import { useTracking, useQueryParams } from '@strapi/helper-plugin';
|
|
||||||
import { Box } from '@strapi/parts/Box';
|
import { Box } from '@strapi/parts/Box';
|
||||||
import { Row } from '@strapi/parts/Row';
|
import { Row } from '@strapi/parts/Row';
|
||||||
import { Text } from '@strapi/parts/Text';
|
import { Text } from '@strapi/parts/Text';
|
||||||
|
import useFormModalNavigation from '../../../hooks/useFormModalNavigation';
|
||||||
import getTrad from '../../../utils/getTrad';
|
import getTrad from '../../../utils/getTrad';
|
||||||
import makeSearch from '../../../utils/makeSearch';
|
|
||||||
import AttributeIcon from '../../AttributeIcon';
|
import AttributeIcon from '../../AttributeIcon';
|
||||||
import BoxWrapper from './BoxWrapper';
|
import BoxWrapper from './BoxWrapper';
|
||||||
|
|
||||||
const AttributeOption = ({ type }) => {
|
const AttributeOption = ({ type }) => {
|
||||||
const { push } = useHistory();
|
|
||||||
const { trackUsage } = useTracking();
|
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const [{ query }] = useQueryParams();
|
|
||||||
|
const { onClickSelectField } = useFormModalNavigation();
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
// FIXME refacto
|
const step = type === 'component' ? '1' : null;
|
||||||
const forTarget = query.forTarget || null;
|
|
||||||
const targetUid = query.targetUid || null;
|
|
||||||
|
|
||||||
const search = makeSearch({
|
onClickSelectField({
|
||||||
modalType: 'attribute',
|
|
||||||
actionType: 'create',
|
|
||||||
settingType: 'base',
|
|
||||||
forTarget,
|
|
||||||
targetUid,
|
|
||||||
attributeType: type,
|
attributeType: type,
|
||||||
step: type === 'component' ? '1' : null,
|
step,
|
||||||
});
|
|
||||||
|
|
||||||
if (forTarget === 'contentType') {
|
|
||||||
trackUsage('didSelectContentTypeFieldType', { type });
|
|
||||||
}
|
|
||||||
|
|
||||||
push({
|
|
||||||
search,
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,12 +4,10 @@ import isEmpty from 'lodash/isEmpty';
|
|||||||
import sortBy from 'lodash/sortBy';
|
import sortBy from 'lodash/sortBy';
|
||||||
import toLower from 'lodash/toLower';
|
import toLower from 'lodash/toLower';
|
||||||
import matchSorter from 'match-sorter';
|
import matchSorter from 'match-sorter';
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import useDataManager from '../../hooks/useDataManager';
|
import useDataManager from '../../hooks/useDataManager';
|
||||||
import useFormModalNavigation from '../../hooks/useFormModalNavigation';
|
import useFormModalNavigation from '../../hooks/useFormModalNavigation';
|
||||||
import pluginId from '../../pluginId';
|
import pluginId from '../../pluginId';
|
||||||
import getTrad from '../../utils/getTrad';
|
import getTrad from '../../utils/getTrad';
|
||||||
import makeSearch from '../../utils/makeSearch';
|
|
||||||
|
|
||||||
const useContentTypeBuilderMenu = () => {
|
const useContentTypeBuilderMenu = () => {
|
||||||
const {
|
const {
|
||||||
@ -21,9 +19,8 @@ const useContentTypeBuilderMenu = () => {
|
|||||||
} = useDataManager();
|
} = useDataManager();
|
||||||
const toggleNotification = useNotification();
|
const toggleNotification = useNotification();
|
||||||
const { trackUsage } = useTracking();
|
const { trackUsage } = useTracking();
|
||||||
const { push } = useHistory();
|
|
||||||
const [search, setSearch] = useState('');
|
const [search, setSearch] = useState('');
|
||||||
const { onOpenModal } = useFormModalNavigation();
|
const { onOpenModalCreateSchema, onOpenModalEditCategory } = useFormModalNavigation();
|
||||||
|
|
||||||
const componentsData = sortBy(
|
const componentsData = sortBy(
|
||||||
Object.keys(componentsGroupedByCategory).map(category => ({
|
Object.keys(componentsGroupedByCategory).map(category => ({
|
||||||
@ -33,14 +30,11 @@ const useContentTypeBuilderMenu = () => {
|
|||||||
onClickEdit: (e, data) => {
|
onClickEdit: (e, data) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
const search = makeSearch({
|
if (canOpenModalCreateCTorComponent) {
|
||||||
actionType: 'edit',
|
onOpenModalEditCategory(data.name);
|
||||||
modalType: 'editCategory',
|
} else {
|
||||||
categoryName: data.name,
|
toggleNotificationCannotCreateSchema();
|
||||||
settingType: 'base',
|
}
|
||||||
});
|
|
||||||
|
|
||||||
push({ search });
|
|
||||||
},
|
},
|
||||||
links: sortBy(
|
links: sortBy(
|
||||||
componentsGroupedByCategory[category].map(compo => ({
|
componentsGroupedByCategory[category].map(compo => ({
|
||||||
@ -58,16 +52,6 @@ const useContentTypeBuilderMenu = () => {
|
|||||||
!Object.keys(contentTypes).some(ct => contentTypes[ct].isTemporary === true) &&
|
!Object.keys(contentTypes).some(ct => contentTypes[ct].isTemporary === true) &&
|
||||||
!Object.keys(components).some(component => components[component].isTemporary === true);
|
!Object.keys(components).some(component => components[component].isTemporary === true);
|
||||||
|
|
||||||
const toggleNotificationCannotCreateSchema = () => {
|
|
||||||
toggleNotification({
|
|
||||||
type: 'info',
|
|
||||||
message: {
|
|
||||||
id: `${getTrad('notification.info.creating.notSaved')}`,
|
|
||||||
defaultMessage: 'Please save your work before creating a new collection type or component',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClickOpenModalCreateCollectionType = () => {
|
const handleClickOpenModalCreateCollectionType = () => {
|
||||||
if (canOpenModalCreateCTorComponent) {
|
if (canOpenModalCreateCTorComponent) {
|
||||||
trackUsage(`willCreateContentType`);
|
trackUsage(`willCreateContentType`);
|
||||||
@ -80,14 +64,7 @@ const useContentTypeBuilderMenu = () => {
|
|||||||
forTarget: 'contentType',
|
forTarget: 'contentType',
|
||||||
};
|
};
|
||||||
|
|
||||||
onOpenModal(nextState);
|
onOpenModalCreateSchema(nextState);
|
||||||
|
|
||||||
// FIXME: to remove
|
|
||||||
const search = makeSearch(nextState);
|
|
||||||
|
|
||||||
push({
|
|
||||||
search,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
toggleNotificationCannotCreateSchema();
|
toggleNotificationCannotCreateSchema();
|
||||||
}
|
}
|
||||||
@ -105,34 +82,12 @@ const useContentTypeBuilderMenu = () => {
|
|||||||
forTarget: 'contentType',
|
forTarget: 'contentType',
|
||||||
};
|
};
|
||||||
|
|
||||||
const search = makeSearch(nextState);
|
onOpenModalCreateSchema(nextState);
|
||||||
|
|
||||||
onOpenModal(nextState);
|
|
||||||
|
|
||||||
push({
|
|
||||||
search,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
toggleNotificationCannotCreateSchema();
|
toggleNotificationCannotCreateSchema();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME : open modal edit
|
|
||||||
// const handleClickOpenModalEditCategory = categoryName => {
|
|
||||||
// if (canOpenModalCreateCTorComponent) {
|
|
||||||
// const search = makeSearch({
|
|
||||||
// actionType: 'edit',
|
|
||||||
// modalType: 'editCategory',
|
|
||||||
// categoryName,
|
|
||||||
// settingType: 'base',
|
|
||||||
// });
|
|
||||||
|
|
||||||
// push({ search });
|
|
||||||
// } else {
|
|
||||||
// toggleNotificationCannotCreateSchema();
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
const handleClickOpenModalCreateComponent = () => {
|
const handleClickOpenModalCreateComponent = () => {
|
||||||
if (canOpenModalCreateCTorComponent) {
|
if (canOpenModalCreateCTorComponent) {
|
||||||
trackUsage('willCreateComponent');
|
trackUsage('willCreateComponent');
|
||||||
@ -145,17 +100,22 @@ const useContentTypeBuilderMenu = () => {
|
|||||||
forTarget: 'component',
|
forTarget: 'component',
|
||||||
};
|
};
|
||||||
|
|
||||||
onOpenModal(nextState);
|
onOpenModalCreateSchema(nextState);
|
||||||
|
|
||||||
const search = makeSearch(nextState);
|
|
||||||
push({
|
|
||||||
search,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
toggleNotificationCannotCreateSchema();
|
toggleNotificationCannotCreateSchema();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toggleNotificationCannotCreateSchema = () => {
|
||||||
|
toggleNotification({
|
||||||
|
type: 'info',
|
||||||
|
message: {
|
||||||
|
id: `${getTrad('notification.info.creating.notSaved')}`,
|
||||||
|
defaultMessage: 'Please save your work before creating a new collection type or component',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const displayedContentTypes = sortedContentTypesList.filter(obj => obj.visible);
|
const displayedContentTypes = sortedContentTypesList.filter(obj => obj.visible);
|
||||||
|
|
||||||
const data = [
|
const data = [
|
||||||
|
@ -12,15 +12,15 @@ import {
|
|||||||
useRBACProvider,
|
useRBACProvider,
|
||||||
} from '@strapi/helper-plugin';
|
} from '@strapi/helper-plugin';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import { useHistory, useLocation, useRouteMatch, Redirect } from 'react-router-dom';
|
import { useLocation, useRouteMatch, Redirect } from 'react-router-dom';
|
||||||
import { connect, useDispatch } from 'react-redux';
|
import { connect, useDispatch } from 'react-redux';
|
||||||
import { compose } from 'redux';
|
import { compose } from 'redux';
|
||||||
import DataManagerContext from '../../contexts/DataManagerContext';
|
import DataManagerContext from '../../contexts/DataManagerContext';
|
||||||
|
import useFormModalNavigation from '../../hooks/useFormModalNavigation';
|
||||||
import getTrad from '../../utils/getTrad';
|
import getTrad from '../../utils/getTrad';
|
||||||
import makeUnique from '../../utils/makeUnique';
|
import makeUnique from '../../utils/makeUnique';
|
||||||
import pluginId from '../../pluginId';
|
import pluginId from '../../pluginId';
|
||||||
import FormModal from '../FormModal';
|
import FormModal from '../FormModal';
|
||||||
import FormModalNavigationProvider from '../FormModalNavigationProvider';
|
|
||||||
import createDataObject from './utils/createDataObject';
|
import createDataObject from './utils/createDataObject';
|
||||||
import createModifiedDataSchema from './utils/createModifiedDataSchema';
|
import createModifiedDataSchema from './utils/createModifiedDataSchema';
|
||||||
import retrieveSpecificInfoFromComponents from './utils/retrieveSpecificInfoFromComponents';
|
import retrieveSpecificInfoFromComponents from './utils/retrieveSpecificInfoFromComponents';
|
||||||
@ -70,9 +70,8 @@ const DataManagerProvider = ({
|
|||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const { trackUsage } = useTracking();
|
const { trackUsage } = useTracking();
|
||||||
const { refetchPermissions } = useRBACProvider();
|
const { refetchPermissions } = useRBACProvider();
|
||||||
|
|
||||||
const { pathname } = useLocation();
|
const { pathname } = useLocation();
|
||||||
const { push } = useHistory();
|
const { onCloseModal } = useFormModalNavigation();
|
||||||
const contentTypeMatch = useRouteMatch(`/plugins/${pluginId}/content-types/:uid`);
|
const contentTypeMatch = useRouteMatch(`/plugins/${pluginId}/content-types/:uid`);
|
||||||
const componentMatch = useRouteMatch(
|
const componentMatch = useRouteMatch(
|
||||||
`/plugins/${pluginId}/component-categories/:categoryUid/:componentUid`
|
`/plugins/${pluginId}/component-categories/:categoryUid/:componentUid`
|
||||||
@ -230,7 +229,7 @@ const DataManagerProvider = ({
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
// Close the modal
|
// Close the modal
|
||||||
push({ search: '' });
|
onCloseModal();
|
||||||
|
|
||||||
if (userConfirm) {
|
if (userConfirm) {
|
||||||
lockAppWithAutoreload();
|
lockAppWithAutoreload();
|
||||||
@ -269,7 +268,7 @@ const DataManagerProvider = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Close the modal
|
// Close the modal
|
||||||
push({ search: '' });
|
onCloseModal();
|
||||||
|
|
||||||
if (userConfirm) {
|
if (userConfirm) {
|
||||||
if (isTemporary) {
|
if (isTemporary) {
|
||||||
@ -311,7 +310,7 @@ const DataManagerProvider = ({
|
|||||||
const requestURL = `/${pluginId}/component-categories/${categoryUid}`;
|
const requestURL = `/${pluginId}/component-categories/${categoryUid}`;
|
||||||
|
|
||||||
// Close the modal
|
// Close the modal
|
||||||
push({ search: '' });
|
onCloseModal();
|
||||||
|
|
||||||
// Lock the app
|
// Lock the app
|
||||||
lockAppWithAutoreload();
|
lockAppWithAutoreload();
|
||||||
@ -544,7 +543,7 @@ const DataManagerProvider = ({
|
|||||||
updateSchema,
|
updateSchema,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<FormModalNavigationProvider>
|
<>
|
||||||
{isLoadingForDataToBeSet ? (
|
{isLoadingForDataToBeSet ? (
|
||||||
<LoadingIndicatorPage />
|
<LoadingIndicatorPage />
|
||||||
) : (
|
) : (
|
||||||
@ -553,7 +552,7 @@ const DataManagerProvider = ({
|
|||||||
{isInDevelopmentMode && <FormModal />}
|
{isInDevelopmentMode && <FormModal />}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</FormModalNavigationProvider>
|
</>
|
||||||
</DataManagerContext.Provider>
|
</DataManagerContext.Provider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,24 +1,197 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
|
import { useTracking } from '@strapi/helper-plugin';
|
||||||
import FormModalNavigationContext from '../../contexts/FormModalNavigationContext';
|
import FormModalNavigationContext from '../../contexts/FormModalNavigationContext';
|
||||||
|
import makeSearch from '../../utils/makeSearch';
|
||||||
import { INITIAL_STATE_DATA } from './constants';
|
import { INITIAL_STATE_DATA } from './constants';
|
||||||
|
|
||||||
const FormModalNavigationProvider = ({ children }) => {
|
const FormModalNavigationProvider = ({ children }) => {
|
||||||
const [state, setFormModalNavigationState] = useState(INITIAL_STATE_DATA);
|
const [state, setFormModalNavigationState] = useState(INITIAL_STATE_DATA);
|
||||||
|
const { trackUsage } = useTracking();
|
||||||
|
// FIXME
|
||||||
|
const { push } = useHistory();
|
||||||
|
|
||||||
const onOpenModal = nextState => {
|
const onClickSelectField = ({ attributeType, step }) => {
|
||||||
|
if (state.forTarget === 'contentType') {
|
||||||
|
trackUsage('didSelectContentTypeFieldType', { type: attributeType });
|
||||||
|
}
|
||||||
|
|
||||||
|
setFormModalNavigationState(prevState => {
|
||||||
|
return {
|
||||||
|
...prevState,
|
||||||
|
actionType: 'create',
|
||||||
|
modalType: 'attribute',
|
||||||
|
settingType: 'base',
|
||||||
|
step,
|
||||||
|
attributeType,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const search = {
|
||||||
|
modalType: 'attribute',
|
||||||
|
forTarget: state.forTarget,
|
||||||
|
targetUid: state.targetUid,
|
||||||
|
attributeType,
|
||||||
|
settingType: 'base',
|
||||||
|
step,
|
||||||
|
actionType: 'create',
|
||||||
|
};
|
||||||
|
|
||||||
|
push({ search: makeSearch(search) });
|
||||||
|
};
|
||||||
|
|
||||||
|
const onOpenModalAddComponentsToDZ = ({ dynamicZoneTarget, targetUid }) => {
|
||||||
|
setFormModalNavigationState(prevState => {
|
||||||
|
return {
|
||||||
|
...prevState,
|
||||||
|
dynamicZoneTarget,
|
||||||
|
targetUid,
|
||||||
|
modalType: 'addComponentToDynamicZone',
|
||||||
|
forTarget: 'contentType',
|
||||||
|
settingType: 'base',
|
||||||
|
step: '1',
|
||||||
|
actionType: 'edit',
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const search = {
|
||||||
|
modalType: 'addComponentToDynamicZone',
|
||||||
|
forTarget: 'contentType',
|
||||||
|
targetUid,
|
||||||
|
dynamicZoneTarget,
|
||||||
|
settingType: 'base',
|
||||||
|
step: '1',
|
||||||
|
actionType: 'edit',
|
||||||
|
};
|
||||||
|
|
||||||
|
push({ search: makeSearch(search) });
|
||||||
|
};
|
||||||
|
|
||||||
|
const onOpenModalAddField = ({ forTarget, targetUid }) => {
|
||||||
|
setFormModalNavigationState(prevState => {
|
||||||
|
return {
|
||||||
|
...prevState,
|
||||||
|
actionType: 'create',
|
||||||
|
forTarget,
|
||||||
|
targetUid,
|
||||||
|
modalType: 'chooseAttribute',
|
||||||
|
isOpen: true,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// FIXME
|
||||||
|
const nextSearch = {
|
||||||
|
modalType: 'chooseAttribute',
|
||||||
|
forTarget,
|
||||||
|
targetUid,
|
||||||
|
actionType: 'create',
|
||||||
|
};
|
||||||
|
|
||||||
|
push({ search: makeSearch(nextSearch) });
|
||||||
|
};
|
||||||
|
|
||||||
|
const onOpenModalCreateSchema = nextState => {
|
||||||
setFormModalNavigationState(prevState => {
|
setFormModalNavigationState(prevState => {
|
||||||
return { ...prevState, ...nextState, isOpen: true };
|
return { ...prevState, ...nextState, isOpen: true };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
push({ search: makeSearch(nextState) });
|
||||||
|
};
|
||||||
|
|
||||||
|
const onOpenModalEditCategory = categoryName => {
|
||||||
|
setFormModalNavigationState(prevState => {
|
||||||
|
return {
|
||||||
|
...prevState,
|
||||||
|
categoryName,
|
||||||
|
isOpen: true,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const nextSearch = {
|
||||||
|
actionType: 'edit',
|
||||||
|
modalType: 'editCategory',
|
||||||
|
categoryName,
|
||||||
|
settingType: 'base',
|
||||||
|
};
|
||||||
|
|
||||||
|
push({ search: makeSearch(nextSearch) });
|
||||||
|
};
|
||||||
|
|
||||||
|
const onOpenModalEditField = ({ forTarget, targetUid, attributeName, attributeType, step }) => {
|
||||||
|
setFormModalNavigationState(prevState => {
|
||||||
|
return {
|
||||||
|
...prevState,
|
||||||
|
modalType: 'attribute',
|
||||||
|
actionType: 'edit',
|
||||||
|
settingType: 'base',
|
||||||
|
forTarget,
|
||||||
|
targetUid,
|
||||||
|
attributeName,
|
||||||
|
attributeType,
|
||||||
|
step,
|
||||||
|
isOpen: true,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const nextSearch = {
|
||||||
|
modalType: 'attribute',
|
||||||
|
actionType: 'edit',
|
||||||
|
settingType: 'base',
|
||||||
|
forTarget,
|
||||||
|
targetUid,
|
||||||
|
attributeName,
|
||||||
|
attributeType,
|
||||||
|
step,
|
||||||
|
};
|
||||||
|
|
||||||
|
push({ search: makeSearch(nextSearch) });
|
||||||
|
};
|
||||||
|
|
||||||
|
const onOpenModalEditSchema = ({ modalType, forTarget, targetUid }) => {
|
||||||
|
setFormModalNavigationState(prevState => {
|
||||||
|
return {
|
||||||
|
...prevState,
|
||||||
|
modalType,
|
||||||
|
actionType: 'edit',
|
||||||
|
settingType: 'base',
|
||||||
|
forTarget,
|
||||||
|
targetUid,
|
||||||
|
isOpen: true,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const nextSearch = {
|
||||||
|
modalType,
|
||||||
|
actionType: 'edit',
|
||||||
|
settingType: 'base',
|
||||||
|
forTarget,
|
||||||
|
targetUid,
|
||||||
|
};
|
||||||
|
|
||||||
|
push({ search: makeSearch(nextSearch) });
|
||||||
};
|
};
|
||||||
|
|
||||||
const onCloseModal = () => {
|
const onCloseModal = () => {
|
||||||
setFormModalNavigationState(INITIAL_STATE_DATA);
|
setFormModalNavigationState(INITIAL_STATE_DATA);
|
||||||
|
|
||||||
|
push({ search: '' });
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormModalNavigationContext.Provider
|
<FormModalNavigationContext.Provider
|
||||||
value={{ ...state, onCloseModal, onOpenModal, setFormModalNavigationState }}
|
value={{
|
||||||
|
...state,
|
||||||
|
onClickSelectField,
|
||||||
|
onCloseModal,
|
||||||
|
onOpenModalAddComponentsToDZ,
|
||||||
|
onOpenModalAddField,
|
||||||
|
onOpenModalCreateSchema,
|
||||||
|
onOpenModalEditCategory,
|
||||||
|
onOpenModalEditField,
|
||||||
|
onOpenModalEditSchema,
|
||||||
|
setFormModalNavigationState,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</FormModalNavigationContext.Provider>
|
</FormModalNavigationContext.Provider>
|
||||||
|
@ -14,7 +14,7 @@ import { TableLabel } from '@strapi/parts/Text';
|
|||||||
import { Table, Thead, Tr, Th, TFooter } from '@strapi/parts/Table';
|
import { Table, Thead, Tr, Th, TFooter } from '@strapi/parts/Table';
|
||||||
import AddIcon from '@strapi/icons/AddIcon';
|
import AddIcon from '@strapi/icons/AddIcon';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import useListView from '../../hooks/useListView';
|
import useFormModalNavigation from '../../hooks/useFormModalNavigation';
|
||||||
import useDataManager from '../../hooks/useDataManager';
|
import useDataManager from '../../hooks/useDataManager';
|
||||||
import DynamicZoneList from '../DynamicZoneList';
|
import DynamicZoneList from '../DynamicZoneList';
|
||||||
import ComponentList from '../ComponentList';
|
import ComponentList from '../ComponentList';
|
||||||
@ -42,11 +42,11 @@ function List({
|
|||||||
const { trackUsage } = useTracking();
|
const { trackUsage } = useTracking();
|
||||||
const { isInDevelopmentMode, modifiedData, isInContentTypeView } = useDataManager();
|
const { isInDevelopmentMode, modifiedData, isInContentTypeView } = useDataManager();
|
||||||
|
|
||||||
const { openModalAddField } = useListView();
|
const { onOpenModalAddField } = useFormModalNavigation();
|
||||||
const onClickAddField = () => {
|
const onClickAddField = () => {
|
||||||
trackUsage('hasClickedCTBAddFieldBanner');
|
trackUsage('hasClickedCTBAddFieldBanner');
|
||||||
|
|
||||||
openModalAddField(editTarget, targetUid);
|
onOpenModalAddField({ forTarget: editTarget, targetUid });
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!targetUid) {
|
if (!targetUid) {
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
import { createContext } from 'react';
|
|
||||||
|
|
||||||
const ListViewContext = createContext();
|
|
||||||
|
|
||||||
export default ListViewContext;
|
|
@ -1,6 +0,0 @@
|
|||||||
import { useContext } from 'react';
|
|
||||||
import ListViewContext from '../contexts/ListViewContext';
|
|
||||||
|
|
||||||
const useListView = () => useContext(ListViewContext);
|
|
||||||
|
|
||||||
export default useListView;
|
|
@ -11,6 +11,7 @@ import { Layout } from '@strapi/parts/Layout';
|
|||||||
import pluginPermissions from '../../permissions';
|
import pluginPermissions from '../../permissions';
|
||||||
import pluginId from '../../pluginId';
|
import pluginId from '../../pluginId';
|
||||||
import DataManagerProvider from '../../components/DataManagerProvider';
|
import DataManagerProvider from '../../components/DataManagerProvider';
|
||||||
|
import FormModalNavigationProvider from '../../components/FormModalNavigationProvider';
|
||||||
import RecursivePath from '../RecursivePath';
|
import RecursivePath from '../RecursivePath';
|
||||||
import icons from './utils/icons.json';
|
import icons from './utils/icons.json';
|
||||||
import ContentTypeBuilderNav from '../../components/ContentTypeBuilderNav';
|
import ContentTypeBuilderNav from '../../components/ContentTypeBuilderNav';
|
||||||
@ -20,6 +21,7 @@ const ListView = lazy(() => import('../ListView'));
|
|||||||
const App = () => {
|
const App = () => {
|
||||||
return (
|
return (
|
||||||
<CheckPagePermissions permissions={pluginPermissions.main}>
|
<CheckPagePermissions permissions={pluginPermissions.main}>
|
||||||
|
<FormModalNavigationProvider>
|
||||||
<DataManagerProvider allIcons={icons}>
|
<DataManagerProvider allIcons={icons}>
|
||||||
<Layout sideNav={<ContentTypeBuilderNav />}>
|
<Layout sideNav={<ContentTypeBuilderNav />}>
|
||||||
<Suspense fallback={<LoadingIndicatorPage />}>
|
<Suspense fallback={<LoadingIndicatorPage />}>
|
||||||
@ -37,6 +39,7 @@ const App = () => {
|
|||||||
</Suspense>
|
</Suspense>
|
||||||
</Layout>
|
</Layout>
|
||||||
</DataManagerProvider>
|
</DataManagerProvider>
|
||||||
|
</FormModalNavigationProvider>
|
||||||
</CheckPagePermissions>
|
</CheckPagePermissions>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -19,14 +19,13 @@ import has from 'lodash/has';
|
|||||||
import isEqual from 'lodash/isEqual';
|
import isEqual from 'lodash/isEqual';
|
||||||
import upperFirst from 'lodash/upperFirst';
|
import upperFirst from 'lodash/upperFirst';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import { Prompt, useHistory, useRouteMatch } from 'react-router-dom';
|
import { Prompt, useRouteMatch } from 'react-router-dom';
|
||||||
import List from '../../components/List';
|
import List from '../../components/List';
|
||||||
import ListRow from '../../components/ListRow';
|
import ListRow from '../../components/ListRow';
|
||||||
import ListViewContext from '../../contexts/ListViewContext';
|
|
||||||
import useDataManager from '../../hooks/useDataManager';
|
import useDataManager from '../../hooks/useDataManager';
|
||||||
|
import useFormModalNavigation from '../../hooks/useFormModalNavigation';
|
||||||
import getAttributeDisplayedType from '../../utils/getAttributeDisplayedType';
|
import getAttributeDisplayedType from '../../utils/getAttributeDisplayedType';
|
||||||
import getTrad from '../../utils/getTrad';
|
import getTrad from '../../utils/getTrad';
|
||||||
import makeSearch from '../../utils/makeSearch';
|
|
||||||
import LinkToCMSettingsView from './LinkToCMSettingsView';
|
import LinkToCMSettingsView from './LinkToCMSettingsView';
|
||||||
|
|
||||||
/* eslint-disable indent */
|
/* eslint-disable indent */
|
||||||
@ -41,11 +40,17 @@ const ListView = () => {
|
|||||||
} = useDataManager();
|
} = useDataManager();
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const { trackUsage } = useTracking();
|
const { trackUsage } = useTracking();
|
||||||
const { push } = useHistory();
|
|
||||||
// const { search } = useLocation();
|
|
||||||
// const [enablePrompt, togglePrompt] = useState(true);
|
// const [enablePrompt, togglePrompt] = useState(true);
|
||||||
const match = useRouteMatch('/plugins/content-type-builder/:kind/:currentUID');
|
const match = useRouteMatch('/plugins/content-type-builder/:kind/:currentUID');
|
||||||
|
|
||||||
|
const {
|
||||||
|
onOpenModalAddComponentsToDZ,
|
||||||
|
onOpenModalAddField,
|
||||||
|
onOpenModalEditField,
|
||||||
|
onOpenModalEditSchema,
|
||||||
|
} = useFormModalNavigation();
|
||||||
|
|
||||||
// useEffect(() => {
|
// useEffect(() => {
|
||||||
// if (search === '') {
|
// if (search === '') {
|
||||||
// togglePrompt(true);
|
// togglePrompt(true);
|
||||||
@ -67,60 +72,26 @@ const ListView = () => {
|
|||||||
const contentTypeKind = get(modifiedData, [firstMainDataPath, 'schema', 'kind'], null);
|
const contentTypeKind = get(modifiedData, [firstMainDataPath, 'schema', 'kind'], null);
|
||||||
|
|
||||||
const attributes = get(modifiedData, mainDataTypeAttributesPath, []);
|
const attributes = get(modifiedData, mainDataTypeAttributesPath, []);
|
||||||
// const attributesLength = attributes.length;
|
|
||||||
const currentDataName = get(initialData, [firstMainDataPath, 'schema', 'name'], '');
|
const currentDataName = get(initialData, [firstMainDataPath, 'schema', 'name'], '');
|
||||||
const isFromPlugin = has(initialData, [firstMainDataPath, 'plugin']);
|
const isFromPlugin = has(initialData, [firstMainDataPath, 'plugin']);
|
||||||
// const hasModelBeenModified = !isEqual(modifiedData, initialData);
|
// const hasModelBeenModified = !isEqual(modifiedData, initialData);
|
||||||
const forTarget = isInContentTypeView ? 'contentType' : 'component';
|
const forTarget = isInContentTypeView ? 'contentType' : 'component';
|
||||||
|
|
||||||
const handleClickAddField = async (forTarget, targetUid) => {
|
const handleClickAddComponentToDZ = dynamicZoneTarget => {
|
||||||
// disable the prompt
|
onOpenModalAddComponentsToDZ({ dynamicZoneTarget, targetUid });
|
||||||
// await wait();
|
|
||||||
|
|
||||||
const searchObj = {
|
|
||||||
modalType: 'chooseAttribute',
|
|
||||||
forTarget,
|
|
||||||
targetUid,
|
|
||||||
};
|
|
||||||
|
|
||||||
push({ search: makeSearch(searchObj) });
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClickAddComponentToDZ = async dzName => {
|
|
||||||
const search = {
|
|
||||||
modalType: 'addComponentToDynamicZone',
|
|
||||||
forTarget: 'contentType',
|
|
||||||
targetUid,
|
|
||||||
dynamicZoneTarget: dzName,
|
|
||||||
settingType: 'base',
|
|
||||||
step: '1',
|
|
||||||
actionType: 'edit',
|
|
||||||
};
|
|
||||||
|
|
||||||
// await wait();
|
|
||||||
|
|
||||||
push({ search: makeSearch(search, true) });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClickEditField = async (forTarget, targetUid, attributeName, type) => {
|
const handleClickEditField = async (forTarget, targetUid, attributeName, type) => {
|
||||||
const attributeType = getAttributeDisplayedType(type);
|
const attributeType = getAttributeDisplayedType(type);
|
||||||
|
const step = type === 'component' ? '2' : null;
|
||||||
|
|
||||||
// await wait();
|
onOpenModalEditField({
|
||||||
|
|
||||||
const search = {
|
|
||||||
modalType: 'attribute',
|
|
||||||
actionType: 'edit',
|
|
||||||
settingType: 'base',
|
|
||||||
forTarget,
|
forTarget,
|
||||||
targetUid,
|
targetUid,
|
||||||
attributeName,
|
attributeName,
|
||||||
attributeType,
|
attributeType,
|
||||||
step: type === 'component' ? '2' : null,
|
step,
|
||||||
};
|
});
|
||||||
|
|
||||||
// await wait();
|
|
||||||
|
|
||||||
push({ search: makeSearch(search, true) });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getDescription = () => {
|
const getDescription = () => {
|
||||||
@ -134,12 +105,6 @@ const ListView = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME
|
|
||||||
// const wait = async () => {
|
|
||||||
// togglePrompt(false);
|
|
||||||
|
|
||||||
// return new Promise(resolve => setTimeout(resolve, 100));
|
|
||||||
// };
|
|
||||||
let label = get(modifiedData, [firstMainDataPath, 'schema', 'name'], '');
|
let label = get(modifiedData, [firstMainDataPath, 'schema', 'name'], '');
|
||||||
const kind = get(modifiedData, [firstMainDataPath, 'schema', 'kind'], '');
|
const kind = get(modifiedData, [firstMainDataPath, 'schema', 'kind'], '');
|
||||||
|
|
||||||
@ -152,18 +117,7 @@ const ListView = () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// const listTitle = [
|
|
||||||
// formatMessage(
|
|
||||||
// {
|
|
||||||
// id: `${pluginId}.table.attributes.title.${attributesLength > 1 ? 'plural' : 'singular'}`,
|
|
||||||
// },
|
|
||||||
// { number: attributesLength }
|
|
||||||
// ),
|
|
||||||
// ];
|
|
||||||
|
|
||||||
const onEdit = () => {
|
const onEdit = () => {
|
||||||
// await wait();
|
|
||||||
|
|
||||||
const contentType = kind || firstMainDataPath;
|
const contentType = kind || firstMainDataPath;
|
||||||
|
|
||||||
if (contentType === 'collectionType') {
|
if (contentType === 'collectionType') {
|
||||||
@ -173,19 +127,14 @@ const ListView = () => {
|
|||||||
trackUsage('willEditNameOfSingleType');
|
trackUsage('willEditNameOfSingleType');
|
||||||
}
|
}
|
||||||
|
|
||||||
push({
|
onOpenModalEditSchema({
|
||||||
search: makeSearch({
|
|
||||||
modalType: firstMainDataPath,
|
modalType: firstMainDataPath,
|
||||||
actionType: 'edit',
|
|
||||||
settingType: 'base',
|
|
||||||
forTarget: firstMainDataPath,
|
forTarget: firstMainDataPath,
|
||||||
targetUid,
|
targetUid,
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ListViewContext.Provider value={{ openModalAddField: handleClickAddField }}>
|
|
||||||
<>
|
<>
|
||||||
<Prompt
|
<Prompt
|
||||||
message={formatMessage({ id: getTrad('prompt.unsaved') })}
|
message={formatMessage({ id: getTrad('prompt.unsaved') })}
|
||||||
@ -203,7 +152,7 @@ const ListView = () => {
|
|||||||
startIcon={<AddIcon />}
|
startIcon={<AddIcon />}
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleClickAddField(forTarget, targetUid);
|
onOpenModalAddField({ forTarget, targetUid });
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{formatMessage({ id: getTrad('button.attributes.add.another') })}
|
{formatMessage({ id: getTrad('button.attributes.add.another') })}
|
||||||
@ -275,7 +224,6 @@ const ListView = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
</ContentLayout>
|
</ContentLayout>
|
||||||
</>
|
</>
|
||||||
</ListViewContext.Provider>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user