@webbio/strapi-plugin-page-builder 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/.prettierignore +17 -0
  2. package/README.md +3 -0
  3. package/admin/src/api/collection-type.ts +110 -0
  4. package/admin/src/api/has-page-relation.ts +34 -0
  5. package/admin/src/api/page-type.ts +31 -0
  6. package/admin/src/api/template.ts +25 -0
  7. package/admin/src/components/Combobox/index.tsx +77 -0
  8. package/admin/src/components/Combobox/react-select-custom-styles.tsx +111 -0
  9. package/admin/src/components/Combobox/styles.ts +22 -0
  10. package/admin/src/components/ConfirmModal/index.tsx +90 -0
  11. package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +118 -0
  12. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +95 -0
  13. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/styles.ts +26 -0
  14. package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +53 -0
  15. package/admin/src/components/EditView/Details/index.tsx +47 -0
  16. package/admin/src/components/EditView/Details/styles.ts +51 -0
  17. package/admin/src/components/EditView/PageSettings/index.tsx +104 -0
  18. package/admin/src/components/EditView/Template/TemplateConfirmModal/index.tsx +36 -0
  19. package/admin/src/components/EditView/Template/TemplateSelect/index.tsx +64 -0
  20. package/admin/src/components/EditView/Template/TemplateSelect/use-template-modules.ts +30 -0
  21. package/admin/src/components/EditView/index.tsx +27 -0
  22. package/admin/src/components/EditView/page-type-select.tsx +30 -0
  23. package/admin/src/components/EditView/wrapper.tsx +35 -0
  24. package/admin/src/components/Initializer/index.tsx +24 -0
  25. package/admin/src/components/PageTypeFilter/index.tsx +17 -0
  26. package/admin/src/components/PageTypeFilter/page-type-filter.tsx +130 -0
  27. package/admin/src/components/PluginIcon/index.tsx +12 -0
  28. package/admin/src/constants.ts +1 -0
  29. package/admin/src/index.tsx +115 -0
  30. package/admin/src/pages/App/index.tsx +25 -0
  31. package/admin/src/pages/HomePage/index.tsx +19 -0
  32. package/admin/src/pluginId.ts +5 -0
  33. package/admin/src/redux/initialData.reducer.ts +0 -0
  34. package/admin/src/translations/en.json +6 -0
  35. package/admin/src/translations/nl.json +6 -0
  36. package/admin/src/utils/getRequestUrl.ts +11 -0
  37. package/admin/src/utils/getTrad.ts +5 -0
  38. package/admin/src/utils/hooks/useDebounce.ts +17 -0
  39. package/admin/src/utils/hooks/useGetLocaleFromUrl.ts +9 -0
  40. package/admin/src/utils/hooks/usePrevious.ts +12 -0
  41. package/admin/src/utils/sanitizeModules.ts +10 -0
  42. package/custom.d.ts +5 -0
  43. package/package.json +71 -0
  44. package/server/bootstrap.ts +106 -0
  45. package/server/config/index.ts +4 -0
  46. package/server/content-types/index.ts +1 -0
  47. package/server/controllers/collection-types.ts +27 -0
  48. package/server/controllers/index.ts +9 -0
  49. package/server/controllers/page-type.ts +12 -0
  50. package/server/controllers/page.ts +20 -0
  51. package/server/destroy.ts +5 -0
  52. package/server/index.ts +23 -0
  53. package/server/middlewares/index.ts +1 -0
  54. package/server/policies/index.ts +1 -0
  55. package/server/register.ts +5 -0
  56. package/server/routes/index.ts +42 -0
  57. package/server/schema/page-end.json +97 -0
  58. package/server/schema/page-start.json +87 -0
  59. package/server/schema/page-type-end.json +49 -0
  60. package/server/schema/page-type-start.json +44 -0
  61. package/server/schema/template.json +35 -0
  62. package/server/services/builder.ts +121 -0
  63. package/server/services/collection-types.ts +49 -0
  64. package/server/services/index.ts +11 -0
  65. package/server/services/page-type.ts +22 -0
  66. package/server/services/page.ts +24 -0
  67. package/server/utils/graphql.ts +110 -0
  68. package/server/utils/reload-strapi-on-load.ts +13 -0
  69. package/shared/utils/constants.ts +4 -0
  70. package/shared/utils/sleep.ts +1 -0
  71. package/strapi-admin.js +3 -0
  72. package/strapi-server.js +3 -0
  73. package/tsconfig.json +20 -0
  74. package/tsconfig.server.json +25 -0
  75. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,95 @@
