Skip to content

Commit

Permalink
Use the getRefList method in more places (#2887)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored May 5, 2020
1 parent c506dfa commit 99da34a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-parents-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystonejs/fields': patch
---

Updated views to make use of the `getRefList()` method of the relationship field controller.
4 changes: 2 additions & 2 deletions packages/fields/src/types/Relationship/views/Cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ export default ({ data, field, Link }) => {
if (!data) {
return null;
}
const refList = field.adminMeta.getListByKey(field.config.ref);
const { path } = field.getRefList();
return (
<Fragment>
{(Array.isArray(data) ? data : [data])
.filter(item => item)
.map((item, index) => (
<Fragment key={item.id}>
{!!index ? ', ' : ''}
<Link path={refList.path} item={item}>
<Link path={path} item={item}>
{item._label_}
</Link>
</Fragment>
Expand Down
4 changes: 1 addition & 3 deletions packages/fields/src/types/Relationship/views/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 `
Expand Down
12 changes: 6 additions & 6 deletions packages/fields/src/types/Relationship/views/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 (
<FieldContainer>
Expand Down

0 comments on commit 99da34a

Please sign in to comment.