strapi-plugin-navigation 2.1.0-beta.2 → 2.2.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 (135) hide show
  1. package/README.md +20 -10
  2. package/admin/src/components/AdditionalFieldInput/index.d.ts +5 -0
  3. package/admin/src/components/AdditionalFieldInput/index.js +71 -0
  4. package/admin/src/components/AdditionalFieldInput/types.d.ts +14 -0
  5. package/admin/src/components/AdditionalFieldInput/types.js +3 -0
  6. package/admin/src/components/DragButton/index.d.ts +4 -0
  7. package/admin/src/components/DragButton/index.js +61 -0
  8. package/admin/src/components/Item/ItemCardHeader/Wrapper.d.ts +1 -1
  9. package/admin/src/components/Item/ItemCardHeader/icons.d.ts +5 -0
  10. package/admin/src/components/Item/ItemCardHeader/icons.js +12 -0
  11. package/admin/src/components/Item/ItemCardHeader/index.d.ts +13 -10
  12. package/admin/src/components/Item/ItemCardHeader/index.js +17 -38
  13. package/admin/src/components/Item/index.js +6 -6
  14. package/admin/src/components/RestartAlert/index.d.ts +1 -1
  15. package/admin/src/components/TextArrayInput/index.d.ts +14 -0
  16. package/admin/src/components/TextArrayInput/index.js +45 -0
  17. package/admin/src/hooks/useAllContentTypes.d.ts +1 -4
  18. package/admin/src/hooks/useAllContentTypes.js +3 -7
  19. package/admin/src/hooks/useI18nCopyNavigationItemsModal.d.ts +9 -0
  20. package/admin/src/hooks/useI18nCopyNavigationItemsModal.js +51 -0
  21. package/admin/src/hooks/useNavigationConfig.d.ts +1 -1
  22. package/admin/src/hooks/useNavigationConfig.js +6 -6
  23. package/admin/src/hooks/useNavigationManager.d.ts +7 -0
  24. package/admin/src/hooks/useNavigationManager.js +41 -0
  25. package/admin/src/pages/DataManagerProvider/index.d.ts +1 -1
  26. package/admin/src/pages/DataManagerProvider/index.js +46 -10
  27. package/admin/src/pages/SettingsPage/components/CustomFieldForm/index.d.ts +12 -0
  28. package/admin/src/pages/SettingsPage/components/CustomFieldForm/index.js +112 -0
  29. package/admin/src/pages/SettingsPage/components/CustomFieldModal/index.d.ts +12 -0
  30. package/admin/src/pages/SettingsPage/components/CustomFieldModal/index.js +20 -0
  31. package/admin/src/pages/SettingsPage/components/CustomFieldTable/index.d.ts +11 -0
  32. package/admin/src/pages/SettingsPage/components/CustomFieldTable/index.js +105 -0
  33. package/admin/src/pages/SettingsPage/index.d.ts +2 -1
  34. package/admin/src/pages/SettingsPage/index.js +111 -75
  35. package/admin/src/pages/SettingsPage/types.d.ts +32 -0
  36. package/admin/src/pages/SettingsPage/types.js +3 -0
  37. package/admin/src/pages/SettingsPage/utils/form.d.ts +18 -0
  38. package/admin/src/pages/SettingsPage/utils/form.js +34 -0
  39. package/admin/src/pages/SettingsPage/utils/functions.d.ts +2 -2
  40. package/admin/src/pages/SettingsPage/utils/functions.js +1 -1
  41. package/admin/src/pages/View/components/I18nCopyNavigationItems/index.d.ts +3 -9
  42. package/admin/src/pages/View/components/I18nCopyNavigationItems/index.js +2 -47
  43. package/admin/src/pages/View/components/NavigationHeader/index.js +11 -6
  44. package/admin/src/pages/View/components/NavigationItemForm/index.d.ts +3 -49
  45. package/admin/src/pages/View/components/NavigationItemForm/index.js +219 -152
  46. package/admin/src/pages/View/components/NavigationItemForm/types.d.ts +90 -0
  47. package/admin/src/pages/View/components/NavigationItemForm/types.js +3 -0
  48. package/admin/src/pages/View/components/NavigationItemForm/utils/form.d.ts +24 -43
  49. package/admin/src/pages/View/components/NavigationItemForm/utils/form.js +84 -48
  50. package/admin/src/pages/View/components/NavigationItemPopup/index.d.ts +4 -1
  51. package/admin/src/pages/View/components/NavigationItemPopup/index.js +32 -7
  52. package/admin/src/pages/View/components/NavigationManager/AllNavigations/icons.d.ts +4 -0
  53. package/admin/src/pages/View/components/NavigationManager/AllNavigations/icons.js +11 -0
  54. package/admin/src/pages/View/components/NavigationManager/AllNavigations/index.d.ts +9 -0
  55. package/admin/src/pages/View/components/NavigationManager/AllNavigations/index.js +139 -0
  56. package/admin/src/pages/View/components/NavigationManager/DeletionConfirm/index.d.ts +9 -0
  57. package/admin/src/pages/View/components/NavigationManager/DeletionConfirm/index.js +34 -0
  58. package/admin/src/pages/View/components/NavigationManager/ErrorDetails/index.d.ts +9 -0
  59. package/admin/src/pages/View/components/NavigationManager/ErrorDetails/index.js +53 -0
  60. package/admin/src/pages/View/components/NavigationManager/Footer/index.d.ts +24 -0
  61. package/admin/src/pages/View/components/NavigationManager/Footer/index.js +13 -0
  62. package/admin/src/pages/View/components/NavigationManager/Form/index.d.ts +20 -0
  63. package/admin/src/pages/View/components/NavigationManager/Form/index.js +103 -0
  64. package/admin/src/pages/View/components/NavigationManager/NavigationUpdate/index.d.ts +9 -0
  65. package/admin/src/pages/View/components/NavigationManager/NavigationUpdate/index.js +59 -0
  66. package/admin/src/pages/View/components/NavigationManager/NewNavigation/index.d.ts +10 -0
  67. package/admin/src/pages/View/components/NavigationManager/NewNavigation/index.js +62 -0
  68. package/admin/src/pages/View/components/NavigationManager/index.d.ts +11 -0
  69. package/admin/src/pages/View/components/NavigationManager/index.js +190 -0
  70. package/admin/src/pages/View/components/NavigationManager/types.d.ts +40 -0
  71. package/admin/src/pages/View/components/NavigationManager/types.js +3 -0
  72. package/admin/src/pages/View/index.d.ts +1 -1
  73. package/admin/src/pages/View/index.js +11 -9
  74. package/admin/src/pages/View/utils/parsers.d.ts +7 -1
  75. package/admin/src/pages/View/utils/parsers.js +21 -10
  76. package/admin/src/translations/en.json +68 -0
  77. package/admin/src/translations/index.d.ts +2 -1
  78. package/admin/src/translations/index.js +1 -1
  79. package/admin/src/utils/api.d.ts +8 -7
  80. package/admin/src/utils/api.js +6 -41
  81. package/admin/src/utils/enums.d.ts +25 -0
  82. package/admin/src/utils/enums.js +30 -0
  83. package/admin/src/utils/functions.d.ts +16 -0
  84. package/admin/src/utils/functions.js +46 -0
  85. package/admin/src/utils/index.d.ts +3 -4
  86. package/admin/src/utils/index.js +16 -24
  87. package/package.json +6 -7
  88. package/server/config/index.js +6 -4
  89. package/server/config/setupStrategy.js +13 -1
  90. package/server/content-types/index.d.ts +5 -25
  91. package/server/content-types/navigation/index.d.ts +0 -7
  92. package/server/content-types/navigation/index.js +0 -2
  93. package/server/content-types/navigation/schema.js +1 -1
  94. package/server/content-types/navigation-item/index.d.ts +5 -13
  95. package/server/content-types/navigation-item/index.js +0 -2
  96. package/server/content-types/navigation-item/schema.d.ts +5 -0
  97. package/server/content-types/navigation-item/schema.js +5 -0
  98. package/server/content-types/navigations-items-related/index.d.ts +0 -5
  99. package/server/content-types/navigations-items-related/index.js +0 -2
  100. package/server/controllers/admin.js +67 -14
  101. package/server/controllers/client.js +43 -19
  102. package/server/graphql/types/navigation-item.d.ts +2 -1
  103. package/server/graphql/types/navigation-item.js +26 -2
  104. package/server/i18n/serviceEnhancers.d.ts +2 -1
  105. package/server/i18n/serviceEnhancers.js +45 -6
  106. package/server/i18n/types.d.ts +6 -0
  107. package/server/index.d.ts +5 -25
  108. package/server/navigation/setupStrategy.js +3 -1
  109. package/server/routes/admin.js +10 -0
  110. package/server/services/admin.js +104 -37
  111. package/server/services/client.js +64 -21
  112. package/server/services/common.js +26 -7
  113. package/server/utils/constant.d.ts +0 -3
  114. package/server/utils/constant.js +1 -2
  115. package/server/utils/functions.d.ts +13 -12
  116. package/server/utils/functions.js +62 -22
  117. package/strapi-server.d.ts +5 -25
  118. package/tsconfig.tsbuildinfo +1 -1
  119. package/types/config.d.ts +6 -2
  120. package/types/contentTypes.d.ts +22 -1
  121. package/types/controllers.d.ts +21 -8
  122. package/types/services.d.ts +20 -5
  123. package/types/utils.d.ts +10 -1
  124. package/types/utils.js +18 -3
  125. package/utils/InvalidParamNavigationError.js +0 -3
  126. package/admin/src/pages/View/utils/enums.d.ts +0 -9
  127. package/admin/src/pages/View/utils/enums.js +0 -12
  128. package/admin/src/utils/getTrad.d.ts +0 -3
  129. package/admin/src/utils/getTrad.js +0 -9
  130. package/server/content-types/navigation/lifecycle.d.ts +0 -9
  131. package/server/content-types/navigation/lifecycle.js +0 -10
  132. package/server/content-types/navigation-item/lifecycle.d.ts +0 -16
  133. package/server/content-types/navigation-item/lifecycle.js +0 -31
  134. package/server/content-types/navigations-items-related/lifecycle.d.ts +0 -8
  135. package/server/content-types/navigations-items-related/lifecycle.js +0 -22
