strapi-plugin-navigation 2.1.0 → 2.2.0

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 (116) hide show
  1. package/README.md +17 -7
  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/Item/index.js +2 -3
  7. package/admin/src/components/RestartAlert/index.d.ts +1 -1
  8. package/admin/src/components/TextArrayInput/index.d.ts +14 -0
  9. package/admin/src/components/TextArrayInput/index.js +45 -0
  10. package/admin/src/hooks/useAllContentTypes.d.ts +1 -4
  11. package/admin/src/hooks/useAllContentTypes.js +3 -7
  12. package/admin/src/hooks/useNavigationConfig.d.ts +1 -1
  13. package/admin/src/hooks/useNavigationConfig.js +6 -6
  14. package/admin/src/pages/DataManagerProvider/index.d.ts +1 -1
  15. package/admin/src/pages/DataManagerProvider/index.js +9 -11
  16. package/admin/src/pages/SettingsPage/components/CustomFieldForm/index.d.ts +12 -0
  17. package/admin/src/pages/SettingsPage/components/CustomFieldForm/index.js +112 -0
  18. package/admin/src/pages/SettingsPage/components/CustomFieldModal/index.d.ts +12 -0
  19. package/admin/src/pages/SettingsPage/components/CustomFieldModal/index.js +20 -0
  20. package/admin/src/pages/SettingsPage/components/CustomFieldTable/index.d.ts +11 -0
  21. package/admin/src/pages/SettingsPage/components/CustomFieldTable/index.js +105 -0
  22. package/admin/src/pages/SettingsPage/index.d.ts +2 -1
  23. package/admin/src/pages/SettingsPage/index.js +109 -74
  24. package/admin/src/pages/SettingsPage/types.d.ts +32 -0
  25. package/admin/src/pages/SettingsPage/types.js +3 -0
  26. package/admin/src/pages/SettingsPage/utils/form.d.ts +18 -0
  27. package/admin/src/pages/SettingsPage/utils/form.js +34 -0
  28. package/admin/src/pages/SettingsPage/utils/functions.d.ts +2 -2
  29. package/admin/src/pages/SettingsPage/utils/functions.js +1 -1
  30. package/admin/src/pages/View/components/NavigationItemForm/index.d.ts +3 -55
  31. package/admin/src/pages/View/components/NavigationItemForm/index.js +162 -177
  32. package/admin/src/pages/View/components/NavigationItemForm/types.d.ts +90 -0
  33. package/admin/src/pages/View/components/NavigationItemForm/types.js +3 -0
  34. package/admin/src/pages/View/components/NavigationItemForm/utils/form.d.ts +24 -43
  35. package/admin/src/pages/View/components/NavigationItemForm/utils/form.js +78 -45
  36. package/admin/src/pages/View/components/NavigationItemPopup/index.js +1 -2
  37. package/admin/src/pages/View/components/NavigationManager/AllNavigations/icons.d.ts +4 -0
  38. package/admin/src/pages/View/components/NavigationManager/AllNavigations/icons.js +11 -0
  39. package/admin/src/pages/View/components/NavigationManager/AllNavigations/index.d.ts +9 -0
  40. package/admin/src/pages/View/components/NavigationManager/{List → AllNavigations}/index.js +32 -31
  41. package/admin/src/pages/View/components/NavigationManager/DeletionConfirm/index.d.ts +9 -0
  42. package/admin/src/pages/View/components/NavigationManager/{Delete → DeletionConfirm}/index.js +18 -12
  43. package/admin/src/pages/View/components/NavigationManager/ErrorDetails/index.d.ts +9 -0
  44. package/admin/src/pages/View/components/NavigationManager/{Error → ErrorDetails}/index.js +10 -10
  45. package/admin/src/pages/View/components/NavigationManager/Footer/index.d.ts +24 -0
  46. package/admin/src/pages/View/components/NavigationManager/Footer/index.js +13 -0
  47. package/admin/src/pages/View/components/NavigationManager/Form/index.d.ts +3 -2
  48. package/admin/src/pages/View/components/NavigationManager/Form/index.js +7 -2
  49. package/admin/src/pages/View/components/NavigationManager/NavigationUpdate/index.d.ts +9 -0
  50. package/admin/src/pages/View/components/NavigationManager/{Edit → NavigationUpdate}/index.js +16 -11
  51. package/admin/src/pages/View/components/NavigationManager/NewNavigation/index.d.ts +10 -0
  52. package/admin/src/pages/View/components/NavigationManager/{Create → NewNavigation}/index.js +16 -11
  53. package/admin/src/pages/View/components/NavigationManager/index.d.ts +3 -2
  54. package/admin/src/pages/View/components/NavigationManager/index.js +22 -21
  55. package/admin/src/pages/View/components/NavigationManager/types.d.ts +2 -15
  56. package/admin/src/pages/View/index.d.ts +1 -1
  57. package/admin/src/pages/View/index.js +1 -1
  58. package/admin/src/pages/View/utils/parsers.d.ts +1 -0
  59. package/admin/src/pages/View/utils/parsers.js +8 -7
  60. package/admin/src/translations/en.json +37 -0
  61. package/admin/src/translations/index.d.ts +2 -1
  62. package/admin/src/translations/index.js +1 -1
  63. package/admin/src/utils/api.d.ts +8 -7
  64. package/admin/src/utils/api.js +6 -41
  65. package/admin/src/utils/enums.d.ts +25 -0
  66. package/admin/src/utils/enums.js +30 -0
  67. package/admin/src/utils/functions.d.ts +16 -0
  68. package/admin/src/utils/functions.js +46 -0
  69. package/admin/src/utils/index.d.ts +3 -17
  70. package/admin/src/utils/index.js +16 -39
  71. package/package.json +5 -5
  72. package/server/config/index.js +6 -4
  73. package/server/config/setupStrategy.js +13 -1
  74. package/server/content-types/index.d.ts +5 -25
  75. package/server/content-types/navigation/index.d.ts +0 -7
  76. package/server/content-types/navigation/index.js +0 -2
  77. package/server/content-types/navigation-item/index.d.ts +5 -13
  78. package/server/content-types/navigation-item/index.js +0 -2
  79. package/server/content-types/navigation-item/schema.d.ts +5 -0
  80. package/server/content-types/navigation-item/schema.js +5 -0
  81. package/server/content-types/navigations-items-related/index.d.ts +0 -5
  82. package/server/content-types/navigations-items-related/index.js +0 -2
  83. package/server/controllers/admin.js +1 -1
  84. package/server/controllers/client.js +2 -1
  85. package/server/graphql/types/navigation-item.d.ts +2 -1
  86. package/server/graphql/types/navigation-item.js +26 -2
  87. package/server/index.d.ts +5 -25
  88. package/server/services/admin.js +26 -14
  89. package/server/services/client.js +64 -21
  90. package/server/services/common.js +25 -6
  91. package/server/utils/constant.d.ts +0 -3
  92. package/server/utils/constant.js +1 -2
  93. package/server/utils/functions.d.ts +12 -12
  94. package/server/utils/functions.js +60 -22
  95. package/strapi-server.d.ts +5 -25
  96. package/tsconfig.tsbuildinfo +1 -1
  97. package/types/config.d.ts +6 -2
  98. package/types/contentTypes.d.ts +22 -1
  99. package/types/services.d.ts +14 -5
  100. package/types/utils.d.ts +6 -1
  101. package/types/utils.js +15 -1
  102. package/admin/src/pages/View/components/NavigationManager/Create/index.d.ts +0 -9
  103. package/admin/src/pages/View/components/NavigationManager/Delete/index.d.ts +0 -8
  104. package/admin/src/pages/View/components/NavigationManager/Edit/index.d.ts +0 -8
  105. package/admin/src/pages/View/components/NavigationManager/Error/index.d.ts +0 -8
  106. package/admin/src/pages/View/components/NavigationManager/List/index.d.ts +0 -8
  107. package/admin/src/pages/View/utils/enums.d.ts +0 -9
  108. package/admin/src/pages/View/utils/enums.js +0 -12
  109. package/admin/src/utils/getTrad.d.ts +0 -3
  110. package/admin/src/utils/getTrad.js +0 -9
  111. package/server/content-types/navigation/lifecycle.d.ts +0 -9
  112. package/server/content-types/navigation/lifecycle.js +0 -10
  113. package/server/content-types/navigation-item/lifecycle.d.ts +0 -16
  114. package/server/content-types/navigation-item/lifecycle.js +0 -31
  115. package/server/content-types/navigations-items-related/lifecycle.d.ts +0 -8
  116. package/server/content-types/navigations-items-related/lifecycle.js +0 -22
