Skip to content

Commit

Permalink
Merge pull request #46 from CodeVoyager/feat/reader-nav-single-type-t…
Browse files Browse the repository at this point in the history
…emplate

feat: support for templates on single types
  • Loading branch information
CodeVoyager authored Mar 8, 2021
2 parents c695af8 + 3d11333 commit c107977
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,14 @@ Return a rendered navigation structure depends on passed type (`tree`, `rfr` or
}
```

### Template name

Depending on a content type `templateName` will be resolved differently

For collection types it will be read from content type's attribute name `template` holding a component which definition has option named `templateName`.

For single types a global name of this content type will be used as a template name or it can be set manually with an option named `templateName`.

## Audit log
If you would like to use the [Strapi Molecules Audit Log](https://github.com/VirtusLab/strapi-molecules/tree/master/packages/strapi-plugin-audit-log) plugin you've to first install and then add in you `config/middleware.js` following section enable it:
```js
Expand Down
3 changes: 2 additions & 1 deletion services/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ module.exports = {
const relatedField = (item.associations || []).find(_ => _.model === 'navigationitem');
const { uid, options, info, collectionName, apiName, plugin, kind } = item;
const { name, description } = info;
const { isManaged, hidden } = options;
const { isManaged, hidden, templateName } = options;
const isSingle = kind === KIND_TYPES.SINGLE;
const endpoint = isSingle ? apiName : pluralize(apiName);
const relationName = utilsFunctions.singularize(apiName);
Expand All @@ -145,6 +145,7 @@ module.exports = {
plugin,
available,
visible: (isManaged || isNil(isManaged)) && !hidden,
templateName,
};
})
.filter((item) => item && item.visible);
Expand Down
8 changes: 4 additions & 4 deletions services/utils/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ module.exports = {
}),
);
const relatedResponseMap = responses.reduce((acc, curr) => ({ ...acc, ...curr }), {});
const singleTypes = new Set(
const singleTypes = new Map(
contentTypes
.filter(x => x.isSingle)
.map(({ contentTypeName }) => contentTypeName)
.map(({ contentTypeName, templateName }) => [contentTypeName, templateName || contentTypeName])
);

return (contentType, id) => {
Expand All @@ -122,8 +122,8 @@ module.exports = {
return get(templateComponent, 'options.templateName', TEMPLATE_DEFAULT);
}

if (singleTypes.has(contentType)) {
return contentType;
if (singleTypes.get(contentType)) {
return singleTypes.get(contentType);
}

return TEMPLATE_DEFAULT;
Expand Down

0 comments on commit c107977

Please sign in to comment.