@@ -0,0 +1,20 @@
1
+ /// <reference types="react" />
2
+ import { useIntl } from "react-intl";
3
+ import { Effect } from "../../../../../../../types";
4
+ import { Navigation } from "../types";
5
+ interface Props {
6
+ navigation: Partial<Navigation>;
7
+ onChange: Effect<Navigation>;
8
+ isLoading?: boolean;
9
+ validationSchema: ReturnType<typeof validationSchemaFactory>;
10
+ }
11
+ export declare const Form: ({ navigation, onChange: onChangeBase, isLoading, validationSchema, }: Props) => JSX.Element;
12
+ export declare const validationSchemaFactory: (alreadyUsedNames: Array<string>, formatMessage: ReturnType<typeof useIntl>["formatMessage"]) => import("yup/lib/object").OptionalObjectSchema<{
13
+ name: import("yup/lib/string").RequiredStringSchema<string | undefined, Record<string, any>>;
14
+ visible: import("yup/lib/boolean").RequiredBooleanSchema<boolean | undefined, Record<string, any>>;
15
+ }, Record<string, any>, import("yup/lib/object").TypeOfShape<{
16
+ name: import("yup/lib/string").RequiredStringSchema<string | undefined, Record<string, any>>;
17
+ visible: import("yup/lib/boolean").RequiredBooleanSchema<boolean | undefined, Record<string, any>>;
18
+ }>>;
19
+ export {};
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,103 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.validationSchemaFactory = exports.Form = void 0;
27
+ const Grid_1 = require("@strapi/design-system/Grid");
28
+ const helper_plugin_1 = require("@strapi/helper-plugin");
29
+ const formik_1 = require("formik");
30
+ const react_1 = __importStar(require("react"));
31
+ const yup = __importStar(require("yup"));
32
+ const translations_1 = require("../../../../../translations");
33
+ const lodash_1 = require("lodash");
34
+ const Form = ({ navigation, onChange: onChangeBase, isLoading, validationSchema, }) => {
35
+ const initialValues = {
36
+ id: (0, lodash_1.get)(navigation, "id", ""),
37
+ name: (0, lodash_1.get)(navigation, "name", ""),
38
+ };
39
+ const onChange = (0, react_1.useCallback)(({ target: { name, value } }) => {
40
+ onChangeBase({
41
+ ...navigation,
42
+ [name]: value,
43
+ });
44
+ }, [onChangeBase, navigation]);
45
+ const [error, setError] = (0, react_1.useState)(null);
46
+ const errorProps = (0, react_1.useMemo)(() => ({
47
+ name: error?.path === "name" ? error.message : undefined,
48
+ visible: error?.path === "visible" ? error.message : undefined,
49
+ }), [error]);
50
+ (0, react_1.useEffect)(() => {
51
+ validationSchema
52
+ .validate(navigation)
53
+ .then(() => setError(null))
54
+ .catch(setError);
55
+ }, [navigation, validationSchema, setError]);
56
+ return (react_1.default.createElement(formik_1.Formik, { initialValues: initialValues, onSubmit: onChangeBase },
57
+ react_1.default.createElement(helper_plugin_1.Form, null,
58
+ react_1.default.createElement(Grid_1.Grid, { gap: 5 },
59
+ react_1.default.createElement(Grid_1.GridItem, { col: 6 },
60
+ react_1.default.createElement(helper_plugin_1.GenericInput, { ...formProps.name, name: "name", description: {
61
+ id: (0, translations_1.getTradId)("popup.item.form.title.placeholder"),
62
+ defaultMessage: "e.g. Blog",
63
+ }, type: "text", error: errorProps.name, onChange: onChange, value: navigation.name, disabled: isLoading, required: true })),
64
+ react_1.default.createElement(Grid_1.GridItem, { col: 6 },
65
+ react_1.default.createElement(helper_plugin_1.GenericInput, { ...formProps.visible, name: "visible", type: "bool", error: errorProps.visible, onChange: onChange, value: navigation.visible, disabled: isLoading }))))));
66
+ };
67
+ exports.Form = Form;
68
+ const formProps = {
69
+ name: {
70
+ intlLabel: {
71
+ id: (0, translations_1.getTradId)("popup.navigation.form.name.label"),
72
+ defaultMessage: "Name",
73
+ },
74
+ placeholder: {
75
+ id: (0, translations_1.getTradId)("popup.navigation.form.name.placeholder"),
76
+ defaultMessage: "Navigations's name",
77
+ },
78
+ },
79
+ visible: {
80
+ intlLabel: {
81
+ id: (0, translations_1.getTradId)("popup.navigation.form.visible.label"),
82
+ defaultMessage: "Visibility",
83
+ },
84
+ },
85
+ };
86
+ const validationSchemaFactory = (alreadyUsedNames, formatMessage) => yup.object({
87
+ name: yup
88
+ .string()
89
+ .notOneOf(alreadyUsedNames, formatMessage({
90
+ id: (0, translations_1.getTradId)("popup.navigation.form.validation.name.alreadyUsed"),
91
+ }))
92
+ .required(formatMessage({
93
+ id: (0, translations_1.getTradId)("popup.navigation.form.validation.name.required"),
94
+ }))
95
+ .min(2, formatMessage({
96
+ id: (0, translations_1.getTradId)("popup.navigation.form.validation.name.tooShort"),
97
+ })),
98
+ visible: yup.boolean().required(formatMessage({
99
+ id: (0, translations_1.getTradId)("popup.navigation.form.validation.visible.required"),
100
+ })),
101
+ });
102
+ exports.validationSchemaFactory = validationSchemaFactory;
103
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { Footer } from "../Footer";
3
+ import { CommonProps, EditState } from "../types";
4
+ interface Props extends EditState, CommonProps {
5
+ }
6
+ export declare const NavigationUpdate: ({ alreadyUsedNames, current, isLoading, navigation: initialValue, setState, }: Props) => JSX.Element;
7
+ export declare const NavigationUpdateFooter: Footer;
8
+ export {};
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,59 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.NavigationUpdateFooter = exports.NavigationUpdate = void 0;
27
+ const react_1 = __importStar(require("react"));
28
+ const react_intl_1 = require("react-intl");
29
+ const utils_1 = require("../../../../../utils");
30
+ const Footer_1 = require("../Footer");
31
+ const Form_1 = require("../Form");
32
+ const NavigationUpdate = ({ alreadyUsedNames, current, isLoading, navigation: initialValue, setState, }) => {
33
+ const { formatMessage } = (0, react_intl_1.useIntl)();
34
+ const onChange = (0, react_1.useCallback)((updated) => {
35
+ setState({
36
+ view: "EDIT",
37
+ alreadyUsedNames,
38
+ current: updated,
39
+ navigation: initialValue,
40
+ });
41
+ }, [setState, initialValue, alreadyUsedNames]);
42
+ const navigation = (0, react_1.useMemo)(() => current ?? initialValue, [current]);
43
+ const validationSchema = (0, react_1.useMemo)(() => (0, Form_1.validationSchemaFactory)(alreadyUsedNames, formatMessage), [alreadyUsedNames]);
44
+ return (react_1.default.createElement(Form_1.Form, { navigation: navigation, onChange: onChange, isLoading: isLoading, validationSchema: validationSchema }));
45
+ };
46
+ exports.NavigationUpdate = NavigationUpdate;
47
+ const NavigationUpdateFooter = ({ state, onSubmit, onReset, }) => (react_1.default.createElement(Footer_1.FooterBase, { start: {
48
+ children: (0, utils_1.getMessage)("popup.item.form.button.cancel"),
49
+ disabled: state.isLoading,
50
+ onClick: onReset,
51
+ variant: "tertiary",
52
+ }, end: {
53
+ children: (0, utils_1.getMessage)("popup.navigation.manage.button.save"),
54
+ disabled: state.isLoading,
55
+ onClick: onSubmit,
56
+ variant: "secondary",
57
+ } }));
58
+ exports.NavigationUpdateFooter = NavigationUpdateFooter;
59
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { Footer } from "../Footer";
3
+ import { CommonProps, CreateState, Navigation } from "../types";
4
+ interface Props extends CreateState, CommonProps {
5
+ }
6
+ export declare const INITIAL_NAVIGATION: Navigation;
7
+ export declare const NewNavigation: ({ setState, current, isLoading, alreadyUsedNames, }: Props) => JSX.Element;
8
+ export declare const NewNavigationFooter: Footer;
9
+ export {};
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,62 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.NewNavigationFooter = exports.NewNavigation = exports.INITIAL_NAVIGATION = void 0;
27
+ const react_1 = __importStar(require("react"));
28
+ const react_intl_1 = require("react-intl");
29
+ const utils_1 = require("../../../../../utils");
30
+ const Footer_1 = require("../Footer");
31
+ const Form_1 = require("../Form");
32
+ exports.INITIAL_NAVIGATION = {
33
+ name: "Navigation",
34
+ items: [],
35
+ visible: true,
36
+ };
37
+ const NewNavigation = ({ setState, current, isLoading, alreadyUsedNames, }) => {
38
+ const { formatMessage } = (0, react_intl_1.useIntl)();
39
+ const onSubmit = (0, react_1.useCallback)((updated) => {
40
+ setState({
41
+ view: "CREATE",
42
+ current: updated,
43
+ alreadyUsedNames,
44
+ });
45
+ }, [setState]);
46
+ const validationSchema = (0, react_1.useMemo)(() => (0, Form_1.validationSchemaFactory)(alreadyUsedNames, formatMessage), [alreadyUsedNames]);
47
+ return (react_1.default.createElement(Form_1.Form, { navigation: current, onChange: onSubmit, isLoading: isLoading, validationSchema: validationSchema }));
48
+ };
49
+ exports.NewNavigation = NewNavigation;
50
+ const NewNavigationFooter = ({ state, onSubmit, onReset, }) => (react_1.default.createElement(Footer_1.FooterBase, { start: {
51
+ children: (0, utils_1.getMessage)("popup.item.form.button.cancel"),
52
+ variant: "tertiary",
53
+ disabled: state.isLoading,
54
+ onClick: onReset,
55
+ }, end: {
56
+ children: (0, utils_1.getMessage)("popup.navigation.manage.button.save"),
57
+ variant: "default",
58
+ disabled: state.isLoading,
59
+ onClick: onSubmit,
60
+ } }));
61
+ exports.NewNavigationFooter = NewNavigationFooter;
62
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { VoidEffect } from "../../../../../../types";
3
+ import { State } from "./types";
4
+ interface Props {
5
+ initialState: State;
6
+ isOpened?: boolean;
7
+ onClose?: VoidEffect;
8
+ }
9
+ export declare const NavigationManager: ({ initialState, isOpened, onClose, }: Props) => JSX.Element;
10
+ export {};
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,190 @@
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
+ exports.NavigationManager = void 0;
30
+ const Flex_1 = require("@strapi/design-system/Flex");
31
+ const Loader_1 = require("@strapi/design-system/Loader");
32
+ const ModalLayout_1 = require("@strapi/design-system/ModalLayout");
33
+ const lodash_1 = require("lodash");
34
+ const fp_1 = require("lodash/fp");
35
+ const react_1 = __importStar(require("react"));
36
+ const react_intl_1 = require("react-intl");
37
+ const useDataManager_1 = __importDefault(require("../../../../hooks/useDataManager"));
38
+ const utils_1 = require("../../../../utils");
39
+ const AllNavigations_1 = require("./AllNavigations");
40
+ const DeletionConfirm_1 = require("./DeletionConfirm");
41
+ const ErrorDetails_1 = require("./ErrorDetails");
42
+ const NavigationUpdate_1 = require("./NavigationUpdate");
43
+ const NewNavigation_1 = require("./NewNavigation");
44
+ const NavigationManager = ({ initialState, isOpened, onClose, }) => {
45
+ const { formatMessage } = (0, react_intl_1.useIntl)();
46
+ const [state, setState] = (0, react_1.useState)(initialState);
47
+ const { items = [], handleNavigationsDeletion, handleSubmitNavigation, hardReset, } = (0, useDataManager_1.default)();
48
+ const navigations = (0, react_1.useMemo)(() => (0, lodash_1.sortBy)(items, "id"), [items]);
49
+ const onReset = (0, react_1.useCallback)(() => setState({ view: "INITIAL" }), [setState]);
50
+ const onSubmit = (0, react_1.useCallback)(async () => {
51
+ const performAction = state.view === "DELETE"
52
+ ? async () => {
53
+ await handleNavigationsDeletion(state.navigations.map((0, fp_1.prop)("id")));
54
+ await hardReset();
55
+ }
56
+ : (state.view === "CREATE" || state.view === "EDIT") && state.current
57
+ ? async () => {
58
+ await handleSubmitNavigation(formatMessage, state.current);
59
+ await hardReset();
60
+ }
61
+ : () => { };
62
+ try {
63
+ setState({
64
+ ...state,
65
+ isLoading: true,
66
+ });
67
+ await performAction();
68
+ setState({ view: "INITIAL" });
69
+ }
70
+ catch (error) {
71
+ setState({
72
+ view: "ERROR",
73
+ errors: error instanceof Error ? [error] : [],
74
+ });
75
+ }
76
+ }, [
77
+ state,
78
+ setState,
79
+ hardReset,
80
+ handleSubmitNavigation,
81
+ handleNavigationsDeletion,
82
+ ]);
83
+ (0, react_1.useEffect)(() => {
84
+ if (state.view === "INITIAL") {
85
+ setState({
86
+ view: "LIST",
87
+ navigations,
88
+ selected: [],
89
+ });
90
+ }
91
+ }, [state.view]);
92
+ const header = renderHeader(state);
93
+ const content = renderContent(state, setState);
94
+ const footer = renderFooter({
95
+ state,
96
+ setState,
97
+ onClose,
98
+ onSubmit,
99
+ onReset,
100
+ navigations,
101
+ });
102
+ return (react_1.default.createElement(ModalLayout_1.ModalLayout, { labelledBy: "condition-modal-breadcrumbs", onClose: onClose, isOpen: isOpened },
103
+ react_1.default.createElement(ModalLayout_1.ModalHeader, null, header),
104
+ react_1.default.createElement(ModalLayout_1.ModalBody, null, content),
105
+ footer));
106
+ };
107
+ exports.NavigationManager = NavigationManager;
108
+ const renderHeader = (state) => {
109
+ switch (state.view) {
110
+ case "LIST":
111
+ case "CREATE":
112
+ case "ERROR":
113
+ case "DELETE": {
114
+ return (react_1.default.createElement(Flex_1.Flex, { direction: "row" },
115
+ state.isLoading ? react_1.default.createElement(Loader_1.Loader, { small: true }) : null,
116
+ (0, utils_1.getMessage)(`popup.navigation.manage.header.${state.view}`)));
117
+ }
118
+ case "EDIT": {
119
+ return (react_1.default.createElement(Flex_1.Flex, { direction: "row" },
120
+ state.isLoading ? react_1.default.createElement(Loader_1.Loader, { small: true }) : null,
121
+ (0, utils_1.getMessage)({
122
+ id: "popup.navigation.manage.header.EDIT",
123
+ props: {
124
+ name: state.navigation.name,
125
+ },
126
+ })));
127
+ }
128
+ case "INITIAL": {
129
+ return null;
130
+ }
131
+ default:
132
+ return handleUnknownState(state);
133
+ }
134
+ };
135
+ const renderContent = (state, setState) => {
136
+ const commonProps = {
137
+ setState,
138
+ };
139
+ switch (state.view) {
140
+ case "LIST": {
141
+ return react_1.default.createElement(AllNavigations_1.AllNavigations, { ...state, ...commonProps });
142
+ }
143
+ case "EDIT": {
144
+ return react_1.default.createElement(NavigationUpdate_1.NavigationUpdate, { ...state, ...commonProps });
145
+ }
146
+ case "CREATE": {
147
+ return react_1.default.createElement(NewNavigation_1.NewNavigation, { ...state, ...commonProps });
148
+ }
149
+ case "DELETE": {
150
+ return react_1.default.createElement(DeletionConfirm_1.DeletionConfirm, { ...state, ...commonProps });
151
+ }
152
+ case "INITIAL": {
153
+ return react_1.default.createElement(Loader_1.Loader, { small: true });
154
+ }
155
+ case "ERROR": {
156
+ return react_1.default.createElement(ErrorDetails_1.ErrorDetails, { ...state, ...commonProps });
157
+ }
158
+ default:
159
+ return handleUnknownState(state);
160
+ }
161
+ };
162
+ const renderFooter = (props) => {
163
+ switch (props.state.view) {
164
+ case "LIST": {
165
+ return react_1.default.createElement(AllNavigations_1.AllNavigationsFooter, { ...props });
166
+ }
167
+ case "CREATE": {
168
+ return react_1.default.createElement(NewNavigation_1.NewNavigationFooter, { ...props });
169
+ }
170
+ case "EDIT": {
171
+ return react_1.default.createElement(NavigationUpdate_1.NavigationUpdateFooter, { ...props });
172
+ }
173
+ case "DELETE": {
174
+ return react_1.default.createElement(DeletionConfirm_1.DeleteConfirmFooter, { ...props });
175
+ }
176
+ case "ERROR": {
177
+ return react_1.default.createElement(ErrorDetails_1.ErrorDetailsFooter, { ...props });
178
+ }
179
+ case "INITIAL": {
180
+ return null;
181
+ }
182
+ default:
183
+ return handleUnknownState(props.state);
184
+ }
185
+ };
186
+ const handleUnknownState = (state) => {
187
+ console.warn(`Unknown state "${state?.view}". (${JSON.stringify(state)})`);
188
+ return null;
189
+ };
190
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,40 @@
1
+ import { Dispatch, SetStateAction } from "react";
2
+ import { Navigation as FullNavigationEntity } from "../../../../../../types";
3
+ export declare type Navigation = Pick<FullNavigationEntity, "id" | "items" | "name" | "localeCode" | "localizations" | "visible">;
4
+ export declare type State = InitialState | ListState | EditState | CreateState | DeleteState | ErrorState;
5
+ export declare type SetState = Dispatch<SetStateAction<State>>;
6
+ interface CommonState {
7
+ isLoading?: boolean;
8
+ }
9
+ export interface CommonProps {
10
+ setState: SetState;
11
+ }
12
+ export interface InitialState extends CommonState {
13
+ view: "INITIAL";
14
+ }
15
+ export interface ListState extends CommonState {
16
+ view: "LIST";
17
+ navigations: Array<Navigation>;
18
+ selected: Array<Navigation>;
19
+ }
20
+ export interface EditState extends CommonState {
21
+ view: "EDIT";
22
+ navigation: Navigation;
23
+ current?: Navigation;
24
+ alreadyUsedNames: Array<string>;
25
+ }
26
+ export interface CreateState extends CommonState {
27
+ view: "CREATE";
28
+ current: Navigation;
29
+ alreadyUsedNames: Array<string>;
30
+ }
31
+ export interface DeleteState extends CommonState {
32
+ view: "DELETE";
33
+ navigations: Array<Navigation>;
34
+ }
35
+ export interface ErrorState extends CommonState {
36
+ view: "ERROR";
37
+ errors: Array<Error>;
38
+ }
39
+ export {};
40
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -1,4 +1,4 @@
1
- declare var _default: React.MemoExoticComponent<() => JSX.Element>;
1
+ declare const _default: React.MemoExoticComponent<() => JSX.Element>;
2
2
  export default _default;
