strapi-plugin-navigation 2.2.3 → 2.2.5

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.
Files changed (66) hide show
  1. package/README.md +35 -6
  2. package/admin/src/components/AdditionalFieldInput/index.js +2 -2
  3. package/admin/src/components/AdditionalFieldInput/types.d.ts +1 -0
  4. package/admin/src/components/Item/ItemCardHeader/icons.d.ts +1 -1
  5. package/admin/src/components/Item/ItemCardHeader/icons.js +2 -1
  6. package/admin/src/components/Item/ItemCardHeader/index.d.ts +1 -0
  7. package/admin/src/components/Item/ItemCardHeader/index.js +10 -8
  8. package/admin/src/components/Item/index.js +7 -6
  9. package/admin/src/components/NavigationItemList/index.d.ts +2 -1
  10. package/admin/src/components/NavigationItemList/index.js +2 -2
  11. package/admin/src/hooks/useNavigationManager.d.ts +0 -1
  12. package/admin/src/index.js +1 -1
  13. package/admin/src/pages/DataManagerProvider/index.js +2 -0
  14. package/admin/src/pages/DataManagerProvider/reducer.d.ts +1 -1
  15. package/admin/src/pages/NoAccessPage/index.d.ts +3 -0
  16. package/admin/src/pages/NoAccessPage/index.js +31 -0
  17. package/admin/src/pages/SettingsPage/index.d.ts +0 -1
  18. package/admin/src/pages/SettingsPage/index.js +9 -0
  19. package/admin/src/pages/SettingsPage/types.d.ts +1 -1
  20. package/admin/src/pages/View/components/NavigationHeader/index.d.ts +2 -1
  21. package/admin/src/pages/View/components/NavigationHeader/index.js +9 -8
  22. package/admin/src/pages/View/components/NavigationItemForm/index.js +36 -24
  23. package/admin/src/pages/View/components/NavigationItemForm/types.d.ts +8 -1
  24. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupFooter.d.ts +4 -2
  25. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupFooter.js +5 -1
  26. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupHeader.d.ts +2 -1
  27. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupHeader.js +6 -2
  28. package/admin/src/pages/View/components/NavigationItemPopup/index.d.ts +4 -1
  29. package/admin/src/pages/View/components/NavigationItemPopup/index.js +5 -3
  30. package/admin/src/pages/View/components/NavigationManager/AllNavigations/icons.d.ts +0 -1
  31. package/admin/src/pages/View/components/NavigationManager/AllNavigations/index.d.ts +0 -1
  32. package/admin/src/pages/View/components/NavigationManager/DeletionConfirm/index.d.ts +0 -1
  33. package/admin/src/pages/View/components/NavigationManager/ErrorDetails/index.d.ts +0 -1
  34. package/admin/src/pages/View/components/NavigationManager/Form/index.d.ts +0 -1
  35. package/admin/src/pages/View/components/NavigationManager/NavigationUpdate/index.d.ts +0 -1
  36. package/admin/src/pages/View/components/NavigationManager/NewNavigation/index.d.ts +0 -1
  37. package/admin/src/pages/View/components/NavigationManager/index.d.ts +0 -1
  38. package/admin/src/pages/View/index.js +40 -20
  39. package/admin/src/permissions.d.ts +4 -0
  40. package/admin/src/permissions.js +1 -0
  41. package/admin/src/translations/en.json +8 -0
  42. package/package.json +2 -2
  43. package/permissions.d.ts +1 -0
  44. package/permissions.js +1 -0
  45. package/server/bootstrap/index.js +6 -0
  46. package/server/config/index.js +0 -1
  47. package/server/config/setupStrategy.js +0 -9
  48. package/server/content-types/index.d.ts +2 -0
  49. package/server/content-types/navigation/index.d.ts +1 -0
  50. package/server/content-types/navigation/schema.d.ts +1 -0
  51. package/server/content-types/navigation/schema.js +2 -1
  52. package/server/content-types/navigation-item/index.d.ts +1 -0
  53. package/server/content-types/navigation-item/schema.d.ts +1 -0
  54. package/server/content-types/navigation-item/schema.js +2 -1
  55. package/server/controllers/admin.js +13 -0
  56. package/server/index.d.ts +2 -0
  57. package/server/routes/admin.js +10 -0
  58. package/server/services/admin.js +2 -10
  59. package/server/services/client.js +10 -14
  60. package/server/services/common.js +27 -1
  61. package/strapi-server.d.ts +2 -0
  62. package/tsconfig.tsbuildinfo +1 -1
  63. package/types/config.d.ts +0 -1
  64. package/types/controllers.d.ts +5 -0
  65. package/types/services.d.ts +1 -0
  66. package/types/utils.d.ts +5 -0
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  const utils_1 = require("@strapi/utils");
7
- const slugify_1 = __importDefault(require("@sindresorhus/slugify"));
8
4
  const lodash_1 = require("lodash");
