mirror of
https://github.com/strapi/strapi.git
synced 2025-11-03 19:36:20 +00:00
Remove useEditView hook which is not needed anymore
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
e0eac0f4e9
commit
237f5b4deb
@ -72,6 +72,10 @@
|
|||||||
},
|
},
|
||||||
"address": {
|
"address": {
|
||||||
"model": "address"
|
"model": "address"
|
||||||
|
},
|
||||||
|
"admin_user": {
|
||||||
|
"plugin": "admin",
|
||||||
|
"model": "user"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,7 +19,6 @@ import { connect, select, styles } from './utils';
|
|||||||
|
|
||||||
function SelectWrapper({
|
function SelectWrapper({
|
||||||
description,
|
description,
|
||||||
displayNavigationLink,
|
|
||||||
editable,
|
editable,
|
||||||
label,
|
label,
|
||||||
isCreatingEntry,
|
isCreatingEntry,
|
||||||
@ -163,7 +162,7 @@ function SelectWrapper({
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!displayNavigationLink) {
|
if (!queryInfos.shouldDisplayRelationLink) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +173,7 @@ function SelectWrapper({
|
|||||||
</FormattedMessage>
|
</FormattedMessage>
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
}, [displayNavigationLink, pathname, to, value]);
|
}, [queryInfos.shouldDisplayRelationLink, pathname, to, value]);
|
||||||
|
|
||||||
const Component = isSingle ? SelectOne : SelectMany;
|
const Component = isSingle ? SelectOne : SelectMany;
|
||||||
const associationsLength = isArray(value) ? value.length : 0;
|
const associationsLength = isArray(value) ? value.length : 0;
|
||||||
@ -225,7 +224,7 @@ function SelectWrapper({
|
|||||||
addRelation({ target: { name, value } });
|
addRelation({ target: { name, value } });
|
||||||
}}
|
}}
|
||||||
components={{ ClearIndicator, DropdownIndicator, IndicatorSeparator, Option }}
|
components={{ ClearIndicator, DropdownIndicator, IndicatorSeparator, Option }}
|
||||||
displayNavigationLink={displayNavigationLink}
|
displayNavigationLink={queryInfos.shouldDisplayRelationLink}
|
||||||
id={name}
|
id={name}
|
||||||
isDisabled={isDisabled}
|
isDisabled={isDisabled}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
@ -269,7 +268,6 @@ SelectWrapper.defaultProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SelectWrapper.propTypes = {
|
SelectWrapper.propTypes = {
|
||||||
displayNavigationLink: PropTypes.bool.isRequired,
|
|
||||||
editable: PropTypes.bool,
|
editable: PropTypes.bool,
|
||||||
description: PropTypes.string,
|
description: PropTypes.string,
|
||||||
label: PropTypes.string,
|
label: PropTypes.string,
|
||||||
@ -285,6 +283,7 @@ SelectWrapper.propTypes = {
|
|||||||
containsKey: PropTypes.string.isRequired,
|
containsKey: PropTypes.string.isRequired,
|
||||||
defaultParams: PropTypes.object,
|
defaultParams: PropTypes.object,
|
||||||
endPoint: PropTypes.string.isRequired,
|
endPoint: PropTypes.string.isRequired,
|
||||||
|
shouldDisplayRelationLink: PropTypes.bool.isRequired,
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { get } from 'lodash';
|
|
||||||
import useDataManager from '../../../hooks/useDataManager';
|
import useDataManager from '../../../hooks/useDataManager';
|
||||||
import useEditView from '../../../hooks/useEditView';
|
|
||||||
|
|
||||||
function useSelect({ isUserAllowedToEditField, isUserAllowedToReadField, name, targetModel }) {
|
function useSelect({ isUserAllowedToEditField, isUserAllowedToReadField, name }) {
|
||||||
const {
|
const {
|
||||||
isCreatingEntry,
|
isCreatingEntry,
|
||||||
createActionAllowedFields,
|
createActionAllowedFields,
|
||||||
@ -11,16 +9,6 @@ function useSelect({ isUserAllowedToEditField, isUserAllowedToReadField, name, t
|
|||||||
updateActionAllowedFields,
|
updateActionAllowedFields,
|
||||||
} = useDataManager();
|
} = useDataManager();
|
||||||
|
|
||||||
// TODO important! remove models dependency from the useEditView hook,
|
|
||||||
// This info should be handle in the layout?
|
|
||||||
const { models } = useEditView();
|
|
||||||
|
|
||||||
const displayNavigationLink = useMemo(() => {
|
|
||||||
const targetModelSchema = models.find(obj => obj.uid === targetModel);
|
|
||||||
|
|
||||||
return get(targetModelSchema, 'isDisplayed', false);
|
|
||||||
}, [targetModel, models]);
|
|
||||||
|
|
||||||
const isFieldAllowed = useMemo(() => {
|
const isFieldAllowed = useMemo(() => {
|
||||||
if (isUserAllowedToEditField === true) {
|
if (isUserAllowedToEditField === true) {
|
||||||
return true;
|
return true;
|
||||||
@ -48,7 +36,6 @@ function useSelect({ isUserAllowedToEditField, isUserAllowedToReadField, name, t
|
|||||||
}, [isCreatingEntry, isUserAllowedToReadField, name, readActionAllowedFields]);
|
}, [isCreatingEntry, isUserAllowedToReadField, name, readActionAllowedFields]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
displayNavigationLink,
|
|
||||||
isCreatingEntry,
|
isCreatingEntry,
|
||||||
isFieldAllowed,
|
isFieldAllowed,
|
||||||
isFieldReadable,
|
isFieldReadable,
|
||||||
|
|||||||
@ -11,13 +11,7 @@ import { getTrad } from '../../../utils';
|
|||||||
import { DeleteButton } from '../components';
|
import { DeleteButton } from '../components';
|
||||||
import { connect, select } from './utils';
|
import { connect, select } from './utils';
|
||||||
|
|
||||||
const DeleteLink = ({
|
const DeleteLink = ({ isCreatingEntry, onDelete, onDeleteSucceeded, trackerProperty }) => {
|
||||||
canDelete,
|
|
||||||
isCreatingEntry,
|
|
||||||
onDelete,
|
|
||||||
onDeleteSucceeded,
|
|
||||||
trackerProperty,
|
|
||||||
}) => {
|
|
||||||
const [showWarningDelete, setWarningDelete] = useState(false);
|
const [showWarningDelete, setWarningDelete] = useState(false);
|
||||||
const [didDeleteEntry, setDidDeleteEntry] = useState(false);
|
const [didDeleteEntry, setDidDeleteEntry] = useState(false);
|
||||||
const [isModalConfirmButtonLoading, setIsModalConfirmButtonLoading] = useState(false);
|
const [isModalConfirmButtonLoading, setIsModalConfirmButtonLoading] = useState(false);
|
||||||
@ -57,7 +51,7 @@ const DeleteLink = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isCreatingEntry || !canDelete) {
|
if (isCreatingEntry) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +83,6 @@ const DeleteLink = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
DeleteLink.propTypes = {
|
DeleteLink.propTypes = {
|
||||||
canDelete: PropTypes.bool.isRequired,
|
|
||||||
isCreatingEntry: PropTypes.bool.isRequired,
|
isCreatingEntry: PropTypes.bool.isRequired,
|
||||||
onDelete: PropTypes.func.isRequired,
|
onDelete: PropTypes.func.isRequired,
|
||||||
onDeleteSucceeded: PropTypes.func.isRequired,
|
onDeleteSucceeded: PropTypes.func.isRequired,
|
||||||
|
|||||||
@ -1,12 +1,8 @@
|
|||||||
import { isEmpty } from 'lodash';
|
import { isEmpty } from 'lodash';
|
||||||
import useDataManager from '../../../../hooks/useDataManager';
|
import useDataManager from '../../../../hooks/useDataManager';
|
||||||
import useEditView from '../../../../hooks/useEditView';
|
|
||||||
|
|
||||||
function useSelect() {
|
function useSelect() {
|
||||||
const { hasDraftAndPublish, modifiedData } = useDataManager();
|
const { hasDraftAndPublish, modifiedData } = useDataManager();
|
||||||
const {
|
|
||||||
allowedActions: { canDelete },
|
|
||||||
} = useEditView();
|
|
||||||
|
|
||||||
let trackerProperty = {};
|
let trackerProperty = {};
|
||||||
|
|
||||||
@ -17,7 +13,6 @@ function useSelect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
canDelete,
|
|
||||||
hasDraftAndPublish,
|
hasDraftAndPublish,
|
||||||
trackerProperty,
|
trackerProperty,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -19,9 +19,7 @@ const primaryButtonObject = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Header = ({
|
const Header = ({
|
||||||
canUpdate,
|
allowedActions: { canUpdate, canCreate, canPublish },
|
||||||
canCreate,
|
|
||||||
canPublish,
|
|
||||||
componentLayouts,
|
componentLayouts,
|
||||||
initialData,
|
initialData,
|
||||||
isCreatingEntry,
|
isCreatingEntry,
|
||||||
@ -237,9 +235,11 @@ const Header = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
Header.propTypes = {
|
Header.propTypes = {
|
||||||
canUpdate: PropTypes.bool.isRequired,
|
allowedActions: PropTypes.shape({
|
||||||
canCreate: PropTypes.bool.isRequired,
|
canUpdate: PropTypes.bool.isRequired,
|
||||||
canPublish: PropTypes.bool.isRequired,
|
canCreate: PropTypes.bool.isRequired,
|
||||||
|
canPublish: PropTypes.bool.isRequired,
|
||||||
|
}).isRequired,
|
||||||
componentLayouts: PropTypes.object.isRequired,
|
componentLayouts: PropTypes.object.isRequired,
|
||||||
initialData: PropTypes.object.isRequired,
|
initialData: PropTypes.object.isRequired,
|
||||||
isCreatingEntry: PropTypes.bool.isRequired,
|
isCreatingEntry: PropTypes.bool.isRequired,
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import useDataManager from '../../../../hooks/useDataManager';
|
import useDataManager from '../../../../hooks/useDataManager';
|
||||||
import useEditView from '../../../../hooks/useEditView';
|
|
||||||
|
|
||||||
function useSelect() {
|
function useSelect() {
|
||||||
const {
|
const {
|
||||||
@ -14,14 +13,8 @@ function useSelect() {
|
|||||||
onPublish,
|
onPublish,
|
||||||
onUnpublish,
|
onUnpublish,
|
||||||
} = useDataManager();
|
} = useDataManager();
|
||||||
const {
|
|
||||||
allowedActions: { canUpdate, canCreate, canPublish },
|
|
||||||
} = useEditView();
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
canUpdate,
|
|
||||||
canCreate,
|
|
||||||
canPublish,
|
|
||||||
componentLayouts: allLayoutData.components,
|
componentLayouts: allLayoutData.components,
|
||||||
initialData,
|
initialData,
|
||||||
isCreatingEntry,
|
isCreatingEntry,
|
||||||
|
|||||||
@ -23,7 +23,6 @@ import { useFetchContentTypeLayout } from '../../hooks';
|
|||||||
import { generatePermissionsObject, getInjectedComponents } from '../../utils';
|
import { generatePermissionsObject, getInjectedComponents } from '../../utils';
|
||||||
import CollectionTypeWrapper from '../CollectionTypeWrapper';
|
import CollectionTypeWrapper from '../CollectionTypeWrapper';
|
||||||
import EditViewDataManagerProvider from '../EditViewDataManagerProvider';
|
import EditViewDataManagerProvider from '../EditViewDataManagerProvider';
|
||||||
import EditViewProvider from '../EditViewProvider';
|
|
||||||
import SingleTypeWrapper from '../SingleTypeWrapper';
|
import SingleTypeWrapper from '../SingleTypeWrapper';
|
||||||
import Header from './Header';
|
import Header from './Header';
|
||||||
import { createAttributesLayout, getFieldsActionMatchingPermissions } from './utils';
|
import { createAttributesLayout, getFieldsActionMatchingPermissions } from './utils';
|
||||||
@ -34,7 +33,7 @@ import InformationCard from './InformationCard';
|
|||||||
/* eslint-disable react/no-array-index-key */
|
/* eslint-disable react/no-array-index-key */
|
||||||
|
|
||||||
// TODO check needed props
|
// TODO check needed props
|
||||||
const EditView = ({ components, currentEnvironment, models, isSingleType, plugins, slug }) => {
|
const EditView = ({ currentEnvironment, isSingleType, plugins, slug }) => {
|
||||||
const { isLoading, layout } = useFetchContentTypeLayout(slug);
|
const { isLoading, layout } = useFetchContentTypeLayout(slug);
|
||||||
const { goBack } = useHistory();
|
const { goBack } = useHistory();
|
||||||
// Legacy to remove for the configurations
|
// Legacy to remove for the configurations
|
||||||
@ -101,210 +100,195 @@ const EditView = ({ components, currentEnvironment, models, isSingleType, plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EditViewProvider
|
<ContentTypeLayoutContext.Provider value={layout}>
|
||||||
allowedActions={allowedActions}
|
<DataManagementWrapper allLayoutData={layout} from={from} slug={slug}>
|
||||||
allLayoutData={layout}
|
{({
|
||||||
components={components}
|
componentsDataStructure,
|
||||||
isSingleType={isSingleType}
|
contentTypeDataStructure,
|
||||||
layout={currentContentTypeLayoutData}
|
data,
|
||||||
// TODO: check if still needed
|
isCreatingEntry,
|
||||||
models={models}
|
isLoadingForData,
|
||||||
>
|
onDelete,
|
||||||
<ContentTypeLayoutContext.Provider value={layout}>
|
onDeleteSucceeded,
|
||||||
<DataManagementWrapper allLayoutData={layout} from={from} slug={slug}>
|
onPost,
|
||||||
{({
|
onPublish,
|
||||||
componentsDataStructure,
|
onPut,
|
||||||
contentTypeDataStructure,
|
onUnpublish,
|
||||||
data,
|
status,
|
||||||
isCreatingEntry,
|
}) => {
|
||||||
isLoadingForData,
|
return (
|
||||||
onDelete,
|
<EditViewDataManagerProvider
|
||||||
onDeleteSucceeded,
|
allowedActions={allowedActions}
|
||||||
onPost,
|
allLayoutData={layout}
|
||||||
onPublish,
|
createActionAllowedFields={createActionAllowedFields}
|
||||||
onPut,
|
componentsDataStructure={componentsDataStructure}
|
||||||
onUnpublish,
|
contentTypeDataStructure={contentTypeDataStructure}
|
||||||
status,
|
from={from}
|
||||||
}) => {
|
initialValues={data}
|
||||||
return (
|
isCreatingEntry={isCreatingEntry}
|
||||||
<EditViewDataManagerProvider
|
isLoadingForData={isLoadingForData}
|
||||||
allowedActions={allowedActions}
|
isSingleType={isSingleType}
|
||||||
allLayoutData={layout}
|
onPost={onPost}
|
||||||
createActionAllowedFields={createActionAllowedFields}
|
onPublish={onPublish}
|
||||||
componentsDataStructure={componentsDataStructure}
|
onPut={onPut}
|
||||||
contentTypeDataStructure={contentTypeDataStructure}
|
onUnpublish={onUnpublish}
|
||||||
from={from}
|
readActionAllowedFields={readActionAllowedFields}
|
||||||
initialValues={data}
|
// TODO check if needed
|
||||||
isCreatingEntry={isCreatingEntry}
|
redirectToPreviousPage={goBack}
|
||||||
isLoadingForData={isLoadingForData}
|
slug={slug}
|
||||||
isSingleType={isSingleType}
|
status={status}
|
||||||
onPost={onPost}
|
updateActionAllowedFields={updateActionAllowedFields}
|
||||||
onPublish={onPublish}
|
>
|
||||||
onPut={onPut}
|
<BackHeader onClick={goBack} />
|
||||||
onUnpublish={onUnpublish}
|
<Container className="container-fluid">
|
||||||
readActionAllowedFields={readActionAllowedFields}
|
<Header allowedActions={allowedActions} />
|
||||||
// TODO check if needed
|
<div className="row" style={{ paddingTop: 3 }}>
|
||||||
redirectToPreviousPage={goBack}
|
<div className="col-md-12 col-lg-9" style={{ marginBottom: 13 }}>
|
||||||
slug={slug}
|
{formattedContentTypeLayout.map((block, blockIndex) => {
|
||||||
status={status}
|
if (isDynamicZone(block)) {
|
||||||
updateActionAllowedFields={updateActionAllowedFields}
|
const {
|
||||||
>
|
0: {
|
||||||
<BackHeader onClick={goBack} />
|
0: { name, fieldSchema, metadatas },
|
||||||
<Container className="container-fluid">
|
},
|
||||||
<Header />
|
} = block;
|
||||||
<div className="row" style={{ paddingTop: 3 }}>
|
|
||||||
<div className="col-md-12 col-lg-9" style={{ marginBottom: 13 }}>
|
|
||||||
{formattedContentTypeLayout.map((block, blockIndex) => {
|
|
||||||
if (isDynamicZone(block)) {
|
|
||||||
const {
|
|
||||||
0: {
|
|
||||||
0: { name, fieldSchema, metadatas },
|
|
||||||
},
|
|
||||||
} = block;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<DynamicZone
|
|
||||||
key={blockIndex}
|
|
||||||
name={name}
|
|
||||||
fieldSchema={fieldSchema}
|
|
||||||
metadatas={metadatas}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormWrapper key={blockIndex}>
|
<DynamicZone
|
||||||
{block.map((fieldsBlock, fieldsBlockIndex) => {
|
key={blockIndex}
|
||||||
return (
|
name={name}
|
||||||
<div className="row" key={fieldsBlockIndex}>
|
fieldSchema={fieldSchema}
|
||||||
{fieldsBlock.map(
|
metadatas={metadatas}
|
||||||
({ name, size, fieldSchema, metadatas }, fieldIndex) => {
|
/>
|
||||||
const isComponent = fieldSchema.type === 'component';
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (isComponent) {
|
return (
|
||||||
const {
|
<FormWrapper key={blockIndex}>
|
||||||
component,
|
{block.map((fieldsBlock, fieldsBlockIndex) => {
|
||||||
max,
|
return (
|
||||||
min,
|
<div className="row" key={fieldsBlockIndex}>
|
||||||
repeatable = false,
|
{fieldsBlock.map(
|
||||||
} = fieldSchema;
|
({ name, size, fieldSchema, metadatas }, fieldIndex) => {
|
||||||
const componentUid = fieldSchema.component;
|
const isComponent = fieldSchema.type === 'component';
|
||||||
|
|
||||||
return (
|
if (isComponent) {
|
||||||
<FieldComponent
|
const {
|
||||||
key={componentUid}
|
component,
|
||||||
componentUid={component}
|
max,
|
||||||
isRepeatable={repeatable}
|
min,
|
||||||
label={metadatas.label}
|
repeatable = false,
|
||||||
max={max}
|
} = fieldSchema;
|
||||||
min={min}
|
const componentUid = fieldSchema.component;
|
||||||
name={name}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`col-${size}`} key={name}>
|
<FieldComponent
|
||||||
<Inputs
|
key={componentUid}
|
||||||
autoFocus={
|
componentUid={component}
|
||||||
blockIndex === 0 &&
|
isRepeatable={repeatable}
|
||||||
fieldsBlockIndex === 0 &&
|
label={metadatas.label}
|
||||||
fieldIndex === 0
|
max={max}
|
||||||
}
|
min={min}
|
||||||
fieldSchema={fieldSchema}
|
name={name}
|
||||||
keys={name}
|
/>
|
||||||
metadatas={metadatas}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
)}
|
|
||||||
</div>
|
return (
|
||||||
);
|
<div className={`col-${size}`} key={name}>
|
||||||
})}
|
<Inputs
|
||||||
</FormWrapper>
|
autoFocus={
|
||||||
);
|
blockIndex === 0 &&
|
||||||
})}
|
fieldsBlockIndex === 0 &&
|
||||||
</div>
|
fieldIndex === 0
|
||||||
<div className="col-md-12 col-lg-3">
|
}
|
||||||
<InformationCard />
|
fieldSchema={fieldSchema}
|
||||||
<Padded size="smd" top />
|
keys={name}
|
||||||
{currentContentTypeLayoutData.layouts.editRelations.length > 0 && (
|
metadatas={metadatas}
|
||||||
<SubWrapper style={{ padding: '0 20px 1px', marginBottom: '25px' }}>
|
/>
|
||||||
<div style={{ paddingTop: '22px' }}>
|
</div>
|
||||||
{currentContentTypeLayoutData.layouts.editRelations.map(
|
);
|
||||||
({ name, fieldSchema, metadatas, queryInfos }) => {
|
}
|
||||||
return (
|
)}
|
||||||
<SelectWrapper
|
</div>
|
||||||
{...fieldSchema}
|
);
|
||||||
{...metadatas}
|
})}
|
||||||
queryInfos={queryInfos}
|
</FormWrapper>
|
||||||
key={name}
|
);
|
||||||
name={name}
|
})}
|
||||||
relationsType={fieldSchema.relationType}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</SubWrapper>
|
|
||||||
)}
|
|
||||||
<LinkWrapper>
|
|
||||||
<ul>
|
|
||||||
<CheckPermissions permissions={configurationPermissions}>
|
|
||||||
<LiLink
|
|
||||||
message={{
|
|
||||||
id: 'app.links.configure-view',
|
|
||||||
}}
|
|
||||||
icon="layout"
|
|
||||||
url={configurationsURL}
|
|
||||||
onClick={() => {
|
|
||||||
// emitEvent('willEditContentTypeLayoutFromEditView');
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</CheckPermissions>
|
|
||||||
{getInjectedComponents(
|
|
||||||
'editView',
|
|
||||||
'right.links',
|
|
||||||
plugins,
|
|
||||||
currentEnvironment,
|
|
||||||
slug
|
|
||||||
)}
|
|
||||||
{allowedActions.canDelete && (
|
|
||||||
<DeleteLink
|
|
||||||
isCreatingEntry={isCreatingEntry}
|
|
||||||
onDelete={onDelete}
|
|
||||||
onDeleteSucceeded={onDeleteSucceeded}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</ul>
|
|
||||||
</LinkWrapper>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</Container>
|
<div className="col-md-12 col-lg-3">
|
||||||
</EditViewDataManagerProvider>
|
<InformationCard />
|
||||||
);
|
<Padded size="smd" top />
|
||||||
}}
|
{currentContentTypeLayoutData.layouts.editRelations.length > 0 && (
|
||||||
</DataManagementWrapper>
|
<SubWrapper style={{ padding: '0 20px 1px', marginBottom: '25px' }}>
|
||||||
</ContentTypeLayoutContext.Provider>
|
<div style={{ paddingTop: '22px' }}>
|
||||||
</EditViewProvider>
|
{currentContentTypeLayoutData.layouts.editRelations.map(
|
||||||
|
({ name, fieldSchema, metadatas, queryInfos }) => {
|
||||||
|
return (
|
||||||
|
<SelectWrapper
|
||||||
|
{...fieldSchema}
|
||||||
|
{...metadatas}
|
||||||
|
queryInfos={queryInfos}
|
||||||
|
key={name}
|
||||||
|
name={name}
|
||||||
|
relationsType={fieldSchema.relationType}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</SubWrapper>
|
||||||
|
)}
|
||||||
|
<LinkWrapper>
|
||||||
|
<ul>
|
||||||
|
<CheckPermissions permissions={configurationPermissions}>
|
||||||
|
<LiLink
|
||||||
|
message={{
|
||||||
|
id: 'app.links.configure-view',
|
||||||
|
}}
|
||||||
|
icon="layout"
|
||||||
|
url={configurationsURL}
|
||||||
|
onClick={() => {
|
||||||
|
// emitEvent('willEditContentTypeLayoutFromEditView');
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</CheckPermissions>
|
||||||
|
{getInjectedComponents(
|
||||||
|
'editView',
|
||||||
|
'right.links',
|
||||||
|
plugins,
|
||||||
|
currentEnvironment,
|
||||||
|
slug
|
||||||
|
)}
|
||||||
|
{allowedActions.canDelete && (
|
||||||
|
<DeleteLink
|
||||||
|
isCreatingEntry={isCreatingEntry}
|
||||||
|
onDelete={onDelete}
|
||||||
|
onDeleteSucceeded={onDeleteSucceeded}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</ul>
|
||||||
|
</LinkWrapper>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Container>
|
||||||
|
</EditViewDataManagerProvider>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</DataManagementWrapper>
|
||||||
|
</ContentTypeLayoutContext.Provider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
EditView.defaultProps = {
|
EditView.defaultProps = {
|
||||||
// TODO
|
|
||||||
currentEnvironment: 'production',
|
currentEnvironment: 'production',
|
||||||
emitEvent: () => {},
|
|
||||||
plugins: {},
|
plugins: {},
|
||||||
isSingleType: false,
|
isSingleType: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
EditView.propTypes = {
|
EditView.propTypes = {
|
||||||
components: PropTypes.array.isRequired,
|
|
||||||
currentEnvironment: PropTypes.string,
|
currentEnvironment: PropTypes.string,
|
||||||
emitEvent: PropTypes.func,
|
|
||||||
isSingleType: PropTypes.bool,
|
isSingleType: PropTypes.bool,
|
||||||
models: PropTypes.array.isRequired,
|
|
||||||
plugins: PropTypes.object,
|
plugins: PropTypes.object,
|
||||||
slug: PropTypes.string.isRequired,
|
slug: PropTypes.string.isRequired,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -5,8 +5,7 @@ import { initialState } from './reducer';
|
|||||||
/**
|
/**
|
||||||
* Direct selector to the main state domain
|
* Direct selector to the main state domain
|
||||||
*/
|
*/
|
||||||
const selectMainDomain = () => state =>
|
const selectMainDomain = () => state => state.get(`${pluginId}_main`) || initialState;
|
||||||
state.get(`${pluginId}_main`) || initialState;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Other specific selectors
|
* Other specific selectors
|
||||||
@ -17,12 +16,16 @@ const selectMainDomain = () => state =>
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const makeSelectMain = () =>
|
const makeSelectMain = () =>
|
||||||
createSelector(
|
createSelector(selectMainDomain(), substate => {
|
||||||
selectMainDomain(),
|
return substate.toJS();
|
||||||
substate => {
|
});
|
||||||
return substate.toJS();
|
|
||||||
}
|
const makeSelectModels = () =>
|
||||||
);
|
createSelector(selectMainDomain(), substate => {
|
||||||
|
const allModels = substate.get('models').toJS();
|
||||||
|
|
||||||
|
return allModels.filter(model => model.isDisplayed === true).map(({ uid }) => uid);
|
||||||
|
});
|
||||||
|
|
||||||
export default makeSelectMain;
|
export default makeSelectMain;
|
||||||
export { selectMainDomain };
|
export { makeSelectModels, selectMainDomain };
|
||||||
|
|||||||
@ -1,5 +0,0 @@
|
|||||||
import { createContext } from 'react';
|
|
||||||
|
|
||||||
const EditViewContext = createContext();
|
|
||||||
|
|
||||||
export default EditViewContext;
|
|
||||||
@ -1,5 +1,4 @@
|
|||||||
export { default as ContentTypeLayoutContext } from './ContentTypeLayout';
|
export { default as ContentTypeLayoutContext } from './ContentTypeLayout';
|
||||||
export { default as EditViewContext } from './EditView';
|
|
||||||
export { default as EditViewDataManagerContext } from './EditViewDataManager';
|
export { default as EditViewDataManagerContext } from './EditViewDataManager';
|
||||||
export { default as LayoutDndContext } from './LayoutDnd';
|
export { default as LayoutDndContext } from './LayoutDnd';
|
||||||
export { default as ListViewContext } from './ListView';
|
export { default as ListViewContext } from './ListView';
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
export { default as useContentTypeLayout } from './useContentTypeLayout';
|
export { default as useContentTypeLayout } from './useContentTypeLayout';
|
||||||
export { default as useFetchContentTypeLayout } from './useFetchContentTypeLayout';
|
export { default as useFetchContentTypeLayout } from './useFetchContentTypeLayout';
|
||||||
export { default as useDataManager } from './useDataManager';
|
export { default as useDataManager } from './useDataManager';
|
||||||
export { default as useEditView } from './useEditView';
|
|
||||||
export { default as useLayoutDnd } from './useLayoutDnd';
|
export { default as useLayoutDnd } from './useLayoutDnd';
|
||||||
export { default as useListView } from './useListView';
|
export { default as useListView } from './useListView';
|
||||||
export { default as useWysiwyg } from './useWysiwyg';
|
export { default as useWysiwyg } from './useWysiwyg';
|
||||||
|
|||||||
@ -1,6 +0,0 @@
|
|||||||
import { useContext } from 'react';
|
|
||||||
import EditViewContext from '../contexts/EditView';
|
|
||||||
|
|
||||||
const useEditView = () => useContext(EditViewContext);
|
|
||||||
|
|
||||||
export default useEditView;
|
|
||||||
@ -1,31 +1,38 @@
|
|||||||
import { useCallback, useEffect, useReducer } from 'react';
|
import { useCallback, useEffect, useMemo, useReducer } from 'react';
|
||||||
|
import { useSelector } from 'react-redux';
|
||||||
import { request } from 'strapi-helper-plugin';
|
import { request } from 'strapi-helper-plugin';
|
||||||
import formatLayouts from './utils/formatLayouts';
|
import formatLayouts from './utils/formatLayouts';
|
||||||
import reducer, { initialState } from './reducer';
|
import reducer, { initialState } from './reducer';
|
||||||
|
import { makeSelectModels } from '../../containers/Main/selectors';
|
||||||
|
|
||||||
const useFetchContentTypeLayout = contentTypeUID => {
|
const useFetchContentTypeLayout = contentTypeUID => {
|
||||||
const [{ error, isLoading, layout }, dispatch] = useReducer(reducer, initialState);
|
const [{ error, isLoading, layout }, dispatch] = useReducer(reducer, initialState);
|
||||||
|
const modelsSelector = useMemo(makeSelectModels, []);
|
||||||
|
const models = useSelector(state => modelsSelector(state), []);
|
||||||
|
|
||||||
const getData = useCallback(async (uid, abortSignal = false) => {
|
const getData = useCallback(
|
||||||
let signal = abortSignal || new AbortController().signal;
|
async (uid, abortSignal = false) => {
|
||||||
|
let signal = abortSignal || new AbortController().signal;
|
||||||
|
|
||||||
dispatch({ type: 'GET_DATA' });
|
dispatch({ type: 'GET_DATA' });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data } = await request(`/content-manager/content-types/${uid}`, {
|
const { data } = await request(`/content-manager/content-types/${uid}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
signal,
|
signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'GET_DATA_SUCCEEDED',
|
type: 'GET_DATA_SUCCEEDED',
|
||||||
data: formatLayouts(data),
|
data: formatLayouts(data, models),
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
dispatch({ type: 'GET_DATA_ERROR', error });
|
dispatch({ type: 'GET_DATA_ERROR', error });
|
||||||
}
|
}
|
||||||
}, []);
|
},
|
||||||
|
[models]
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const abortController = new AbortController();
|
const abortController = new AbortController();
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { get, set } from 'lodash';
|
import { get, set } from 'lodash';
|
||||||
import pluginId from '../../../pluginId';
|
import pluginId from '../../../pluginId';
|
||||||
|
|
||||||
const formatLayoutWithMetas = (obj, ctUid) => {
|
const formatLayoutWithMetas = (obj, ctUid, models) => {
|
||||||
const formatted = obj.layouts.edit.reduce((acc, current) => {
|
const formatted = obj.layouts.edit.reduce((acc, current) => {
|
||||||
const row = current.map(attribute => {
|
const row = current.map(attribute => {
|
||||||
const fieldSchema = get(obj, ['schema', 'attributes', attribute.name], {});
|
const fieldSchema = get(obj, ['schema', 'attributes', attribute.name], {});
|
||||||
@ -14,8 +14,8 @@ const formatLayoutWithMetas = (obj, ctUid) => {
|
|||||||
|
|
||||||
if (fieldSchema.type === 'relation') {
|
if (fieldSchema.type === 'relation') {
|
||||||
const queryInfos = ctUid
|
const queryInfos = ctUid
|
||||||
? generateRelationQueryInfosForComponents(obj, attribute.name, ctUid)
|
? generateRelationQueryInfosForComponents(obj, attribute.name, ctUid, models)
|
||||||
: generateRelationQueryInfos(obj, attribute.name);
|
: generateRelationQueryInfos(obj, attribute.name, models);
|
||||||
|
|
||||||
set(data, 'queryInfos', queryInfos);
|
set(data, 'queryInfos', queryInfos);
|
||||||
}
|
}
|
||||||
@ -31,23 +31,28 @@ const formatLayoutWithMetas = (obj, ctUid) => {
|
|||||||
return formatted;
|
return formatted;
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateRelationQueryInfos = (obj, fieldName) => {
|
const generateRelationQueryInfos = (obj, fieldName, models) => {
|
||||||
const uid = obj.uid;
|
const uid = obj.uid;
|
||||||
const endPoint = `/${pluginId}/explorer/${uid}/relation-list/${fieldName}`;
|
const endPoint = `/${pluginId}/explorer/${uid}/relation-list/${fieldName}`;
|
||||||
const mainField = get(obj, ['metadatas', fieldName, 'edit', 'mainField'], '');
|
const mainField = get(obj, ['metadatas', fieldName, 'edit', 'mainField'], '');
|
||||||
|
const targetModel = get(obj, ['schema', 'attributes', fieldName, 'targetModel'], '');
|
||||||
|
const shouldDisplayRelationLink = models.indexOf(targetModel) !== -1;
|
||||||
|
|
||||||
const queryInfos = {
|
const queryInfos = {
|
||||||
endPoint,
|
endPoint,
|
||||||
containsKey: `${mainField}_contains`,
|
containsKey: `${mainField}_contains`,
|
||||||
defaultParams: {},
|
defaultParams: {},
|
||||||
|
shouldDisplayRelationLink,
|
||||||
};
|
};
|
||||||
|
|
||||||
return queryInfos;
|
return queryInfos;
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateRelationQueryInfosForComponents = (obj, fieldName, ctUid) => {
|
const generateRelationQueryInfosForComponents = (obj, fieldName, ctUid, models) => {
|
||||||
const endPoint = `/${pluginId}/explorer/${ctUid}/relation-list/${fieldName}`;
|
const endPoint = `/${pluginId}/explorer/${ctUid}/relation-list/${fieldName}`;
|
||||||
const mainField = get(obj, ['metadatas', fieldName, 'edit', 'mainField'], '');
|
const mainField = get(obj, ['metadatas', fieldName, 'edit', 'mainField'], '');
|
||||||
|
const targetModel = get(obj, ['schema', 'attributes', fieldName, 'targetModel'], '');
|
||||||
|
const shouldDisplayRelationLink = models.indexOf(targetModel) !== -1;
|
||||||
|
|
||||||
const queryInfos = {
|
const queryInfos = {
|
||||||
endPoint,
|
endPoint,
|
||||||
@ -55,19 +60,20 @@ const generateRelationQueryInfosForComponents = (obj, fieldName, ctUid) => {
|
|||||||
defaultParams: {
|
defaultParams: {
|
||||||
_component: obj.uid,
|
_component: obj.uid,
|
||||||
},
|
},
|
||||||
|
shouldDisplayRelationLink,
|
||||||
};
|
};
|
||||||
|
|
||||||
return queryInfos;
|
return queryInfos;
|
||||||
};
|
};
|
||||||
|
|
||||||
// editRelations is an array of strings...
|
// editRelations is an array of strings...
|
||||||
const formatEditRelationsLayoutWithMetas = obj => {
|
const formatEditRelationsLayoutWithMetas = (obj, models) => {
|
||||||
const formatted = obj.layouts.editRelations.reduce((acc, current) => {
|
const formatted = obj.layouts.editRelations.reduce((acc, current) => {
|
||||||
const fieldSchema = get(obj, ['schema', 'attributes', current], {});
|
const fieldSchema = get(obj, ['schema', 'attributes', current], {});
|
||||||
const metadatas = get(obj, ['metadatas', current, 'edit'], {});
|
const metadatas = get(obj, ['metadatas', current, 'edit'], {});
|
||||||
const size = 6;
|
const size = 6;
|
||||||
|
|
||||||
const queryInfos = generateRelationQueryInfos(obj, current);
|
const queryInfos = generateRelationQueryInfos(obj, current, models);
|
||||||
|
|
||||||
acc.push({
|
acc.push({
|
||||||
name: current,
|
name: current,
|
||||||
@ -83,16 +89,20 @@ const formatEditRelationsLayoutWithMetas = obj => {
|
|||||||
return formatted;
|
return formatted;
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatLayouts = data => {
|
const formatLayouts = (data, models) => {
|
||||||
const formattedCTEditLayout = formatLayoutWithMetas(data.contentType);
|
const formattedCTEditLayout = formatLayoutWithMetas(data.contentType, models);
|
||||||
const ctUid = data.contentType.uid;
|
const ctUid = data.contentType.uid;
|
||||||
const formattedEditRelationsLayout = formatEditRelationsLayoutWithMetas(data.contentType);
|
const formattedEditRelationsLayout = formatEditRelationsLayoutWithMetas(data.contentType, models);
|
||||||
|
|
||||||
set(data, ['contentType', 'layouts', 'edit'], formattedCTEditLayout);
|
set(data, ['contentType', 'layouts', 'edit'], formattedCTEditLayout);
|
||||||
set(data, ['contentType', 'layouts', 'editRelations'], formattedEditRelationsLayout);
|
set(data, ['contentType', 'layouts', 'editRelations'], formattedEditRelationsLayout);
|
||||||
|
|
||||||
Object.keys(data.components).forEach(compoUID => {
|
Object.keys(data.components).forEach(compoUID => {
|
||||||
const formattedCompoEditLayout = formatLayoutWithMetas(data.components[compoUID], ctUid);
|
const formattedCompoEditLayout = formatLayoutWithMetas(
|
||||||
|
data.components[compoUID],
|
||||||
|
ctUid,
|
||||||
|
models
|
||||||
|
);
|
||||||
|
|
||||||
set(data, ['components', compoUID, 'layouts', 'edit'], formattedCompoEditLayout);
|
set(data, ['components', compoUID, 'layouts', 'edit'], formattedCompoEditLayout);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user