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.
- package/README.md +20 -10
- package/admin/src/components/AdditionalFieldInput/index.d.ts +5 -0
- package/admin/src/components/AdditionalFieldInput/index.js +71 -0
- package/admin/src/components/AdditionalFieldInput/types.d.ts +14 -0
- package/admin/src/components/AdditionalFieldInput/types.js +3 -0
- package/admin/src/components/DragButton/index.d.ts +4 -0
- package/admin/src/components/DragButton/index.js +61 -0
- package/admin/src/components/Item/ItemCardHeader/Wrapper.d.ts +1 -1
- package/admin/src/components/Item/ItemCardHeader/icons.d.ts +5 -0
- package/admin/src/components/Item/ItemCardHeader/icons.js +12 -0
- package/admin/src/components/Item/ItemCardHeader/index.d.ts +13 -10
- package/admin/src/components/Item/ItemCardHeader/index.js +17 -38
- package/admin/src/components/Item/index.js +6 -6
- package/admin/src/components/RestartAlert/index.d.ts +1 -1
- package/admin/src/components/TextArrayInput/index.d.ts +14 -0
- package/admin/src/components/TextArrayInput/index.js +45 -0
- package/admin/src/hooks/useAllContentTypes.d.ts +1 -4
- package/admin/src/hooks/useAllContentTypes.js +3 -7
- package/admin/src/hooks/useI18nCopyNavigationItemsModal.d.ts +9 -0
- package/admin/src/hooks/useI18nCopyNavigationItemsModal.js +51 -0
- package/admin/src/hooks/useNavigationConfig.d.ts +1 -1
- package/admin/src/hooks/useNavigationConfig.js +6 -6
- package/admin/src/hooks/useNavigationManager.d.ts +7 -0
- package/admin/src/hooks/useNavigationManager.js +41 -0
- package/admin/src/pages/DataManagerProvider/index.d.ts +1 -1
- package/admin/src/pages/DataManagerProvider/index.js +46 -10
- package/admin/src/pages/SettingsPage/components/CustomFieldForm/index.d.ts +12 -0
- package/admin/src/pages/SettingsPage/components/CustomFieldForm/index.js +112 -0
- package/admin/src/pages/SettingsPage/components/CustomFieldModal/index.d.ts +12 -0
- package/admin/src/pages/SettingsPage/components/CustomFieldModal/index.js +20 -0
- package/admin/src/pages/SettingsPage/components/CustomFieldTable/index.d.ts +11 -0
- package/admin/src/pages/SettingsPage/components/CustomFieldTable/index.js +105 -0
- package/admin/src/pages/SettingsPage/index.d.ts +2 -1
- package/admin/src/pages/SettingsPage/index.js +111 -75
- package/admin/src/pages/SettingsPage/types.d.ts +32 -0
- package/admin/src/pages/SettingsPage/types.js +3 -0
- package/admin/src/pages/SettingsPage/utils/form.d.ts +18 -0
- package/admin/src/pages/SettingsPage/utils/form.js +34 -0
- package/admin/src/pages/SettingsPage/utils/functions.d.ts +2 -2
- package/admin/src/pages/SettingsPage/utils/functions.js +1 -1
- package/admin/src/pages/View/components/I18nCopyNavigationItems/index.d.ts +3 -9
- package/admin/src/pages/View/components/I18nCopyNavigationItems/index.js +2 -47
- package/admin/src/pages/View/components/NavigationHeader/index.js +11 -6
- package/admin/src/pages/View/components/NavigationItemForm/index.d.ts +3 -49
- package/admin/src/pages/View/components/NavigationItemForm/index.js +219 -152
- package/admin/src/pages/View/components/NavigationItemForm/types.d.ts +90 -0
- package/admin/src/pages/View/components/NavigationItemForm/types.js +3 -0
- package/admin/src/pages/View/components/NavigationItemForm/utils/form.d.ts +24 -43
- package/admin/src/pages/View/components/NavigationItemForm/utils/form.js +84 -48
- package/admin/src/pages/View/components/NavigationItemPopup/index.d.ts +4 -1
- package/admin/src/pages/View/components/NavigationItemPopup/index.js +32 -7
- package/admin/src/pages/View/components/NavigationManager/AllNavigations/icons.d.ts +4 -0
- package/admin/src/pages/View/components/NavigationManager/AllNavigations/icons.js +11 -0
- package/admin/src/pages/View/components/NavigationManager/AllNavigations/index.d.ts +9 -0
- package/admin/src/pages/View/components/NavigationManager/AllNavigations/index.js +139 -0
- package/admin/src/pages/View/components/NavigationManager/DeletionConfirm/index.d.ts +9 -0
- package/admin/src/pages/View/components/NavigationManager/DeletionConfirm/index.js +34 -0
- package/admin/src/pages/View/components/NavigationManager/ErrorDetails/index.d.ts +9 -0
- package/admin/src/pages/View/components/NavigationManager/ErrorDetails/index.js +53 -0
- package/admin/src/pages/View/components/NavigationManager/Footer/index.d.ts +24 -0
- package/admin/src/pages/View/components/NavigationManager/Footer/index.js +13 -0
- package/admin/src/pages/View/components/NavigationManager/Form/index.d.ts +20 -0
- package/admin/src/pages/View/components/NavigationManager/Form/index.js +103 -0
- package/admin/src/pages/View/components/NavigationManager/NavigationUpdate/index.d.ts +9 -0
- package/admin/src/pages/View/components/NavigationManager/NavigationUpdate/index.js +59 -0
- package/admin/src/pages/View/components/NavigationManager/NewNavigation/index.d.ts +10 -0
- package/admin/src/pages/View/components/NavigationManager/NewNavigation/index.js +62 -0
- package/admin/src/pages/View/components/NavigationManager/index.d.ts +11 -0
- package/admin/src/pages/View/components/NavigationManager/index.js +190 -0
- package/admin/src/pages/View/components/NavigationManager/types.d.ts +40 -0
- package/admin/src/pages/View/components/NavigationManager/types.js +3 -0
- package/admin/src/pages/View/index.d.ts +1 -1
- package/admin/src/pages/View/index.js +11 -9
- package/admin/src/pages/View/utils/parsers.d.ts +7 -1
- package/admin/src/pages/View/utils/parsers.js +21 -10
- package/admin/src/translations/en.json +68 -0
- package/admin/src/translations/index.d.ts +2 -1
- package/admin/src/translations/index.js +1 -1
- package/admin/src/utils/api.d.ts +8 -7
- package/admin/src/utils/api.js +6 -41
- package/admin/src/utils/enums.d.ts +25 -0
- package/admin/src/utils/enums.js +30 -0
- package/admin/src/utils/functions.d.ts +16 -0
- package/admin/src/utils/functions.js +46 -0
- package/admin/src/utils/index.d.ts +3 -4
- package/admin/src/utils/index.js +16 -24
- package/package.json +6 -7
- package/server/config/index.js +6 -4
- package/server/config/setupStrategy.js +13 -1
- package/server/content-types/index.d.ts +5 -25
- package/server/content-types/navigation/index.d.ts +0 -7
- package/server/content-types/navigation/index.js +0 -2
- package/server/content-types/navigation/schema.js +1 -1
- package/server/content-types/navigation-item/index.d.ts +5 -13
- package/server/content-types/navigation-item/index.js +0 -2
- package/server/content-types/navigation-item/schema.d.ts +5 -0
- package/server/content-types/navigation-item/schema.js +5 -0
- package/server/content-types/navigations-items-related/index.d.ts +0 -5
- package/server/content-types/navigations-items-related/index.js +0 -2
- package/server/controllers/admin.js +67 -14
- package/server/controllers/client.js +43 -19
- package/server/graphql/types/navigation-item.d.ts +2 -1
- package/server/graphql/types/navigation-item.js +26 -2
- package/server/i18n/serviceEnhancers.d.ts +2 -1
- package/server/i18n/serviceEnhancers.js +45 -6
- package/server/i18n/types.d.ts +6 -0
- package/server/index.d.ts +5 -25
- package/server/navigation/setupStrategy.js +3 -1
- package/server/routes/admin.js +10 -0
- package/server/services/admin.js +104 -37
- package/server/services/client.js +64 -21
- package/server/services/common.js +26 -7
- package/server/utils/constant.d.ts +0 -3
- package/server/utils/constant.js +1 -2
- package/server/utils/functions.d.ts +13 -12
- package/server/utils/functions.js +62 -22
- package/strapi-server.d.ts +5 -25
- package/tsconfig.tsbuildinfo +1 -1
- package/types/config.d.ts +6 -2
- package/types/contentTypes.d.ts +22 -1
- package/types/controllers.d.ts +21 -8
- package/types/services.d.ts +20 -5
- package/types/utils.d.ts +10 -1
- package/types/utils.js +18 -3
- package/utils/InvalidParamNavigationError.js +0 -3
- package/admin/src/pages/View/utils/enums.d.ts +0 -9
- package/admin/src/pages/View/utils/enums.js +0 -12
- package/admin/src/utils/getTrad.d.ts +0 -3
- package/admin/src/utils/getTrad.js +0 -9
- package/server/content-types/navigation/lifecycle.d.ts +0 -9
- package/server/content-types/navigation/lifecycle.js +0 -10
- package/server/content-types/navigation-item/lifecycle.d.ts +0 -16
- package/server/content-types/navigation-item/lifecycle.js +0 -31
- package/server/content-types/navigations-items-related/lifecycle.d.ts +0 -8
- package/server/content-types/navigations-items-related/lifecycle.js +0 -22
|
@@ -0,0 +1,41 @@
|
|
|
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.useNavigationManager = void 0;
|
|
27
|
+
const react_1 = __importStar(require("react"));
|
|
28
|
+
const NavigationManager_1 = require("../pages/View/components/NavigationManager");
|
|
29
|
+
const useNavigationManager = () => {
|
|
30
|
+
const [isOpened, setIsOpened] = (0, react_1.useState)(false);
|
|
31
|
+
const open = (0, react_1.useCallback)(() => setIsOpened(true), [setIsOpened]);
|
|
32
|
+
const close = (0, react_1.useCallback)(() => setIsOpened(false), [setIsOpened]);
|
|
33
|
+
const modal = (0, react_1.useMemo)(() => isOpened ? (react_1.default.createElement(NavigationManager_1.NavigationManager, { initialState: { view: "INITIAL" }, isOpened: true, onClose: close })) : null, [isOpened, close]);
|
|
34
|
+
return (0, react_1.useMemo)(() => ({
|
|
35
|
+
navigationManagerModal: modal,
|
|
36
|
+
openNavigationManagerModal: open,
|
|
37
|
+
closeNavigationManagerModal: close,
|
|
38
|
+
}), [modal, open, close]);
|
|
39
|
+
};
|
|
40
|
+
exports.useNavigationManager = useNavigationManager;
|
|
41
|
+
//# sourceMappingURL=useNavigationManager.js.map
|
|
@@ -33,12 +33,13 @@ 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");
|
|
42
|
+
const utils_1 = require("../../utils");
|
|
42
43
|
const i18nAwareItems = ({ items, config }) => config.i18nEnabled ? items.filter(({ localeCode }) => localeCode === config.defaultLocale) : items;
|
|
43
44
|
const DataManagerProvider = ({ children }) => {
|
|
44
45
|
const [reducerState, dispatch] = (0, react_1.useReducer)(reducer_1.default, reducer_1.initialState, init_1.default);
|
|
@@ -60,7 +61,7 @@ const DataManagerProvider = ({ children }) => {
|
|
|
60
61
|
const passedActiveItems = (0, react_1.useMemo)(() => {
|
|
61
62
|
return i18nAwareItems({ config, items });
|
|
62
63
|
}, [config, items]);
|
|
63
|
-
const getNavigation = async (id,
|
|
64
|
+
const getNavigation = async (id, navigationConfig) => {
|
|
64
65
|
try {
|
|
65
66
|
if (activeId || id) {
|
|
66
67
|
dispatch({
|
|
@@ -74,7 +75,10 @@ const DataManagerProvider = ({ children }) => {
|
|
|
74
75
|
type: actions_1.GET_NAVIGATION_DATA_SUCCEEDED,
|
|
75
76
|
activeItem: {
|
|
76
77
|
...activeItem,
|
|
77
|
-
items: (0, parsers_1.prepareItemToViewPayload)(
|
|
78
|
+
items: (0, parsers_1.prepareItemToViewPayload)({
|
|
79
|
+
config: navigationConfig,
|
|
80
|
+
items: activeItem.items,
|
|
81
|
+
}),
|
|
78
82
|
},
|
|
79
83
|
});
|
|
80
84
|
}
|
|
@@ -83,7 +87,7 @@ const DataManagerProvider = ({ children }) => {
|
|
|
83
87
|
console.error({ err });
|
|
84
88
|
toggleNotification({
|
|
85
89
|
type: 'warning',
|
|
86
|
-
message:
|
|
90
|
+
message: (0, translations_1.getTrad)('notification.error'),
|
|
87
91
|
});
|
|
88
92
|
}
|
|
89
93
|
};
|
|
@@ -119,7 +123,7 @@ const DataManagerProvider = ({ children }) => {
|
|
|
119
123
|
console.error({ err });
|
|
120
124
|
toggleNotification({
|
|
121
125
|
type: 'warning',
|
|
122
|
-
message:
|
|
126
|
+
message: (0, translations_1.getTrad)('notification.error'),
|
|
123
127
|
});
|
|
124
128
|
}
|
|
125
129
|
};
|
|
@@ -135,7 +139,7 @@ const DataManagerProvider = ({ children }) => {
|
|
|
135
139
|
if (!autoReload) {
|
|
136
140
|
toggleNotification({
|
|
137
141
|
type: 'info',
|
|
138
|
-
message: { id:
|
|
142
|
+
message: { id: 'notification.info.autoreaload-disable' },
|
|
139
143
|
});
|
|
140
144
|
}
|
|
141
145
|
}, [autoReload]);
|
|
@@ -186,6 +190,26 @@ const DataManagerProvider = ({ children }) => {
|
|
|
186
190
|
});
|
|
187
191
|
handleChangeSelection(targetId);
|
|
188
192
|
};
|
|
193
|
+
const readNavigationItemFromLocale = async ({ locale, structureId }) => {
|
|
194
|
+
try {
|
|
195
|
+
const source = changedActiveItem.localizations?.find((navigation) => navigation.locale === locale);
|
|
196
|
+
if (!source) {
|
|
197
|
+
return (0, utils_1.errorStatusResourceFor)(['popup.item.form.i18n.locale.error.unavailable']);
|
|
198
|
+
}
|
|
199
|
+
const url = `/navigation/i18n/item/read/${source.id}/${changedActiveItem.id}?path=${structureId}`;
|
|
200
|
+
return (0, utils_1.resolvedResourceFor)(await (0, helper_plugin_1.request)(url, {
|
|
201
|
+
method: "GET",
|
|
202
|
+
signal,
|
|
203
|
+
}));
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
let messageKey;
|
|
207
|
+
if (error instanceof Error) {
|
|
208
|
+
messageKey = (0, lodash_1.get)(error, 'response.payload.error.details.messageKey');
|
|
209
|
+
}
|
|
210
|
+
return (0, utils_1.errorStatusResourceFor)([messageKey ?? 'popup.item.form.i18n.locale.error.generic']);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
189
213
|
const handleChangeNavigationPopupVisibility = (visible) => {
|
|
190
214
|
dispatch({
|
|
191
215
|
type: actions_1.CHANGE_NAVIGATION_POPUP_VISIBILITY,
|
|
@@ -227,12 +251,15 @@ const DataManagerProvider = ({ children }) => {
|
|
|
227
251
|
type: actions_1.SUBMIT_NAVIGATION_SUCCEEDED,
|
|
228
252
|
navigation: {
|
|
229
253
|
...navigation,
|
|
230
|
-
items: (0, parsers_1.prepareItemToViewPayload)(
|
|
254
|
+
items: (0, parsers_1.prepareItemToViewPayload)({
|
|
255
|
+
config,
|
|
256
|
+
items: navigation.items,
|
|
257
|
+
}),
|
|
231
258
|
},
|
|
232
259
|
});
|
|
233
260
|
toggleNotification({
|
|
234
261
|
type: 'success',
|
|
235
|
-
message:
|
|
262
|
+
message: (0, translations_1.getTrad)('notification.navigation.submit'),
|
|
236
263
|
});
|
|
237
264
|
}
|
|
238
265
|
catch (err) {
|
|
@@ -245,16 +272,22 @@ const DataManagerProvider = ({ children }) => {
|
|
|
245
272
|
return toggleNotification({
|
|
246
273
|
type: 'warning',
|
|
247
274
|
message: {
|
|
248
|
-
id: formatMessage((0,
|
|
275
|
+
id: formatMessage((0, translations_1.getTrad)('notification.navigation.error'), { ...err.response.payload.data, errorTitles: err.response.payload.data.errorTitles.join(' and ') })
|
|
249
276
|
},
|
|
250
277
|
});
|
|
251
278
|
}
|
|
252
279
|
toggleNotification({
|
|
253
280
|
type: 'warning',
|
|
254
|
-
message:
|
|
281
|
+
message: (0, translations_1.getTrad)('notification.error'),
|
|
255
282
|
});
|
|
256
283
|
}
|
|
257
284
|
};
|
|
285
|
+
const handleNavigationsDeletion = (ids) => Promise.all(ids.map(handleNavigationDeletion));
|
|
286
|
+
const handleNavigationDeletion = (id) => (0, helper_plugin_1.request)(`/${pluginId_1.default}/${id}`, {
|
|
287
|
+
method: "DELETE",
|
|
288
|
+
signal,
|
|
289
|
+
});
|
|
290
|
+
const hardReset = () => getDataRef.current();
|
|
258
291
|
return (react_1.default.createElement(DataManagerContext_1.default.Provider, { value: {
|
|
259
292
|
items: passedActiveItems,
|
|
260
293
|
activeItem,
|
|
@@ -280,6 +313,9 @@ const DataManagerProvider = ({ children }) => {
|
|
|
280
313
|
isInDevelopmentMode,
|
|
281
314
|
error,
|
|
282
315
|
availableLocale,
|
|
316
|
+
readNavigationItemFromLocale,
|
|
317
|
+
handleNavigationsDeletion,
|
|
318
|
+
hardReset,
|
|
283
319
|
} }, isLoading ? react_1.default.createElement(helper_plugin_1.LoadingIndicatorPage, null) : children));
|
|
284
320
|
};
|
|
285
321
|
DataManagerProvider.propTypes = {
|
|
@@ -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
|
|
@@ -0,0 +1,105 @@
|
|
|
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 lodash_1 = require("lodash");
|
|
30
|
+
const react_1 = __importStar(require("react"));
|
|
31
|
+
const helper_plugin_1 = require("@strapi/helper-plugin");
|
|
32
|
+
const VisuallyHidden_1 = require("@strapi/design-system/VisuallyHidden");
|
|
33
|
+
const Table_1 = require("@strapi/design-system/Table");
|
|
34
|
+
const icons_1 = require("@strapi/icons");
|
|
35
|
+
const Typography_1 = require("@strapi/design-system/Typography");
|
|
36
|
+
const Tooltip_1 = require("@strapi/design-system/Tooltip");
|
|
37
|
+
const Stack_1 = require("@strapi/design-system/Stack");
|
|
38
|
+
const IconButton_1 = require("@strapi/design-system/IconButton");
|
|
39
|
+
const utils_1 = require("../../../../utils");
|
|
40
|
+
const ConfirmationDialog_1 = __importDefault(require("../../../../components/ConfirmationDialog"));
|
|
41
|
+
const translations_1 = require("../../../../translations");
|
|
42
|
+
const refreshIcon = react_1.default.createElement(icons_1.Refresh, null);
|
|
43
|
+
const plusIcon = react_1.default.createElement(icons_1.Plus, null);
|
|
44
|
+
const tradPrefix = "pages.settings.form.customFields.table.";
|
|
45
|
+
const CustomFieldTable = ({ data, onOpenModal, onRemoveCustomField, onToggleCustomField, }) => {
|
|
46
|
+
const [confirmationVisible, setIsConfirmationVisible] = (0, react_1.useState)(false);
|
|
47
|
+
const [fieldToRemove, setFieldToRemove] = (0, react_1.useState)(null);
|
|
48
|
+
const toggleNotification = (0, helper_plugin_1.useNotification)();
|
|
49
|
+
const customFields = (0, react_1.useMemo)(() => (0, lodash_1.sortBy)(data, "name"), [data]);
|
|
50
|
+
const handleRemove = (0, react_1.useCallback)((field) => {
|
|
51
|
+
setFieldToRemove(field);
|
|
52
|
+
setIsConfirmationVisible(true);
|
|
53
|
+
}, [setFieldToRemove, setIsConfirmationVisible]);
|
|
54
|
+
const cleanup = (0, react_1.useCallback)(() => {
|
|
55
|
+
setFieldToRemove(null);
|
|
56
|
+
setIsConfirmationVisible(false);
|
|
57
|
+
}, [setFieldToRemove, setIsConfirmationVisible]);
|
|
58
|
+
const handleConfirm = (0, react_1.useCallback)(() => {
|
|
59
|
+
if (fieldToRemove === null) {
|
|
60
|
+
toggleNotification({
|
|
61
|
+
type: 'warning',
|
|
62
|
+
message: {
|
|
63
|
+
id: (0, translations_1.getTradId)(`${tradPrefix}confirmation.error`),
|
|
64
|
+
default: 'Something went wrong',
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
onRemoveCustomField(fieldToRemove);
|
|
70
|
+
}
|
|
71
|
+
cleanup();
|
|
72
|
+
}, [cleanup, fieldToRemove, translations_1.getTradId, onRemoveCustomField, toggleNotification]);
|
|
73
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
74
|
+
react_1.default.createElement(ConfirmationDialog_1.default, { isVisible: confirmationVisible, header: (0, utils_1.getMessage)(`${tradPrefix}confirmation.header`), children: (0, utils_1.getMessage)(`${tradPrefix}confirmation.message`), labelConfirm: (0, utils_1.getMessage)(`${tradPrefix}confirmation.confirm`), iconConfirm: refreshIcon, mainIcon: refreshIcon, onConfirm: handleConfirm, onCancel: cleanup }),
|
|
75
|
+
react_1.default.createElement(Table_1.Table, { colCount: 4, rowCount: data.length + 1, footer: react_1.default.createElement(Table_1.TFooter, { onClick: (e) => { e.preventDefault(); onOpenModal(null); }, icon: plusIcon }, (0, utils_1.getMessage)(`${tradPrefix}footer`)) },
|
|
76
|
+
react_1.default.createElement(Table_1.Thead, null,
|
|
77
|
+
react_1.default.createElement(Table_1.Tr, null,
|
|
78
|
+
react_1.default.createElement(Table_1.Th, { width: "20%" },
|
|
79
|
+
react_1.default.createElement(Typography_1.Typography, { variant: "sigma", textColor: "neutral600" }, (0, utils_1.getMessage)(`${tradPrefix}header.name`))),
|
|
80
|
+
react_1.default.createElement(Table_1.Th, { width: "60%" },
|
|
81
|
+
react_1.default.createElement(Typography_1.Typography, { variant: "sigma", textColor: "neutral600" }, (0, utils_1.getMessage)(`${tradPrefix}header.label`))),
|
|
82
|
+
react_1.default.createElement(Table_1.Th, { width: "15%" },
|
|
83
|
+
react_1.default.createElement(Typography_1.Typography, { variant: "sigma", textColor: "neutral600" }, (0, utils_1.getMessage)(`${tradPrefix}header.type`))),
|
|
84
|
+
react_1.default.createElement(Table_1.Th, { width: "5%" },
|
|
85
|
+
react_1.default.createElement(Typography_1.Typography, { variant: "sigma", textColor: "neutral600" }, (0, utils_1.getMessage)(`${tradPrefix}header.required`))),
|
|
86
|
+
react_1.default.createElement(Table_1.Th, null,
|
|
87
|
+
react_1.default.createElement(VisuallyHidden_1.VisuallyHidden, null)))),
|
|
88
|
+
react_1.default.createElement(Table_1.Tbody, null, customFields.map(customField => (react_1.default.createElement(Table_1.Tr, { key: customField.name },
|
|
89
|
+
react_1.default.createElement(Table_1.Td, { width: '20%' },
|
|
90
|
+
react_1.default.createElement(Typography_1.Typography, { fontWeight: "semiBold", textColor: "neutral800" }, customField.name)),
|
|
91
|
+
react_1.default.createElement(Table_1.Td, { width: "60%" },
|
|
92
|
+
react_1.default.createElement(Typography_1.Typography, { textColor: "neutral800" }, customField.label)),
|
|
93
|
+
react_1.default.createElement(Table_1.Td, { width: "15%" },
|
|
94
|
+
react_1.default.createElement(Typography_1.Typography, { textColor: "neutral800" }, customField.type)),
|
|
95
|
+
react_1.default.createElement(Table_1.Td, { width: "5%" },
|
|
96
|
+
react_1.default.createElement(Tooltip_1.Tooltip, { description: (0, utils_1.getMessage)(`${tradPrefix}${customField.required ? "required" : "notRequired"}`) },
|
|
97
|
+
react_1.default.createElement(Typography_1.Typography, { textColor: "neutral800" }, customField.required ? react_1.default.createElement(icons_1.Check, null) : react_1.default.createElement(icons_1.Minus, null)))),
|
|
98
|
+
react_1.default.createElement(Table_1.Td, null,
|
|
99
|
+
react_1.default.createElement(Stack_1.Stack, { horizontal: true, size: 1 },
|
|
100
|
+
react_1.default.createElement(IconButton_1.IconButton, { onClick: () => onOpenModal(customField), label: (0, utils_1.getMessage)(`${tradPrefix}edit`), icon: react_1.default.createElement(icons_1.Pencil, null), noBorder: true }),
|
|
101
|
+
react_1.default.createElement(IconButton_1.IconButton, { onClick: () => onToggleCustomField(customField), label: (0, utils_1.getMessage)(`${tradPrefix}${customField.enabled ? 'disable' : 'enable'}`), icon: customField.enabled ? react_1.default.createElement(icons_1.Eye, null) : react_1.default.createElement(icons_1.EyeStriked, null), noBorder: true }),
|
|
102
|
+
react_1.default.createElement(IconButton_1.IconButton, { onClick: () => handleRemove(customField), label: (0, utils_1.getMessage)(`${tradPrefix}remove`), icon: react_1.default.createElement(icons_1.Trash, null), noBorder: true }))))))))));
|
|
103
|
+
};
|
|
104
|
+
exports.default = CustomFieldTable;
|
|
105
|
+
//# sourceMappingURL=index.js.map
|