package/README.md CHANGED
@@ -155,25 +155,38 @@ Config for this plugin is stored as a part of the `config/plugins.js` or `config
155
155
  navigation: {
156
156
  enabled: true,
157
157
  config: {
158
- additionalFields: ['audience'],
158
+ additionalFields: ['audience', { name: 'my_custom_field', type: 'boolean', label: 'My custom field' }],
159
159
  contentTypes: ['api::page.page'],
160
160
  contentTypesNameFields: {
161
161
  'api::page.page': ['title']
162
162
  },
163
163
  allowedLevels: 2,
164
164
  gql: {...},
165
+ slugify: {
166
+ customReplacements: [
167
+ ["🤔", "thinking"],
168
+ ],
169
+ }
165
170
  }
166
171
  }
167
172
  });
168
173
  ```
169
174
 
170
175
  ### Properties
171
- - `additionalFields` - Additional fields: 'audience', more in the future
176
+ - `additionalFields` - Additional fields for navigation items. More **[ here ](#additional-fields)**
172
177
  - `allowedLevels` - Maximum level for which you're able to mark item as "Menu attached"
173
178
  - `contentTypes` - UIDs of related content types
174
179
  - `contentTypesNameFields` - Definition of content type title fields like `'api::<collection name>.<content type name>': ['field_name_1', 'field_name_2']`, if not set titles are pulled from fields like `['title', 'subject', 'name']`. **TIP** - Proper content type uid you can find in the URL of Content Manager where you're managing relevant entities like: `admin/content-manager/collectionType/< THE UID HERE >?page=1&pageSize=10&sort=Title:ASC&plugins[i18n][locale]=en`
175
180
  - `gql` - If you're using GraphQL that's the right place to put all necessary settings. More **[ here ](#gql-configuration)**
176
181
  - `i18nEnabled` - should you want to manage multi-locale content via navigation set this value `Enabled`. More **[ here ](#i18n-internationalization)**
182
+ - `slugify` - allows to extend configuration of our "slugging" solution of choice. To learn more visit the [documentation](https://github.com/sindresorhus/slugify#api). It can be left unset since it's optional. **This option can only be handled by configuration in config file**.
183
+
184
+ ### Properties
185
+
186
+ ### Additional Fields
187
+ It is advised to configure additional fields through the plugin's Settings Page. There you can find the table of custom fields and toggle input for the audience field. When enabled, the audience field can be customized through the content manager. Custom fields can be added, edited, toggled, and removed with the use of the table provided on the Settings Page. When removing custom fields be advised that their values in navigation items will be lost. Disabling the custom fields will not affect the data and can be done with no consequence of loosing information.
188
+
189
+ Creating configuration for additional fields with the `config.js` file should be done with caution. Config object contains the `additionalFields` property of type `Array<CustomField | 'audience'>`, where CustomField is of type `{type: 'string' | 'boolean', name: string, label: string}`. When creating custom fields be advised that the `name` property has to be unique. When editing a custom field it is advised not to edit its `name` and `type` properties. After config has been restored the custom fields that are not present in `config.js` file will be deleted and their values in navigation items will be lost.
177
190
 
178
191
  ## 🔧 GQL Configuration
179
192
  Using navigation with GraphQL requires both plugins to be installed and working. You can find installation guide for GraphQL plugin **[here](https://docs.strapi.io/developer-docs/latest/plugins/graphql.html#graphql)**. To properly configure GQL to work with navigation you should provide `gql` prop. This should contain union types that will be used to define GQL response format for your data while fetching:
@@ -579,11 +592,8 @@ query {
579
592
  "title": "Another page",
580
593
  "path": "/another",
581
594
  "related": {
582
- "id": 2,
583
- "attributes": {
584
- "__typename": "Page",
585
- "Title": "dfdfdf"
586
- }
595
+ "__typename": "Page",
596
+ "Title": "Eg. Page title"
587
597
  },
588
598
  "items": []
589
599
  }
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { AdditionalFieldInputProps } from './types';
3
+ declare const AdditionalFieldInput: React.FC<AdditionalFieldInputProps>;
4
+ export default AdditionalFieldInput;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,71 @@
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
+ const react_1 = __importStar(require("react"));
27
+ const types_1 = require("../../../../types");
28
+ const ToggleInput_1 = require("@strapi/design-system/ToggleInput");
29
+ const TextInput_1 = require("@strapi/design-system/TextInput");
30
+ const Select_1 = require("@strapi/design-system/Select");
31
+ const helper_plugin_1 = require("@strapi/helper-plugin");
32
+ const translations_1 = require("../../translations");
33
+ const lodash_1 = require("lodash");
34
+ const react_intl_1 = require("react-intl");
35
+ const DEFAULT_STRING_VALUE = "";
36
+ const handlerFactory = ({ field, prop, onChange }) => ({ target }) => {
37
+ onChange(field.name, target[prop]);
38
+ };
39
+ const AdditionalFieldInput = ({ field, isLoading, onChange, value, error }) => {
40
+ const toggleNotification = (0, helper_plugin_1.useNotification)();
41
+ const { formatMessage } = (0, react_intl_1.useIntl)();
42
+ const defaultInputProps = (0, react_1.useMemo)(() => ({
43
+ id: field.name,
44
+ name: field.name,
45
+ label: field.label,
46
+ disabled: isLoading,
47
+ error: error && formatMessage(error),
48
+ }), [field, isLoading, error]);
49
+ const handleBoolean = (0, react_1.useMemo)(() => handlerFactory({ field, onChange, prop: "checked" }), [onChange, field]);
50
+ const handleString = (0, react_1.useMemo)(() => handlerFactory({ field, onChange, prop: "value" }), [onChange, field]);
51
+ switch (field.type) {
52
+ case 'boolean':
53
+ if (!(0, lodash_1.isNil)(value))
54
+ (0, types_1.assertBoolean)(value);
55
+ return (react_1.default.createElement(ToggleInput_1.ToggleInput, { ...defaultInputProps, checked: !!value, onChange: handleBoolean, onLabel: "true", offLabel: "false" }));
56
+ case 'string':
57
+ if (!(0, lodash_1.isNil)(value))
58
+ (0, types_1.assertString)(value);
59
+ return (react_1.default.createElement(TextInput_1.TextInput, { ...defaultInputProps, onChange: handleString, value: value || DEFAULT_STRING_VALUE }));
60
+ case 'select':
61
+ return (react_1.default.createElement(Select_1.Select, { ...defaultInputProps, onChange: (v) => onChange(field.name, v), value: (0, lodash_1.isNil)(value) ? field.multi ? [] : null : value, multi: field.multi, withTags: field.multi }, field.options.map((option, index) => (react_1.default.createElement(Select_1.Option, { key: `${field.name}-option-${index}`, value: option }, option)))));
62
+ default:
63
+ toggleNotification({
64
+ type: 'warning',
65
+ message: (0, translations_1.getTrad)('notification.error.customField.type'),
66
+ });
67
+ throw new Error(`Type of custom field is unsupported`);
68
+ }
69
+ };
70
+ exports.default = AdditionalFieldInput;
71
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,14 @@
1
+ import { MessageDescriptor } from "react-intl";
2
+ import { NavigationItemCustomField } from "../../../../types";
3
+ export declare type AdditionalFieldInputProps = {
4
+ field: NavigationItemCustomField;
5
+ isLoading: boolean;
6
+ onChange: (name: string, value: string) => void;
7
+ value: string | boolean | string[] | null;
8
+ error: MessageDescriptor | null;
9
+ };
10
+ export declare type TargetProp = "value" | "checked";
11
+ export declare type Input = {
12
+ prop: TargetProp;
13
+ } & Pick<AdditionalFieldInputProps, "onChange" | "field">;
14
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -37,7 +37,6 @@ const Link_1 = require("@strapi/design-system/Link");
37
37
  const TextButton_1 = require("@strapi/design-system/TextButton");
38
38
  const Typography_1 = require("@strapi/design-system/Typography");
39
39
  const icons_1 = require("@strapi/icons");
40
- const enums_1 = require("../../pages/View/utils/enums");
41
40
  const ItemCardHeader_1 = __importDefault(require("./ItemCardHeader"));
42
41
  const NavigationItemList_1 = __importDefault(require("../NavigationItemList"));
43
42
  const Wrapper_1 = __importDefault(require("./Wrapper"));
@@ -50,8 +49,8 @@ const Item = (props) => {
50
49
  const { item, isLast = false, level = 0, levelPath = '', allowedLevels, relatedRef, isParentAttachedToMenu, onItemLevelAdd, onItemRemove, onItemRestore, onItemEdit, onItemReOrder, onItemToggleCollapse, error, displayChildren, config = {}, } = props;
51
50
  const { viewId, title, type, path, removed, externalPath, menuAttached, collapsed, structureId, items = [], } = item;
52
51
  const { contentTypes = [], contentTypesNameFields } = config;
53
- const isExternal = type === enums_1.navigationItemType.EXTERNAL;
54
- const isWrapper = type === enums_1.navigationItemType.WRAPPER;
52
+ const isExternal = type === utils_1.navigationItemType.EXTERNAL;
53
+ const isWrapper = type === utils_1.navigationItemType.WRAPPER;
55
54
  const isHandledByPublishFlow = contentTypes.find(_ => _.uid === relatedRef?.__collectionUid)?.draftAndPublish;
56
55
  const isPublished = isHandledByPublishFlow && relatedRef.publishedAt;
57
56
  const isNextMenuAllowedLevel = (0, lodash_1.isNumber)(allowedLevels) ? level < (allowedLevels - 1) : true;
@@ -1,3 +1,3 @@
1
- declare var _default: any;
1
+ declare const _default: any;
2
2
  export default _default;
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { Effect } from '../../../../types';
3
+ interface IProps {
4
+ onChange: Effect<string[]>;
5
+ initialValue?: string[];
6
+ id?: string;
7
+ name?: string;
8
+ label?: string;
9
+ disabled?: boolean;
10
+ error?: string | string[];
11
+ }
12
+ declare const TextArrayInput: React.FC<IProps>;
13
+ export default TextArrayInput;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,45 @@
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
+ const react_1 = __importStar(require("react"));
27
+ const TextInput_1 = require("@strapi/design-system/TextInput");
28
+ const lodash_1 = require("lodash");
29
+ const TextArrayInput = ({ onChange, initialValue, ...props }) => {
30
+ const [value, setValue] = (0, react_1.useState)((0, lodash_1.isArray)(initialValue)
31
+ ? initialValue.reduce((acc, cur) => `${acc}${cur}; `, "")
32
+ : "");
33
+ const handleOnChange = ({ target: { value } }) => {
34
+ const newValue = value;
35
+ const valuesArray = newValue
36
+ .split(';')
37
+ .map(v => v.trim())
38
+ .filter(v => !!v.length);
39
+ setValue(value);
40
+ onChange(valuesArray);
41
+ };
42
+ return (react_1.default.createElement(TextInput_1.TextInput, { ...props, onChange: handleOnChange, value: value }));
43
+ };
44
+ exports.default = TextArrayInput;
45
+ //# sourceMappingURL=index.js.map
@@ -1,6 +1,3 @@
1
+ declare const useAllContentTypes: () => Pick<any, "data" | "isLoading" | "error">;
1
2
  export default useAllContentTypes;
2
- declare function useAllContentTypes(): {
3
- data: any;
4
- isLoading: any;
5
- };
6
3
  //# sourceMappingURL=useAllContentTypes.d.ts.map
@@ -1,12 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const react_query_1 = require("react-query");
4
- const helper_plugin_1 = require("@strapi/helper-plugin");
5
- const api_1 = require("../utils/api");
6
- const useAllContentTypes = () => {
7
- const toggleNotification = (0, helper_plugin_1.useNotification)();
8
- const { isLoading, data } = (0, react_query_1.useQuery)('contentTypes', () => (0, api_1.fetchAllContentTypes)(toggleNotification));
9
- return { data, isLoading, };
10
- };
4
+ const lodash_1 = require("lodash");
5
+ const utils_1 = require("../utils");
6
+ const useAllContentTypes = () => (0, lodash_1.pick)((0, react_query_1.useQuery)('contentTypes', () => (0, utils_1.fetchAllContentTypes)()), ["data", "isLoading", "error"]);
11
7
  exports.default = useAllContentTypes;
12
8
  //# sourceMappingURL=useAllContentTypes.js.map
@@ -2,7 +2,7 @@ export default useNavigationConfig;
2
2
  declare function useNavigationConfig(): {
3
3
  data: any;
4
4
  isLoading: any;
5
- err: any;
5
+ error: any;
6
6
  submitMutation: (...args: any[]) => Promise<void>;
7
7
  restoreMutation: (...args: any[]) => Promise<void>;
8
8
  restartMutation: (...args: any[]) => Promise<void>;
@@ -2,12 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const react_query_1 = require("react-query");
4
4
  const helper_plugin_1 = require("@strapi/helper-plugin");
5
- const api_1 = require("../utils/api");
5
+ const utils_1 = require("../utils");
6
6
  const translations_1 = require("../translations");
7
7
  const useNavigationConfig = () => {
8
8
  const queryClient = (0, react_query_1.useQueryClient)();
9
9
  const toggleNotification = (0, helper_plugin_1.useNotification)();
10
- const { isLoading, data, err } = (0, react_query_1.useQuery)('navigationConfig', () => (0, api_1.fetchNavigationConfig)(toggleNotification));
10
+ const { isLoading, data, error } = (0, react_query_1.useQuery)('navigationConfig', () => (0, utils_1.fetchNavigationConfig)(toggleNotification));
11
11
  const handleError = (type) => {
12
12
  toggleNotification({
13
13
  type: 'warning',
@@ -23,7 +23,7 @@ const useNavigationConfig = () => {
23
23
  };
24
24
  const submitMutation = async (...args) => {
25
25
  try {
26
- await (0, api_1.updateNavigationConfig)(...args);
26
+ await (0, utils_1.updateNavigationConfig)(...args);
27
27
  await handleSuccess('submit');
28
28
  }
29
29
  catch (e) {
@@ -32,7 +32,7 @@ const useNavigationConfig = () => {
32
32
  };
33
33
  const restoreMutation = async (...args) => {
34
34
  try {
35
- await (0, api_1.restoreNavigationConfig)(...args);
35
+ await (0, utils_1.restoreNavigationConfig)(...args);
36
36
  await handleSuccess('restore');
37
37
  }
38
38
  catch (e) {
@@ -41,14 +41,14 @@ const useNavigationConfig = () => {
41
41
  };
42
42
  const restartMutation = async (...args) => {
43
43
  try {
44
- await (0, api_1.restartStrapi)(...args);
44
+ await (0, utils_1.restartStrapi)(...args);
45
45
  await handleSuccess('restart');
46
46
  }
47
47
  catch (e) {
48
48
  handleError('restart');
49
49
  }
50
50
  };
51
- return { data, isLoading, err, submitMutation, restoreMutation, restartMutation };
51
+ return { data, isLoading, error, submitMutation, restoreMutation, restartMutation };
52
52
  };
53
53
  exports.default = useNavigationConfig;
54
54
  //# sourceMappingURL=useNavigationConfig.js.map
@@ -1,4 +1,4 @@
1
- declare var _default: React.MemoExoticComponent<{
1
+ declare const _default: React.MemoExoticComponent<{
2
2
  ({ children }: {
3
3
  children: any;
4
4
  }): JSX.Element;
@@ -33,9 +33,9 @@ const prop_types_1 = __importDefault(require("prop-types"));
33
33
  const lodash_1 = require("lodash");
34
34
  const helper_plugin_1 = require("@strapi/helper-plugin");
35
35
  const DataManagerContext_1 = __importDefault(require("../../contexts/DataManagerContext"));
36
- const getTrad_1 = __importDefault(require("../../utils/getTrad"));
37
36
  const pluginId_1 = __importDefault(require("../../pluginId"));
38
37
  const init_1 = __importDefault(require("./init"));
38
+ const translations_1 = require("../../translations");
39
39
  const reducer_1 = __importStar(require("./reducer"));
40
40
  const actions_1 = require("./actions");
41
41
  const parsers_1 = require("../View/utils/parsers");
@@ -87,7 +87,7 @@ const DataManagerProvider = ({ children }) => {
87
87
  console.error({ err });
88
88
  toggleNotification({
89
89
  type: 'warning',
90
- message: { id: (0, getTrad_1.default)('notification.error') },
90
+ message: (0, translations_1.getTrad)('notification.error'),
91
91
  });
92
92
  }
93
93
  };
@@ -123,7 +123,7 @@ const DataManagerProvider = ({ children }) => {
123
123
  console.error({ err });
124
124
  toggleNotification({
125
125
  type: 'warning',
126
- message: { id: (0, getTrad_1.default)('notification.error') },
126
+ message: (0, translations_1.getTrad)('notification.error'),
127
127
  });
128
128
  }
129
129
  };
@@ -139,7 +139,7 @@ const DataManagerProvider = ({ children }) => {
139
139
  if (!autoReload) {
140
140
  toggleNotification({
141
141
  type: 'info',
142
- message: { id: (0, getTrad_1.default)('notification.info.autoreaload-disable') },
142
+ message: { id: 'notification.info.autoreaload-disable' },
143
143
  });
144
144
  }
145
145
  }, [autoReload]);
@@ -259,7 +259,7 @@ const DataManagerProvider = ({ children }) => {
259
259
  });
260
260
  toggleNotification({
261
261
  type: 'success',
262
- message: { id: (0, getTrad_1.default)('notification.navigation.submit') },
262
+ message: (0, translations_1.getTrad)('notification.navigation.submit'),
263
263
  });
264
264
  }
265
265
  catch (err) {
@@ -272,24 +272,22 @@ const DataManagerProvider = ({ children }) => {
272
272
  return toggleNotification({
273
273
  type: 'warning',
274
274
  message: {
275
- id: formatMessage((0, getTrad_1.default)('notification.navigation.error'), { ...err.response.payload.data, errorTitles: err.response.payload.data.errorTitles.join(' and ') })
275
+ id: formatMessage((0, translations_1.getTrad)('notification.navigation.error'), { ...err.response.payload.data, errorTitles: err.response.payload.data.errorTitles.join(' and ') })
276
276
  },
277
277
  });
278
278
  }
279
279
  toggleNotification({
280
280
  type: 'warning',
281
- message: { id: (0, getTrad_1.default)('notification.error') },
281
+ message: (0, translations_1.getTrad)('notification.error'),
282
282
  });
283
283
  }
284
284
  };
285
- const handleNavigationsDeletion = async (ids) => Promise.all(ids.map((id) => handleNavigationDeletion(id)));
285
+ const handleNavigationsDeletion = (ids) => Promise.all(ids.map(handleNavigationDeletion));
286
286
  const handleNavigationDeletion = (id) => (0, helper_plugin_1.request)(`/${pluginId_1.default}/${id}`, {
287
287
  method: "DELETE",
288
288
  signal,
289
289
  });
290
- const hardReset = () => {
291
- return getDataRef.current();
292
- };
290
+ const hardReset = () => getDataRef.current();
293
291
  return (react_1.default.createElement(DataManagerContext_1.default.Provider, { value: {
294
292
  items: passedActiveItems,
295
293
  activeItem,
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { Effect, NavigationItemCustomField, VoidEffect } from '../../../../../../types';
3
+ interface ICustomFieldFormProps {
4
+ customField: Partial<NavigationItemCustomField>;
5
+ isEditForm: boolean;
6
+ onSubmit: Effect<NavigationItemCustomField>;
7
+ onClose: VoidEffect;
8
+ usedCustomFieldNames: string[];
9
+ }
10
+ declare const CustomFieldForm: React.FC<ICustomFieldFormProps>;
11
+ export default CustomFieldForm;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,112 @@
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 ModalLayout_1 = require("@strapi/design-system/ModalLayout");
31
+ const Button_1 = require("@strapi/design-system/Button");
32
+ const helper_plugin_1 = require("@strapi/helper-plugin");
33
+ const Grid_1 = require("@strapi/design-system/Grid");
34
+ const formik_1 = require("formik");
35
+ const formDefinition = __importStar(require("../../utils/form"));
36
+ const utils_1 = require("../../../../utils");
37
+ const lodash_1 = require("lodash");
38
+ const translations_1 = require("../../../../translations");
39
+ const TextArrayInput_1 = __importDefault(require("../../../../components/TextArrayInput"));
40
+ const tradPrefix = 'pages.settings.form.customFields.popup.';
41
+ const customFieldsTypes = ["string", "boolean", "select"];
42
+ const prepareSelectOptions = (options) => options.map((option, index) => ({
43
+ key: index,
44
+ metadatas: {
45
+ intlLabel: {
46
+ id: option,
47
+ defaultMessage: option,
48
+ }
49
+ },
50
+ value: option,
51
+ label: option,
52
+ }));
53
+ const CustomFieldForm = ({ isEditForm, customField, onSubmit, onClose, usedCustomFieldNames }) => {
54
+ const typeSelectOptions = prepareSelectOptions(customFieldsTypes);
55
+ const initialValues = (0, react_1.useMemo)(() => {
56
+ if ((0, lodash_1.isNil)(customField.type)) {
57
+ return formDefinition.defaultValues;
58
+ }
59
+ else if (customField.type === 'select') {
60
+ return {
61
+ type: customField.type,
62
+ name: customField.name || formDefinition.defaultValues.name,
63
+ label: customField.label || formDefinition.defaultValues.label,
64
+ required: customField.required || formDefinition.defaultValues.required,
65
+ options: customField.options || formDefinition.defaultValues.options,
66
+ multi: customField.multi || formDefinition.defaultValues.multi,
67
+ };
68
+ }
69
+ else {
70
+ return {
71
+ type: customField.type,
72
+ name: customField.name || formDefinition.defaultValues.name,
73
+ label: customField.label || formDefinition.defaultValues.label,
74
+ required: customField.required || formDefinition.defaultValues.required,
75
+ options: [],
76
+ multi: false,
77
+ };
78
+ }
79
+ }, [customField]);
80
+ const { handleChange, setFieldValue, values, errors, handleSubmit, isSubmitting, } = (0, formik_1.useFormik)({
81
+ initialValues,
82
+ onSubmit,
83
+ validationSchema: formDefinition.schemaFactory(usedCustomFieldNames),
84
+ validateOnChange: false,
85
+ });
86
+ const defaultProps = (0, react_1.useCallback)((fieldName) => ({
87
+ intlLabel: (0, translations_1.getTrad)(`${tradPrefix}${fieldName}.label`),
88
+ onChange: handleChange,
89
+ name: fieldName,
90
+ value: values[fieldName],
91
+ error: errors[fieldName],
92
+ }), [values, errors, handleChange]);
93
+ return (react_1.default.createElement("form", null,
94
+ react_1.default.createElement(ModalLayout_1.ModalBody, null,
95
+ react_1.default.createElement(Grid_1.Grid, { gap: 5 },
96
+ react_1.default.createElement(Grid_1.GridItem, { key: "name", col: 12 },
97
+ react_1.default.createElement(helper_plugin_1.GenericInput, { ...defaultProps("name"), autoFocused: true, placeholder: (0, translations_1.getTrad)(`${tradPrefix}name.placeholder`), description: (0, translations_1.getTrad)(`${tradPrefix}name.description`), type: "text", disabled: isEditForm })),
98
+ react_1.default.createElement(Grid_1.GridItem, { key: "label", col: 12 },
99
+ react_1.default.createElement(helper_plugin_1.GenericInput, { ...defaultProps("label"), placeholder: (0, translations_1.getTrad)(`${tradPrefix}label.placeholder`), description: (0, translations_1.getTrad)(`${tradPrefix}label.description`), type: "text" })),
100
+ react_1.default.createElement(Grid_1.GridItem, { key: "type", col: 12 },
101
+ react_1.default.createElement(helper_plugin_1.GenericInput, { ...defaultProps("type"), options: typeSelectOptions, type: "select", disabled: isEditForm })),
102
+ values.type === 'select' && (react_1.default.createElement(react_1.default.Fragment, null,
103
+ react_1.default.createElement(Grid_1.GridItem, { key: "multi", col: 12 },
104
+ react_1.default.createElement(helper_plugin_1.GenericInput, { ...defaultProps("multi"), type: "bool" })),
105
+ react_1.default.createElement(Grid_1.GridItem, { key: "options", col: 12 },
106
+ react_1.default.createElement(TextArrayInput_1.default, { ...defaultProps("options"), onChange: v => setFieldValue("options", v), label: (0, utils_1.getMessage)(`${tradPrefix}options.label`), initialValue: values.options })))),
107
+ react_1.default.createElement(Grid_1.GridItem, { key: "required", col: 12 },
108
+ react_1.default.createElement(helper_plugin_1.GenericInput, { ...defaultProps("required"), type: "bool", description: (0, translations_1.getTrad)(`${tradPrefix}required.description`) })))),
109
+ react_1.default.createElement(ModalLayout_1.ModalFooter, { startActions: react_1.default.createElement(Button_1.Button, { onClick: onClose, variant: "tertiary" }, (0, utils_1.getMessage)('popup.item.form.button.cancel')), endActions: react_1.default.createElement(Button_1.Button, { onClick: handleSubmit, disabled: !(0, lodash_1.isEmpty)(errors) || isSubmitting }, (0, utils_1.getMessage)(`popup.item.form.button.save`)) })));
110
+ };
111
+ exports.default = CustomFieldForm;
112
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { Effect, NavigationItemCustomField, VoidEffect } from '../../../../../../types';
3
+ interface ICustomFieldModalProps {
4
+ data: NavigationItemCustomField | null;
5
+ isOpen: boolean;
6
+ onClose: VoidEffect;
7
+ onSubmit: Effect<NavigationItemCustomField>;
8
+ usedCustomFieldNames: string[];
9
+ }
10
+ declare const CustomFieldModal: React.FC<ICustomFieldModalProps>;
11
+ export default CustomFieldModal;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const react_1 = __importDefault(require("react"));
7
+ const Typography_1 = require("@strapi/design-system/Typography");
8
+ const ModalLayout_1 = require("@strapi/design-system/ModalLayout");
9
+ const CustomFieldForm_1 = __importDefault(require("../CustomFieldForm"));
10
+ const utils_1 = require("../../../../utils");
11
+ const lodash_1 = require("lodash");
12
+ const CustomFieldModal = ({ isOpen, onClose, onSubmit, data, usedCustomFieldNames, }) => {
13
+ const isEditMode = !!data;
14
+ return (react_1.default.createElement(ModalLayout_1.ModalLayout, { onClose: onClose, isOpen: isOpen, labelledBy: "custom-field-modal" },
15
+ react_1.default.createElement(ModalLayout_1.ModalHeader, null,
16
+ react_1.default.createElement(Typography_1.Typography, { variant: "omega", fontWeight: "bold", textColor: "neutral800", as: "h2", id: "asset-dialog-title" }, (0, utils_1.getMessage)(`pages.settings.form.customFields.popup.header.${isEditMode ? 'edit' : 'new'}`))),
17
+ react_1.default.createElement(CustomFieldForm_1.default, { isEditForm: isEditMode, customField: (0, lodash_1.pick)(data, "name", "label", "type", "required", "options", "multi"), onSubmit: onSubmit, onClose: onClose, usedCustomFieldNames: usedCustomFieldNames })));
18
+ };
19
+ exports.default = CustomFieldModal;
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { Effect, NavigationItemCustomField } from '../../../../../../types';
3
+ interface ICustomFieldTableProps {
4
+ data: NavigationItemCustomField[];
5
+ onOpenModal: (field: NavigationItemCustomField | null) => void;
6
+ onRemoveCustomField: Effect<NavigationItemCustomField>;
7
+ onToggleCustomField: Effect<NavigationItemCustomField>;
8
+ }
9
+ declare const CustomFieldTable: React.FC<ICustomFieldTableProps>;
10
+ export default CustomFieldTable;
11
+ //# sourceMappingURL=index.d.ts.map