Skip to content

Commit

Permalink
Select custom field uids from layout using reselect
Browse files Browse the repository at this point in the history
  • Loading branch information
markkaylor committed Nov 23, 2022
1 parent cfd9262 commit 0343495
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Expand Up @@ -27,10 +27,10 @@ import useLazyComponents from '../../hooks/useLazyComponents';
import DraftAndPublishBadge from './DraftAndPublishBadge';
import Informations from './Informations';
import Header from './Header';
import { getFieldsActionMatchingPermissions, getCustomFieldUidsFromLayout } from './utils';
import { getFieldsActionMatchingPermissions } from './utils';
import DeleteLink from './DeleteLink';
import GridRow from './GridRow';
import { selectCurrentLayout, selectAttributesLayout } from './selectors';
import { selectCurrentLayout, selectAttributesLayout, selectCustomFieldUids } from './selectors';

const cmPermissions = permissions.contentManager;
const ctbPermissions = [{ action: 'plugin::content-type-builder.read', subject: null }];
Expand All @@ -40,12 +40,12 @@ const EditView = ({ allowedActions, isSingleType, goBack, slug, id, origin, user
const { trackUsage } = useTracking();
const { formatMessage } = useIntl();

const { layout, formattedContentTypeLayout } = useSelector((state) => ({
const { layout, formattedContentTypeLayout, customFieldUids } = useSelector((state) => ({
layout: selectCurrentLayout(state),
formattedContentTypeLayout: selectAttributesLayout(state),
customFieldUids: selectCustomFieldUids(state),
}));

const customFieldUids = getCustomFieldUidsFromLayout(layout);
const { isLazyLoading, lazyComponentStore } = useLazyComponents(customFieldUids);

const { createActionAllowedFields, readActionAllowedFields, updateActionAllowedFields } =
Expand Down
@@ -1,10 +1,14 @@
import { createSelector } from 'reselect';
import { createAttributesLayout } from './utils';
import { createAttributesLayout, getCustomFieldUidsFromLayout } from './utils';

const selectCurrentLayout = (state) => state['content-manager_editViewLayoutManager'].currentLayout;

const selectAttributesLayout = createSelector(selectCurrentLayout, (layout) =>
createAttributesLayout(layout?.contentType ?? {})
);

export { selectCurrentLayout, selectAttributesLayout };
const selectCustomFieldUids = createSelector(selectCurrentLayout, (layout) =>
getCustomFieldUidsFromLayout(layout)
);

export { selectCurrentLayout, selectAttributesLayout, selectCustomFieldUids };
@@ -1,4 +1,5 @@
const getCustomFieldUidsFromLayout = (layout) => {
if (!layout) return [];
// Get all the fields on the content-type and its components
const allFields = [
...layout.contentType.layouts.edit,
Expand Down

0 comments on commit 0343495

Please sign in to comment.