From 99da34a8db26b8861b08cee330407605e787a80c Mon Sep 17 00:00:00 2001 From: Tim Leslie Date: Wed, 6 May 2020 09:25:04 +1000 Subject: [PATCH] Use the getRefList method in more places (#2887) --- .changeset/stale-parents-peel.md | 5 +++++ packages/fields/src/types/Relationship/views/Cell.js | 4 ++-- .../src/types/Relationship/views/Controller.js | 4 +--- .../fields/src/types/Relationship/views/Field.js | 12 ++++++------ 4 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 .changeset/stale-parents-peel.md diff --git a/.changeset/stale-parents-peel.md b/.changeset/stale-parents-peel.md new file mode 100644 index 00000000000..24ae1fa7d88 --- /dev/null +++ b/.changeset/stale-parents-peel.md @@ -0,0 +1,5 @@ +--- +'@keystonejs/fields': patch +--- + +Updated views to make use of the `getRefList()` method of the relationship field controller. diff --git a/packages/fields/src/types/Relationship/views/Cell.js b/packages/fields/src/types/Relationship/views/Cell.js index b36dcb9e6f3..334ca5bac4b 100644 --- a/packages/fields/src/types/Relationship/views/Cell.js +++ b/packages/fields/src/types/Relationship/views/Cell.js @@ -4,7 +4,7 @@ export default ({ data, field, Link }) => { if (!data) { return null; } - const refList = field.adminMeta.getListByKey(field.config.ref); + const { path } = field.getRefList(); return ( {(Array.isArray(data) ? data : [data]) @@ -12,7 +12,7 @@ export default ({ data, field, Link }) => { .map((item, index) => ( {!!index ? ', ' : ''} - + {item._label_} diff --git a/packages/fields/src/types/Relationship/views/Controller.js b/packages/fields/src/types/Relationship/views/Controller.js index c5ed5b06b7c..c40a5ad33c6 100644 --- a/packages/fields/src/types/Relationship/views/Controller.js +++ b/packages/fields/src/types/Relationship/views/Controller.js @@ -6,9 +6,7 @@ export default class RelationshipController extends FieldController { super({ ...config, defaultValue }, ...args); } getRefList() { - const { getListByKey } = this.adminMeta; - const { ref } = this.config; - return getListByKey(ref); + return this.adminMeta.getListByKey(this.config.ref); } getQueryFragment = (path = this.path) => { return ` diff --git a/packages/fields/src/types/Relationship/views/Field.js b/packages/fields/src/types/Relationship/views/Field.js index 112f24cc799..ff45feda4e9 100644 --- a/packages/fields/src/types/Relationship/views/Field.js +++ b/packages/fields/src/types/Relationship/views/Field.js @@ -56,12 +56,12 @@ function SetAsCurrentUser({ listKey, value, onAddUser, many }) { } function LinkToRelatedItems({ field, value }) { - const { many, ref } = field.config; - const { adminPath, getListByKey } = field.adminMeta; - const refList = getListByKey(ref); + const { many } = field.config; + const { adminPath } = field.adminMeta; + const { path } = field.getRefList(); let isDisabled = false; let label; - let link = `${adminPath}/${refList.path}`; + let link = `${adminPath}/${path}`; if (many) { label = 'View List of Related Items'; @@ -106,7 +106,7 @@ function LinkToRelatedItems({ field, value }) { function CreateAndAddItem({ field, item, onCreate, CreateItemModal }) { const { list, openCreateItemModal } = useList(); - let relatedList = field.adminMeta.getListByKey(field.config.ref); + let relatedList = field.getRefList(); let label = `Create and add ${relatedList.singular}`; let prefillData; @@ -182,7 +182,7 @@ const RelationshipField = ({ const { authStrategy } = field.adminMeta; const htmlID = `ks-input-${field.path}`; - const relatedList = field.adminMeta.getListByKey(field.config.ref); + const relatedList = field.getRefList(); return (