strapi-plugin-navigation 2.0.13 → 2.1.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.
- package/README.md +105 -27
- package/admin/src/components/Alert/styles.d.ts +2 -0
- package/admin/src/components/Alert/styles.js +10 -4
- package/admin/src/components/CollapseButton/index.d.ts +7 -0
- package/admin/src/components/CollapseButton/index.js +21 -22
- package/admin/src/components/ConfirmationDialog/index.d.ts +28 -0
- package/admin/src/components/ConfirmationDialog/index.js +32 -54
- package/admin/src/components/EmptyView/index.d.ts +3 -0
- package/admin/src/components/EmptyView/index.js +9 -7
- package/admin/src/components/Item/ItemCardBadge/index.d.ts +3 -0
- package/admin/src/components/Item/ItemCardBadge/index.js +11 -7
- package/admin/src/components/Item/ItemCardHeader/Wrapper.d.ts +3 -0
- package/admin/src/components/Item/ItemCardHeader/Wrapper.js +10 -6
- package/admin/src/components/Item/ItemCardHeader/index.d.ts +12 -0
- package/admin/src/components/Item/ItemCardHeader/index.js +33 -52
- package/admin/src/components/Item/ItemCardRemovedOverlay/index.d.ts +2 -0
- package/admin/src/components/Item/ItemCardRemovedOverlay/index.js +10 -4
- package/admin/src/components/Item/Wrapper.d.ts +3 -0
- package/admin/src/components/Item/Wrapper.js +10 -6
- package/admin/src/components/Item/index.d.ts +31 -0
- package/admin/src/components/Item/index.js +163 -242
- package/admin/src/components/NavigationItemList/Wrapper.d.ts +3 -0
- package/admin/src/components/NavigationItemList/Wrapper.js +9 -5
- package/admin/src/components/NavigationItemList/index.d.ts +35 -0
- package/admin/src/components/NavigationItemList/index.js +28 -66
- package/admin/src/components/RestartAlert/index.d.ts +3 -0
- package/admin/src/components/RestartAlert/index.js +10 -5
- package/admin/src/components/Search/index.d.ts +6 -0
- package/admin/src/components/Search/index.js +57 -46
- package/admin/src/components/icons/navigation.d.ts +6 -0
- package/admin/src/components/icons/navigation.js +11 -13
- package/admin/src/contexts/DataManagerContext.d.ts +3 -0
- package/admin/src/contexts/DataManagerContext.js +6 -5
- package/admin/src/hooks/useAllContentTypes.d.ts +6 -0
- package/admin/src/hooks/useAllContentTypes.js +10 -11
- package/admin/src/hooks/useDataManager.d.ts +3 -0
- package/admin/src/hooks/useDataManager.js +10 -6
- package/admin/src/hooks/useI18nCopyNavigationItemsModal.d.ts +9 -0
- package/admin/src/hooks/useI18nCopyNavigationItemsModal.js +51 -0
- package/admin/src/hooks/useNavigationConfig.d.ts +10 -0
- package/admin/src/hooks/useNavigationConfig.js +52 -56
- package/admin/src/hooks/useNavigationManager.d.ts +7 -0
- package/admin/src/hooks/useNavigationManager.js +41 -0
- package/admin/src/index.d.ts +14 -0
- package/admin/src/index.js +92 -76
- package/admin/src/pages/App/index.d.ts +3 -0
- package/admin/src/pages/App/index.js +43 -31
- package/admin/src/pages/DataManagerProvider/actions.d.ts +19 -0
- package/admin/src/pages/DataManagerProvider/actions.js +22 -26
- package/admin/src/pages/DataManagerProvider/index.d.ts +12 -0
- package/admin/src/pages/DataManagerProvider/index.js +316 -298
- package/admin/src/pages/DataManagerProvider/init.d.ts +3 -0
- package/admin/src/pages/DataManagerProvider/init.js +5 -3
- package/admin/src/pages/DataManagerProvider/reducer.d.ts +19 -0
- package/admin/src/pages/DataManagerProvider/reducer.js +119 -121
- package/admin/src/pages/SettingsPage/components/DisableI18nModal/index.d.ts +24 -0
- package/admin/src/pages/SettingsPage/components/DisableI18nModal/index.js +88 -0
- package/admin/src/pages/SettingsPage/index.d.ts +3 -0
- package/admin/src/pages/SettingsPage/index.js +242 -335
- package/admin/src/pages/SettingsPage/utils/functions.d.ts +5 -0
- package/admin/src/pages/SettingsPage/utils/functions.js +3 -8
- package/admin/src/pages/View/components/I18nCopyNavigationItems/index.d.ts +14 -0
- package/admin/src/pages/View/components/I18nCopyNavigationItems/index.js +15 -0
- package/admin/src/pages/View/components/NavigationContentHeader/index.d.ts +6 -0
- package/admin/src/pages/View/components/NavigationContentHeader/index.js +13 -17
- package/admin/src/pages/View/components/NavigationHeader/index.d.ts +12 -0
- package/admin/src/pages/View/components/NavigationHeader/index.js +79 -65
- package/admin/src/pages/View/components/NavigationHeader/styles.d.ts +2 -0
- package/admin/src/pages/View/components/NavigationHeader/styles.js +10 -5
- package/admin/src/pages/View/components/NavigationItemForm/index.d.ts +57 -0
- package/admin/src/pages/View/components/NavigationItemForm/index.js +416 -453
- package/admin/src/pages/View/components/NavigationItemForm/utils/form.d.ts +45 -0
- package/admin/src/pages/View/components/NavigationItemForm/utils/form.js +84 -52
- package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupFooter.d.ts +23 -0
- package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupFooter.js +24 -34
- package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupHeader.d.ts +4 -0
- package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupHeader.js +16 -16
- package/admin/src/pages/View/components/NavigationItemPopup/index.d.ts +30 -0
- package/admin/src/pages/View/components/NavigationItemPopup/index.js +85 -108
- package/admin/src/pages/View/components/NavigationManager/Create/index.d.ts +9 -0
- package/admin/src/pages/View/components/NavigationManager/Create/index.js +57 -0
- package/admin/src/pages/View/components/NavigationManager/Delete/index.d.ts +8 -0
- package/admin/src/pages/View/components/NavigationManager/Delete/index.js +28 -0
- package/admin/src/pages/View/components/NavigationManager/Edit/index.d.ts +8 -0
- package/admin/src/pages/View/components/NavigationManager/Edit/index.js +54 -0
- package/admin/src/pages/View/components/NavigationManager/Error/index.d.ts +8 -0
- package/admin/src/pages/View/components/NavigationManager/Error/index.js +53 -0
- package/admin/src/pages/View/components/NavigationManager/Form/index.d.ts +19 -0
- package/admin/src/pages/View/components/NavigationManager/Form/index.js +98 -0
- package/admin/src/pages/View/components/NavigationManager/List/index.d.ts +8 -0
- package/admin/src/pages/View/components/NavigationManager/List/index.js +138 -0
- package/admin/src/pages/View/components/NavigationManager/index.d.ts +10 -0
- package/admin/src/pages/View/components/NavigationManager/index.js +189 -0
- package/admin/src/pages/View/components/NavigationManager/types.d.ts +53 -0
- package/admin/src/pages/View/components/NavigationManager/types.js +3 -0
- package/admin/src/pages/View/index.d.ts +4 -0
- package/admin/src/pages/View/index.js +231 -304
- package/admin/src/pages/View/utils/enums.d.ts +9 -0
- package/admin/src/pages/View/utils/enums.js +11 -8
- package/admin/src/pages/View/utils/form.d.ts +2 -0
- package/admin/src/pages/View/utils/form.js +15 -12
- package/admin/src/pages/View/utils/index.d.ts +2 -0
- package/admin/src/pages/View/utils/index.js +11 -3
- package/admin/src/pages/View/utils/parsers.d.ts +49 -0
- package/admin/src/pages/View/utils/parsers.js +239 -278
- package/admin/src/permissions.d.ts +12 -0
- package/admin/src/permissions.js +11 -7
- package/admin/src/pluginId.d.ts +3 -0
- package/admin/src/pluginId.js +2 -2
- package/admin/src/translations/en.json +157 -104
- package/admin/src/translations/fr.json +44 -44
- package/admin/src/translations/index.d.ts +12 -0
- package/admin/src/translations/index.js +17 -11
- package/admin/src/utils/api.d.ts +8 -0
- package/admin/src/utils/api.js +54 -50
- package/admin/src/utils/getTrad.d.ts +3 -0
- package/admin/src/utils/getTrad.js +9 -5
- package/admin/src/utils/index.d.ts +18 -0
- package/admin/src/utils/index.js +36 -15
- package/package.json +20 -19
- package/permissions.d.ts +9 -0
- package/permissions.js +5 -4
- package/server/bootstrap/index.d.ts +4 -0
- package/server/bootstrap/index.js +41 -0
- package/server/config/index.d.ts +5 -0
- package/server/config/index.js +33 -9
- package/server/config/setupStrategy.d.ts +3 -0
- package/server/config/setupStrategy.js +38 -0
- package/server/content-types/audience/index.d.ts +27 -0
- package/server/content-types/audience/index.js +9 -8
- package/server/content-types/audience/schema.d.ts +25 -0
- package/server/content-types/audience/schema.js +26 -0
- package/server/content-types/index.d.ts +255 -0
- package/server/content-types/index.js +15 -12
- package/server/content-types/navigation/index.d.ts +64 -0
- package/server/content-types/navigation/index.js +11 -8
- package/server/content-types/navigation/lifecycle.d.ts +9 -0
- package/server/content-types/navigation/lifecycle.js +8 -12
- package/server/content-types/navigation/schema.d.ts +55 -0
- package/server/content-types/navigation/schema.js +56 -0
- package/server/content-types/navigation-item/index.d.ts +112 -0
- package/server/content-types/navigation-item/index.js +11 -8
- package/server/content-types/navigation-item/lifecycle.d.ts +16 -0
- package/server/content-types/navigation-item/lifecycle.js +28 -32
- package/server/content-types/navigation-item/schema.d.ts +97 -0
- package/server/content-types/navigation-item/schema.js +102 -0
- package/server/content-types/navigations-items-related/index.d.ts +56 -0
- package/server/content-types/navigations-items-related/index.js +11 -8
- package/server/content-types/navigations-items-related/lifecycle.d.ts +8 -0
- package/server/content-types/navigations-items-related/lifecycle.js +20 -17
- package/server/content-types/navigations-items-related/schema.d.ts +49 -0
- package/server/content-types/navigations-items-related/schema.js +50 -0
- package/server/controllers/admin.d.ts +4 -0
- package/server/controllers/admin.js +130 -0
- package/server/controllers/client.d.ts +4 -0
- package/server/controllers/client.js +57 -0
- package/server/controllers/index.d.ts +4 -0
- package/server/controllers/index.js +12 -6
- package/server/destroy.d.ts +3 -0
- package/server/destroy.js +5 -0
- package/server/graphql/config.d.ts +4 -0
- package/server/graphql/config.js +28 -0
- package/server/graphql/index.d.ts +2 -0
- package/server/graphql/index.js +18 -22
- package/server/graphql/queries/index.d.ts +3 -0
- package/server/graphql/queries/index.js +15 -15
- package/server/graphql/queries/render-navigation-child.d.ts +15 -0
- package/server/graphql/queries/render-navigation-child.js +24 -15
- package/server/graphql/queries/render-navigation.d.ts +21 -0
- package/server/graphql/queries/render-navigation.js +31 -15
- package/server/graphql/resolvers-config.d.ts +10 -0
- package/server/graphql/resolvers-config.js +5 -3
- package/server/graphql/setupStrategy.d.ts +3 -0
- package/server/graphql/setupStrategy.js +15 -0
- package/server/graphql/types/content-types-name-fields.d.ts +6 -0
- package/server/graphql/types/content-types-name-fields.js +13 -9
- package/server/graphql/types/content-types.d.ts +5 -0
- package/server/graphql/types/content-types.js +17 -15
- package/server/graphql/types/create-navigation-item.d.ts +5 -0
- package/server/graphql/types/create-navigation-item.js +18 -16
- package/server/graphql/types/create-navigation-related.d.ts +5 -0
- package/server/graphql/types/create-navigation-related.js +9 -7
- package/server/graphql/types/create-navigation.d.ts +5 -0
- package/server/graphql/types/create-navigation.js +8 -6
- package/server/graphql/types/index.d.ts +3 -0
- package/server/graphql/types/index.js +15 -13
- package/server/graphql/types/navigation-config.d.ts +5 -0
- package/server/graphql/types/navigation-config.js +10 -8
- package/server/graphql/types/navigation-details.d.ts +5 -0
- package/server/graphql/types/navigation-details.js +11 -9
- package/server/graphql/types/navigation-item-related-data.d.ts +5 -0
- package/server/graphql/types/navigation-item-related-data.js +9 -0
- package/server/graphql/types/navigation-item-related.d.ts +7 -0
- package/server/graphql/types/navigation-item-related.js +25 -0
- package/server/graphql/types/navigation-item.d.ts +5 -0
- package/server/graphql/types/navigation-item.js +28 -29
- package/server/graphql/types/navigation-render-type.d.ts +5 -0
- package/server/graphql/types/navigation-render-type.js +7 -4
- package/server/graphql/types/navigation.d.ts +5 -0
- package/server/graphql/types/navigation.js +10 -8
- package/server/i18n/constant.d.ts +2 -0
- package/server/i18n/constant.js +5 -0
- package/server/i18n/errors.d.ts +7 -0
- package/server/i18n/errors.js +14 -0
- package/server/i18n/graphQLEnhancers.d.ts +10 -0
- package/server/i18n/graphQLEnhancers.js +10 -0
- package/server/i18n/index.d.ts +8 -0
- package/server/i18n/index.js +23 -0
- package/server/i18n/navigationSetupStrategy.d.ts +3 -0
- package/server/i18n/navigationSetupStrategy.js +119 -0
- package/server/i18n/serviceEnhancers.d.ts +13 -0
- package/server/i18n/serviceEnhancers.js +156 -0
- package/server/i18n/types.d.ts +60 -0
- package/server/i18n/types.js +3 -0
- package/server/i18n/utils.d.ts +12 -0
- package/server/i18n/utils.js +29 -0
- package/server/index.d.ts +273 -0
- package/server/index.js +26 -0
- package/server/navigation/index.d.ts +2 -0
- package/server/navigation/index.js +18 -0
- package/server/navigation/setupStrategy.d.ts +3 -0
- package/server/navigation/setupStrategy.js +39 -0
- package/server/register/index.d.ts +3 -0
- package/server/register/index.js +4 -0
- package/server/routes/admin.d.ts +4 -0
- package/server/routes/admin.js +82 -61
- package/server/routes/client.d.ts +4 -0
- package/server/routes/client.js +25 -21
- package/server/routes/index.d.ts +6 -0
- package/server/routes/index.js +13 -4
- package/server/services/admin.d.ts +5 -0
- package/server/services/admin.js +238 -0
- package/server/services/client.d.ts +5 -0
- package/server/services/client.js +249 -0
- package/server/services/common.d.ts +5 -0
- package/server/services/common.js +313 -0
- package/server/services/index.d.ts +7 -0
- package/server/services/index.js +14 -6
- package/server/utils/constant.d.ts +27 -0
- package/server/utils/constant.js +24 -0
- package/server/utils/functions.d.ts +139 -0
- package/server/utils/functions.js +226 -0
- package/server/utils/index.d.ts +3 -0
- package/server/utils/index.js +19 -0
- package/strapi-admin.d.ts +3 -0
- package/strapi-admin.js +8 -1
- package/strapi-server.d.ts +273 -0
- package/strapi-server.js +6 -17
- package/tsconfig.tsbuildinfo +1 -0
- package/types/bootstrap.d.ts +13 -0
- package/types/bootstrap.js +3 -0
- package/types/config.d.ts +21 -0
- package/types/config.js +3 -0
- package/types/contentTypes.d.ts +85 -0
- package/types/contentTypes.js +3 -0
- package/types/controllers.d.ts +48 -0
- package/types/controllers.js +5 -0
- package/types/graphQL.d.ts +3 -0
- package/types/graphQL.js +3 -0
- package/types/i18n.d.ts +9 -0
- package/types/i18n.js +3 -0
- package/types/index.d.ts +9 -0
- package/types/index.js +25 -0
- package/types/services.d.ts +74 -0
- package/types/services.js +3 -0
- package/types/utils.d.ts +62 -0
- package/types/utils.js +27 -0
- package/utils/InvalidParamNavigationError.d.ts +4 -0
- package/utils/InvalidParamNavigationError.js +8 -0
- package/utils/NavigationError.d.ts +5 -0
- package/utils/NavigationError.js +7 -7
- package/__mocks__/pages.settings.json +0 -25
- package/__mocks__/strapi.js +0 -207
- package/jest.config.js +0 -14
- package/server/bootstrap.js +0 -52
- package/server/config.js +0 -9
- package/server/content-types/audience/lifecycle.js +0 -8
- package/server/content-types/audience/schema.json +0 -23
- package/server/content-types/navigation/schema.json +0 -45
- package/server/content-types/navigation-item/schema.json +0 -99
- package/server/content-types/navigations-items-related/schema.json +0 -47
- package/server/controllers/navigation.js +0 -105
- package/server/graphql/types/navigation-related.js +0 -25
- package/server/services/__tests__/functions.test.js +0 -48
- package/server/services/__tests__/navigation.test.js +0 -91
- package/server/services/navigation.js +0 -791
- package/server/services/utils/constant.js +0 -21
- package/server/services/utils/functions.js +0 -226
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
TEMPLATE_DEFAULT: 'Generic',
|
|
3
|
-
|
|
4
|
-
KIND_TYPES: {
|
|
5
|
-
SINGLE: 'singleType',
|
|
6
|
-
COLLECTION: 'collectionType'
|
|
7
|
-
},
|
|
8
|
-
|
|
9
|
-
MODEL_TYPES: {
|
|
10
|
-
CONTENT_TYPE: 'contentType'
|
|
11
|
-
},
|
|
12
|
-
ALLOWED_CONTENT_TYPES: [
|
|
13
|
-
'api::',
|
|
14
|
-
'plugin::'
|
|
15
|
-
],
|
|
16
|
-
RESTRICTED_CONTENT_TYPES: [
|
|
17
|
-
'plugin::users-permissions',
|
|
18
|
-
'plugin::i18n.locale',
|
|
19
|
-
'plugin::navigation',
|
|
20
|
-
],
|
|
21
|
-
};
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
last,
|
|
3
|
-
isObject,
|
|
4
|
-
isEmpty,
|
|
5
|
-
flatten,
|
|
6
|
-
find,
|
|
7
|
-
isString,
|
|
8
|
-
get,
|
|
9
|
-
isNil,
|
|
10
|
-
isArray,
|
|
11
|
-
first,
|
|
12
|
-
} = require('lodash');
|
|
13
|
-
|
|
14
|
-
const { type: itemType } = require('../../content-types/navigation-item/lifecycle');
|
|
15
|
-
const { NavigationError } = require('../../../utils/NavigationError');
|
|
16
|
-
const { TEMPLATE_DEFAULT, ALLOWED_CONTENT_TYPES, RESTRICTED_CONTENT_TYPES } = require('./constant');
|
|
17
|
-
|
|
18
|
-
module.exports = ({ strapi }) => {
|
|
19
|
-
return {
|
|
20
|
-
singularize(value = '') {
|
|
21
|
-
return last(value) === 's' ? value.substr(0, value.length - 1) : value;
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
extractMeta(plugins) {
|
|
25
|
-
const { navigation: plugin } = plugins;
|
|
26
|
-
return {
|
|
27
|
-
masterModel: plugin.contentType('navigation'),
|
|
28
|
-
itemModel: plugin.contentType('navigation-item'),
|
|
29
|
-
relatedModel: plugin.contentType('navigations-items-related'),
|
|
30
|
-
audienceModel: plugin.contentType('audience'),
|
|
31
|
-
service: plugin.service('navigation'),
|
|
32
|
-
plugin,
|
|
33
|
-
pluginName: 'navigation',
|
|
34
|
-
};
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
buildNestedStructure(entities, id = null, field = 'parent') {
|
|
38
|
-
return entities
|
|
39
|
-
.filter(entity => {
|
|
40
|
-
if (entity[field] == null && id === null) {
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
let data = entity[field];
|
|
44
|
-
if (data && typeof id === 'string') {
|
|
45
|
-
data = data.toString();
|
|
46
|
-
}
|
|
47
|
-
return (data && data === id) || (isObject(entity[field]) && (entity[field].id === id));
|
|
48
|
-
})
|
|
49
|
-
.map(entity => {
|
|
50
|
-
return ({
|
|
51
|
-
...entity,
|
|
52
|
-
related: !isEmpty(entity.related) ? [last(entity.related)] : entity.related,
|
|
53
|
-
items: this.buildNestedStructure(entities, entity.id, field),
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
buildNestedPaths({items, id = null, field = 'parent', parentPath = null}){
|
|
59
|
-
return items
|
|
60
|
-
.filter(entity => {
|
|
61
|
-
if (entity[field] == null && id === null) {
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
let data = entity[field];
|
|
65
|
-
if (data && typeof id === 'string') {
|
|
66
|
-
data = data.toString();
|
|
67
|
-
}
|
|
68
|
-
return (data && data === id) || (isObject(entity[field]) && (entity[field].id === id));
|
|
69
|
-
})
|
|
70
|
-
.reduce((acc, entity) => {
|
|
71
|
-
const path = `${parentPath || ''}/${entity.path}`
|
|
72
|
-
return [
|
|
73
|
-
{
|
|
74
|
-
id: entity.id,
|
|
75
|
-
parent: parentPath && {
|
|
76
|
-
id: get(entity, 'parent.id'),
|
|
77
|
-
path: parentPath,
|
|
78
|
-
},
|
|
79
|
-
path
|
|
80
|
-
},
|
|
81
|
-
...this.buildNestedPaths({items, id: entity.id, field, parentPath: path}),
|
|
82
|
-
...acc,
|
|
83
|
-
];
|
|
84
|
-
}, [])
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
filterByPath(items, path) {
|
|
88
|
-
const itemsWithPaths = this.buildNestedPaths({ items }).filter(({path: itemPath}) => itemPath.includes(path));
|
|
89
|
-
const root = itemsWithPaths.find(({ path: itemPath }) => itemPath === path);
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
root,
|
|
93
|
-
items: isNil(root) ? [] : items.filter(({ id }) => (itemsWithPaths.find(v => v.id === id))),
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
prepareAuditLog(actions) {
|
|
98
|
-
return [
|
|
99
|
-
...new Set(
|
|
100
|
-
actions
|
|
101
|
-
.filter(_ => !!_)
|
|
102
|
-
.flatMap(({ remove, create, update }) => {
|
|
103
|
-
return [create ? 'CREATE' : '', update ? 'UPDATE' : '', remove ? 'REMOVE' : '']
|
|
104
|
-
.filter(_ => !!_);
|
|
105
|
-
}),
|
|
106
|
-
),
|
|
107
|
-
]
|
|
108
|
-
.join('_');
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
sendAuditLog(auditLogInstance, event, data) {
|
|
112
|
-
if (auditLogInstance && auditLogInstance.emit) {
|
|
113
|
-
auditLogInstance.emit(event, data);
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
checkDuplicatePath(parentItem, checkData) {
|
|
118
|
-
return new Promise((resolve, reject) => {
|
|
119
|
-
if (parentItem && parentItem.items) {
|
|
120
|
-
for (let item of checkData) {
|
|
121
|
-
for (let _ of parentItem.items) {
|
|
122
|
-
if (_.path === item.path && (_.id !== item.id) && (item.type === itemType.INTERNAL)) {
|
|
123
|
-
return reject(
|
|
124
|
-
new NavigationError(
|
|
125
|
-
`Duplicate path:${item.path} in parent: ${parentItem.title || 'root'} for ${item.title} and ${_.title} items`,
|
|
126
|
-
{
|
|
127
|
-
parentTitle: parentItem.title,
|
|
128
|
-
parentId: parentItem.id,
|
|
129
|
-
path: item.path,
|
|
130
|
-
errorTitles: [item.title, _.title],
|
|
131
|
-
},
|
|
132
|
-
),
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return resolve();
|
|
139
|
-
});
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
async templateNameFactory(items, strapi, contentTypes = []) {
|
|
143
|
-
const flatRelated = flatten(items.map(i => i.related)).filter(_ => !!_);
|
|
144
|
-
const relatedMap = flatRelated.reduce((acc, curr) => {
|
|
145
|
-
if (!acc[curr.__contentType]) {
|
|
146
|
-
acc[curr.__contentType] = [];
|
|
147
|
-
}
|
|
148
|
-
acc[curr.__contentType].push(curr.id);
|
|
149
|
-
return acc;
|
|
150
|
-
}, {});
|
|
151
|
-
const responses = await Promise.all(
|
|
152
|
-
Object.entries(relatedMap)
|
|
153
|
-
.map(
|
|
154
|
-
([contentType, ids]) => {
|
|
155
|
-
const contentTypeUid = get(find(contentTypes, cnt => cnt.uid === contentType), 'uid');
|
|
156
|
-
return strapi.query(contentTypeUid)
|
|
157
|
-
.findMany({ id_in: ids, _limit: -1 })
|
|
158
|
-
.then(res => ({ [contentType]: res }))
|
|
159
|
-
}),
|
|
160
|
-
);
|
|
161
|
-
const relatedResponseMap = responses.reduce((acc, curr) => ({ ...acc, ...curr }), {});
|
|
162
|
-
const singleTypes = new Map(
|
|
163
|
-
contentTypes
|
|
164
|
-
.filter(x => x.isSingle)
|
|
165
|
-
.map(({ contentTypeName, templateName }) => [contentTypeName, templateName || contentTypeName])
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
return (contentType, id) => {
|
|
169
|
-
const template = get(relatedResponseMap[contentType].find(data => data.id === id), 'template');
|
|
170
|
-
|
|
171
|
-
if (template) {
|
|
172
|
-
const templateComponent = this.getTemplateComponentFromTemplate(template);
|
|
173
|
-
return get(templateComponent, 'options.templateName', TEMPLATE_DEFAULT);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (singleTypes.get(contentType)) {
|
|
177
|
-
return singleTypes.get(contentType);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return TEMPLATE_DEFAULT;
|
|
181
|
-
};
|
|
182
|
-
},
|
|
183
|
-
|
|
184
|
-
getTemplateComponentFromTemplate(template = []) {
|
|
185
|
-
const componentName = get(first(template), '__component');
|
|
186
|
-
return componentName ? strapi.components[componentName] : null;
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
composeItemTitle(item = {}, fields = {}, contentTypes = []) {
|
|
190
|
-
const { title, related } = item;
|
|
191
|
-
if (title) {
|
|
192
|
-
return isString(title) && !isEmpty(title) ? title : undefined;
|
|
193
|
-
} else if (related) {
|
|
194
|
-
const relationTitle = this.extractItemRelationTitle(isArray(related) ? last(related) : related, fields, { contentTypes });
|
|
195
|
-
return isString(relationTitle) && !isEmpty(relationTitle) ? relationTitle : undefined;
|
|
196
|
-
}
|
|
197
|
-
return undefined;
|
|
198
|
-
},
|
|
199
|
-
|
|
200
|
-
extractItemRelationTitle(relatedItem = {}, fields = {}, contentTypes = []) {
|
|
201
|
-
const { __contentType } = relatedItem;
|
|
202
|
-
const contentType = find(contentTypes, _ => _.contentTypeName === __contentType);
|
|
203
|
-
const { default: defaultFields = [] } = fields;
|
|
204
|
-
return get(fields, `${contentType ? contentType.collectionName : ''}`, defaultFields).map((_) => relatedItem[_]).filter((_) => _)[0] || '';
|
|
205
|
-
},
|
|
206
|
-
|
|
207
|
-
filterOutUnpublished(item) {
|
|
208
|
-
const relatedItem = item.related && last(item.related);
|
|
209
|
-
const isHandledByPublshFlow = relatedItem ? 'published_at' in relatedItem : false;
|
|
210
|
-
|
|
211
|
-
if (isHandledByPublshFlow) {
|
|
212
|
-
const isRelatedDefinedAndPublished = relatedItem ?
|
|
213
|
-
isHandledByPublshFlow && get(relatedItem, 'published_at') :
|
|
214
|
-
false;
|
|
215
|
-
return item.type === itemType.INTERNAL ? isRelatedDefinedAndPublished : true;
|
|
216
|
-
}
|
|
217
|
-
return (item.type !== itemType.INTERNAL) || relatedItem;
|
|
218
|
-
},
|
|
219
|
-
|
|
220
|
-
isContentTypeEligible(uid = '') {
|
|
221
|
-
const isOneOfAllowedType = ALLOWED_CONTENT_TYPES.filter(_ => uid.includes(_)).length > 0;
|
|
222
|
-
const isNoneOfRestricted = RESTRICTED_CONTENT_TYPES.filter(_ => uid.includes(_) || (uid === _)).length === 0;
|
|
223
|
-
return uid && isOneOfAllowedType && isNoneOfRestricted;
|
|
224
|
-
},
|
|
225
|
-
};
|
|
226
|
-
}
|