1
+ import React from 'react';
2
+ import { useHistory } from 'react-router-dom';
3
+
4
+ import { Plus } from '@strapi/icons';
5
+ import { useFetchClient, useCMEditViewDataManager } from '@strapi/helper-plugin';
6
+
7
+ import getRequestUrl from '../../../../utils/getRequestUrl';
8
+ import { sanitizeModules } from '../../../../utils/sanitizeModules';
9
+ import { PAGE_UID } from '../../../../../../shared/utils/constants';
10
+ import { IGetTranslationPageLinks } from '../../../../../../server/controllers/collection-types';
11
+
12
+ import S from './styles';
13
+
14
+ export const CreatePageButton = () => {
15
+ const history = useHistory();
16
+ const { layout, initialData } = useCMEditViewDataManager();
17
+
18
+ const { post, get } = useFetchClient();
19
+ const url = `/content-manager/collectionType/${PAGE_UID}/create`;
20
+
21
+ const handleCreatePage = async (e: React.MouseEvent<HTMLAnchorElement>) => {
22
+ e.preventDefault();
23
+ try {
24
+ const pageTypeUrl = getRequestUrl(`/page-types/${layout.uid}`);
25
+ const { data: pageType } = await get(pageTypeUrl);
26
+ const mappedLocalizations = (initialData?.localizations || []).map((x: any) => x?.id).join(',');
27
+ const linkedPages: { data: IGetTranslationPageLinks[] } = await get(
28
+ getRequestUrl(`/collection-types-page-links/${layout.uid}/${mappedLocalizations}`)
29
+ );
30
+ const createLocalizedPage = !linkedPages?.data?.find((x) => x.locale === initialData?.locale);
31
+ const locale = initialData?.locale;
32
+ const modules = sanitizeModules(pageType?.template?.modules || []);
33
+
34
+ const newPage = await createNewPage({
35
+ modules,
36
+ post,
37
+ locale,
38
+ pageTypeId: pageType.id,
39
+ collectionTypeId: initialData.id,
40
+ layoutUid: layout.uid,
41
+ relatedEntityId: createLocalizedPage ? linkedPages.data?.[0]?.id : undefined
42
+ });
43
+
44
+ if (newPage?.id) {
45
+ history.push(`/content-manager/collectionType/${PAGE_UID}/${newPage.id}?plugins[i18n][locale]=${locale}`);
46
+ }
47
+ } catch (error) {
48
+ console.error(error);
49
+ }
50
+ };
51
+
52
+ return (
53
+ <S.CreateButton to={url} onClick={handleCreatePage} size="S" variant="secondary" startIcon={<Plus />} width="100%">
54
+ Create new page
55
+ </S.CreateButton>
56
+ );
57
+ };
58
+
59
+ interface ICreateNewPageProps {
60
+ locale: string;
61
+ collectionTypeId: number;
62
+ layoutUid: string;
63
+ modules?: Record<string, any>[];
64
+ post: any;
65
+ pageTypeId: number;
66
+ relatedEntityId?: number;
67
+ }
68
+
69
+ const createNewPage = async ({
70
+ post,
71
+ locale,
72
+ collectionTypeId,
73
+ layoutUid,
74
+ modules,
75
+ pageTypeId,
76
+ relatedEntityId
77
+ }: ICreateNewPageProps) => {
78
+ // Including locale in url is neccesary.
79
+ const relatedEntityIdQuery = relatedEntityId ? `&plugins[i18n][relatedEntityId]=${relatedEntityId}` : '';
80
+ const url = `/content-manager/collection-types/${PAGE_UID}?plugins[i18n][locale]=${locale}${relatedEntityIdQuery}`;
81
+ const { data: page } = await post(url, {
82
+ locale,
83
+ pageType: { connect: [{ id: pageTypeId }] },
84
+ collectionTypeData: {
85
+ id: collectionTypeId,
86
+ __type: layoutUid,
87
+ __pivot: {
88
+ field: 'page'
89
+ }
90
+ },
91
+ modules
92
+ });
93
+
94
+ return page;
95
+ };
@@ -0,0 +1,26 @@
1
+ import styled, { css } from 'styled-components';
2
+
3
+ import { Typography, Button } from '@strapi/design-system';
4
+
5
+ const SubtleType = styled(Typography)`
6
+ ${({ _theme }) => css`
7
+ text-transform: capitalize;
8
+ `}
9
+ `;
10
+
11
+ const CreateButton = styled(Button)`
12
+ ${({ _theme }) => css`
13
+ text-decoration: none;
14
+
15
+ > div {
16
+ display: flex;
17
+ }
18
+ `}
19
+ `;
20
+
21
+ const CreatePageButtonStyles = {
22
+ SubtleType,
23
+ CreateButton
24
+ };
25
+
26
+ export default CreatePageButtonStyles;
@@ -0,0 +1,53 @@
1
+ import React from 'react';
2
+
3
+ import { useCMEditViewDataManager } from '@strapi/helper-plugin';
4
+ import { Flex } from '@strapi/design-system';
5
+ import { Link } from '@strapi/icons';
6
+
7
+ import { Wrapper } from '../wrapper';
8
+ import { CreatePageButton } from './CreatePageButton';
9
+ import { PAGE_TYPE_PAGE, PAGE_UID } from '../../../../../shared/utils/constants';
10
+ import S from '../Details/styles';
11
+
12
+ export const CollectionTypeSettings = () => {
13
+ const { layout, isCreatingEntry, initialData } = useCMEditViewDataManager();
14
+
15
+ const isUserCreatedContentType = layout.uid.startsWith('api::');
16
+ const linkedPage = initialData.page?.[0];
17
+
18
+ const showCreatePageButton = isUserCreatedContentType && !isCreatingEntry && !linkedPage;
19
+ const url = generateLink(linkedPage?.id, initialData?.locale);
20
+
21
+ if (isCreatingEntry) {
22
+ return null;
23
+ }
24
+
25
+ return (
26
+ <Wrapper title="Settings">
27
+ <Flex direction="column" gap={4} width="100%" alignItems="start">
28
+ {showCreatePageButton && <CreatePageButton />}
29
+
30
+ {url && (
31
+ <Flex direction="column" alignItems="start" width="100%" gap={1}>
32
+ <S.SubtleType variant="omega" fontWeight="bold" textColor="neutral800">
33
+ {PAGE_TYPE_PAGE}
34
+ </S.SubtleType>
35
+ <S.EntityLinkWrapper variant="pi" textColor="neutral800">
36
+ <S.EntityLink title={linkedPage.title || '-'} to={url} variant="pi">
37
+ <Link />
38
+ {linkedPage.title || '-'}
39
+ </S.EntityLink>
40
+ </S.EntityLinkWrapper>
41
+ </Flex>
42
+ )}
43
+ </Flex>
44
+ </Wrapper>
45
+ );
46
+ };
47
+
48
+ const generateLink = (entityId?: string, locale?: string) => {
49
+ if (!entityId) {
50
+ return '';
51
+ }
52
+ return `/content-manager/collectionType/${PAGE_UID}/${entityId}?plugins[i18n][locale]=${locale}`;
53
+ };
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+
3
+ import { Flex } from '@strapi/design-system';
4
+ import { Link } from '@strapi/icons';
5
+
6
+ import { PageType } from '../../../api/page-type';
7
+ import { PAGE_TYPE_PAGE } from '../../../../../shared/utils/constants';
8
+ import S from './styles';
9
+
10
+ interface Props {
11
+ pageType?: PageType | null;
12
+ entityId?: number;
13
+ entityTitle?: string;
14
+ locale?: string;
15
+ }
16
+
17
+ const Details = (props: Props) => {
18
+ const { entityTitle, pageType } = props;
19
+
20
+ const url = generateLink(props);
21
+
22
+ return (
23
+ <Flex gap={4} width="100%" direction="column">
24
+ <Flex direction="column" alignItems="start" width="100%" gap={1}>
25
+ <S.SubtleType variant="omega" fontWeight="bold" textColor="neutral800">
26
+ {pageType?.title || PAGE_TYPE_PAGE}
27
+ </S.SubtleType>
28
+ <S.EntityLinkWrapper variant="pi" textColor="neutral800">
29
+ <S.EntityLink title={entityTitle} to={url} variant="pi">
30
+ <Link />
31
+ {entityTitle}
32
+ </S.EntityLink>
33
+ </S.EntityLinkWrapper>
34
+ </Flex>
35
+ </Flex>
36
+ );
37
+ };
38
+
39
+ export { Details };
40
+
41
+ const generateLink = ({ locale, pageType, entityId }: Props) => {
42
+ if (!pageType?.uid || !entityId) {
43
+ return '';
44
+ }
45
+
46
+ return `/content-manager/collectionType/${pageType.uid}/${entityId}?plugins[i18n][locale]=${locale}`;
47
+ };
@@ -0,0 +1,51 @@
1
+ import styled, { css } from 'styled-components';
2
+
3
+ import { Typography, Link, Button } from '@strapi/design-system';
4
+
5
+ const SubtleType = styled(Typography)`
6
+ ${({ _theme }) => css`
7
+ text-transform: capitalize;
8
+ `}
9
+ `;
10
+
11
+ const EntityLinkWrapper = styled(Typography)`
12
+ ${({ _theme }) => css`
13
+ display: flex;
14
+ `}
15
+ `;
16
+
17
+ const EntityLink = styled(Link)`
18
+ ${({ _theme }) => css`
19
+ span {
20
+ line-height: 1.2;
21
+ font-size: inherit;
22
+ display: flex;
23
+ gap: 4px;
24
+ align-items: center;
25
+ }
26
+
27
+ svg {
28
+ width: 0.7rem;
29
+ height: 0.7rem;
30
+ }
31
+ `}
32
+ `;
33
+
34
+ const EditLink = styled(Button)`
35
+ ${({ _theme }) => css`
36
+ text-decoration: none;
37
+
38
+ > div {
39
+ display: flex;
40
+ }
41
+ `}
42
+ `;
43
+
44
+ const DetailsStyles = {
45
+ SubtleType,
46
+ EntityLink,
47
+ EntityLinkWrapper,
48
+ EditLink
49
+ };
50
+
51
+ export default DetailsStyles;
@@ -0,0 +1,104 @@
1
+ import React, { useEffect, useMemo, useState } from 'react';
2
+
3
+ import { useCMEditViewDataManager } from '@strapi/helper-plugin';
4
+ import { Stack, Flex } from '@strapi/design-system';
5
+ import { Cog, Cross } from '@strapi/icons';
6
+
7
+ import { TemplateSelect } from '../Template/TemplateSelect';
8
+ import { PageTypeSelect } from '../page-type-select';
9
+ import { CollectionTypeSearch } from '../CollectionTypeSearch';
10
+ import { Wrapper } from '../wrapper';
11
+ import { PageType, useGetPageTypes } from '../../../api/page-type';
12
+ import { Details } from '../Details';
13
+ import S from '../Details/styles';
14
+
15
+ export const PageSettings = () => {
16
+ const { isCreatingEntry, initialData, onChange, modifiedData } = useCMEditViewDataManager();
17
+ const { data: pageTypes } = useGetPageTypes({});
18
+
19
+ const [selectedPageType, setSelectedPageType] = useState<PageType | undefined | null>(initialData?.initialPageType);
20
+ const [isEditting, setIsEditting] = useState(false);
21
+ const showEditFields = useMemo(
22
+ () => isCreatingEntry || !selectedPageType?.id || !initialData.collectionTypeTitle || isEditting,
23
+ [isCreatingEntry, isEditting, selectedPageType, initialData]
24
+ );
25
+
26
+ const setFormValue = (name: string, value?: string | Record<string, any>[]) => {
27
+ onChange({
28
+ target: {
29
+ name,
30
+ value
31
+ },
32
+ shouldSetInitialValue: true
33
+ });
34
+ };
35
+
36
+ useEffect(() => {
37
+ setSelectedPageType(initialData?.initialPageType);
38
+ setIsEditting(false);
39
+ }, [initialData]);
40
+
41
+ const cancelEdit = () => {
42
+ setIsEditting(false);
43
+ setSelectedPageType(initialData?.initialPageType || []);
44
+ setFormValue('pageType', initialData?.initialPageType || []);
45
+ setFormValue('collectionTypeTitle', initialData?.collectionTypeTitle);
46
+ setFormValue('collectionTypeId', initialData?.collectionTypeId);
47
+ };
48
+
49
+ const removePageType = () => {
50
+ setSelectedPageType(undefined);
51
+ setFormValue('pageType', []);
52
+ setFormValue('collectionTypeTitle', undefined);
53
+ setFormValue('collectionTypeId', undefined);
54
+ };
55
+
56
+ const handleSelectPageType = (pageTypeId: string) => {
57
+ const pageType = pageTypes?.find((pageType) => pageType.id === Number(pageTypeId));
58
+
59
+ if (pageType) {
60
+ setSelectedPageType(pageType);
61
+ const formPageType = {
62
+ ...pageType,
63
+ mainField: pageType.uid,
64
+ label: pageType.uid,
65
+ value: pageType.id
66
+ };
67
+ setFormValue('pageType', [formPageType]);
68
+ } else {
69
+ removePageType();
70
+ }
71
+ };
72
+
73
+ return (
74
+ <Wrapper title="Settings">
75
+ <Flex direction="column" gap={4} width="100%">
76
+ {showEditFields ? (
77
+ <Stack spacing={4} width="100%">
78
+ <PageTypeSelect pageTypes={pageTypes} selectedPageType={selectedPageType} onChange={handleSelectPageType} />
79
+ <TemplateSelect />
80
+ {selectedPageType?.uid && <CollectionTypeSearch uid={selectedPageType.uid} />}
81
+ </Stack>
82
+ ) : (
83
+ <Details
84
+ locale={initialData?.locale}
85
+ pageType={selectedPageType}
86
+ entityId={modifiedData.collectionTypeId}
87
+ entityTitle={modifiedData.collectionTypeTitle}
88
+ />
89
+ )}
90
+ {(!showEditFields || isEditting) && (
91
+ <S.EditLink
92
+ onClick={() => (isEditting ? cancelEdit() : setIsEditting(true))}
93
+ size="S"
94
+ variant={isEditting ? 'danger-light' : 'secondary'}
95
+ startIcon={isEditting ? <Cross /> : <Cog />}
96
+ width="100%"
97
+ >
98
+ {isEditting ? 'Annuleer bewerking' : 'Bewerk koppeling'}
99
+ </S.EditLink>
100
+ )}
101
+ </Flex>
102
+ </Wrapper>
103
+ );
104
+ };
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl';
3
+
4
+ import { Icon, Flex } from '@strapi/design-system';
5
+ import { Rotate } from '@strapi/icons';
6
+
7
+ import getTrad from '../../../../utils/getTrad';
8
+ import ConfirmModal, { IConfirmModalProps } from '../../../ConfirmModal';
9
+
10
+ interface ITemplateConfirmModalProps extends IConfirmModalProps {}
11
+
12
+ const TemplateConfirmModal = (props: ITemplateConfirmModalProps): JSX.Element => {
13
+ const { formatMessage } = useIntl();
14
+
15
+ return (
16
+ <ConfirmModal
17
+ {...props}
18
+ title={
19
+ <Flex gap={4}>
20
+ <Icon as={Rotate} color="neutral900" width={4} height={4} />
21
+ {formatMessage({
22
+ id: getTrad('template.confirmModal.title')
23
+ })}
24
+ </Flex>
25
+ }
26
+ body={formatMessage({
27
+ id: getTrad('template.confirmModal.body')
28
+ })}
29
+ submitText={formatMessage({
30
+ id: getTrad('template.confirmModal.buttons.submit')
31
+ })}
32
+ />
33
+ );
34
+ };
35
+
36
+ export default TemplateConfirmModal;
@@ -0,0 +1,64 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { SingleSelect, SingleSelectOption } from '@strapi/design-system';
3
+ import { useCMEditViewDataManager } from '@strapi/helper-plugin';
4
+ import { Template } from '../../../../api/template';
5
+ import TemplateConfirmModal from '../TemplateConfirmModal';
6
+ import { useTemplateModules } from './use-template-modules';
7
+
8
+ export const TemplateSelect = () => {
9
+ const { onChange, modifiedData } = useCMEditViewDataManager();
10
+ const [selectedTemplate, setSelectedTemplate] = useState<Template | null>(null);
11
+ const { templates, replaceContentTypeModules } = useTemplateModules(onChange);
12
+ const [templateIdToSelect, setTemplateIdToSelect] = useState<string | undefined>();
13
+
14
+ const handleSelectChange = (templateId?: string) => {
15
+ setTemplateIdToSelect(templateId);
16
+ };
17
+
18
+ const handleSelectTemplate = (templateId?: string) => {
19
+ const template = templates?.find((template) => template.id === Number(templateId));
20
+ template == null ? setSelectedTemplate(null) : setSelectedTemplate(template);
21
+
22
+ setTemplateIdToSelect(undefined);
23
+ };
24
+
25
+ useEffect(() => {
26
+ const noModules = getHasModules(modifiedData?.modules);
27
+
28
+ const template = templates?.find((template) => template.id === Number(modifiedData?.pageType?.[0]?.templateId));
29
+ if (template && noModules) {
30
+ setSelectedTemplate(template);
31
+ }
32
+ }, [modifiedData?.pageType]);
33
+
34
+ useEffect(() => {
35
+ if (selectedTemplate !== null) {
36
+ replaceContentTypeModules(selectedTemplate.modules);
37
+ }
38
+ }, [selectedTemplate]);
39
+
40
+ return (
41
+ <>
42
+ <SingleSelect
43
+ label="Template"
44
+ placeholder="Choose a template"
45
+ value={selectedTemplate?.id || 0}
46
+ onChange={handleSelectChange}
47
+ >
48
+ <SingleSelectOption value={0}>None</SingleSelectOption>
49
+ {templates?.map((template) => (
50
+ <SingleSelectOption key={template.id} value={template.id}>
51
+ {template.title}
52
+ </SingleSelectOption>
53
+ ))}
54
+ </SingleSelect>
55
+ <TemplateConfirmModal
56
+ isOpen={Boolean(templateIdToSelect)}
57
+ onSubmit={() => handleSelectTemplate(templateIdToSelect)}
58
+ closeModal={() => setTemplateIdToSelect(undefined)}
59
+ />
60
+ </>
61
+ );
62
+ };
63
+
64
+ const getHasModules = (modules: any[]): boolean => (modules?.length || 0) === 0;
@@ -0,0 +1,30 @@
1
+ import { Template, useGetTemplates } from '../../../../api/template';
2
+
3
+ import { sanitizeModules } from '../../../../utils/sanitizeModules';
4
+
5
+ type OnChangeFormType = (props: { target: Record<string, any>; shouldSetInitialValue: boolean }) => void;
6
+
7
+ export const useTemplateModules = (onChange: OnChangeFormType) => {
8
+ const { data: templates } = useGetTemplates({});
9
+
10
+ return {
11
+ findTemplate,
12
+ templates,
13
+ replaceContentTypeModules: (modules: Record<string, any>[]) => replaceContentTypeModules(onChange, modules)
14
+ };
15
+ };
16
+
17
+ const findTemplate = (templates?: Template[], selectedTemplateId?: string | number) =>
18
+ templates?.find((template) => template.id === Number(selectedTemplateId));
19
+
20
+ const replaceContentTypeModules = (onChange: OnChangeFormType, modules: Record<string, any>[]) => {
21
+ const sanitizedModules = sanitizeModules(modules);
22
+
23
+ return onChange({
24
+ target: {
25
+ name: 'modules',
26
+ value: sanitizedModules
27
+ },
28
+ shouldSetInitialValue: true
29
+ });
30
+ };
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+
3
+ import { useCMEditViewDataManager } from '@strapi/helper-plugin';
4
+
5
+ import { PAGE_UID } from '../../../../shared/utils/constants';
6
+ import { PageSettings } from './PageSettings';
7
+ import { CollectionTypeSettings } from './CollectionTypeSettings';
8
+ import { useHasPageRelation } from '../../api/has-page-relation';
9
+
10
+ export const EditView = () => {
11
+ const { layout } = useCMEditViewDataManager();
12
+
13
+ const isPageCollectionType = layout.uid === PAGE_UID;
14
+ const isCollectionType = layout.kind === 'collectionType';
15
+
16
+ const { data: hasPageRelation, isLoading } = useHasPageRelation({ uid: layout.uid });
17
+
18
+ if (isPageCollectionType) {
19
+ return <PageSettings />;
20
+ }
21
+
22
+ if (isCollectionType && !isLoading && hasPageRelation) {
23
+ return <CollectionTypeSettings />;
24
+ }
25
+
26
+ return null;
27
+ };
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+
3
+ import { SingleSelect, SingleSelectOption } from '@strapi/design-system';
4
+
5
+ import { PageType } from '../../api/page-type';
6
+ import { PAGE_TYPE_PAGE } from '../../../../shared/utils/constants';
7
+
8
+ interface Props {
9
+ onChange: (pageTypeId: string) => void;
10
+ selectedPageType?: PageType | null;
11
+ pageTypes?: PageType[];
12
+ }
13
+
14
+ export const PageTypeSelect = ({ onChange, pageTypes, selectedPageType }: Props) => {
15
+ return (
16
+ <SingleSelect
17
+ label="Page type"
18
+ placeholder="Choose a page type"
19
+ value={selectedPageType?.id || PAGE_TYPE_PAGE}
20
+ onChange={onChange}
21
+ >
22
+ <SingleSelectOption value={PAGE_TYPE_PAGE}>Page</SingleSelectOption>
23
+ {pageTypes?.map((pageType: PageType) => (
24
+ <SingleSelectOption key={pageType?.uid} value={pageType?.id}>
25
+ {pageType?.title}
26
+ </SingleSelectOption>
27
+ ))}
28
+ </SingleSelect>
29
+ );
30
+ };
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ import { Flex, Box, Divider, Typography } from '@strapi/design-system';
3
+
4
+ interface Props {
5
+ title: string;
6
+ children: React.ReactNode;
7
+ }
8
+
9
+ export const Wrapper = (props: Props) => {
10
+ return (
11
+ <Flex
12
+ as="aside"
13
+ direction="column"
14
+ background="neutral0"
15
+ borderColor="neutral150"
16
+ hasRadius={true}
17
+ paddingTop={6}
18
+ paddingBottom={4}
19
+ paddingRight={4}
20
+ paddingLeft={4}
21
+ shadow="tableShadow"
22
+ alignItems="left"
23
+ >
24
+ <Typography variant="sigma" textColor="neutral600" id="additional-information">
25
+ {props.title}
26
+ </Typography>
27
+
28
+ <Box paddingTop={2} paddingBottom={4}>
29
+ <Divider />
30
+ </Box>
31
+
32
+ {props.children}
33
+ </Flex>
34
+ );
35
+ };
@@ -0,0 +1,24 @@
1
+ /**
2
+ *
3
+ * Initializer
4
+ *
5
+ */
6
+
7
+ import { useEffect, useRef } from 'react';
8
+ import pluginId from '../../pluginId';
9
+
10
+ type InitializerProps = {
11
+ setPlugin: (id: string) => void;
12
+ };
13
+
14
+ const Initializer = ({ setPlugin }: InitializerProps) => {
15
+ const ref = useRef(setPlugin);
16
+
17
+ useEffect(() => {
18
+ ref.current(pluginId);
19
+ }, []);
20
+
21
+ return null;
22
+ };
23
+
24
+ export default Initializer;
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { useLocation } from 'react-router-dom';
3
+
4
+ import { PageTypeFilter } from './page-type-filter';
5
+ import { PAGE_UID } from '../../../../shared/utils/constants';
6
+
7
+ const PageTypeFilterContainer = () => {
8
+ const { pathname } = useLocation();
9
+
10
+ if (pathname === `/content-manager/collectionType/${PAGE_UID}`) {
11
+ return <PageTypeFilter />;
12
+ }
13
+
14
+ return null;
15
+ };
16
+
17
+ export default PageTypeFilterContainer;