strapi-plugin-navigation 1.1.2 → 2.0.0-beta.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 +36 -15
- package/admin/src/components/EmptyView/index.js +7 -16
- package/admin/src/components/Item/ItemCardBadge/index.js +8 -0
- package/admin/src/components/Item/ItemCardHeader/Wrapper.js +21 -0
- package/admin/src/components/Item/ItemCardHeader/index.js +59 -0
- package/admin/src/components/Item/Wrapper.js +39 -0
- package/admin/src/components/Item/index.js +76 -124
- package/admin/src/components/NavigationItemList/Wrapper.js +22 -0
- package/admin/src/components/NavigationItemList/index.js +54 -0
- package/admin/src/components/PluginIcon/index.js +6 -0
- package/admin/src/index.js +49 -45
- package/admin/src/pages/App/index.js +31 -0
- package/admin/src/{containers → pages}/DataManagerProvider/actions.js +0 -0
- package/admin/src/{containers → pages}/DataManagerProvider/index.js +81 -85
- package/admin/src/{containers → pages}/DataManagerProvider/init.js +0 -0
- package/admin/src/{containers → pages}/DataManagerProvider/reducer.js +0 -0
- package/admin/src/pages/View/components/NavigationContentHeader/index.js +18 -0
- package/admin/src/pages/View/components/NavigationHeader/index.js +60 -0
- package/admin/src/pages/View/components/NavigationItemForm/index.js +403 -0
- package/admin/src/{containers → pages}/View/components/NavigationItemForm/utils/form.js +2 -2
- package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupFooter.js +40 -0
- package/admin/src/pages/View/components/NavigationItemPopup/NavigationItemPopupHeader.js +20 -0
- package/admin/src/{containers → pages}/View/components/NavigationItemPopup/index.js +16 -16
- package/admin/src/pages/View/index.js +209 -0
- package/admin/src/{containers → pages}/View/utils/enums.js +0 -0
- package/admin/src/{containers → pages}/View/utils/form.js +1 -1
- package/admin/src/{containers → pages}/View/utils/index.js +0 -0
- package/admin/src/{containers → pages}/View/utils/parsers.js +13 -12
- package/admin/src/pluginId.js +4 -3
- package/admin/src/translations/en.json +47 -38
- package/admin/src/translations/fr.json +7 -1
- package/admin/src/utils/getTrad.js +2 -2
- package/package.json +13 -5
- package/server/bootstrap.js +41 -0
- package/server/config.js +8 -0
- package/server/content-types/audience/index.js +9 -0
- package/{models/audience.js → server/content-types/audience/lifecycle.js} +0 -0
- package/{models/audience.settings.json → server/content-types/audience/schema.json} +4 -2
- package/server/content-types/index.js +13 -0
- package/server/content-types/navigation/index.js +9 -0
- package/{models/navigation.js → server/content-types/navigation/lifecycle.js} +0 -0
- package/server/content-types/navigation/schema.js +45 -0
- package/server/content-types/navigation-item/index.js +9 -0
- package/{models/navigationItem.js → server/content-types/navigation-item/lifecycle.js} +0 -0
- package/{models/navigationItem.settings.json → server/content-types/navigation-item/schema.json} +16 -12
- package/server/content-types/navigations-items-related/index.js +9 -0
- package/{models/navigations_items_related.js → server/content-types/navigations-items-related/lifecycle.js} +0 -0
- package/{models/navigations_items_related.settings.json → server/content-types/navigations-items-related/schema.json} +4 -2
- package/server/controllers/index.js +7 -0
- package/{controllers → server/controllers}/navigation.js +7 -39
- package/server/routes/admin.js +38 -0
- package/server/routes/index.js +3 -0
- package/{services → server/services}/__tests__/navigation.test.js +0 -0
- package/server/services/index.js +7 -0
- package/server/services/navigation.js +463 -0
- package/{services → server/services}/utils/constant.js +3 -1
- package/server/services/utils/functions.js +103 -0
- package/strapi-admin.js +1 -0
- package/strapi-server.js +18 -0
- package/__mocks__/helpers/another-plugin/blog-post.settings.json +0 -31
- package/__mocks__/helpers/another-plugin/pages.settings.json +0 -28
- package/__mocks__/helpers/blog-post.settings.json +0 -31
- package/__mocks__/helpers/home-page.settings.json +0 -4
- package/__mocks__/helpers/my-homepage.settings.json +0 -27
- package/__mocks__/helpers/pages.settings.json +0 -27
- package/__mocks__/helpers/strapi.js +0 -101
- package/admin/src/assets/images/icon-cross-blue.svg +0 -1
- package/admin/src/assets/images/icon_remove.svg +0 -19
- package/admin/src/components/Container/index.js +0 -7
- package/admin/src/components/Input/index.js +0 -41
- package/admin/src/components/Item/CardItem.js +0 -46
- package/admin/src/components/Item/CardItemLevelAdd.js +0 -41
- package/admin/src/components/Item/CardItemLevelWrapper.js +0 -27
- package/admin/src/components/Item/CardItemPath.js +0 -9
- package/admin/src/components/Item/CardItemRestore.js +0 -19
- package/admin/src/components/Item/CardItemTitle.js +0 -5
- package/admin/src/components/Item/CardWrapper.js +0 -78
- package/admin/src/components/ItemFooter/CardItemError.js +0 -11
- package/admin/src/components/ItemFooter/CardItemRelation.js +0 -18
- package/admin/src/components/ItemFooter/CardItemRelationStatus.js +0 -17
- package/admin/src/components/ItemFooter/CardItemType.js +0 -18
- package/admin/src/components/ItemFooter/Wrapper.js +0 -26
- package/admin/src/components/ItemFooter/index.js +0 -66
- package/admin/src/components/ItemOrdering/CardOrderingButton.js +0 -24
- package/admin/src/components/ItemOrdering/Wrapper.js +0 -24
- package/admin/src/components/ItemOrdering/index.js +0 -36
- package/admin/src/components/List/Container.js +0 -34
- package/admin/src/components/List/ListLevelRoot.js +0 -18
- package/admin/src/components/List/index.js +0 -81
- package/admin/src/components/Option/OptionButton.js +0 -18
- package/admin/src/components/Option/OptionSet.js +0 -14
- package/admin/src/components/Option/Wrapper.js +0 -15
- package/admin/src/components/Option/index.js +0 -47
- package/admin/src/components/Search/index.js +0 -86
- package/admin/src/components/Select/ClearIndicator.js +0 -15
- package/admin/src/components/Select/DropdownIndicator.js +0 -39
- package/admin/src/components/Select/ErrorMessage.js +0 -10
- package/admin/src/components/Select/IndicatorSeparator.js +0 -3
- package/admin/src/components/Select/MultiValueContainer.js +0 -43
- package/admin/src/components/Select/StyledOption.js +0 -11
- package/admin/src/components/Select/index.js +0 -68
- package/admin/src/components/Select/utils/styles.js +0 -92
- package/admin/src/containers/App/Wrapper.js +0 -14
- package/admin/src/containers/App/index.js +0 -34
- package/admin/src/containers/DetailsView/Wrapper.js +0 -21
- package/admin/src/containers/DetailsView/index.js +0 -111
- package/admin/src/containers/Initializer/index.js +0 -26
- package/admin/src/containers/ListView/Footer.js +0 -56
- package/admin/src/containers/ListView/components.js +0 -138
- package/admin/src/containers/ListView/index.js +0 -54
- package/admin/src/containers/View/FadedWrapper.js +0 -51
- package/admin/src/containers/View/HeaderForm.js +0 -9
- package/admin/src/containers/View/HeaderFormCell.js +0 -25
- package/admin/src/containers/View/Wrapper.js +0 -17
- package/admin/src/containers/View/components/NavigationItemForm/ModalFooter.js +0 -45
- package/admin/src/containers/View/components/NavigationItemForm/index.js +0 -427
- package/admin/src/containers/View/components/NavigationItemPopup/MediumPopup.js +0 -6
- package/admin/src/containers/View/index.js +0 -240
- package/admin/src/lifecycles.js +0 -3
- package/admin/src/permissions.js +0 -14
- package/config/functions/bootstrap.js +0 -138
- package/config/routes.json +0 -60
- package/config/schema.graphql.js +0 -204
- package/examples/audit-log-integrations.js.md +0 -38
- package/models/navigation.settings.json +0 -43
- package/public/assets/preview.png +0 -0
- package/services/navigation.js +0 -730
- package/services/utils/functions.js +0 -186
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
*
|
|
3
|
-
* ListView
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import React from "react";
|
|
8
|
-
import { useGlobalContext, LoadingIndicatorPage } from "strapi-helper-plugin";
|
|
9
|
-
import { FormattedMessage } from "react-intl";
|
|
10
|
-
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
11
|
-
import { faSearch } from "@fortawesome/free-solid-svg-icons";
|
|
12
|
-
import useDataManager from "../../hooks/useDataManager";
|
|
13
|
-
import { isEmpty } from "lodash";
|
|
14
|
-
import { Header } from "@buffetjs/custom";
|
|
15
|
-
import Footer from "./Footer";
|
|
16
|
-
import Wrapper from "../View/Wrapper";
|
|
17
|
-
import FadedWrapper from "../View/FadedWrapper";
|
|
18
|
-
import List from "../../components/List";
|
|
19
|
-
import EmptyView from "../../components/EmptyView";
|
|
20
|
-
import { getTrad, getTradId } from "../../translations";
|
|
21
|
-
|
|
22
|
-
const ListView = () => {
|
|
23
|
-
const { items, isLoadingForDataToBeSet } = useDataManager();
|
|
24
|
-
|
|
25
|
-
const { formatMessage } = useGlobalContext();
|
|
26
|
-
const newItemsCount = items.filter((_) => _.isNew).length;
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<Wrapper className="col-md-4">
|
|
30
|
-
<Header
|
|
31
|
-
title={{
|
|
32
|
-
label: formatMessage(getTrad('list.header.title')),
|
|
33
|
-
}}
|
|
34
|
-
content={formatMessage(
|
|
35
|
-
getTrad('list.header.description'),
|
|
36
|
-
{ count: newItemsCount },
|
|
37
|
-
)}
|
|
38
|
-
/>
|
|
39
|
-
{isLoadingForDataToBeSet && <LoadingIndicatorPage />}
|
|
40
|
-
<FadedWrapper>
|
|
41
|
-
{isEmpty(items) && (
|
|
42
|
-
<EmptyView>
|
|
43
|
-
<FontAwesomeIcon icon={faSearch} size="5x" />
|
|
44
|
-
<FormattedMessage id={getTradId('list.content.empty')} />
|
|
45
|
-
</EmptyView>
|
|
46
|
-
)}
|
|
47
|
-
{!isEmpty(items) && <List items={[...items]} />}
|
|
48
|
-
</FadedWrapper>
|
|
49
|
-
<Footer />
|
|
50
|
-
</Wrapper>
|
|
51
|
-
);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export default ListView;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import styled from "styled-components";
|
|
2
|
-
|
|
3
|
-
import { sizes } from "strapi-helper-plugin";
|
|
4
|
-
|
|
5
|
-
const FadedWrapper = styled.div`
|
|
6
|
-
display: flex;
|
|
7
|
-
flex-direction: column;
|
|
8
|
-
flex-grow: 1;
|
|
9
|
-
padding: 0;
|
|
10
|
-
margin: ${-2 * sizes.margin}px;
|
|
11
|
-
padding-left: ${ 2 * sizes.margin}px;
|
|
12
|
-
|
|
13
|
-
position: relative;
|
|
14
|
-
z-index: 0;
|
|
15
|
-
|
|
16
|
-
overflow: hidden;
|
|
17
|
-
|
|
18
|
-
&:before,
|
|
19
|
-
&:after {
|
|
20
|
-
display: block;
|
|
21
|
-
content: "";
|
|
22
|
-
height: ${4 * sizes.margin}px;
|
|
23
|
-
|
|
24
|
-
position: absolute;
|
|
25
|
-
left: 0;
|
|
26
|
-
right: 0;
|
|
27
|
-
z-index: 1;
|
|
28
|
-
|
|
29
|
-
background: #ffffff;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
&:before {
|
|
33
|
-
top: 0;
|
|
34
|
-
background: linear-gradient(
|
|
35
|
-
180deg,
|
|
36
|
-
rgba(250, 250, 251, 1) 0%,
|
|
37
|
-
rgba(250, 250, 251, 0) 100%
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
&:after {
|
|
42
|
-
bottom: 0;
|
|
43
|
-
background: linear-gradient(
|
|
44
|
-
0deg,
|
|
45
|
-
rgba(250, 250, 251, 1) 0%,
|
|
46
|
-
rgba(250, 250, 251, 0) 100%
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
`;
|
|
50
|
-
|
|
51
|
-
export default FadedWrapper;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import styled from "styled-components";
|
|
2
|
-
import { Header, HeaderActions } from "@buffetjs/styles";
|
|
3
|
-
|
|
4
|
-
const HeaderFormCell = styled.div`
|
|
5
|
-
display: flex;
|
|
6
|
-
flex-direction: column;
|
|
7
|
-
align-items: ${(props) =>
|
|
8
|
-
props.align === "right" ? "flex-end" : "flex-start"};
|
|
9
|
-
justify-content: center;
|
|
10
|
-
flex-grow: ${(props) => (props.fill ? 1 : "unset")};
|
|
11
|
-
|
|
12
|
-
${Header} {
|
|
13
|
-
margin-bottom: 0;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
${HeaderActions} {
|
|
17
|
-
padding-top: 0;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
.header-title {
|
|
21
|
-
max-width: 100%;
|
|
22
|
-
}
|
|
23
|
-
`;
|
|
24
|
-
|
|
25
|
-
export default HeaderFormCell;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import styled from "styled-components";
|
|
2
|
-
|
|
3
|
-
import { sizes } from "strapi-helper-plugin";
|
|
4
|
-
|
|
5
|
-
const Wrapper = styled.div`
|
|
6
|
-
display: flex;
|
|
7
|
-
flex-direction: column;
|
|
8
|
-
width: 100%;
|
|
9
|
-
height: calc(100vh - ${sizes.header.height});
|
|
10
|
-
min-height: calc(100vh - ${sizes.header.height});
|
|
11
|
-
max-height: calc(100vh - ${sizes.header.height});
|
|
12
|
-
padding-top: 1.8rem;
|
|
13
|
-
padding-left: 2rem;
|
|
14
|
-
padding-right: 2rem;
|
|
15
|
-
`;
|
|
16
|
-
|
|
17
|
-
export default Wrapper;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import styled from "styled-components";
|
|
3
|
-
import { ModalFooter as StrapiModalFooter, colors } from "strapi-helper-plugin";
|
|
4
|
-
|
|
5
|
-
const ModalFooter = styled(StrapiModalFooter)`
|
|
6
|
-
display: flex;
|
|
7
|
-
flex-direction: row;
|
|
8
|
-
|
|
9
|
-
section {
|
|
10
|
-
justify-content: flex-start;
|
|
11
|
-
flex-grow: 1;
|
|
12
|
-
|
|
13
|
-
background-color: ${colors.brightGrey};
|
|
14
|
-
|
|
15
|
-
&:last-of-type {
|
|
16
|
-
justify-content: flex-end;
|
|
17
|
-
|
|
18
|
-
background-color: ${colors.brightGrey};
|
|
19
|
-
|
|
20
|
-
button {
|
|
21
|
-
margin-left: 1rem;
|
|
22
|
-
margin-right: 0;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
label {
|
|
27
|
-
display: flex;
|
|
28
|
-
flex-direction: row;
|
|
29
|
-
align-items: center;
|
|
30
|
-
justify-content: center;
|
|
31
|
-
padding: 0;
|
|
32
|
-
margin: 0;
|
|
33
|
-
|
|
34
|
-
color: ${colors.leftMenu.darkGrey};
|
|
35
|
-
font-weight: 600;
|
|
36
|
-
font-style: italic;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
button {
|
|
40
|
-
margin-right: 1rem;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
`;
|
|
44
|
-
|
|
45
|
-
export default ModalFooter;
|
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useMemo, useState, useCallback } from 'react';
|
|
2
|
-
import { Button, Enumeration, Flex, Label, Text, Toggle } from '@buffetjs/core';
|
|
3
|
-
import { useIntl } from 'react-intl';
|
|
4
|
-
import { debounce, find, get, isEmpty, isEqual, isNil, isString } from 'lodash';
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
|
-
import { ButtonModal, ModalBody, ModalForm } from 'strapi-helper-plugin';
|
|
7
|
-
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
8
|
-
import { faEye, faInfoCircle } from '@fortawesome/free-solid-svg-icons';
|
|
9
|
-
import ModalFooter from './ModalFooter';
|
|
10
|
-
import Input from '../../../../components/Input';
|
|
11
|
-
import { navigationItemAdditionalFields, navigationItemType } from '../../utils/enums';
|
|
12
|
-
import slugify from 'slugify';
|
|
13
|
-
import Select from '../../../../components/Select';
|
|
14
|
-
import { extractRelatedItemLabel } from '../../utils/parsers';
|
|
15
|
-
import { form as formDefinition } from './utils/form';
|
|
16
|
-
import { checkFormValidity } from '../../utils/form';
|
|
17
|
-
import { getTrad, getTradId } from '../../../../translations';
|
|
18
|
-
|
|
19
|
-
const NavigationItemForm = ({
|
|
20
|
-
isLoading,
|
|
21
|
-
inputsPrefix,
|
|
22
|
-
data = {},
|
|
23
|
-
contentTypes = [],
|
|
24
|
-
contentTypeEntities = [],
|
|
25
|
-
usedContentTypeEntities = [],
|
|
26
|
-
availableAudience = [],
|
|
27
|
-
additionalFields = [],
|
|
28
|
-
contentTypesNameFields = {},
|
|
29
|
-
onSubmit,
|
|
30
|
-
getContentTypeEntities,
|
|
31
|
-
usedContentTypesData,
|
|
32
|
-
appendLabelPublicationStatus = () => '',
|
|
33
|
-
}) => {
|
|
34
|
-
const [hasBeenInitialized, setInitializedState] = useState(false);
|
|
35
|
-
const [hasChanged, setChangedState] = useState(false);
|
|
36
|
-
const [contentTypeSearchQuery, setContentTypeSearchQuery] = useState(undefined);
|
|
37
|
-
const [contentTypeSearchInputValue, setContentTypeSearchInputValue] = useState(undefined);
|
|
38
|
-
const [form, setFormState] = useState({});
|
|
39
|
-
const [formErrors, setFormErrorsState] = useState({});
|
|
40
|
-
const { relatedType } = form;
|
|
41
|
-
const { formatMessage } = useIntl();
|
|
42
|
-
|
|
43
|
-
const relatedFieldName = `${inputsPrefix}related`;
|
|
44
|
-
|
|
45
|
-
if (!hasBeenInitialized && !isEmpty(data)) {
|
|
46
|
-
setInitializedState(true);
|
|
47
|
-
setFormState({ ...data });
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const sanitizePayload = (payload = {}) => {
|
|
51
|
-
const { onItemClick, onItemLevelAddClick, related, relatedType, menuAttached, ...purePayload } = payload;
|
|
52
|
-
const sanitizedType = purePayload.type || navigationItemType.INTERNAL;
|
|
53
|
-
const relatedId = related?.value
|
|
54
|
-
const relatedCollectionType = relatedType?.value;
|
|
55
|
-
return {
|
|
56
|
-
...purePayload,
|
|
57
|
-
menuAttached: isNil(menuAttached) ? false : menuAttached,
|
|
58
|
-
type: sanitizedType,
|
|
59
|
-
path: sanitizedType === navigationItemType.INTERNAL ? purePayload.path : undefined,
|
|
60
|
-
externalPath: sanitizedType === navigationItemType.EXTERNAL ? purePayload.externalPath : undefined,
|
|
61
|
-
related: relatedId,
|
|
62
|
-
relatedType: relatedCollectionType,
|
|
63
|
-
isSingle: isSingleSelected,
|
|
64
|
-
uiRouterKey: generateUiRouterKey(purePayload.title, relatedId, relatedCollectionType),
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const handleSubmit = async e => {
|
|
69
|
-
if (e) {
|
|
70
|
-
e.preventDefault();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const payload = sanitizePayload(form);
|
|
74
|
-
const errors = await checkFormValidity(payload, formDefinition.schema(isSingleSelected));
|
|
75
|
-
if (!errors || isEmpty(errors)) {
|
|
76
|
-
return onSubmit(payload);
|
|
77
|
-
} else {
|
|
78
|
-
setFormErrorsState(errors);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const handleRemove = e => {
|
|
83
|
-
if (e) {
|
|
84
|
-
e.preventDefault();
|
|
85
|
-
}
|
|
86
|
-
return onSubmit(sanitizePayload({
|
|
87
|
-
...form,
|
|
88
|
-
removed: true,
|
|
89
|
-
}));
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const onChange = ({ target: { name, value } }) => {
|
|
93
|
-
setFormState(prevState => ({
|
|
94
|
-
...prevState,
|
|
95
|
-
updated: true,
|
|
96
|
-
[name]: value,
|
|
97
|
-
}));
|
|
98
|
-
if (!hasChanged) {
|
|
99
|
-
setChangedState(true);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const onChangeRelatedType = ({ target: { name, value } }) => {
|
|
104
|
-
const relatedTypeBeingReverted = data.relatedType && (data.relatedType.value === get(value, 'value', value));
|
|
105
|
-
setContentTypeSearchQuery(undefined);
|
|
106
|
-
setContentTypeSearchInputValue(undefined);
|
|
107
|
-
setFormState(prevState => ({
|
|
108
|
-
...prevState,
|
|
109
|
-
updated: true,
|
|
110
|
-
related: relatedTypeBeingReverted ? {
|
|
111
|
-
...data.related
|
|
112
|
-
} : undefined,
|
|
113
|
-
[name]: value,
|
|
114
|
-
}));
|
|
115
|
-
if (!hasChanged) {
|
|
116
|
-
setChangedState(true);
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const generateUiRouterKey = (title, related, relatedType) => {
|
|
122
|
-
if (title) {
|
|
123
|
-
return isString(title) && !isEmpty(title) ? slugify(title).toLowerCase() : undefined;
|
|
124
|
-
} else if (related) {
|
|
125
|
-
const relationTitle = extractRelatedItemLabel({
|
|
126
|
-
...contentTypeEntities.find(_ => _.id === related),
|
|
127
|
-
__collectionName: relatedType }, contentTypesNameFields, { contentTypes });
|
|
128
|
-
return isString(relationTitle) && !isEmpty(relationTitle) ? slugify(relationTitle).toLowerCase() : undefined;
|
|
129
|
-
}
|
|
130
|
-
return undefined;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
const typeSelectValue = form.type || navigationItemType.INTERNAL;
|
|
134
|
-
const relatedTypeSelectValue = form.relatedType;
|
|
135
|
-
const relatedSelectValue = form.related;
|
|
136
|
-
|
|
137
|
-
const typeSelectOptions = useMemo(
|
|
138
|
-
() => Object.keys(navigationItemType).map((key) => ({
|
|
139
|
-
value: key,
|
|
140
|
-
label: formatMessage(getTrad(`popup.item.form.type.${key.toLowerCase()}.label`)),
|
|
141
|
-
})),
|
|
142
|
-
[],
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
const isSingleSelected = useMemo(
|
|
146
|
-
() => relatedTypeSelectValue ? contentTypes.find(_ => _.uid === relatedType.value)?.isSingle : false,
|
|
147
|
-
[relatedTypeSelectValue, contentTypes],
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
const relatedTypeSelectOptions = useMemo(
|
|
151
|
-
() => contentTypes
|
|
152
|
-
.filter((contentType) => {
|
|
153
|
-
if (contentType.isSingle) {
|
|
154
|
-
return !usedContentTypesData.some((_) => _.__collectionName === contentType.uid);
|
|
155
|
-
}
|
|
156
|
-
return true;
|
|
157
|
-
})
|
|
158
|
-
.map((item) => ({
|
|
159
|
-
value: get(item, 'uid'),
|
|
160
|
-
label: appendLabelPublicationStatus(get(item, 'label', get(item, 'name')), item, true),
|
|
161
|
-
})),
|
|
162
|
-
[contentTypes, usedContentTypesData],
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
const relatedSelectOptions = contentTypeEntities
|
|
166
|
-
.filter((item) => {
|
|
167
|
-
const usedContentTypeEntitiesOfSameType = usedContentTypeEntities
|
|
168
|
-
.filter(uctItem => (get(relatedTypeSelectValue, 'value') === uctItem.__collectionName) && (uctItem.id !== get(relatedSelectValue, 'value')));
|
|
169
|
-
return !find(usedContentTypeEntitiesOfSameType, uctItem => item.id === uctItem.id);
|
|
170
|
-
})
|
|
171
|
-
.map((item) => ({
|
|
172
|
-
value: item.id,
|
|
173
|
-
label: appendLabelPublicationStatus(
|
|
174
|
-
extractRelatedItemLabel({
|
|
175
|
-
...item,
|
|
176
|
-
__collectionName: get(relatedTypeSelectValue, 'value', relatedTypeSelectValue),
|
|
177
|
-
}, contentTypesNameFields, { contentTypes }),
|
|
178
|
-
item
|
|
179
|
-
),
|
|
180
|
-
}));
|
|
181
|
-
|
|
182
|
-
const isExternal = form.type === navigationItemType.EXTERNAL;
|
|
183
|
-
const pathSourceName = isExternal ? 'externalPath' : 'path';
|
|
184
|
-
|
|
185
|
-
const audience = get(form, `${inputsPrefix}audience`, []);
|
|
186
|
-
const audienceOptions = availableAudience.map((item) => ({
|
|
187
|
-
value: item.id,
|
|
188
|
-
label: item.name,
|
|
189
|
-
}));
|
|
190
|
-
|
|
191
|
-
const submitDisabled = (form.type !== navigationItemType.EXTERNAL) && isNil(form.related);
|
|
192
|
-
|
|
193
|
-
const generatePreviewPath = () => {
|
|
194
|
-
if (!isExternal && data.levelPath) {
|
|
195
|
-
return (
|
|
196
|
-
<Text fontSize="sm" color="grey">
|
|
197
|
-
<FontAwesomeIcon icon={faEye} />{' '}
|
|
198
|
-
{formatMessage(getTrad('popup.item.form.path.preview'))}{' '}
|
|
199
|
-
{data.levelPath !== '/' ? `${data.levelPath}` : ''}/{form.path}
|
|
200
|
-
</Text>
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
return null;
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
const debouncedSearch = useCallback(
|
|
207
|
-
debounce(nextValue => setContentTypeSearchQuery(nextValue), 500),
|
|
208
|
-
[],
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
const debounceContentTypeSearchQuery = value => {
|
|
212
|
-
setContentTypeSearchInputValue(value);
|
|
213
|
-
debouncedSearch(value);
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
const thereAreNoMoreContentTypes = isEmpty(relatedSelectOptions) && !contentTypeSearchQuery;
|
|
217
|
-
|
|
218
|
-
useEffect(
|
|
219
|
-
() => {
|
|
220
|
-
const value = get(relatedSelectOptions, '0');
|
|
221
|
-
if (isSingleSelected && relatedSelectOptions.length === 1 && !isEqual(value, relatedSelectValue)) {
|
|
222
|
-
onChange({ target: { name: relatedFieldName, value} });
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
[isSingleSelected, relatedSelectOptions],
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
useEffect(() => {
|
|
229
|
-
const { value } = relatedType || {};
|
|
230
|
-
const fetchContentTypeEntities = async () => {
|
|
231
|
-
if (value) {
|
|
232
|
-
const item = find(
|
|
233
|
-
contentTypes,
|
|
234
|
-
(_) => _.uid === value,
|
|
235
|
-
);
|
|
236
|
-
if (item) {
|
|
237
|
-
await getContentTypeEntities({
|
|
238
|
-
type: item.endpoint || item.collectionName,
|
|
239
|
-
query: contentTypeSearchQuery,
|
|
240
|
-
}, item.plugin);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
fetchContentTypeEntities();
|
|
245
|
-
}, [relatedType, contentTypeSearchQuery]);
|
|
246
|
-
|
|
247
|
-
return (
|
|
248
|
-
<form onSubmit={handleSubmit}>
|
|
249
|
-
<ModalForm>
|
|
250
|
-
<ModalBody>
|
|
251
|
-
<section className="col-12">
|
|
252
|
-
<div className="row">
|
|
253
|
-
<div className="col-lg-9 col-md-12">
|
|
254
|
-
<Input
|
|
255
|
-
autoFocus
|
|
256
|
-
error={get(formErrors, `${inputsPrefix}title`)}
|
|
257
|
-
label={getTradId('popup.item.form.title.label')}
|
|
258
|
-
name={`${inputsPrefix}title`}
|
|
259
|
-
onChange={onChange}
|
|
260
|
-
placeholder={!isExternal ? getTradId('popup.item.form.title.placeholder') : ''}
|
|
261
|
-
type="text"
|
|
262
|
-
validations={{ required: true }}
|
|
263
|
-
value={get(form, `${inputsPrefix}title`, '')}
|
|
264
|
-
/>
|
|
265
|
-
</div>
|
|
266
|
-
<div className="col-lg-3 col-md-12">
|
|
267
|
-
<Flex alignItems="flex-start" flexWrap="wrap">
|
|
268
|
-
<Label
|
|
269
|
-
htmlFor={`${inputsPrefix}menuAttached`}
|
|
270
|
-
style={{ display: 'block' }}
|
|
271
|
-
message={formatMessage(getTrad('popup.item.form.menuAttached.label'))}
|
|
272
|
-
/>
|
|
273
|
-
<Toggle
|
|
274
|
-
name={`${inputsPrefix}menuAttached`}
|
|
275
|
-
onChange={onChange}
|
|
276
|
-
disabled={!(data.isMenuAllowedLevel && data.parentAttachedToMenu)}
|
|
277
|
-
value={get(form, `${inputsPrefix}menuAttached`, false)}
|
|
278
|
-
/>
|
|
279
|
-
</Flex>
|
|
280
|
-
</div>
|
|
281
|
-
</div>
|
|
282
|
-
<div className="row">
|
|
283
|
-
<div className="col-lg-7 col-md-12">
|
|
284
|
-
<Input
|
|
285
|
-
error={get(formErrors, `${inputsPrefix}${pathSourceName}`)}
|
|
286
|
-
label={getTradId(`popup.item.form.${pathSourceName}.label`)}
|
|
287
|
-
name={`${inputsPrefix}${pathSourceName}`}
|
|
288
|
-
onChange={onChange}
|
|
289
|
-
placeholder={getTradId(`popup.item.form.${pathSourceName}.placeholder`)}
|
|
290
|
-
description={generatePreviewPath()}
|
|
291
|
-
type="text"
|
|
292
|
-
validations={{ required: true }}
|
|
293
|
-
value={get(form, `${inputsPrefix}${pathSourceName}`, '')}
|
|
294
|
-
/>
|
|
295
|
-
</div>
|
|
296
|
-
<div className="col-lg-5 col-md-12">
|
|
297
|
-
<Label
|
|
298
|
-
htmlFor={`${inputsPrefix}type`}
|
|
299
|
-
message={formatMessage(getTrad('popup.item.form.type.label'))}
|
|
300
|
-
/>
|
|
301
|
-
<Enumeration
|
|
302
|
-
name={`${inputsPrefix}type`}
|
|
303
|
-
onChange={onChange}
|
|
304
|
-
options={typeSelectOptions}
|
|
305
|
-
value={typeSelectValue}
|
|
306
|
-
/>
|
|
307
|
-
</div>
|
|
308
|
-
</div>
|
|
309
|
-
{additionalFields.includes(navigationItemAdditionalFields.AUDIENCE) && (<div className="row">
|
|
310
|
-
<div className="col-lg-12">
|
|
311
|
-
<Label
|
|
312
|
-
htmlFor={`${inputsPrefix}audience`}
|
|
313
|
-
message={formatMessage(getTrad('popup.item.form.audience.label'))}
|
|
314
|
-
/>
|
|
315
|
-
<Select
|
|
316
|
-
name={`${inputsPrefix}audience`}
|
|
317
|
-
onChange={onChange}
|
|
318
|
-
options={audienceOptions}
|
|
319
|
-
isMulti={true}
|
|
320
|
-
value={audience}
|
|
321
|
-
/>
|
|
322
|
-
</div>
|
|
323
|
-
</div>)}
|
|
324
|
-
{!isExternal && (
|
|
325
|
-
<>
|
|
326
|
-
<div className="row">
|
|
327
|
-
<div className="col-lg-12">
|
|
328
|
-
<hr />
|
|
329
|
-
<Label
|
|
330
|
-
message={formatMessage(getTrad('popup.item.form.relatedSection.label'))}
|
|
331
|
-
/>
|
|
332
|
-
</div>
|
|
333
|
-
</div>
|
|
334
|
-
<div className="row">
|
|
335
|
-
<div className="col-lg-6 col-md-12">
|
|
336
|
-
<Label
|
|
337
|
-
htmlFor={`${inputsPrefix}relatedType`}
|
|
338
|
-
message={formatMessage(getTrad('popup.item.form.relatedType.label'))}
|
|
339
|
-
/>
|
|
340
|
-
<Select
|
|
341
|
-
name={`${inputsPrefix}relatedType`}
|
|
342
|
-
error={get(formErrors, `${inputsPrefix}relatedType`)}
|
|
343
|
-
onChange={onChangeRelatedType}
|
|
344
|
-
options={relatedTypeSelectOptions}
|
|
345
|
-
value={relatedTypeSelectValue}
|
|
346
|
-
/>
|
|
347
|
-
</div>
|
|
348
|
-
{relatedTypeSelectValue && !isSingleSelected && (
|
|
349
|
-
<div className="col-lg-6 col-md-12">
|
|
350
|
-
<Label
|
|
351
|
-
htmlFor={relatedFieldName}
|
|
352
|
-
message={formatMessage(getTrad('popup.item.form.related.label'))}
|
|
353
|
-
/>
|
|
354
|
-
<Select
|
|
355
|
-
name={relatedFieldName}
|
|
356
|
-
error={get(formErrors, relatedFieldName)}
|
|
357
|
-
onChange={onChange}
|
|
358
|
-
onInputChange={debounceContentTypeSearchQuery}
|
|
359
|
-
inputValue={contentTypeSearchInputValue}
|
|
360
|
-
isLoading={isLoading}
|
|
361
|
-
options={relatedSelectOptions}
|
|
362
|
-
value={relatedSelectValue}
|
|
363
|
-
/>
|
|
364
|
-
{!isLoading && thereAreNoMoreContentTypes && (
|
|
365
|
-
<Text
|
|
366
|
-
color="orange"
|
|
367
|
-
fontSize="sm"
|
|
368
|
-
>
|
|
369
|
-
<FontAwesomeIcon icon={faInfoCircle} />{' '}
|
|
370
|
-
{formatMessage(getTrad('popup.item.form.related.empty'), { contentTypeName: get(relatedTypeSelectValue, 'label') })}
|
|
371
|
-
</Text>)}
|
|
372
|
-
</div>
|
|
373
|
-
)}
|
|
374
|
-
</div>
|
|
375
|
-
</>
|
|
376
|
-
)}
|
|
377
|
-
</section>
|
|
378
|
-
</ModalBody>
|
|
379
|
-
</ModalForm>
|
|
380
|
-
<ModalFooter>
|
|
381
|
-
<section>
|
|
382
|
-
<Button
|
|
383
|
-
onClick={handleRemove}
|
|
384
|
-
color="delete"
|
|
385
|
-
label={formatMessage(getTrad('popup.item.form.button.remove'))}
|
|
386
|
-
/>
|
|
387
|
-
</section>
|
|
388
|
-
<section>
|
|
389
|
-
<ButtonModal
|
|
390
|
-
onClick={handleSubmit}
|
|
391
|
-
disabled={submitDisabled}
|
|
392
|
-
message={getTradId(`popup.item.form.button.${
|
|
393
|
-
form.viewId ? 'update' : 'create'
|
|
394
|
-
}`)}
|
|
395
|
-
/>
|
|
396
|
-
</section>
|
|
397
|
-
</ModalFooter>
|
|
398
|
-
</form>
|
|
399
|
-
);
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
NavigationItemForm.defaultProps = {
|
|
403
|
-
fieldsToDisable: [],
|
|
404
|
-
formErrors: {},
|
|
405
|
-
inputsPrefix: '',
|
|
406
|
-
onSubmit: (e) => e.preventDefault(),
|
|
407
|
-
requestError: null,
|
|
408
|
-
};
|
|
409
|
-
|
|
410
|
-
NavigationItemForm.propTypes = {
|
|
411
|
-
isLoading: PropTypes.bool,
|
|
412
|
-
fieldsToDisable: PropTypes.array,
|
|
413
|
-
formErrors: PropTypes.object.isRequired,
|
|
414
|
-
inputsPrefix: PropTypes.string,
|
|
415
|
-
data: PropTypes.object.isRequired,
|
|
416
|
-
onSubmit: PropTypes.func,
|
|
417
|
-
requestError: PropTypes.object,
|
|
418
|
-
contentTypes: PropTypes.array,
|
|
419
|
-
contentTypeEntities: PropTypes.array,
|
|
420
|
-
usedContentTypeEntities: PropTypes.array,
|
|
421
|
-
availableAudience: PropTypes.array,
|
|
422
|
-
additionalFields: PropTypes.array,
|
|
423
|
-
getContentTypeEntities: PropTypes.func.isRequired,
|
|
424
|
-
appendLabelPublicationStatus: PropTypes.func,
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
export default NavigationItemForm;
|