strapi-plugin-navigation 2.0.12 → 2.1.0-beta.2

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 (268) hide show
  1. package/README.md +260 -41
  2. package/admin/src/components/Alert/styles.d.ts +2 -0
  3. package/admin/src/components/Alert/styles.js +10 -4
  4. package/admin/src/components/CollapseButton/index.d.ts +7 -0
  5. package/admin/src/components/CollapseButton/index.js +21 -22
  6. package/admin/src/components/ConfirmationDialog/index.d.ts +28 -0
  7. package/admin/src/components/ConfirmationDialog/index.js +32 -54
  8. package/admin/src/components/EmptyView/index.d.ts +3 -0
  9. package/admin/src/components/EmptyView/index.js +9 -7
  10. package/admin/src/components/Item/ItemCardBadge/index.d.ts +3 -0
  11. package/admin/src/components/Item/ItemCardBadge/index.js +11 -7
  12. package/admin/src/components/Item/ItemCardHeader/Wrapper.d.ts +3 -0
  13. package/admin/src/components/Item/ItemCardHeader/Wrapper.js +10 -6
  14. package/admin/src/components/Item/ItemCardHeader/index.d.ts +12 -0
  15. package/admin/src/components/Item/ItemCardHeader/index.js +33 -52
  16. package/admin/src/components/Item/ItemCardRemovedOverlay/index.d.ts +2 -0
  17. package/admin/src/components/Item/ItemCardRemovedOverlay/index.js +10 -4
  18. package/admin/src/components/Item/Wrapper.d.ts +3 -0
  19. package/admin/src/components/Item/Wrapper.js +10 -6
  20. package/admin/src/components/Item/index.d.ts +31 -0
  21. package/admin/src/components/Item/index.js +162 -242
  22. package/admin/src/components/NavigationItemList/Wrapper.d.ts +3 -0
  23. package/admin/src/components/NavigationItemList/Wrapper.js +9 -5
  24. package/admin/src/components/NavigationItemList/index.d.ts +35 -0
  25. package/admin/src/components/NavigationItemList/index.js +28 -66
  26. package/admin/src/components/RestartAlert/index.d.ts +3 -0
  27. package/admin/src/components/RestartAlert/index.js +10 -5
  28. package/admin/src/components/Search/index.d.ts +6 -0
  29. package/admin/src/components/Search/index.js +57 -46
  30. package/admin/src/components/icons/navigation.d.ts +6 -0
  31. package/admin/src/components/icons/navigation.js +11 -13
  32. package/admin/src/contexts/DataManagerContext.d.ts +3 -0
  33. package/admin/src/contexts/DataManagerContext.js +6 -5
  34. package/admin/src/hooks/useAllContentTypes.d.ts +6 -0
  35. package/admin/src/hooks/useAllContentTypes.js +10 -11
  36. package/admin/src/hooks/useDataManager.d.ts +3 -0
  37. package/admin/src/hooks/useDataManager.js +10 -6
  38. package/admin/src/hooks/useNavigationConfig.d.ts +10 -0
  39. package/admin/src/hooks/useNavigationConfig.js +52 -56
  40. package/admin/src/index.d.ts +14 -0
  41. package/admin/src/index.js +92 -76
  42. package/admin/src/pages/App/index.d.ts +3 -0
  43. package/admin/src/pages/App/index.js +43 -31
  44. package/admin/src/pages/DataManagerProvider/actions.d.ts +19 -0
  45. package/admin/src/pages/DataManagerProvider/actions.js +22 -26
  46. package/admin/src/pages/DataManagerProvider/index.d.ts +12 -0
  47. package/admin/src/pages/DataManagerProvider/index.js +280 -300
  48. package/admin/src/pages/DataManagerProvider/init.d.ts +3 -0
  49. package/admin/src/pages/DataManagerProvider/init.js +5 -3
  50. package/admin/src/pages/DataManagerProvider/reducer.d.ts +19 -0
  51. package/admin/src/pages/DataManagerProvider/reducer.js +119 -121
  52. package/admin/src/pages/SettingsPage/components/DisableI18nModal/index.d.ts +24 -0
  53. package/admin/src/pages/SettingsPage/components/DisableI18nModal/index.js +88 -0
  54. package/admin/src/pages/SettingsPage/index.d.ts +3 -0
  55. package/admin/src/pages/SettingsPage/index.js +242 -335
  56. package/admin/src/pages/SettingsPage/utils/functions.d.ts +5 -0
  57. package/admin/src/pages/SettingsPage/utils/functions.js +3 -8
  58. package/admin/src/pages/View/components/I18nCopyNavigationItems/index.d.ts +20 -0
  59. package/admin/src/pages/View/components/I18nCopyNavigationItems/index.js +60 -0
  60. package/admin/src/pages/View/components/NavigationContentHeader/index.d.ts +6 -0
  61. package/admin/src/pages/View/components/NavigationContentHeader/index.js +13 -17
  62. package/admin/src/pages/View/components/NavigationHeader/index.d.ts +12 -0
  63. package/admin/src/pages/View/components/NavigationHeader/index.js +74 -65
  64. package/admin/src/pages/View/components/NavigationHeader/styles.d.ts +2 -0
  65. package/admin/src/pages/View/components/NavigationHeader/styles.js +10 -5
  66. package/admin/src/pages/View/components/NavigationItemForm/index.d.ts +51 -0
  67. package/admin/src/pages/View/components/NavigationItemForm/index.js +335 -454
  68. package/admin/src/pages/View/components/NavigationItemForm/utils/form.d.ts +45 -0
  69. package/admin/src/pages/View/components/NavigationItemForm/utils/form.js +81 -52
  70. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupFooter.d.ts +23 -0
  71. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupFooter.js +24 -34
  72. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupHeader.d.ts +4 -0
  73. package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupHeader.js +16 -16
  74. package/admin/src/pages/View/components/NavigationItemPopup/index.d.ts +27 -0
  75. package/admin/src/pages/View/components/NavigationItemPopup/index.js +59 -108
  76. package/admin/src/pages/View/index.d.ts +4 -0
  77. package/admin/src/pages/View/index.js +229 -304
  78. package/admin/src/pages/View/utils/enums.d.ts +9 -0
  79. package/admin/src/pages/View/utils/enums.js +11 -8
  80. package/admin/src/pages/View/utils/form.d.ts +2 -0
  81. package/admin/src/pages/View/utils/form.js +15 -12
  82. package/admin/src/pages/View/utils/index.d.ts +2 -0
  83. package/admin/src/pages/View/utils/index.js +11 -3
  84. package/admin/src/pages/View/utils/parsers.d.ts +44 -0
  85. package/admin/src/pages/View/utils/parsers.js +231 -278
  86. package/admin/src/permissions.d.ts +12 -0
  87. package/admin/src/permissions.js +11 -7
  88. package/admin/src/pluginId.d.ts +3 -0
  89. package/admin/src/pluginId.js +2 -2
  90. package/admin/src/translations/en.json +126 -104
  91. package/admin/src/translations/fr.json +44 -44
  92. package/admin/src/translations/index.d.ts +12 -0
  93. package/admin/src/translations/index.js +17 -11
  94. package/admin/src/utils/api.d.ts +8 -0
  95. package/admin/src/utils/api.js +54 -50
  96. package/admin/src/utils/getTrad.d.ts +3 -0
  97. package/admin/src/utils/getTrad.js +9 -5
  98. package/admin/src/utils/index.d.ts +5 -0
  99. package/admin/src/utils/index.js +21 -15
  100. package/package.json +19 -17
  101. package/permissions.d.ts +9 -0
  102. package/permissions.js +5 -4
  103. package/server/bootstrap/index.d.ts +4 -0
  104. package/server/bootstrap/index.js +41 -0
  105. package/server/config/index.d.ts +5 -0
  106. package/server/config/index.js +33 -9
  107. package/server/config/setupStrategy.d.ts +3 -0
  108. package/server/config/setupStrategy.js +38 -0
  109. package/server/content-types/audience/index.d.ts +27 -0
  110. package/server/content-types/audience/index.js +9 -8
  111. package/server/content-types/audience/schema.d.ts +25 -0
  112. package/server/content-types/audience/schema.js +26 -0
  113. package/server/content-types/index.d.ts +255 -0
  114. package/server/content-types/index.js +15 -12
  115. package/server/content-types/navigation/index.d.ts +64 -0
  116. package/server/content-types/navigation/index.js +11 -8
  117. package/server/content-types/navigation/lifecycle.d.ts +9 -0
  118. package/server/content-types/navigation/lifecycle.js +8 -12
  119. package/server/content-types/navigation/schema.d.ts +55 -0
  120. package/server/content-types/navigation/schema.js +56 -0
  121. package/server/content-types/navigation-item/index.d.ts +112 -0
  122. package/server/content-types/navigation-item/index.js +11 -8
  123. package/server/content-types/navigation-item/lifecycle.d.ts +16 -0
  124. package/server/content-types/navigation-item/lifecycle.js +28 -32
  125. package/server/content-types/navigation-item/schema.d.ts +97 -0
  126. package/server/content-types/navigation-item/schema.js +102 -0
  127. package/server/content-types/navigations-items-related/index.d.ts +56 -0
  128. package/server/content-types/navigations-items-related/index.js +11 -8
  129. package/server/content-types/navigations-items-related/lifecycle.d.ts +8 -0
  130. package/server/content-types/navigations-items-related/lifecycle.js +20 -17
  131. package/server/content-types/navigations-items-related/schema.d.ts +49 -0
  132. package/server/content-types/navigations-items-related/schema.js +50 -0
  133. package/server/controllers/admin.d.ts +4 -0
  134. package/server/controllers/admin.js +77 -0
  135. package/server/controllers/client.d.ts +4 -0
  136. package/server/controllers/client.js +34 -0
  137. package/server/controllers/index.d.ts +4 -0
  138. package/server/controllers/index.js +12 -6
  139. package/server/destroy.d.ts +3 -0
  140. package/server/destroy.js +5 -0
  141. package/server/graphql/config.d.ts +4 -0
  142. package/server/graphql/config.js +28 -0
  143. package/server/graphql/index.d.ts +2 -0
  144. package/server/graphql/index.js +18 -22
  145. package/server/graphql/queries/index.d.ts +3 -0
  146. package/server/graphql/queries/index.js +15 -15
  147. package/server/graphql/queries/render-navigation-child.d.ts +15 -0
  148. package/server/graphql/queries/render-navigation-child.js +24 -15
  149. package/server/graphql/queries/render-navigation.d.ts +21 -0
  150. package/server/graphql/queries/render-navigation.js +31 -15
  151. package/server/graphql/resolvers-config.d.ts +10 -0
  152. package/server/graphql/resolvers-config.js +5 -3
  153. package/server/graphql/setupStrategy.d.ts +3 -0
  154. package/server/graphql/setupStrategy.js +15 -0
  155. package/server/graphql/types/content-types-name-fields.d.ts +6 -0
  156. package/server/graphql/types/content-types-name-fields.js +13 -9
  157. package/server/graphql/types/content-types.d.ts +5 -0
  158. package/server/graphql/types/content-types.js +17 -15
  159. package/server/graphql/types/create-navigation-item.d.ts +5 -0
  160. package/server/graphql/types/create-navigation-item.js +18 -16
  161. package/server/graphql/types/create-navigation-related.d.ts +5 -0
  162. package/server/graphql/types/create-navigation-related.js +9 -7
  163. package/server/graphql/types/create-navigation.d.ts +5 -0
  164. package/server/graphql/types/create-navigation.js +8 -6
  165. package/server/graphql/types/index.d.ts +3 -0
  166. package/server/graphql/types/index.js +15 -13
  167. package/server/graphql/types/navigation-config.d.ts +5 -0
  168. package/server/graphql/types/navigation-config.js +10 -8
  169. package/server/graphql/types/navigation-details.d.ts +5 -0
  170. package/server/graphql/types/navigation-details.js +11 -9
  171. package/server/graphql/types/navigation-item-related-data.d.ts +5 -0
  172. package/server/graphql/types/navigation-item-related-data.js +9 -0
  173. package/server/graphql/types/navigation-item-related.d.ts +7 -0
  174. package/server/graphql/types/navigation-item-related.js +25 -0
  175. package/server/graphql/types/navigation-item.d.ts +5 -0
  176. package/server/graphql/types/navigation-item.js +28 -29
  177. package/server/graphql/types/navigation-render-type.d.ts +5 -0
  178. package/server/graphql/types/navigation-render-type.js +7 -4
  179. package/server/graphql/types/navigation.d.ts +5 -0
  180. package/server/graphql/types/navigation.js +10 -8
  181. package/server/i18n/constant.d.ts +2 -0
  182. package/server/i18n/constant.js +5 -0
  183. package/server/i18n/errors.d.ts +7 -0
  184. package/server/i18n/errors.js +14 -0
  185. package/server/i18n/graphQLEnhancers.d.ts +10 -0
  186. package/server/i18n/graphQLEnhancers.js +10 -0
  187. package/server/i18n/index.d.ts +8 -0
  188. package/server/i18n/index.js +23 -0
  189. package/server/i18n/navigationSetupStrategy.d.ts +3 -0
  190. package/server/i18n/navigationSetupStrategy.js +119 -0
  191. package/server/i18n/serviceEnhancers.d.ts +12 -0
  192. package/server/i18n/serviceEnhancers.js +117 -0
  193. package/server/i18n/types.d.ts +54 -0
  194. package/server/i18n/types.js +3 -0
  195. package/server/i18n/utils.d.ts +12 -0
  196. package/server/i18n/utils.js +29 -0
  197. package/server/index.d.ts +273 -0
  198. package/server/index.js +26 -0
  199. package/server/navigation/index.d.ts +2 -0
  200. package/server/navigation/index.js +18 -0
  201. package/server/navigation/setupStrategy.d.ts +3 -0
  202. package/server/navigation/setupStrategy.js +37 -0
  203. package/server/register/index.d.ts +3 -0
  204. package/server/register/index.js +4 -0
  205. package/server/routes/admin.d.ts +4 -0
  206. package/server/routes/admin.js +72 -61
  207. package/server/routes/client.d.ts +4 -0
  208. package/server/routes/client.js +25 -21
  209. package/server/routes/index.d.ts +6 -0
  210. package/server/routes/index.js +13 -4
  211. package/server/services/admin.d.ts +5 -0
  212. package/server/services/admin.js +183 -0
  213. package/server/services/client.d.ts +5 -0
  214. package/server/services/client.js +249 -0
  215. package/server/services/common.d.ts +5 -0
  216. package/server/services/common.js +313 -0
  217. package/server/services/index.d.ts +7 -0
  218. package/server/services/index.js +14 -6
  219. package/server/utils/constant.d.ts +27 -0
  220. package/server/utils/constant.js +24 -0
  221. package/server/utils/functions.d.ts +138 -0
  222. package/server/utils/functions.js +224 -0
  223. package/server/utils/index.d.ts +3 -0
  224. package/server/utils/index.js +19 -0
  225. package/strapi-admin.d.ts +3 -0
  226. package/strapi-admin.js +8 -1
  227. package/strapi-server.d.ts +273 -0
  228. package/strapi-server.js +6 -17
  229. package/tsconfig.tsbuildinfo +1 -0
  230. package/types/bootstrap.d.ts +13 -0
  231. package/types/bootstrap.js +3 -0
  232. package/types/config.d.ts +21 -0
  233. package/types/config.js +3 -0
  234. package/types/contentTypes.d.ts +85 -0
  235. package/types/contentTypes.js +3 -0
  236. package/types/controllers.d.ts +35 -0
  237. package/types/controllers.js +5 -0
  238. package/types/graphQL.d.ts +3 -0
  239. package/types/graphQL.js +3 -0
  240. package/types/i18n.d.ts +9 -0
  241. package/types/i18n.js +3 -0
  242. package/types/index.d.ts +9 -0
  243. package/types/index.js +25 -0
  244. package/types/services.d.ts +68 -0
  245. package/types/services.js +3 -0
  246. package/types/utils.d.ts +58 -0
  247. package/types/utils.js +26 -0
  248. package/utils/InvalidParamNavigationError.d.ts +4 -0
  249. package/utils/InvalidParamNavigationError.js +11 -0
  250. package/utils/NavigationError.d.ts +5 -0
  251. package/utils/NavigationError.js +7 -7
  252. package/__mocks__/pages.settings.json +0 -25
  253. package/__mocks__/strapi.js +0 -207
  254. package/jest.config.js +0 -14
  255. package/server/bootstrap.js +0 -52
  256. package/server/config.js +0 -9
  257. package/server/content-types/audience/lifecycle.js +0 -8
  258. package/server/content-types/audience/schema.json +0 -23
  259. package/server/content-types/navigation/schema.json +0 -45
  260. package/server/content-types/navigation-item/schema.json +0 -99
  261. package/server/content-types/navigations-items-related/schema.json +0 -47
  262. package/server/controllers/navigation.js +0 -105
  263. package/server/graphql/types/navigation-related.js +0 -25
  264. package/server/services/__tests__/functions.test.js +0 -48
  265. package/server/services/__tests__/navigation.test.js +0 -91
  266. package/server/services/navigation.js +0 -791
  267. package/server/services/utils/constant.js +0 -21
  268. package/server/services/utils/functions.js +0 -226
