strapi-plugin-navigation 1.0.4 → 2.0.0-beta.1

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 (130) hide show
  1. package/README.md +7 -5
  2. package/admin/src/components/EmptyView/index.js +7 -16
  3. package/admin/src/components/Item/ItemCardBadge/index.js +8 -0
  4. package/admin/src/components/Item/ItemCardHeader/Wrapper.js +21 -0
  5. package/admin/src/components/Item/ItemCardHeader/index.js +59 -0
  6. package/admin/src/components/Item/Wrapper.js +39 -0
  7. package/admin/src/components/Item/index.js +76 -124
  8. package/admin/src/components/NavigationItemList/Wrapper.js +22 -0
  9. package/admin/src/components/NavigationItemList/index.js +54 -0
  10. package/admin/src/components/PluginIcon/index.js +6 -0
  11. package/admin/src/index.js +49 -45
  12. package/admin/src/pages/App/index.js +31 -0
  13. package/admin/src/{containers → pages}/DataManagerProvider/actions.js +0 -0
  14. package/admin/src/{containers → pages}/DataManagerProvider/index.js +81 -85
  15. package/admin/src/{containers → pages}/DataManagerProvider/init.js +0 -0
  16. package/admin/src/{containers → pages}/DataManagerProvider/reducer.js +0 -0
  17. package/admin/src/pages/View/components/NavigationContentHeader/index.js +18 -0
  18. package/admin/src/pages/View/components/NavigationHeader/index.js +60 -0
  19. package/admin/src/pages/View/components/NavigationItemForm/index.js +403 -0
  20. package/admin/src/{containers → pages}/View/components/NavigationItemForm/utils/form.js +1 -1
  21. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupFooter.js +40 -0
  22. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupHeader.js +20 -0
  23. package/admin/src/{containers → pages}/View/components/NavigationItemPopup/index.js +16 -16
  24. package/admin/src/pages/View/index.js +209 -0
  25. package/admin/src/{containers → pages}/View/utils/enums.js +0 -0
  26. package/admin/src/{containers → pages}/View/utils/form.js +1 -1
  27. package/admin/src/{containers → pages}/View/utils/index.js +0 -0
  28. package/admin/src/{containers → pages}/View/utils/parsers.js +19 -19
  29. package/admin/src/pluginId.js +4 -3
  30. package/admin/src/translations/en.json +47 -38
  31. package/admin/src/translations/fr.json +7 -1
  32. package/admin/src/utils/getTrad.js +2 -2
  33. package/package.json +13 -5
  34. package/{config/functions → server}/bootstrap.js +10 -11
  35. package/server/config.js +8 -0
  36. package/server/content-types/audience/index.js +9 -0
  37. package/{models/audience.js → server/content-types/audience/lifecycle.js} +0 -0
  38. package/{models/audience.settings.json → server/content-types/audience/schema.json} +4 -2
  39. package/server/content-types/index.js +13 -0
  40. package/server/content-types/navigation/index.js +9 -0
  41. package/{models/navigation.js → server/content-types/navigation/lifecycle.js} +0 -0
  42. package/server/content-types/navigation/schema.js +45 -0
  43. package/server/content-types/navigation-item/index.js +9 -0
  44. package/server/content-types/navigation-item/lifecycle.js +34 -0
  45. package/{models/navigationItem.settings.json → server/content-types/navigation-item/schema.json} +29 -14
  46. package/server/content-types/navigations-items-related/index.js +9 -0
  47. package/server/content-types/navigations-items-related/lifecycle.js +19 -0
  48. package/server/content-types/navigations-items-related/schema.json +47 -0
  49. package/server/controllers/index.js +7 -0
  50. package/server/controllers/navigation.js +51 -0
  51. package/server/routes/admin.js +38 -0
  52. package/server/routes/index.js +3 -0
  53. package/server/services/__tests__/navigation.test.js +84 -0
  54. package/server/services/index.js +7 -0
  55. package/server/services/navigation.js +463 -0
  56. package/{services → server/services}/utils/constant.js +3 -1
  57. package/server/services/utils/functions.js +103 -0
  58. package/strapi-admin.js +1 -0
  59. package/strapi-server.js +18 -0
  60. package/__mocks__/helpers/another-plugin/blog-post.settings.json +0 -31
  61. package/__mocks__/helpers/another-plugin/pages.settings.json +0 -28
  62. package/__mocks__/helpers/blog-post.settings.json +0 -31
  63. package/__mocks__/helpers/home-page.settings.json +0 -4
  64. package/__mocks__/helpers/my-homepage.settings.json +0 -27
  65. package/__mocks__/helpers/pages.settings.json +0 -27
  66. package/__mocks__/helpers/strapi.js +0 -89
  67. package/admin/src/assets/images/icon-cross-blue.svg +0 -1
  68. package/admin/src/assets/images/icon_remove.svg +0 -19
  69. package/admin/src/components/Container/index.js +0 -7
  70. package/admin/src/components/Input/index.js +0 -41
  71. package/admin/src/components/Item/CardItem.js +0 -46
  72. package/admin/src/components/Item/CardItemLevelAdd.js +0 -41
  73. package/admin/src/components/Item/CardItemLevelWrapper.js +0 -27
  74. package/admin/src/components/Item/CardItemPath.js +0 -9
  75. package/admin/src/components/Item/CardItemRestore.js +0 -19
  76. package/admin/src/components/Item/CardItemTitle.js +0 -5
  77. package/admin/src/components/Item/CardWrapper.js +0 -78
  78. package/admin/src/components/ItemFooter/CardItemError.js +0 -11
  79. package/admin/src/components/ItemFooter/CardItemRelation.js +0 -18
  80. package/admin/src/components/ItemFooter/CardItemRelationStatus.js +0 -17
  81. package/admin/src/components/ItemFooter/CardItemType.js +0 -18
  82. package/admin/src/components/ItemFooter/Wrapper.js +0 -26
  83. package/admin/src/components/ItemFooter/index.js +0 -66
  84. package/admin/src/components/ItemOrdering/CardOrderingButton.js +0 -24
  85. package/admin/src/components/ItemOrdering/Wrapper.js +0 -24
  86. package/admin/src/components/ItemOrdering/index.js +0 -36
  87. package/admin/src/components/List/Container.js +0 -34
  88. package/admin/src/components/List/ListLevelRoot.js +0 -18
  89. package/admin/src/components/List/index.js +0 -81
  90. package/admin/src/components/Option/OptionButton.js +0 -18
  91. package/admin/src/components/Option/OptionSet.js +0 -14
  92. package/admin/src/components/Option/Wrapper.js +0 -15
  93. package/admin/src/components/Option/index.js +0 -47
  94. package/admin/src/components/Search/index.js +0 -86
  95. package/admin/src/components/Select/ClearIndicator.js +0 -15
  96. package/admin/src/components/Select/DropdownIndicator.js +0 -39
  97. package/admin/src/components/Select/ErrorMessage.js +0 -10
  98. package/admin/src/components/Select/IndicatorSeparator.js +0 -3
  99. package/admin/src/components/Select/MultiValueContainer.js +0 -43
  100. package/admin/src/components/Select/StyledOption.js +0 -11
  101. package/admin/src/components/Select/index.js +0 -68
  102. package/admin/src/components/Select/utils/styles.js +0 -92
  103. package/admin/src/containers/App/Wrapper.js +0 -14
  104. package/admin/src/containers/App/index.js +0 -34
  105. package/admin/src/containers/DetailsView/Wrapper.js +0 -21
  106. package/admin/src/containers/DetailsView/index.js +0 -111
  107. package/admin/src/containers/Initializer/index.js +0 -26
  108. package/admin/src/containers/ListView/Footer.js +0 -56
  109. package/admin/src/containers/ListView/components.js +0 -138
  110. package/admin/src/containers/ListView/index.js +0 -54
  111. package/admin/src/containers/View/FadedWrapper.js +0 -51
  112. package/admin/src/containers/View/HeaderForm.js +0 -9
  113. package/admin/src/containers/View/HeaderFormCell.js +0 -25
  114. package/admin/src/containers/View/Wrapper.js +0 -17
  115. package/admin/src/containers/View/components/NavigationItemForm/ModalFooter.js +0 -45
  116. package/admin/src/containers/View/components/NavigationItemForm/index.js +0 -427
  117. package/admin/src/containers/View/components/NavigationItemPopup/MediumPopup.js +0 -6
  118. package/admin/src/containers/View/index.js +0 -240
  119. package/admin/src/lifecycles.js +0 -3
  120. package/admin/src/permissions.js +0 -14
  121. package/config/routes.json +0 -60
  122. package/config/schema.graphql.js +0 -205
  123. package/controllers/navigation.js +0 -85
  124. package/examples/audit-log-integrations.js.md +0 -38
  125. package/models/navigation.settings.json +0 -43
  126. package/models/navigationItem.js +0 -16
  127. package/public/assets/preview.png +0 -0
  128. package/services/__tests__/navigation.test.js +0 -85
  129. package/services/navigation.js +0 -638
  130. package/services/utils/functions.js +0 -186