3
3
  import React from "react";
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -44,15 +44,15 @@ const NavigationItemList_1 = __importDefault(require("../../components/Navigatio
44
44
  const NavigationContentHeader_1 = __importDefault(require("./components/NavigationContentHeader"));
45
45
  const NavigationHeader_1 = __importDefault(require("./components/NavigationHeader"));
46
46
  const NavigationItemPopup_1 = __importDefault(require("./components/NavigationItemPopup"));
47
- const I18nCopyNavigationItems_1 = require("./components/I18nCopyNavigationItems");
47
+ const useI18nCopyNavigationItemsModal_1 = require("../../hooks/useI18nCopyNavigationItemsModal");
48
48
  const Search_1 = __importDefault(require("../../components/Search"));
49
49
  const useDataManager_1 = __importDefault(require("../../hooks/useDataManager"));
50
50
  const translations_1 = require("../../translations");
51
51
  const parsers_1 = require("./utils/parsers");
52
52
  const View = () => {
53
- const { items: availableNavigations, activeItem: activeNavigation, changedActiveItem: changedActiveNavigation, config, navigationItemPopupOpened, isLoading, isLoadingForAdditionalDataToBeSet, isLoadingForSubmit, handleChangeNavigationItemPopupVisibility, handleChangeSelection, handleChangeNavigationData, handleResetNavigationData, handleSubmitNavigation, handleLocalizationSelection, handleI18nCopy, getContentTypeItems, error, availableLocale: allAvailableLocale, } = (0, useDataManager_1.default)();
53
+ const { items: availableNavigations, activeItem: activeNavigation, changedActiveItem: changedActiveNavigation, config, navigationItemPopupOpened, isLoading, isLoadingForAdditionalDataToBeSet, isLoadingForSubmit, handleChangeNavigationItemPopupVisibility, handleChangeSelection, handleChangeNavigationData, handleResetNavigationData, handleSubmitNavigation, handleLocalizationSelection, handleI18nCopy, getContentTypeItems, error, availableLocale: allAvailableLocale, readNavigationItemFromLocale, } = (0, useDataManager_1.default)();
54
54
  const availableLocale = (0, react_1.useMemo)(() => allAvailableLocale.filter(locale => locale !== changedActiveNavigation?.localeCode), [changedActiveNavigation, allAvailableLocale]);
55
- const { i18nCopyItemsModal, i18nCopySourceLocale, setI18nCopyModalOpened, setI18nCopySourceLocale } = (0, I18nCopyNavigationItems_1.useI18nCopyNavigationItemsModal)((0, react_1.useCallback)((sourceLocale) => {
55
+ const { i18nCopyItemsModal, i18nCopySourceLocale, setI18nCopyModalOpened, setI18nCopySourceLocale } = (0, useI18nCopyNavigationItemsModal_1.useI18nCopyNavigationItemsModal)((0, react_1.useCallback)((sourceLocale) => {
56
56
  const source = activeNavigation?.localizations?.find(({ localeCode }) => localeCode === sourceLocale);
57
57
  if (source) {
58
58
  handleI18nCopy(source.id, activeNavigation?.id);
@@ -73,16 +73,17 @@ const View = () => {
73
73
  setActiveNavigationItemState(editedItem);
74
74
  handleChangeNavigationItemPopupVisibility(visible);
75
75
  };
76
- const addNewNavigationItem = (e, viewId = null, isMenuAllowedLevel = true, levelPath = '', parentAttachedToMenu = true) => {
77
- e.preventDefault();
78
- e.stopPropagation();
76
+ const addNewNavigationItem = (0, react_1.useCallback)((event, viewParentId = null, isMenuAllowedLevel = true, levelPath = '', parentAttachedToMenu = true, structureId = "0") => {
77
+ event.preventDefault();
78
+ event.stopPropagation();
79
79
  changeNavigationItemPopupState(true, {
80
- viewParentId: viewId,
80
+ viewParentId,
81
81
  isMenuAllowedLevel,
82
82
  levelPath,
83
83
  parentAttachedToMenu,
84
+ structureId,
84
85
  });
85
- };
86
+ }, [changeNavigationItemPopupState]);
86
87
  const usedContentTypesData = (0, react_1.useMemo)(() => changedActiveNavigation ? (0, parsers_1.usedContentTypes)(changedActiveNavigation.items) : [], [changedActiveNavigation]);
87
88
  const pullUsedContentTypeItem = (items = []) => items.reduce((prev, curr) => [...prev, curr.relatedRef ? {
88
89
  __collectionUid: curr.relatedRef.__collectionUid,
@@ -196,6 +197,7 @@ const View = () => {
196
197
  startIcon: react_1.default.createElement(Plus_1.default, null),
197
198
  disabled: isLoadingForSubmit,
198
199
  type: "submit",
200
+ variant: "default",
199
201
  tradId: 'header.action.newItem',
200
202
  margin: '16px',
201
203
  },
@@ -225,7 +227,7 @@ const View = () => {
225
227
  react_1.default.createElement(Button_1.Button, { variant: "tertiary", onClick: openI18nCopyModalOpened, disabled: !i18nCopySourceLocale, size: "S" }, formatMessage((0, translations_1.getTrad)('view.i18n.fill.cta.button'))))))) : null)),
226
228
  !(0, lodash_1.isEmpty)(changedActiveNavigation.items || [])
227
229
  && react_1.default.createElement(NavigationItemList_1.default, { items: isSearchEmpty ? changedActiveNavigation.items || [] : filteredList, onItemLevelAdd: addNewNavigationItem, onItemRemove: handleItemRemove, onItemEdit: handleItemEdit, onItemRestore: handleItemRestore, onItemReOrder: handleItemReOrder, onItemToggleCollapse: handleItemToggleCollapse, displayFlat: !isSearchEmpty, root: true, error: error, allowedLevels: config.allowedLevels, contentTypes: config.contentTypes, isParentAttachedToMenu: true, contentTypesNameFields: config.contentTypesNameFields })))),
228
- navigationItemPopupOpened && react_1.default.createElement(NavigationItemPopup_1.default, { isLoading: isLoadingForAdditionalDataToBeSet, data: activeNavigationItem, config: config, usedContentTypesData: usedContentTypesData, usedContentTypeItems: usedContentTypeItems, getContentTypeItems: getContentTypeItems, onSubmit: handleSubmitNavigationItem, onClose: onPopUpClose, locale: activeNavigation.localeCode }),
230
+ navigationItemPopupOpened && react_1.default.createElement(NavigationItemPopup_1.default, { availableLocale: availableLocale, isLoading: isLoadingForAdditionalDataToBeSet, data: activeNavigationItem, config: config, usedContentTypesData: usedContentTypesData, usedContentTypeItems: usedContentTypeItems, getContentTypeItems: getContentTypeItems, onSubmit: handleSubmitNavigationItem, onClose: onPopUpClose, locale: activeNavigation.localeCode, readNavigationItemFromLocale: readNavigationItemFromLocale }),
229
231
  i18nCopyItemsModal));
230
232
  };
231
233
  exports.default = (0, react_1.memo)(View);
@@ -9,6 +9,7 @@ export function transformItemToRESTPayload(item: any, parent?: undefined, master
9
9
  order: any;
10
10
  uiRouterKey: any;
11
11
  collapsed: any;
12
+ additionalFields: any;
12
13
  menuAttached: any;
13
14
  audience: any;
14
15
  path: any;
@@ -27,7 +28,12 @@ export function transformToRESTPayload(payload: any, config?: {}): {
27
28
  items: any;
28
29
  };
29
30
  export function transformItemToViewPayload(payload: any, items: any[] | undefined, config: any): any;
30
- export function prepareItemToViewPayload(items?: any[], viewParentId?: null, config?: {}): any;
31
+ export function prepareItemToViewPayload({ items, viewParentId, config, structureIdPrefix }: {
32
+ items?: any[] | undefined;
33
+ viewParentId?: null | undefined;
34
+ config?: {} | undefined;
35
+ structureIdPrefix?: string | undefined;
36
+ }): any;
31
37
  export function extractRelatedItemLabel(item?: {}, fields?: {}, config?: {}): any;
32
38
  export function usedContentTypes(items?: any[]): any;
33
39
  export function isRelationCorrect({ related, type }: {