Skip to content
This repository has been archived by the owner on Oct 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #131 from Financial-Times/sort-relationships
Browse files Browse the repository at this point in the history
reinstate sorting of relationships in UI
  • Loading branch information
wheresrhys authored Jan 9, 2020
2 parents 4eee333 + e556204 commit 76e815d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/tc-ui/src/primitives/relationship/server.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ const {
setRelationshipAnnotator,
} = require('./lib/view-relationship');

const maybeSort = (hasMany, props) => {
if (!hasMany) {
return '';
}
const sortField = props.has('name') ? 'name' : 'code';
return `(orderBy: ${sortField}_asc)`;
};

module.exports = {
ViewComponent: ViewRelationship,
EditComponent: props => (
Expand All @@ -40,7 +48,7 @@ module.exports = {
hasValue: (value, { hasMany }) =>
hasMany ? value && value.length : !!value,
setRelationshipAnnotator,
graphqlFragment: (propName, { type }) => {
graphqlFragment: (propName, { type, hasMany }) => {
const typeDef = getType(type);
const props = new Set(['code']);
if (typeDef.properties.name) {
Expand All @@ -54,6 +62,8 @@ module.exports = {
.filter(([, { useInSummary }]) => useInSummary)
.forEach(([name]) => props.add(name));

return `${propName} {${[...props].join(' ')}}`;
return `${propName} ${maybeSort(hasMany, props)} {${[...props].join(
' ',
)}}`;
},
};

0 comments on commit 76e815d

Please sign in to comment.