9
5
  const utils_2 = require("../utils");
10
6
  const i18n_1 = require("../i18n");
@@ -21,7 +17,6 @@ const adminService = ({ strapi }) => ({
21
17
  const contentTypesPopulate = config.contentTypesPopulate;
22
18
  const pathDefaultFields = config.pathDefaultFields;
23
19
  const allowedLevels = config.allowedLevels;
24
- const slugify = config.slugify;
25
20
  const isGQLPluginEnabled = !(0, lodash_1.isNil)(strapi.plugin('graphql'));
26
21
  let extendedResult = {
27
22
  allowedContentTypes: utils_2.ALLOWED_CONTENT_TYPES,
@@ -44,7 +39,6 @@ const adminService = ({ strapi }) => ({
44
39
  navigationItemRelated: configContentTypes.map(({ labelSingular }) => labelSingular.replace(/\s+/g, ''))
45
40
  },
46
41
  isGQLPluginEnabled: viaSettingsPage ? isGQLPluginEnabled : undefined,
47
- slugify,
48
42
  cascadeMenuAttached,
49
43
  };
50
44
  const i18nConfig = await (0, i18n_1.addI18NConfigFields)({ strapi, viaSettingsPage, previousConfig: {} });
@@ -101,12 +95,11 @@ const adminService = ({ strapi }) => ({
101
95
  const commonService = (0, utils_2.getPluginService)('common');
102
96
  const adminService = (0, utils_2.getPluginService)('admin');
103
97
  const { enabled: i18nEnabled, defaultLocale } = await (0, i18n_1.getI18nStatus)({ strapi });
104
- const { slugify: customSlugifyConfig } = await adminService.config(false);
105
98
  const { masterModel } = (0, utils_2.getPluginModels)();
106
99
  const { name, visible } = payload;
107
100
  const data = {
108
101
  name,
109
- slug: (0, slugify_1.default)(name, customSlugifyConfig).toLowerCase(),
102
+ slug: await commonService.getSlug(name),
110
103
  visible,
111
104
  };
112
105
  const existingEntity = await strapi
@@ -129,14 +122,13 @@ const adminService = ({ strapi }) => ({
129
122
  const adminService = (0, utils_2.getPluginService)('admin');
130
123
  const commonService = (0, utils_2.getPluginService)('common');
131
124
  const { enabled: i18nEnabled } = await (0, i18n_1.getI18nStatus)({ strapi });
132
- const { slugify: customSlugifyConfig } = await adminService.config(false);
133
125
  const { masterModel } = (0, utils_2.getPluginModels)();
134
126
  const { name, visible } = payload;
135
127
  const existingEntity = await adminService.getById(id);
136
128
  const detailsHaveChanged = existingEntity.name !== name || existingEntity.visible !== visible;
137
129
  if (detailsHaveChanged) {
138
130
  const newName = detailsHaveChanged ? name : existingEntity.name;
139
- const newSlug = detailsHaveChanged ? (0, slugify_1.default)(name, customSlugifyConfig).toLowerCase() : existingEntity.slug;
131
+ const newSlug = detailsHaveChanged ? await commonService.getSlug(name) : existingEntity.slug;
140
132
  await strapi.query(masterModel.uid).update({
141
133
  where: { id },
142
134
  data: {
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  const lodash_1 = require("lodash");
7
- const slugify_1 = __importDefault(require("@sindresorhus/slugify"));
8
4
  const uuid_1 = require("uuid");
9
5
  const types_1 = require("../../types");
10
6
  const utils_1 = require("../utils");
@@ -144,8 +140,8 @@ const clientService = ({ strapi }) => ({
144
140
  ...enabledCustomFieldsNames.reduce((acc, field) => ({ ...acc, [field]: (0, lodash_1.get)(item, field) }), {})
145
141
  };
146
142
  },
147
- renderTree(items = [], id = null, field = 'parent', path = '', itemParser = (i) => i) {
148
- return items
143
+ async renderTree(items = [], id = null, field = 'parent', path = '', itemParser = (i) => i) {
144
+ return (await Promise.all(items
149
145
  .filter((item) => {
150
146
  if (item[field] === null && id === null) {
151
147
  return true;
@@ -160,9 +156,9 @@ const clientService = ({ strapi }) => ({
160
156
  return (data && data === id);
161
157
  })
162
158
  .filter(utils_1.filterOutUnpublished)
163
- .map(item => itemParser({
159
+ .map(async (item) => itemParser({
164
160
  ...item,
165
- }, path, field))
161
+ }, path, field))))
166
162
  .sort((x, y) => {
167
163
  if (x.order !== undefined && y.order !== undefined)
168
164
  return x.order - y.order;
@@ -204,7 +200,7 @@ const clientService = ({ strapi }) => ({
204
200
  return [];
205
201
  }
206
202
  const items = await commonService.getRelatedItems(entities, populate);
207
- const { contentTypes, contentTypesNameFields, additionalFields, slugify: customSlugifyConfig } = await adminService.config(false);
203
+ const { contentTypes, contentTypesNameFields, additionalFields } = await adminService.config(false);
208
204
  const enabledCustomFieldsNames = (0, utils_1.getCustomFields)(additionalFields)
209
205
  .reduce((acc, curr) => curr.enabled ? [...acc, curr.name] : acc, []);
210
206
  const wrapContentType = (itemContentType) => wrapRelated && itemContentType ? {
@@ -215,12 +211,12 @@ const clientService = ({ strapi }) => ({
215
211
  case utils_1.RENDER_TYPES.TREE:
216
212
  case utils_1.RENDER_TYPES.RFR:
217
213
  const getTemplateName = await (0, utils_1.templateNameFactory)(items, strapi, contentTypes);
218
- const itemParser = (item, path = '', field) => {
214
+ const itemParser = async (item, path = '', field) => {
219
215
  const isExternal = item.type === "EXTERNAL";
220
216
  const parentPath = isExternal ? undefined : `${path === '/' ? '' : path}/${(0, lodash_1.first)(item.path) === '/'
221
217
  ? item.path.substring(1)
222
218
  : item.path}`;
223
- const slug = (0, lodash_1.isString)(parentPath) ? (0, slugify_1.default)(((0, lodash_1.first)(parentPath) === '/' ? parentPath.substring(1) : parentPath).replace(/\//g, '-'), customSlugifyConfig) : undefined;
219
+ const slug = (0, lodash_1.isString)(parentPath) ? await commonService.getSlug(((0, lodash_1.first)(parentPath) === '/' ? parentPath.substring(1) : parentPath).replace(/\//g, '-')) : undefined;
224
220
  const lastRelated = (0, lodash_1.isArray)(item.related) ? (0, lodash_1.last)(item.related) : item.related;
225
221
  const relatedContentType = wrapContentType(lastRelated);
226
222
  return {
@@ -231,19 +227,19 @@ const clientService = ({ strapi }) => ({
231
227
  path: isExternal ? item.externalPath : parentPath,
232
228
  type: item.type,
233
229
  uiRouterKey: item.uiRouterKey,
234
- slug: !slug && item.uiRouterKey ? (0, slugify_1.default)(item.uiRouterKey, customSlugifyConfig) : slug,
230
+ slug: !slug && item.uiRouterKey ? commonService.getSlug(item.uiRouterKey) : slug,
235
231
  external: isExternal,
236
232
  related: isExternal || !lastRelated ? undefined : {
237
233
  ...relatedContentType,
238
234
  __templateName: getTemplateName((lastRelated.relatedType || lastRelated.__contentType), lastRelated.id),
239
235
  },
240
236
  audience: !(0, lodash_1.isEmpty)(item.audience) ? item.audience.map(({ key }) => key) : undefined,
241
- items: isExternal ? undefined : clientService.renderTree(items, item.id, field, parentPath, itemParser),
237
+ items: isExternal ? undefined : await clientService.renderTree(items, item.id, field, parentPath, itemParser),
242
238
  ...enabledCustomFieldsNames.reduce((acc, field) => ({ ...acc, [field]: (0, lodash_1.get)(item, `additionalFields.${field}`) }), {}),
243
239
  };
244
240
  };
245
241
  const { items: itemsFilteredByPath, root: rootElement, } = (0, utils_1.filterByPath)(items, rootPath);
246
- const treeStructure = clientService.renderTree((0, lodash_1.isNil)(rootPath) ? items : itemsFilteredByPath, (0, lodash_1.get)(rootElement, 'parent.id'), 'parent', (0, lodash_1.get)(rootElement, 'parent.path'), itemParser);
242
+ const treeStructure = await clientService.renderTree((0, lodash_1.isNil)(rootPath) ? items : itemsFilteredByPath, (0, lodash_1.get)(rootElement, 'parent.id'), 'parent', (0, lodash_1.get)(rootElement, 'parent.path'), itemParser);
247
243
  const filteredStructure = filter
248
244
  ? treeStructure.filter((item) => item.uiRouterKey === filter)
249
245
  : treeStructure;
@@ -9,6 +9,7 @@ const utils_1 = require("@strapi/utils");
9
9
  const config_1 = require("../config");
10
10
  const i18n_1 = require("../i18n");
11
11
  const utils_2 = require("../utils");
12
+ const slugify_1 = __importDefault(require("@sindresorhus/slugify"));
12
13
  const commonService = ({ strapi }) => ({
13
14
  analyzeBranch(items = [], masterEntity = null, parentItem = null, prevOperations = {}) {
14
15
  const commonService = (0, utils_2.getPluginService)('common');
@@ -326,7 +327,32 @@ const commonService = ({ strapi }) => ({
326
327
  where: { id: item.id },
327
328
  data: { additionalFields: item.additionalFields },
328
329
  })));
329
- }
330
+ },
331
+ async getSlug(query) {
332
+ let slug = (0, slugify_1.default)(query);
333
+ if (slug) {
334
+ const { itemModel } = (0, utils_2.getPluginModels)();
335
+ const existingItems = await strapi
336
+ .query(itemModel.uid)
337
+ .count({
338
+ where: {
339
+ $or: [
340
+ {
341
+ uiRouterKey: {
342
+ $startsWith: slug
343
+ }
344
+ },
345
+ { uiRouterKey: slug }
346
+ ]
347
+ },
348
+ limit: Number.MAX_SAFE_INTEGER,
349
+ });
350
+ if (existingItems) {
351
+ slug = `${slug}-${existingItems}`;
352
+ }
353
+ }
354
+ return slug.toLowerCase();
355
+ },
330
356
  });
331
357
  exports.default = commonService;
332
358
  //# sourceMappingURL=common.js.map
@@ -70,6 +70,7 @@ declare const _default: () => {
70
70
  relation: string;
71
71
  target: string;
72
72
  configurable: boolean;
73
+ mappedBy: string;
73
74
  };
74
75
  localizations: {
75
76
  type: string;
@@ -170,6 +171,7 @@ declare const _default: () => {
170
171
  relation: string;
171
172
  target: string;
172
173
  configurable: boolean;
174
+ inversedBy: string;
173
175
  };
174
176
  audience: {
175
177
  type: string;