@@ -1,26 +1,22 @@
1
- export const GET_LIST_DATA = "GET_LIST_DATA";
2
- export const GET_LIST_DATA_SUCCEEDED = "GET_LIST_DATA_SUCCEEDED";
3
- export const GET_NAVIGATION_DATA = "GET_NAVIGATION_DATA";
4
- export const GET_NAVIGATION_DATA_SUCCEEDED = "GET_NAVIGATION_DATA_SUCCEEDED";
5
-
6
- export const CHANGE_NAVIGATION_DATA = "CHANGE_NAVIGATION_DATA";
7
- export const RESET_NAVIGATION_DATA = "RESET_NAVIGATION_DATA";
8
-
9
- export const CHANGE_NAVIGATION_POPUP_VISIBILITY =
10
- "CHANGE_NAVIGATION_POPUP_VISIBILITY";
11
- export const CHANGE_NAVIGATION_ITEM_POPUP_VISIBILITY =
12
- "CHANGE_NAVIGATION_ITEM_POPUP_VISIBILITY";
13
-
14
- export const GET_CONTENT_TYPE_ITEMS = "GET_CONTENT_TYPE_ITEMS";
15
- export const GET_CONTENT_TYPE_ITEMS_SUCCEEDED =
16
- "GET_CONTENT_TYPE_ITEMS_SUCCEEDED";
17
-
18
- export const GET_CONFIG = "GET_CONFIG";
19
- export const GET_CONFIG_SUCCEEDED = "GET_CONFIG_SUCCEEDED";
20
-
21
- export const SUBMIT_NAVIGATION = "SUBMIT_NAVIGATION";
22
- export const SUBMIT_NAVIGATION_SUCCEEDED = "SUBMIT_NAVIGATION_SUCCEEDED";
23
- export const SUBMIT_NAVIGATION_ERROR = "SUBMIT_NAVIGATION_ERROR";
24
-
25
-
26
- export const RELOAD_PLUGIN = "RELOAD_PLUGIN";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.I18N_COPY_NAVIGATION_SUCCESS = exports.I18N_COPY_NAVIGATION = exports.RELOAD_PLUGIN = exports.SUBMIT_NAVIGATION_ERROR = exports.SUBMIT_NAVIGATION_SUCCEEDED = exports.SUBMIT_NAVIGATION = exports.GET_CONFIG_SUCCEEDED = exports.GET_CONFIG = exports.GET_CONTENT_TYPE_ITEMS_SUCCEEDED = exports.GET_CONTENT_TYPE_ITEMS = exports.CHANGE_NAVIGATION_ITEM_POPUP_VISIBILITY = exports.CHANGE_NAVIGATION_POPUP_VISIBILITY = exports.RESET_NAVIGATION_DATA = exports.CHANGE_NAVIGATION_DATA = exports.GET_NAVIGATION_DATA_SUCCEEDED = exports.GET_NAVIGATION_DATA = exports.GET_LIST_DATA_SUCCEEDED = exports.GET_LIST_DATA = void 0;
4
+ exports.GET_LIST_DATA = "GET_LIST_DATA";
5
+ exports.GET_LIST_DATA_SUCCEEDED = "GET_LIST_DATA_SUCCEEDED";
6
+ exports.GET_NAVIGATION_DATA = "GET_NAVIGATION_DATA";
7
+ exports.GET_NAVIGATION_DATA_SUCCEEDED = "GET_NAVIGATION_DATA_SUCCEEDED";
8
+ exports.CHANGE_NAVIGATION_DATA = "CHANGE_NAVIGATION_DATA";
9
+ exports.RESET_NAVIGATION_DATA = "RESET_NAVIGATION_DATA";
10
+ exports.CHANGE_NAVIGATION_POPUP_VISIBILITY = "CHANGE_NAVIGATION_POPUP_VISIBILITY";
11
+ exports.CHANGE_NAVIGATION_ITEM_POPUP_VISIBILITY = "CHANGE_NAVIGATION_ITEM_POPUP_VISIBILITY";
12
+ exports.GET_CONTENT_TYPE_ITEMS = "GET_CONTENT_TYPE_ITEMS";
13
+ exports.GET_CONTENT_TYPE_ITEMS_SUCCEEDED = "GET_CONTENT_TYPE_ITEMS_SUCCEEDED";
14
+ exports.GET_CONFIG = "GET_CONFIG";
15
+ exports.GET_CONFIG_SUCCEEDED = "GET_CONFIG_SUCCEEDED";
16
+ exports.SUBMIT_NAVIGATION = "SUBMIT_NAVIGATION";
17
+ exports.SUBMIT_NAVIGATION_SUCCEEDED = "SUBMIT_NAVIGATION_SUCCEEDED";
18
+ exports.SUBMIT_NAVIGATION_ERROR = "SUBMIT_NAVIGATION_ERROR";
19
+ exports.RELOAD_PLUGIN = "RELOAD_PLUGIN";
20
+ exports.I18N_COPY_NAVIGATION = "I18N_COPY_NAVIGATION";
21
+ exports.I18N_COPY_NAVIGATION_SUCCESS = "I18N_COPY_NAVIGATION_SUCCESS";
22
+ //# sourceMappingURL=actions.js.map
@@ -0,0 +1,12 @@
1
+ declare var _default: React.MemoExoticComponent<{
2
+ ({ children }: {
3
+ children: any;
4
+ }): JSX.Element;
5
+ propTypes: {
6
+ children: PropTypes.Validator<string | number | boolean | PropTypes.ReactElementLike | PropTypes.ReactNodeArray>;
7
+ };
8
+ }>;
9
+ export default _default;
10
+ import PropTypes from "prop-types";
11
+ import React from "react";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -1,309 +1,289 @@
1
- import React, { memo, useEffect, useReducer, useRef } from "react";
2
- import { useLocation, useRouteMatch } from "react-router-dom";
3
- import { useIntl } from 'react-intl';
4
- import PropTypes from "prop-types";
5
- import { get, find, first, isEmpty } from "lodash";
6
- import {
7
- request,
8
- LoadingIndicatorPage,
9
- useNotification,
10
- useAppInfos,
11
- } from "@strapi/helper-plugin";
12
- import DataManagerContext from "../../contexts/DataManagerContext";
13
- import getTrad from "../../utils/getTrad";
14
- import pluginId from "../../pluginId";
15
- import init from "./init";
16
- import reducer, { initialState } from "./reducer";
17
- import {
18
- GET_NAVIGATION_DATA,
19
- GET_NAVIGATION_DATA_SUCCEEDED,
20
- GET_LIST_DATA,
21
- GET_LIST_DATA_SUCCEEDED,
22
- CHANGE_NAVIGATION_POPUP_VISIBILITY,
23
- CHANGE_NAVIGATION_ITEM_POPUP_VISIBILITY,
24
- RESET_NAVIGATION_DATA,
25
- CHANGE_NAVIGATION_DATA,
26
- GET_CONFIG,
27
- GET_CONFIG_SUCCEEDED,
28
- GET_CONTENT_TYPE_ITEMS_SUCCEEDED,
29
- GET_CONTENT_TYPE_ITEMS,
30
- SUBMIT_NAVIGATION,
31
- SUBMIT_NAVIGATION_SUCCEEDED,
32
- SUBMIT_NAVIGATION_ERROR,
33
- } from './actions';
34
- import { prepareItemToViewPayload } from '../View/utils/parsers';
35
-
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const react_1 = __importStar(require("react"));
30
+ const react_router_dom_1 = require("react-router-dom");
31
+ const react_intl_1 = require("react-intl");
32
+ const prop_types_1 = __importDefault(require("prop-types"));
33
+ const lodash_1 = require("lodash");
34
+ const helper_plugin_1 = require("@strapi/helper-plugin");
35
+ const DataManagerContext_1 = __importDefault(require("../../contexts/DataManagerContext"));
36
+ const getTrad_1 = __importDefault(require("../../utils/getTrad"));
37
+ const pluginId_1 = __importDefault(require("../../pluginId"));
38
+ const init_1 = __importDefault(require("./init"));
39
+ const reducer_1 = __importStar(require("./reducer"));
40
+ const actions_1 = require("./actions");
41
+ const parsers_1 = require("../View/utils/parsers");
42
+ const i18nAwareItems = ({ items, config }) => config.i18nEnabled ? items.filter(({ localeCode }) => localeCode === config.defaultLocale) : items;
36
43
  const DataManagerProvider = ({ children }) => {
37
- const [reducerState, dispatch] = useReducer(reducer, initialState, init);
38
- const toggleNotification = useNotification();
39
- const { autoReload } = useAppInfos();
40
- const { formatMessage } = useIntl();
41
-
42
- const {
43
- items,
44
- config,
45
- activeItem,
46
- initialData,
47
- changedActiveItem,
48
- navigationPopupOpened,
49
- navigationItemPopupOpened,
50
- isLoading,
51
- isLoadingForDataToBeSet,
52
- isLoadingForDetailsDataToBeSet,
53
- isLoadingForAdditionalDataToBeSet,
54
- isLoadingForSubmit,
55
- error
56
- } = reducerState;
57
- const { pathname } = useLocation();
58
- const formatMessageRef = useRef();
59
- formatMessageRef.current = formatMessage;
60
-
61
- const getLayoutSettingRef = useRef();
62
- getLayoutSettingRef.current = (settingName) =>
63
- get({}, ["settings", settingName], "");
64
-
65
- const isInDevelopmentMode = autoReload;
66
-
67
- const abortController = new AbortController();
68
- const { signal } = abortController;
69
- const getDataRef = useRef();
70
-
71
- const menuViewMatch = useRouteMatch(`/plugins/${pluginId}/:id`);
72
- const activeId = get(menuViewMatch, "params.id", null);
73
-
74
- const getNavigation = async (id, cfg) => {
75
- try {
76
- if (activeId || id) {
44
+ const [reducerState, dispatch] = (0, react_1.useReducer)(reducer_1.default, reducer_1.initialState, init_1.default);
45
+ const toggleNotification = (0, helper_plugin_1.useNotification)();
46
+ const { autoReload } = (0, helper_plugin_1.useAppInfos)();
47
+ const { formatMessage } = (0, react_intl_1.useIntl)();
48
+ const { items, config, activeItem, initialData, changedActiveItem, navigationPopupOpened, navigationItemPopupOpened, isLoading, isLoadingForDataToBeSet, isLoadingForDetailsDataToBeSet, isLoadingForAdditionalDataToBeSet, isLoadingForSubmit, error, availableLocale, } = reducerState;
49
+ const { pathname } = (0, react_router_dom_1.useLocation)();
50
+ const formatMessageRef = (0, react_1.useRef)();
51
+ formatMessageRef.current = formatMessage;
52
+ const getLayoutSettingRef = (0, react_1.useRef)();
53
+ getLayoutSettingRef.current = (settingName) => (0, lodash_1.get)({}, ["settings", settingName], "");
54
+ const isInDevelopmentMode = autoReload;
55
+ const abortController = new AbortController();
56
+ const { signal } = abortController;
57
+ const getDataRef = (0, react_1.useRef)();
58
+ const menuViewMatch = (0, react_router_dom_1.useRouteMatch)(`/plugins/${pluginId_1.default}/:id`);
59
+ const activeId = (0, lodash_1.get)(menuViewMatch, "params.id", null);
60
+ const passedActiveItems = (0, react_1.useMemo)(() => {
61
+ return i18nAwareItems({ config, items });
62
+ }, [config, items]);
63
+ const getNavigation = async (id, cfg) => {
64
+ try {
65
+ if (activeId || id) {
66
+ dispatch({
67
+ type: actions_1.GET_NAVIGATION_DATA,
68
+ });
69
+ const activeItem = await (0, helper_plugin_1.request)(`/${pluginId_1.default}/${activeId || id}`, {
70
+ method: "GET",
71
+ signal,
72
+ });
73
+ dispatch({
74
+ type: actions_1.GET_NAVIGATION_DATA_SUCCEEDED,
75
+ activeItem: {
76
+ ...activeItem,
77
+ items: (0, parsers_1.prepareItemToViewPayload)(activeItem.items, null, cfg),
78
+ },
79
+ });
80
+ }
81
+ }
82
+ catch (err) {
83
+ console.error({ err });
84
+ toggleNotification({
85
+ type: 'warning',
86
+ message: { id: (0, getTrad_1.default)('notification.error') },
87
+ });
88
+ }
89
+ };
90
+ getDataRef.current = async (id) => {
91
+ try {
92
+ dispatch({
93
+ type: actions_1.GET_CONFIG,
94
+ });
95
+ const config = await (0, helper_plugin_1.request)(`/${pluginId_1.default}/config`, {
96
+ method: "GET",
97
+ signal,
98
+ });
99
+ dispatch({
100
+ type: actions_1.GET_CONFIG_SUCCEEDED,
101
+ config,
102
+ });
103
+ dispatch({
104
+ type: actions_1.GET_LIST_DATA,
105
+ });
106
+ const items = await (0, helper_plugin_1.request)(`/${pluginId_1.default}`, {
107
+ method: "GET",
108
+ signal,
109
+ });
110
+ dispatch({
111
+ type: actions_1.GET_LIST_DATA_SUCCEEDED,
112
+ items,
113
+ });
114
+ if (id || !(0, lodash_1.isEmpty)(items)) {
115
+ await getNavigation(id || (0, lodash_1.first)(i18nAwareItems({ items, config })).id, config);
116
+ }
117
+ }
118
+ catch (err) {
119
+ console.error({ err });
120
+ toggleNotification({
121
+ type: 'warning',
122
+ message: { id: (0, getTrad_1.default)('notification.error') },
123
+ });
124
+ }
125
+ };
126
+ (0, react_1.useEffect)(() => {
127
+ getDataRef.current();
128
+ }, []);
129
+ (0, react_1.useEffect)(() => {
130
+ if (!isLoading) {
131
+ getNavigation();
132
+ }
133
+ }, [isLoading, pathname]);
134
+ (0, react_1.useEffect)(() => {
135
+ if (!autoReload) {
136
+ toggleNotification({
137
+ type: 'info',
138
+ message: { id: (0, getTrad_1.default)('notification.info.autoreaload-disable') },
139
+ });
140
+ }
141
+ }, [autoReload]);
142
+ const getContentTypeItems = async ({ modelUID, query, locale }) => {
77
143
  dispatch({
78
- type: GET_NAVIGATION_DATA,
144
+ type: actions_1.GET_CONTENT_TYPE_ITEMS,
79
145
  });
80
-
81
- const activeItem = await request(`/${pluginId}/${activeId || id}`, {
82
- method: "GET",
83
- signal,
146
+ const url = `/navigation/content-type-items/${modelUID}`;
147
+ const queryParams = new URLSearchParams();
148
+ queryParams.append('_publicationState', 'preview');
149
+ if (query) {
150
+ queryParams.append('_q', query);
151
+ }
152
+ if (locale) {
153
+ queryParams.append('localeCode', locale);
154
+ }
155
+ const contentTypeItems = await (0, helper_plugin_1.request)(`${url}?${queryParams.toString()}`, {
156
+ method: "GET",
157
+ signal,
84
158
  });
85
-
159
+ const fetchedContentType = (0, lodash_1.find)(config.contentTypes, ct => ct.uid === modelUID);
160
+ const isArray = Array.isArray(contentTypeItems);
86
161
  dispatch({
87
- type: GET_NAVIGATION_DATA_SUCCEEDED,
88
- activeItem: {
89
- ...activeItem,
90
- items: prepareItemToViewPayload(activeItem.items, null, cfg),
91
- },
162
+ type: actions_1.GET_CONTENT_TYPE_ITEMS_SUCCEEDED,
163
+ contentTypeItems: (isArray ? contentTypeItems : [contentTypeItems]).map(item => ({
164
+ ...item,
165
+ __collectionUid: (0, lodash_1.get)(fetchedContentType, 'collectionUid', modelUID),
166
+ })),
92
167
  });
93
- }
94
- } catch (err) {
95
- console.error({ err });
96
- toggleNotification({
97
- type: 'warning',
98
- message: { id: getTrad('notification.error') },
99
- });
100
- }
101
- };
102
-
103
- getDataRef.current = async (id) => {
104
- try {
105
- dispatch({
106
- type: GET_CONFIG,
107
- });
108
- const config = await request(`/${pluginId}/config`, {
109
- method: "GET",
110
- signal,
111
- });
112
- dispatch({
113
- type: GET_CONFIG_SUCCEEDED,
114
- config,
115
- });
116
-
117
- dispatch({
118
- type: GET_LIST_DATA,
119
- });
120
- const items = await request(`/${pluginId}`, {
121
- method: "GET",
122
- signal,
123
- });
124
-
125
- dispatch({
126
- type: GET_LIST_DATA_SUCCEEDED,
127
- items,
128
- });
129
-
130
- if (id || !isEmpty(items)) {
131
- await getNavigation(id || first(items).id, config);
132
- }
133
- } catch (err) {
134
- console.error({ err });
135
- toggleNotification({
136
- type: 'warning',
137
- message: { id: getTrad('notification.error') },
138
- });
139
- }
140
- };
141
-
142
- useEffect(() => {
143
- getDataRef.current();
144
- }, []);
145
-
146
- useEffect(() => {
147
- // We need to set the modifiedData after the data has been retrieved
148
- // and also on pathname change
149
- if (!isLoading) {
150
- getNavigation();
151
- }
152
- // eslint-disable-next-line react-hooks/exhaustive-deps
153
- }, [isLoading, pathname]);
154
-
155
- useEffect(() => {
156
- if (!autoReload) {
157
- toggleNotification({
158
- type: 'info',
159
- message: { id: getTrad('notification.info.autoreaload-disable') },
160
- });
161
- }
162
- }, [autoReload]);
163
-
164
- const getContentTypeItems = async ({ modelUID, query }) => {
165
- dispatch({
166
- type: GET_CONTENT_TYPE_ITEMS,
167
- });
168
- const url =`/navigation/content-type-items/${modelUID}`;
169
- const queryParams = new URLSearchParams();
170
- queryParams.append('_publicationState', 'preview');
171
- if (query) {
172
- queryParams.append('_q', query);
173
- }
174
-
175
- const contentTypeItems = await request(`${url}?${queryParams.toString()}`, {
176
- method: "GET",
177
- signal,
178
- });
179
-
180
- const fetchedContentType = find(config.contentTypes, ct => ct.uid === modelUID);
181
- const isArray = Array.isArray(contentTypeItems);
182
- dispatch({
183
- type: GET_CONTENT_TYPE_ITEMS_SUCCEEDED,
184
- contentTypeItems: (isArray ? contentTypeItems : [contentTypeItems]).map(item => ({
185
- ...item,
186
- __collectionUid: get(fetchedContentType, 'collectionUid', modelUID),
187
- })),
188
- });
189
- };
190
-
191
- const handleChangeSelection = (id) => {
192
- getNavigation(id, config);
193
- };
194
-
195
- const handleChangeNavigationPopupVisibility = (visible) => {
196
- dispatch({
197
- type: CHANGE_NAVIGATION_POPUP_VISIBILITY,
198
- navigationPopupOpened: visible,
199
- });
200
- };
201
-
202
- const handleChangeNavigationItemPopupVisibility = (visible) => {
203
- dispatch({
204
- type: CHANGE_NAVIGATION_ITEM_POPUP_VISIBILITY,
205
- navigationItemPopupOpened: visible,
206
- });
207
- };
208
-
209
- const handleChangeNavigationData = (payload, forceClosePopups) => {
210
- dispatch({
211
- type: CHANGE_NAVIGATION_DATA,
212
- changedActiveItem: payload,
213
- forceClosePopups,
214
- });
215
- };
216
-
217
- const handleResetNavigationData = () => {
218
- dispatch({
219
- type: RESET_NAVIGATION_DATA,
220
- activeItem,
221
- });
222
- };
223
-
224
- const handleSubmitNavigation = async (formatMessage, payload = {}) => {
225
- try {
226
- dispatch({
227
- type: SUBMIT_NAVIGATION,
228
- });
229
-
230
- const nagivationId = payload.id ? `/${payload.id}` : "";
231
- const method = payload.id ? "PUT" : "POST";
232
- const navigation = await request(`/${pluginId}${nagivationId}`, {
233
- method,
234
- signal,
235
- body: payload,
236
- });
237
- dispatch({
238
- type: SUBMIT_NAVIGATION_SUCCEEDED,
239
- navigation: {
240
- ...navigation,
241
- items: prepareItemToViewPayload(navigation.items, null, config),
242
- },
243
- });
244
- toggleNotification({
245
- type: 'success',
246
- message: { id: getTrad('notification.navigation.submit') },
247
- });
248
- } catch (err) {
249
- dispatch({
250
- type: SUBMIT_NAVIGATION_ERROR,
251
- error: err.response.payload.data
252
- });
253
- console.error({ err: err.response });
254
-
255
- if (err.response.payload.data && err.response.payload.data.errorTitles) {
256
- return toggleNotification({
257
- type: 'warning',
258
- message: {
259
- id: formatMessage(
260
- getTrad('notification.navigation.error'),
261
- { ...err.response.payload.data, errorTitles: err.response.payload.data.errorTitles.join(' and ') },
262
- )
263
- },
264
- });
265
- }
266
- toggleNotification({
267
- type: 'warning',
268
- message: { id: getTrad('notification.error') },
269
- });
270
- }
271
- };
272
-
273
- return (
274
- <DataManagerContext.Provider
275
- value={{
276
- items,
277
- activeItem,
278
- initialData,
279
- changedActiveItem,
280
- config,
281
- navigationPopupOpened,
282
- navigationItemPopupOpened,
283
- isLoading:
284
- isLoading ||
285
- isLoadingForDataToBeSet ||
286
- isLoadingForDetailsDataToBeSet,
287
- isLoadingForAdditionalDataToBeSet,
288
- isLoadingForSubmit,
289
- handleChangeNavigationPopupVisibility,
290
- handleChangeNavigationItemPopupVisibility,
291
- handleChangeSelection,
292
- handleChangeNavigationData,
293
- handleResetNavigationData,
294
- handleSubmitNavigation,
295
- getContentTypeItems,
296
- isInDevelopmentMode,
297
- error,
298
- }}
299
- >
300
- {isLoading ? <LoadingIndicatorPage /> : children}
301
- </DataManagerContext.Provider>
302
- );
168
+ };
169
+ const handleChangeSelection = (id) => {
170
+ getNavigation(id, config);
171
+ };
172
+ const handleLocalizationSelection = (id) => {
173
+ getNavigation(id, config);
174
+ };
175
+ const handleI18nCopy = async (sourceId, targetId) => {
176
+ dispatch({
177
+ type: actions_1.I18N_COPY_NAVIGATION
178
+ });
179
+ const url = `/navigation/i18n/copy/${sourceId}/${targetId}`;
180
+ await (0, helper_plugin_1.request)(url, {
181
+ method: "PUT",
182
+ signal,
183
+ });
184
+ dispatch({
185
+ type: actions_1.I18N_COPY_NAVIGATION_SUCCESS,
186
+ });
187
+ handleChangeSelection(targetId);
188
+ };
189
+ const handleChangeNavigationPopupVisibility = (visible) => {
190
+ dispatch({
191
+ type: actions_1.CHANGE_NAVIGATION_POPUP_VISIBILITY,
192
+ navigationPopupOpened: visible,
193
+ });
194
+ };
195
+ const handleChangeNavigationItemPopupVisibility = (visible) => {
196
+ dispatch({
197
+ type: actions_1.CHANGE_NAVIGATION_ITEM_POPUP_VISIBILITY,
198
+ navigationItemPopupOpened: visible,
199
+ });
200
+ };
201
+ const handleChangeNavigationData = (payload, forceClosePopups) => {
202
+ dispatch({
203
+ type: actions_1.CHANGE_NAVIGATION_DATA,
204
+ changedActiveItem: payload,
205
+ forceClosePopups,
206
+ });
207
+ };
208
+ const handleResetNavigationData = () => {
209
+ dispatch({
210
+ type: actions_1.RESET_NAVIGATION_DATA,
211
+ activeItem,
212
+ });
213
+ };
214
+ const handleSubmitNavigation = async (formatMessage, payload = {}) => {
215
+ try {
216
+ dispatch({
217
+ type: actions_1.SUBMIT_NAVIGATION,
218
+ });
219
+ const nagivationId = payload.id ? `/${payload.id}` : "";
220
+ const method = payload.id ? "PUT" : "POST";
221
+ const navigation = await (0, helper_plugin_1.request)(`/${pluginId_1.default}${nagivationId}`, {
222
+ method,
223
+ signal,
224
+ body: payload,
225
+ });
226
+ dispatch({
227
+ type: actions_1.SUBMIT_NAVIGATION_SUCCEEDED,
228
+ navigation: {
229
+ ...navigation,
230
+ items: (0, parsers_1.prepareItemToViewPayload)(navigation.items, null, config),
231
+ },
232
+ });
233
+ toggleNotification({
234
+ type: 'success',
235
+ message: { id: (0, getTrad_1.default)('notification.navigation.submit') },
236
+ });
237
+ }
238
+ catch (err) {
239
+ dispatch({
240
+ type: actions_1.SUBMIT_NAVIGATION_ERROR,
241
+ error: err.response.payload.data
242
+ });
243
+ console.error({ err: err.response });
244
+ if (err.response.payload.data && err.response.payload.data.errorTitles) {
245
+ return toggleNotification({
246
+ type: 'warning',
247
+ message: {
248
+ id: formatMessage((0, getTrad_1.default)('notification.navigation.error'), { ...err.response.payload.data, errorTitles: err.response.payload.data.errorTitles.join(' and ') })
249
+ },
250
+ });
251
+ }
252
+ toggleNotification({
253
+ type: 'warning',
254
+ message: { id: (0, getTrad_1.default)('notification.error') },
255
+ });
256
+ }
257
+ };
258
+ return (react_1.default.createElement(DataManagerContext_1.default.Provider, { value: {
259
+ items: passedActiveItems,
260
+ activeItem,
261
+ initialData,
262
+ changedActiveItem,
263
+ config,
264
+ navigationPopupOpened,
265
+ navigationItemPopupOpened,
266
+ isLoading: isLoading ||
267
+ isLoadingForDataToBeSet ||
268
+ isLoadingForDetailsDataToBeSet,
269
+ isLoadingForAdditionalDataToBeSet,
270
+ isLoadingForSubmit,
271
+ handleChangeNavigationPopupVisibility,
272
+ handleChangeNavigationItemPopupVisibility,
273
+ handleChangeSelection,
274
+ handleLocalizationSelection,
275
+ handleChangeNavigationData,
276
+ handleResetNavigationData,
277
+ handleSubmitNavigation,
278
+ handleI18nCopy,
279
+ getContentTypeItems,
280
+ isInDevelopmentMode,
281
+ error,
282
+ availableLocale,
283
+ } }, isLoading ? react_1.default.createElement(helper_plugin_1.LoadingIndicatorPage, null) : children));
303
284
  };
304
-
305
285
  DataManagerProvider.propTypes = {
306
- children: PropTypes.node.isRequired,
286
+ children: prop_types_1.default.node.isRequired,
307
287
  };
308
-
309
- export default memo(DataManagerProvider);
288
+ exports.default = (0, react_1.memo)(DataManagerProvider);
289
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ export default init;
2
+ declare function init(initialState: any): any;
3
+ //# sourceMappingURL=init.d.ts.map