strapi-plugin-navigation 2.0.9 → 2.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -56,7 +56,13 @@ const SettingsPage = () => {
56
56
  additionalFields: audienceFieldChecked ? [navigationItemAdditionalFields.AUDIENCE] : [],
57
57
  allowedLevels: allowedLevels,
58
58
  gql: {
59
- navigationItemRelated: selectedContentTypes.map(uid => allContentTypes.find(ct => ct.uid === uid).info.displayName.replace(/\s+/g, ''))
59
+ navigationItemRelated: selectedContentTypes.map(uid => {
60
+ const singularName = allContentTypes.find(ct => ct.uid === uid).info.singularName;
61
+ const globalIdLike = singularName.split('-')
62
+ .map(_ => capitalize(_))
63
+ .join('')
64
+ return globalIdLike;
65
+ })
60
66
  }
61
67
  });
62
68
 
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useMemo, useState, useCallback } from 'react';
2
- import { debounce, find, get, isEmpty, isEqual, isNil, isString } from 'lodash';
2
+ import { debounce, find, get, first, isEmpty, isEqual, isNil, isString } from 'lodash';
3
3
  import PropTypes from 'prop-types';
4
4
  import { Formik } from 'formik'
5
5
  import slugify from 'slugify';
@@ -75,11 +75,11 @@ const NavigationItemForm = ({
75
75
 
76
76
  const sanitizePayload = (payload = {}) => {
77
77
  const { onItemClick, onItemLevelAddClick, related, relatedType, menuAttached, type, ...purePayload } = payload;
78
- const relatedId = related
78
+ const relatedId = related;
79
+ const singleRelatedItem = isSingleSelected ? first(contentTypeEntities) : undefined;
79
80
  const relatedCollectionType = relatedType;
80
- const title = isSingleSelected ?
81
- relatedTypeSelectOptions.find(v => v.key == relatedType).label :
82
- payload.title || relatedSelectOptions.find(v => v.key == relatedId)?.label;
81
+ const title = payload.title;
82
+
83
83
  return {
84
84
  ...purePayload,
85
85
  title,
@@ -90,6 +90,7 @@ const NavigationItemForm = ({
90
90
  related: type === navigationItemType.INTERNAL ? relatedId : undefined,
91
91
  relatedType: type === navigationItemType.INTERNAL ? relatedCollectionType : undefined,
92
92
  isSingle: isSingleSelected,
93
+ singleRelatedItem,
93
94
  uiRouterKey: generateUiRouterKey(title, relatedId, relatedCollectionType),
94
95
  };
95
96
  };
@@ -136,6 +137,7 @@ const NavigationItemForm = ({
136
137
  return undefined;
137
138
  };
138
139
 
140
+ const initialRelatedTypeSelected = data?.relatedType?.value;
139
141
  const relatedTypeSelectValue = form.relatedType;
140
142
  const relatedSelectValue = form.related;
141
143
 
@@ -221,6 +223,9 @@ const NavigationItemForm = ({
221
223
  () => contentTypes
222
224
  .filter((contentType) => {
223
225
  if (contentType.isSingle) {
226
+ if (relatedTypeSelectValue && [relatedTypeSelectValue, initialRelatedTypeSelected].includes(contentType.uid)) {
227
+ return true;
228
+ }
224
229
  return !usedContentTypesData.some((_) => _.__collectionUid === contentType.uid && _.__collectionUid !== form.relatedType);
225
230
  }
226
231
  return true;
@@ -236,7 +241,7 @@ const NavigationItemForm = ({
236
241
  value: get(item, 'uid'),
237
242
  label: get(item, 'label', get(item, 'name')),
238
243
  })),
239
- [contentTypes, usedContentTypesData],
244
+ [contentTypes, usedContentTypesData, relatedTypeSelectValue],
240
245
  );
241
246
 
242
247
  const thereAreNoMoreContentTypes = isEmpty(relatedSelectOptions) && !contentTypeSearchQuery;
@@ -89,10 +89,12 @@ const linkRelations = (item, config) => {
89
89
 
90
90
  if (isSingle && relatedType) {
91
91
  const relatedContentType = contentTypes.find(_ => relatedType === _.uid) || {};
92
+ const { singleRelatedItem = {} } = item;
92
93
  return {
93
94
  ...item,
94
95
  relatedType,
95
96
  relatedRef: {
97
+ ...singleRelatedItem,
96
98
  ...omit(relatedContentType, 'collectionName'),
97
99
  isSingle,
98
100
  __collectionUid: relatedContentType.uid,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-plugin-navigation",
3
- "version": "2.0.9",
3
+ "version": "2.0.10",
4
4
  "description": "Strapi - Navigation plugin",
5
5
  "strapi": {
6
6
  "name": "navigation",
@@ -8,7 +8,9 @@ module.exports = ({ strapi, nexus, config }) => {
8
8
  definition(t) {
9
9
  t.members(...related)
10
10
  },
11
- resolveType: (item) => strapi.contentTypes[item.__contentType]?.globalId
11
+ resolveType: (item) => {
12
+ return strapi.contentTypes[item.__contentType]?.globalId
13
+ }
12
14
  });
13
15
  }
14
16
 
@@ -33,7 +33,7 @@ module.exports = ({ strapi }) => {
33
33
  const entities = await strapi
34
34
  .query(masterModel.uid)
35
35
  .findMany({
36
- limit: -1,
36
+ limit: 0
37
37
  });
38
38
  return entities;
39
39
  },
@@ -50,7 +50,7 @@ module.exports = ({ strapi }) => {
50
50
  where: {
51
51
  master: id,
52
52
  },
53
- limit: -1,
53
+ limit: 0,
54
54
  sort: ['order:asc'],
55
55
  populate: ['related', 'parent', 'audience']
56
56
  });
@@ -95,9 +95,7 @@ module.exports = ({ strapi }) => {
95
95
  const audienceItems = await strapi
96
96
  .query(audienceModel.uid)
97
97
  .findMany({
98
- paggination: {
99
- limit: -1,
100
- }
98
+ limit: 0
101
99
  });
102
100
  extendedResult = {
103
101
  ...extendedResult,
@@ -395,9 +393,7 @@ module.exports = ({ strapi }) => {
395
393
  master: entity.id,
396
394
  ...itemCriteria,
397
395
  },
398
- paggination: {
399
- limit: -1,
400
- },
396
+ limit: 0,
401
397
  sort: ['order:asc'],
402
398
  populate: ['related', 'audience', 'parent'],
403
399
  });
@@ -424,6 +420,7 @@ module.exports = ({ strapi }) => {
424
420
  id: item.id,
425
421
  title: utilsFunctions.composeItemTitle(item, contentTypesNameFields, contentTypes),
426
422
  menuAttached: item.menuAttached,
423
+ order: item.order,
427
424
  path: isExternal ? item.externalPath : parentPath,
428
425
  type: item.type,
429
426
  uiRouterKey: item.uiRouterKey,
@@ -507,7 +504,10 @@ module.exports = ({ strapi }) => {
507
504
  .filter(utilsFunctions.filterOutUnpublished)
508
505
  .map(item => itemParser({
509
506
  ...item,
510
- }, path, field));
507
+ }, path, field))
508
+ .sort((x, y) => {
509
+ return x.order - y.order;
510
+ });
511
511
  },
512
512
 
513
513
  renderRFR({ items, parent = null, parentNavItem = null, contentTypes = [] }) {