@@ -1,60 +0,0 @@
1
- {
2
- "routes": [
3
- {
4
- "method": "GET",
5
- "path": "/",
6
- "handler": "navigation.get",
7
- "config": {
8
- "policies": []
9
- }
10
- },
11
- {
12
- "method": "POST",
13
- "path": "/",
14
- "handler": "navigation.post",
15
- "config": {
16
- "policies": []
17
- }
18
- },
19
- {
20
- "method": "GET",
21
- "path": "/config",
22
- "handler": "navigation.config",
23
- "config": {
24
- "policies": []
25
- }
26
- },
27
- {
28
- "method": "GET",
29
- "path": "/:id",
30
- "handler": "navigation.getById",
31
- "config": {
32
- "policies": []
33
- }
34
- },
35
- {
36
- "method": "PUT",
37
- "path": "/:id",
38
- "handler": "navigation.put",
39
- "config": {
40
- "policies": []
41
- }
42
- },
43
- {
44
- "method": "GET",
45
- "path": "/render/:idOrSlug",
46
- "handler": "navigation.render",
47
- "config": {
48
- "policies": []
49
- }
50
- },
51
- {
52
- "method": "GET",
53
- "path": "/render/:idOrSlug/:childUIKey",
54
- "handler": "navigation.renderChild",
55
- "config": {
56
- "policies": []
57
- }
58
- }
59
- ]
60
- }
@@ -1,205 +0,0 @@
1
- const {get} = require('lodash');
2
- const NAVIGATION_DATE = `
3
- # SQL
4
- created_at: String
5
- updated_at: String
6
- # MONGO
7
- createdAt: String
8
- updatedAt: String
9
- `;
10
-
11
- const NAVIGATION_USER = `
12
- # SQL
13
- created_by: String
14
- updated_by: String
15
- # MONGO
16
- createdBy: String
17
- updatedBy: String
18
- `;
19
-
20
- const NAVIGATION = `
21
- id: String!
22
- name: String!
23
- slug: String!
24
- visible: Boolean!
25
- `;
26
-
27
- const getContentTypesNamesFields = () => {
28
- const contentTypesNameFields = strapi.config.get('custom.plugins.navigation.contentTypesNameFields');
29
- return Object.keys(contentTypesNameFields || {}).map(key => `${key}: [String]!`).join('\n');
30
- };
31
-
32
- const getNavigationRelated = () => {
33
- const related = strapi.config.get('custom.plugins.navigation.gql.navigationItemRelated');
34
- if (related) {
35
- return related;
36
- }
37
- return `
38
- type NavigationRelated {
39
- id: Int
40
- title: String
41
- name: String
42
- }
43
- `;
44
- };
45
-
46
- module.exports = {
47
- // language=GraphQL
48
- definition: `
49
- enum NavigationRenderType {
50
- FLAT,
51
- TREE,
52
- RFR
53
- }
54
-
55
- ${getNavigationRelated()}
56
-
57
-
58
- type NavigationItem {
59
- id: Int!
60
- title: String!
61
- type: String!
62
- path: String
63
- externalPath: String
64
- uiRouterKey: String!
65
- menuAttached: Boolean!
66
- order: Int!
67
- parent: Int
68
- master: Int
69
- items: [NavigationItem]
70
- related: NavigationRelated
71
- audience: [String]
72
- ${NAVIGATION_DATE}
73
- ${NAVIGATION_USER}
74
- }
75
-
76
- type Navigation {
77
- ${NAVIGATION}
78
- }
79
-
80
- type NavigationDetails {
81
- ${NAVIGATION}
82
- items: [NavigationItem]!
83
- }
84
-
85
-
86
- type ContentTypesNameFields {
87
- default: [String!]!
88
- ${getContentTypesNamesFields()}
89
- }
90
-
91
- type ContentTypes {
92
- uid: String!
93
- name: String!
94
- isSingle: Boolean!
95
- collectionName: String!
96
- contentTypeName: String!
97
- label: String!
98
- relatedField: String!
99
- labelSingular: String!
100
- endpoint: String!
101
- available: Boolean!
102
- visible: Boolean!
103
- }
104
-
105
- type NavigationConfig {
106
- allowedLevels: Int
107
- availableAudience: [NavigationAudience]!
108
- additionalFields: [String]!
109
- contentTypesNameFields: ContentTypesNameFields
110
- contentTypes: [ContentTypes]
111
- }
112
-
113
- input CreateNavigationRelated {
114
- ref: String!
115
- field: String!
116
- refId: String!
117
- }
118
-
119
- input CreateNavigationItem {
120
- title: String!
121
- type: String!
122
- path: String
123
- externalPath: String
124
- uiRouterKey: String!
125
- menuAttached: Boolean!
126
- order: Int!
127
- parent: Int
128
- master: Int
129
- items: [CreateNavigationItem]
130
- audience: [String]
131
- related: CreateNavigationRelated
132
- }
133
-
134
- input CreateNavigation {
135
- name: String!
136
- items: [CreateNavigationItem]!
137
- }
138
- `,
139
- query: `
140
- renderNavigation(navigationIdOrSlug: String!, type: NavigationRenderType, menuOnly: Boolean): [NavigationItem]!
141
- renderNavigationChild(id: String!, childUIKey: String!, type: NavigationRenderType, menuOnly: Boolean): [NavigationItem]!
142
- getNavigation: [Navigation]!
143
- configNavigation: NavigationConfig
144
- getByIdNavigation(id: String!): NavigationItem
145
- `,
146
- type: {},
147
- mutation: `
148
- navigationCreate(newNavigation: CreateNavigation!): Navigation!
149
- navigationUpdate(id: String!, navigation: CreateNavigation!): Navigation!
150
- `,
151
- resolver: {
152
- Query: {
153
- renderNavigation: {
154
- resolverOf: 'plugins::navigation.navigation.render',
155
- resolver(obj, options) {
156
- const { navigationIdOrSlug, type, menuOnly } = options;
157
- return strapi.plugins.navigation.services.navigation.render(navigationIdOrSlug, type, menuOnly);
158
- },
159
- },
160
- renderNavigationChild: {
161
- resolverOf: 'plugins::navigation.navigation.renderChild',
162
- async resolver(obj, options) {
163
- const { id, childUIKey, type, menuOnly } = options;
164
- return strapi.plugins.navigation.services.navigation.renderChildren(id, childUIKey, type, menuOnly);
165
- },
166
- },
167
- getNavigation: {
168
- resolverOf: 'plugins::navigation.navigation.get',
169
- resolver() {
170
- return strapi.plugins.navigation.services.navigation.get();
171
- },
172
- },
173
- configNavigation: {
174
- resolverOf: 'plugins::navigation.navigation.config',
175
- resolver() {
176
- return strapi.plugins.navigation.services.navigation.config();
177
- },
178
- },
179
- getByIdNavigation: {
180
- resolverOf: 'plugins::navigation.navigation.getById',
181
- async resolver(obj, options) {
182
- const { id } = options;
183
- return strapi.plugins.navigation.services.navigation.getById(id);
184
- },
185
- },
186
- },
187
- Mutation: {
188
- navigationCreate: {
189
- resolverOf: 'plugins::navigation.navigation.post',
190
- resolver(obj, options) {
191
- const { newNavigation } = options;
192
- return strapi.plugins.navigation.services.navigation.post(newNavigation);
193
- },
194
- },
195
- navigationUpdate: {
196
- resolverOf: 'plugins::navigation.navigation.put',
197
- resolver(obj, options) {
198
- const { id, navigation } = options;
199
- return strapi.plugins.navigation.services.navigation.put(id, navigation);
200
- },
201
- },
202
- },
203
- },
204
- };
205
-
@@ -1,85 +0,0 @@
1
- 'use strict';
2
-
3
- const { NavigationError } = require('../utils/NavigationError');
4
- /**
5
- * navigation.js controller
6
- *
7
- * @description: A set of functions called "actions" of the `navigation` plugin.
8
- */
9
-
10
- const parseParams = (params) =>
11
- Object.keys(params).reduce((prev, curr) => {
12
- const value = params[curr];
13
- const parsedValue = isNaN(Number(value)) ? value : parseInt(value, 10);
14
- return {
15
- ...prev,
16
- [curr]: parsedValue,
17
- };
18
- }, {});
19
-
20
- const errorHandler = (ctx) => (error) => {
21
- if (error instanceof NavigationError) {
22
- return ctx.badRequest(error.message, error.additionalInfo);
23
- }
24
- throw error;
25
- };
26
-
27
- module.exports = {
28
- getService() {
29
- return strapi.plugins.navigation.services.navigation;
30
- },
31
- /**
32
- * Default action.
33
- *
34
- * @return {Object}
35
- */
36
- async config() {
37
- return this.getService().config();
38
- },
39
-
40
- async get() {
41
- return this.getService().get();
42
- },
43
-
44
- async getById(ctx) {
45
- const { params } = ctx;
46
- const { id } = parseParams(params);
47
- return this.getService().getById(id);
48
- },
49
-
50
- async render(ctx) {
51
- const { params, query = {} } = ctx;
52
- const { type, menu: menuOnly } = query;
53
- const { idOrSlug } = parseParams(params);
54
- return this.getService().render(
55
- idOrSlug,
56
- type,
57
- menuOnly,
58
- );
59
- },
60
- async renderChild(ctx) {
61
- const { params, query = {} } = ctx;
62
- const { type, menu: menuOnly } = query;
63
- const { idOrSlug, childUIKey } = parseParams(params);
64
- return this.getService().renderChildren(
65
- idOrSlug,
66
- childUIKey,
67
- type,
68
- menuOnly
69
- );
70
- },
71
-
72
- post(ctx) {
73
- const { auditLog } = ctx;
74
- const { body = {} } = ctx.request;
75
- return this.getService().post(body, auditLog);
76
- },
77
-
78
- put(ctx) {
79
- const { params, auditLog } = ctx;
80
- const { id } = parseParams(params);
81
- const { body = {} } = ctx.request;
82
- return this.getService().put(id, body, auditLog)
83
- .catch(errorHandler(ctx));
84
- },
85
- };
@@ -1,38 +0,0 @@
1
- ```javascript
2
- const { Base, AvailableAction } = require('strapi-plugin-audit-log');
3
-
4
- class Navigation extends Base {
5
- constructor(strapi, user) {
6
- super(strapi, user);
7
-
8
- this.once('onChangeNavigation', ({ actionType, oldEntity, newEntity }) => {
9
- this.actionType = actionType;
10
- this.add('beforeUpdate', oldEntity);
11
- this.add('afterUpdate', newEntity);
12
- });
13
- }
14
-
15
- async run(method, ctx, config) {
16
- const data = this.sanitize(this.entities);
17
- switch (method) {
18
- case 'POST':
19
- case 'PUT': {
20
- const { beforeUpdate, afterUpdate } = data;
21
- if (beforeUpdate && afterUpdate) {
22
- const diffs = this.getDiff(beforeUpdate, afterUpdate);
23
- return this.save(
24
- ctx.params.id,
25
- this.actionType || AvailableAction.UPDATE,
26
- config.pluginName,
27
- diffs,
28
- );
29
- }
30
- break;
31
- }
32
- }
33
- return Promise.resolve();
34
- }
35
- }
36
-
37
- module.exports = Navigation;
38
- ```
@@ -1,43 +0,0 @@
1
- {
2
- "collectionName": "navigations",
3
- "info": {
4
- "name": "navigation",
5
- "description": "Navigation container"
6
- },
7
- "options": {
8
- "increments": true,
9
- "comment": ""
10
- },
11
- "pluginOptions": {
12
- "content-manager": {
13
- "visible": false
14
- },
15
- "content-type-builder": {
16
- "visible": false
17
- }
18
- },
19
- "attributes": {
20
- "name": {
21
- "type": "text",
22
- "configurable": false,
23
- "required": true
24
- },
25
- "slug": {
26
- "type": "uid",
27
- "target": "name",
28
- "configurable": false,
29
- "required": true
30
- },
31
- "visible": {
32
- "type": "boolean",
33
- "default": false,
34
- "configurable": false
35
- },
36
- "items": {
37
- "collection": "navigationitem",
38
- "plugin": "navigation",
39
- "via": "master",
40
- "configurable": false
41
- }
42
- }
43
- }
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * Read the documentation (https://strapi.io/documentation/3.0.0-beta.x/concepts/models.html#life-cycle-callbacks)
5
- * to customize this model
6
- */
7
-
8
- module.exports = {
9
- type: {
10
- INTERNAL: "INTERNAL",
11
- EXTERNAL: "EXTERNAL",
12
- },
13
- additionalFields: {
14
- AUDIENCE: 'audience',
15
- },
16
- };
Binary file
@@ -1,85 +0,0 @@
1
-
2
- const { setupStrapi } = require("../../__mocks__/helpers/strapi");
3
-
4
- beforeAll(setupStrapi);
5
-
6
- describe('Navigation service', () => {
7
- it('Strapi is defined', () => {
8
- expect(strapi).toBeDefined();
9
- expect(strapi.contentTypes).toBeDefined();
10
- expect(Object.keys(strapi.contentTypes).length).toBe(6);
11
- });
12
- it('Config Content Types', async () => {
13
- const { configContentTypes } = require("../navigation");
14
- const result = [{
15
- uid: "application::pages.pages",
16
- collectionName: "pages",
17
- isSingle: false,
18
- contentTypeName: "Pages",
19
- endpoint: "pages",
20
- label: "Pages",
21
- labelSingular: "Page",
22
- name: "page",
23
- visible: true,
24
- }, {
25
- uid: "application::blog-post.blog-post",
26
- collectionName: "blog_posts",
27
- isSingle: false,
28
- contentTypeName: "BlogPost",
29
- endpoint: "blog-posts",
30
- label: "Blog posts",
31
- labelSingular: "Blog post",
32
- name: "blog-post",
33
- visible: true,
34
- }, {
35
- uid: "application::my-homepages.my-homepage",
36
- collectionName: "my-homepages",
37
- isSingle: true,
38
- contentTypeName: "MyHomepage",
39
- endpoint: "my-homepage",
40
- label: "My Homepage",
41
- labelSingular: "My Homepage",
42
- name: "my-homepage",
43
- visible: true,
44
- }, {
45
- uid: "application::page-homes.home-page",
46
- collectionName: "page_homes",
47
- isSingle: true,
48
- contentTypeName: "HomePage",
49
- endpoint: "custom-api",
50
- label: "Page Home",
51
- labelSingular: "Page Home",
52
- name: "home-page",
53
- visible: true,
54
- }, {
55
- uid: "plugins::another-plugin.pages",
56
- collectionName: "pages",
57
- isSingle: false,
58
- contentTypeName: "Plugin-pages",
59
- endpoint: "plugin-pages",
60
- label: "Pages",
61
- labelSingular: "Page",
62
- name: "plugin-page",
63
- visible: true,
64
- plugin: "another-plugin"
65
- }, {
66
- uid: "plugins::another-plugin.blog-post",
67
- collectionName: "blog_posts",
68
- isSingle: false,
69
- contentTypeName: "BlogPost",
70
- endpoint: "plugin-blog-posts",
71
- label: "Blog posts",
72
- labelSingular: "Blog post",
73
- name: "plugin-blog-post",
74
- visible: true,
75
- plugin: "another-plugin"
76
- }];
77
- const types = await configContentTypes();
78
- expect(types[0]).toMatchObject(result[0]);
79
- expect(types[1]).toMatchObject(result[1]);
80
- expect(types[2]).toMatchObject(result[2]);
81
- expect(types[3]).toMatchObject(result[3]);
82
- expect(types[4]).toMatchObject(result[4]);
83
- expect(types[5]).toMatchObject(result[5]);
84
- });
85
- });