From 1b9a5dfe4e9dfb235c809112c1c109a756a216cd Mon Sep 17 00:00:00 2001 From: Jess Telford Date: Mon, 23 Dec 2019 16:47:37 +1100 Subject: [PATCH] Correctly load Content field views when field access set to update: false --- .changeset/swift-gorillas-switch.md | 5 + .../app-admin-ui/client/pages/Item/index.js | 138 +++++++++--------- 2 files changed, 75 insertions(+), 68 deletions(-) create mode 100644 .changeset/swift-gorillas-switch.md diff --git a/.changeset/swift-gorillas-switch.md b/.changeset/swift-gorillas-switch.md new file mode 100644 index 00000000000..5d970ad77db --- /dev/null +++ b/.changeset/swift-gorillas-switch.md @@ -0,0 +1,5 @@ +--- +'@keystonejs/app-admin-ui': patch +--- + +Correctly load Content field views when field access set to update: false diff --git a/packages/app-admin-ui/client/pages/Item/index.js b/packages/app-admin-ui/client/pages/Item/index.js index 4a1d77cfc0a..0f0be0dc573 100644 --- a/packages/app-admin-ui/client/pages/Item/index.js +++ b/packages/app-admin-ui/client/pages/Item/index.js @@ -53,6 +53,12 @@ const getCurrentValues = memoizeOne(getValues); const deserializeItem = memoizeOne((list, data) => list.deserializeItemData(data)); +const getRenderableFields = memoizeOne(list => + list.fields + .filter(({ isPrimaryKey }) => !isPrimaryKey) + .filter(({ maybeAccess, config }) => !!maybeAccess.update || !!config.isReadOnly) +); + const ItemDetails = withRouter( class ItemDetails extends Component { constructor(props) { @@ -60,10 +66,8 @@ const ItemDetails = withRouter( // memoized function so we can call it multiple times _per component_ this.getFieldsObject = memoizeOne(() => arrayToObject( - props.list.fields - .filter(({ isPrimaryKey }) => !isPrimaryKey) - .filter(({ isReadOnly }) => !isReadOnly) - .filter(({ maybeAccess }) => !!maybeAccess.update), + // NOTE: We _exclude_ read only fields + getRenderableFields(props.list).filter(({ config }) => !config.isReadOnly), 'path' ) ); @@ -295,66 +299,61 @@ const ItemDetails = withRouter(
- {list.fields - .filter(({ isPrimaryKey }) => !isPrimaryKey) - .filter(({ maybeAccess, config }) => { - return !!maybeAccess.update || config.isReadOnly; - }) - .map((field, i) => ( - - {() => { - const [Field] = field.adminMeta.readViews([field.views.Field]); - - let onChange = useCallback( - value => { - this.setState(({ item: itm }) => ({ - item: { - ...itm, - [field.path]: value, - }, - validationErrors: {}, - validationWarnings: {}, - itemHasChanged: true, - })); - }, - [field] - ); - - return useMemo( - () => ( - - ), - [ - i, - field, - list, - itemErrors[field.path], - item[field.path], - item.id, - validationErrors[field.path], - validationWarnings[field.path], - savedData[field.path], - onChange, - ] - ); - }} - - ))} + {getRenderableFields(list).map((field, i) => ( + + {() => { + const [Field] = field.adminMeta.readViews([field.views.Field]); + + let onChange = useCallback( + value => { + this.setState(({ item: itm }) => ({ + item: { + ...itm, + [field.path]: value, + }, + validationErrors: {}, + validationWarnings: {}, + itemHasChanged: true, + })); + }, + [field] + ); + + return useMemo( + () => ( + + ), + [ + i, + field, + list, + itemErrors[field.path], + item[field.path], + item.id, + validationErrors[field.path], + validationWarnings[field.path], + savedData[field.path], + onChange, + ] + ); + }} + + ))}