@webbio/strapi-plugin-page-builder 0.2.2 → 0.2.4

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 (93) hide show
  1. package/README.md +98 -98
  2. package/admin/src/api/collection-type.ts +110 -110
  3. package/admin/src/api/has-page-relation.ts +34 -34
  4. package/admin/src/api/page-type.ts +31 -31
  5. package/admin/src/api/template.ts +27 -27
  6. package/admin/src/components/Combobox/index.tsx +77 -77
  7. package/admin/src/components/Combobox/react-select-custom-styles.tsx +120 -111
  8. package/admin/src/components/Combobox/styles.ts +22 -22
  9. package/admin/src/components/ConfirmModal/index.tsx +90 -90
  10. package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +124 -124
  11. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +104 -101
  12. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/styles.ts +19 -19
  13. package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +74 -74
  14. package/admin/src/components/EditView/Details/index.tsx +47 -47
  15. package/admin/src/components/EditView/Details/styles.ts +51 -51
  16. package/admin/src/components/EditView/PageSettings/index.tsx +104 -104
  17. package/admin/src/components/EditView/Template/TemplateConfirmModal/index.tsx +36 -36
  18. package/admin/src/components/EditView/Template/TemplateSelect/index.tsx +69 -69
  19. package/admin/src/components/EditView/Template/TemplateSelect/use-template-modules.ts +38 -38
  20. package/admin/src/components/EditView/index.tsx +29 -29
  21. package/admin/src/components/EditView/page-type-select.tsx +32 -32
  22. package/admin/src/components/EditView/wrapper.tsx +35 -35
  23. package/admin/src/components/Initializer/index.tsx +24 -24
  24. package/admin/src/components/PageTypeFilter/index.tsx +17 -17
  25. package/admin/src/components/PageTypeFilter/page-type-filter.tsx +130 -130
  26. package/admin/src/components/PluginIcon/index.tsx +12 -12
  27. package/admin/src/constants.ts +3 -3
  28. package/admin/src/index.tsx +59 -59
  29. package/admin/src/middlewares/index.tsx +37 -37
  30. package/admin/src/pluginId.ts +5 -5
  31. package/admin/src/translations/en.json +6 -6
  32. package/admin/src/translations/nl.json +6 -6
  33. package/admin/src/utils/getRequestUrl.ts +11 -11
  34. package/admin/src/utils/getTrad.ts +5 -5
  35. package/admin/src/utils/hooks/useDebounce.ts +17 -17
  36. package/admin/src/utils/hooks/useGetLocaleFromUrl.ts +9 -9
  37. package/admin/src/utils/hooks/usePrevious.ts +12 -12
  38. package/admin/src/utils/sanitizeModules.ts +43 -10
  39. package/custom.d.ts +5 -5
  40. package/dist/package.json +9 -9
  41. package/dist/server/graphql/page-by-slug.js +9 -9
  42. package/dist/server/graphql/pages-by-uid.js +14 -14
  43. package/dist/server/services/builder.js +7 -4
  44. package/dist/server/services/template.js +1 -2
  45. package/dist/server/utils/graphql.js +18 -18
  46. package/dist/server/utils/strapi.js +1 -4
  47. package/dist/tsconfig.server.tsbuildinfo +1 -1
  48. package/package.json +71 -71
  49. package/server/bootstrap/collection-type-lifecycles.ts +47 -47
  50. package/server/bootstrap/permissions.ts +42 -42
  51. package/server/bootstrap.ts +198 -198
  52. package/server/config/index.ts +4 -4
  53. package/server/content-types/index.ts +1 -1
  54. package/server/controllers/collection-types.ts +27 -27
  55. package/server/controllers/index.ts +11 -11
  56. package/server/controllers/page-type.ts +13 -13
  57. package/server/controllers/page.ts +9 -9
  58. package/server/controllers/template.ts +16 -16
  59. package/server/destroy.ts +5 -5
  60. package/server/graphql/index.ts +9 -9
  61. package/server/graphql/page-by-slug.ts +98 -98
  62. package/server/graphql/page-type.ts +67 -67
  63. package/server/graphql/pages-by-uid.ts +127 -127
  64. package/server/index.ts +23 -23
  65. package/server/middlewares/index.ts +1 -1
  66. package/server/policies/index.ts +1 -1
  67. package/server/register.ts +15 -15
  68. package/server/routes/index.ts +58 -58
  69. package/server/schema/page-end.json +91 -91
  70. package/server/schema/page-start.json +87 -87
  71. package/server/schema/page-type-end.json +43 -43
  72. package/server/schema/page-type-start.json +38 -38
  73. package/server/schema/template-start.json +35 -35
  74. package/server/services/builder.ts +137 -134
  75. package/server/services/collection-types.ts +88 -88
  76. package/server/services/index.ts +13 -13
  77. package/server/services/page-type.ts +26 -26
  78. package/server/services/page.ts +24 -24
  79. package/server/services/template.ts +13 -14
  80. package/server/utils/filter-underscore-arguments.ts +12 -12
  81. package/server/utils/graphql.ts +113 -113
  82. package/server/utils/paginationValidation.ts +39 -39
  83. package/server/utils/reload-strapi-on-load.ts +13 -13
  84. package/server/utils/strapi.ts +45 -49
  85. package/shared/utils/constants.ts +4 -4
  86. package/shared/utils/sleep.ts +1 -1
  87. package/strapi-admin.js +3 -3
  88. package/strapi-server.js +3 -3
  89. package/tsconfig.json +20 -20
  90. package/tsconfig.server.json +25 -25
  91. package/dist/server/controllers/platform.js +0 -20
  92. package/dist/server/schema/platform-start.json +0 -31
  93. package/dist/server/services/platform.js +0 -36
@@ -1,124 +1,124 @@
1
- import React, { useEffect, useState } from 'react';
2
- import { useSelector } from 'react-redux';
3
- import debounce from 'lodash/debounce';
4
- import { OptionProps, SingleValue, components } from 'react-select';
5
- import { useCMEditViewDataManager, useFetchClient } from '@strapi/helper-plugin';
6
-
7
- import { Combobox, IReactSelectValue } from '../../Combobox';
8
- import { getSearchEntities } from '../../../api/collection-type';
9
- import { usePrevious } from '../../../utils/hooks/usePrevious';
10
- import { useGetLocaleFromUrl } from '../../../utils/hooks/useGetLocaleFromUrl';
11
-
12
- const SEARCH_DEBOUNCE_MS = 150;
13
- const PAGE = 1;
14
-
15
- interface Props {
16
- uid: string;
17
- }
18
-
19
- export const CollectionTypeSearch = ({ uid }: Props) => {
20
- const fetchClient = useFetchClient();
21
- const form = useCMEditViewDataManager();
22
- const { locales } = useSelector((state: any) => state.i18n_locales);
23
- const urlLocale = useGetLocaleFromUrl();
24
- const defaultLocale = locales.find((locale: any) => locale.isDefault);
25
- const selectedLocale = form.initialData?.locale ?? urlLocale ?? defaultLocale.code;
26
- const prevUid = usePrevious(uid);
27
-
28
- const [selected, setSelected] = useState<SingleValue<IReactSelectValue | null>>(
29
- getInitialSelectItem(form.initialData?.collectionTypeId, form.initialData?.collectionTypeTitle)
30
- );
31
-
32
- const isPagePageType = !uid;
33
- const searchEntitiesIsEnabled = !isPagePageType;
34
-
35
- useEffect(() => {
36
- if (form.isCreatingEntry) {
37
- setSelected(null);
38
- }
39
- }, []);
40
-
41
- const getItems = async (inputValue?: string): Promise<IReactSelectValue[]> => {
42
- const searchEntities = await getSearchEntities({
43
- fetchClient,
44
- page: PAGE,
45
- locale: selectedLocale,
46
- uid,
47
- searchQuery: inputValue,
48
- currentCollectionTypeId: form.initialData?.collectionTypeId,
49
- currentPageId: form.initialData?.id
50
- });
51
-
52
- return searchEntities.results.map((x) => ({
53
- value: String(x.id),
54
- label: x.title,
55
- isDisabled: x.hasPages && !x.isCurrentSelected,
56
- initialSelected: x.isCurrentSelected
57
- }));
58
- };
59
-
60
- const setCollectionTypeId = (item?: SingleValue<IReactSelectValue>) => {
61
- form.onChange({
62
- target: {
63
- name: 'collectionTypeId',
64
- value: item?.value || null
65
- },
66
- shouldSetInitialValue: true
67
- });
68
- setSelected(item || null);
69
- };
70
-
71
- const handleChange = (item?: SingleValue<IReactSelectValue>) => {
72
- setCollectionTypeId(item);
73
- };
74
-
75
- useEffect(() => {
76
- if (prevUid !== null && prevUid !== uid) {
77
- setSelected(null);
78
- }
79
- }, [uid]);
80
-
81
- const debouncedFetch = debounce((searchTerm, callback) => {
82
- promiseOptions(searchTerm).then((result) => {
83
- return callback(result || []);
84
- });
85
- }, SEARCH_DEBOUNCE_MS);
86
-
87
- const promiseOptions = (inputValue: string): Promise<IReactSelectValue[]> =>
88
- new Promise<IReactSelectValue[]>((resolve) => {
89
- resolve(getItems(inputValue));
90
- });
91
-
92
- return (
93
- <Combobox
94
- key={`rerenderOnUidChange-${uid}`}
95
- id="collectionTypeSearch"
96
- label="Entity"
97
- loadOptions={debouncedFetch}
98
- cacheOptions
99
- onChange={handleChange}
100
- customOption={CustomOption}
101
- value={selected}
102
- defaultOptions={searchEntitiesIsEnabled}
103
- />
104
- );
105
- };
106
-
107
- const CustomOption = (props: OptionProps<IReactSelectValue, false>) => {
108
- return (
109
- <components.Option {...props}>
110
- <span>{props.children}</span>
111
- {props.isDisabled && <span>Entity is in use</span>}
112
- {props.data.initialSelected && <span>Currently selected</span>}
113
- </components.Option>
114
- );
115
- };
116
-
117
- const getInitialSelectItem = (id?: string, title?: string): SingleValue<IReactSelectValue | null> =>
118
- id
119
- ? {
120
- value: String(id),
121
- label: title ?? '',
122
- initialSelected: true
123
- }
124
- : null;
1
+ import React, { useEffect, useState } from 'react';
2
+ import { useSelector } from 'react-redux';
3
+ import debounce from 'lodash/debounce';
4
+ import { OptionProps, SingleValue, components } from 'react-select';
5
+ import { useCMEditViewDataManager, useFetchClient } from '@strapi/helper-plugin';
6
+
7
+ import { Combobox, IReactSelectValue } from '../../Combobox';
8
+ import { getSearchEntities } from '../../../api/collection-type';
9
+ import { usePrevious } from '../../../utils/hooks/usePrevious';
10
+ import { useGetLocaleFromUrl } from '../../../utils/hooks/useGetLocaleFromUrl';
11
+
12
+ const SEARCH_DEBOUNCE_MS = 150;
13
+ const PAGE = 1;
14
+
15
+ interface Props {
16
+ uid: string;
17
+ }
18
+
19
+ export const CollectionTypeSearch = ({ uid }: Props) => {
20
+ const fetchClient = useFetchClient();
21
+ const form = useCMEditViewDataManager() as any;
22
+ const { locales } = useSelector((state: any) => state.i18n_locales);
23
+ const urlLocale = useGetLocaleFromUrl();
24
+ const defaultLocale = locales.find((locale: any) => locale.isDefault);
25
+ const selectedLocale = form.initialData?.locale ?? urlLocale ?? defaultLocale.code;
26
+ const prevUid = usePrevious(uid);
27
+
28
+ const [selected, setSelected] = useState<SingleValue<IReactSelectValue | null>>(
29
+ getInitialSelectItem(form.initialData?.collectionTypeId, form.initialData?.collectionTypeTitle)
30
+ );
31
+
32
+ const isPagePageType = !uid;
33
+ const searchEntitiesIsEnabled = !isPagePageType;
34
+
35
+ useEffect(() => {
36
+ if (form.isCreatingEntry) {
37
+ setSelected(null);
38
+ }
39
+ }, []);
40
+
41
+ const getItems = async (inputValue?: string): Promise<IReactSelectValue[]> => {
42
+ const searchEntities = await getSearchEntities({
43
+ fetchClient,
44
+ page: PAGE,
45
+ locale: selectedLocale,
46
+ uid,
47
+ searchQuery: inputValue,
48
+ currentCollectionTypeId: form.initialData?.collectionTypeId,
49
+ currentPageId: form.initialData?.id
50
+ });
51
+
52
+ return searchEntities.results.map((x) => ({
53
+ value: String(x.id),
54
+ label: x.title,
55
+ isDisabled: x.hasPages && !x.isCurrentSelected,
56
+ initialSelected: x.isCurrentSelected
57
+ }));
58
+ };
59
+
60
+ const setCollectionTypeId = (item?: SingleValue<IReactSelectValue>) => {
61
+ form.onChange({
62
+ target: {
63
+ name: 'collectionTypeId',
64
+ value: item?.value || null
65
+ },
66
+ shouldSetInitialValue: true
67
+ });
68
+ setSelected(item || null);
69
+ };
70
+
71
+ const handleChange = (item?: SingleValue<IReactSelectValue>) => {
72
+ setCollectionTypeId(item);
73
+ };
74
+
75
+ useEffect(() => {
76
+ if (prevUid !== null && prevUid !== uid) {
77
+ setSelected(null);
78
+ }
79
+ }, [uid]);
80
+
81
+ const debouncedFetch = debounce((searchTerm, callback) => {
82
+ promiseOptions(searchTerm).then((result) => {
83
+ return callback(result || []);
84
+ });
85
+ }, SEARCH_DEBOUNCE_MS);
86
+
87
+ const promiseOptions = (inputValue: string): Promise<IReactSelectValue[]> =>
88
+ new Promise<IReactSelectValue[]>((resolve) => {
89
+ resolve(getItems(inputValue));
90
+ });
91
+
92
+ return (
93
+ <Combobox
94
+ key={`rerenderOnUidChange-${uid}`}
95
+ id="collectionTypeSearch"
96
+ label="Entity"
97
+ loadOptions={debouncedFetch}
98
+ cacheOptions
99
+ onChange={handleChange}
100
+ customOption={CustomOption}
101
+ value={selected}
102
+ defaultOptions={searchEntitiesIsEnabled}
103
+ />
104
+ );
105
+ };
106
+
107
+ const CustomOption = (props: OptionProps<IReactSelectValue, false>) => {
108
+ return (
109
+ <components.Option {...props}>
110
+ <span>{props.children}</span>
111
+ {props.isDisabled && <span>Entiteit heeft al een pagina</span>}
112
+ {props.data.initialSelected && <span>Oorspronkelijk gekoppeld</span>}
113
+ </components.Option>
114
+ );
115
+ };
116
+
117
+ const getInitialSelectItem = (id?: string, title?: string): SingleValue<IReactSelectValue | null> =>
118
+ id
119
+ ? {
120
+ value: String(id),
121
+ label: title ?? '',
122
+ initialSelected: true
123
+ }
124
+ : null;
@@ -1,101 +1,104 @@
1
- import React, { useEffect } 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, put } = 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
- title: initialData?.title,
36
- modules,
37
- post,
38
- locale,
39
- pageTypeId: pageType.id,
40
- collectionTypeId: initialData.id,
41
- layoutUid: layout.uid,
42
- relatedEntityId: createLocalizedPage ? linkedPages.data?.[0]?.id : undefined
43
- });
44
- if (newPage?.id) {
45
- await put(`/content-manager/collection-types/${layout.uid}/${initialData.id}`, {
46
- hasPage: true
47
- });
48
- history.push(`/content-manager/collectionType/${PAGE_UID}/${newPage.id}?plugins[i18n][locale]=${locale}`);
49
- }
50
- } catch (error) {
51
- console.error(error);
52
- }
53
- };
54
-
55
- return (
56
- <S.CreateButton to={url} onClick={handleCreatePage} size="S" variant="secondary" startIcon={<Plus />} width="100%">
57
- Create new page
58
- </S.CreateButton>
59
- );
60
- };
61
-
62
- interface ICreateNewPageProps {
63
- title?: string;
64
- locale: string;
65
- collectionTypeId: number;
66
- layoutUid: string;
67
- modules?: Record<string, any>[];
68
- post: any;
69
- pageTypeId: number;
70
- relatedEntityId?: number;
71
- }
72
-
73
- const createNewPage = async ({
74
- title,
75
- post,
76
- locale,
77
- collectionTypeId,
78
- layoutUid,
79
- modules,
80
- pageTypeId,
81
- relatedEntityId
82
- }: ICreateNewPageProps) => {
83
- // Including locale in url is neccesary.
84
- const relatedEntityIdQuery = relatedEntityId ? `&plugins[i18n][relatedEntityId]=${relatedEntityId}` : '';
85
- const url = `/content-manager/collection-types/${PAGE_UID}?plugins[i18n][locale]=${locale}${relatedEntityIdQuery}`;
86
- const { data: page } = await post(url, {
87
- title,
88
- locale,
89
- pageType: { connect: [{ id: pageTypeId }] },
90
- collectionTypeData: {
91
- id: collectionTypeId,
92
- __type: layoutUid,
93
- __pivot: {
94
- field: 'page'
95
- }
96
- },
97
- modules
98
- });
99
-
100
- return page;
101
- };
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() as any;
17
+
18
+ const { post, get, put } = 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
+
33
+ // Get data inside template
34
+ const templateData = await get(getRequestUrl(`/template/${pageType?.template?.id}`));
35
+ const modules = sanitizeModules(templateData?.data?.modules || []);
36
+
37
+ const newPage = await createNewPage({
38
+ title: initialData?.title,
39
+ modules,
40
+ post,
41
+ locale,
42
+ pageTypeId: pageType.id,
43
+ collectionTypeId: initialData.id,
44
+ layoutUid: layout.uid,
45
+ relatedEntityId: createLocalizedPage ? linkedPages.data?.[0]?.id : undefined
46
+ });
47
+ if (newPage?.id) {
48
+ await put(`/content-manager/collection-types/${layout.uid}/${initialData.id}`, {
49
+ hasPage: true
50
+ });
51
+ history.push(`/content-manager/collectionType/${PAGE_UID}/${newPage.id}?plugins[i18n][locale]=${locale}`);
52
+ }
53
+ } catch (error) {
54
+ console.error(error);
55
+ }
56
+ };
57
+
58
+ return (
59
+ <S.CreateButton to={url} onClick={handleCreatePage} size="S" variant="secondary" startIcon={<Plus />} width="100%">
60
+ Create new page
61
+ </S.CreateButton>
62
+ );
63
+ };
64
+
65
+ interface ICreateNewPageProps {
66
+ title?: string;
67
+ locale: string;
68
+ collectionTypeId: number;
69
+ layoutUid: string;
70
+ modules?: Record<string, any>[];
71
+ post: any;
72
+ pageTypeId: number;
73
+ relatedEntityId?: number;
74
+ }
75
+
76
+ const createNewPage = async ({
77
+ title,
78
+ post,
79
+ locale,
80
+ collectionTypeId,
81
+ layoutUid,
82
+ modules,
83
+ pageTypeId,
84
+ relatedEntityId
85
+ }: ICreateNewPageProps) => {
86
+ // Including locale in url is neccesary.
87
+ const relatedEntityIdQuery = relatedEntityId ? `&plugins[i18n][relatedEntityId]=${relatedEntityId}` : '';
88
+ const url = `/content-manager/collection-types/${PAGE_UID}?plugins[i18n][locale]=${locale}${relatedEntityIdQuery}`;
89
+ const { data: page } = await post(url, {
90
+ title,
91
+ locale,
92
+ pageType: { connect: [{ id: pageTypeId }] },
93
+ collectionTypeData: {
94
+ id: collectionTypeId,
95
+ __type: layoutUid,
96
+ __pivot: {
97
+ field: 'page'
98
+ }
99
+ },
100
+ modules
101
+ });
102
+
103
+ return page;
104
+ };
@@ -1,19 +1,19 @@
1
- import styled, { css } from 'styled-components';
2
-
3
- import { Button } from '@strapi/design-system';
4
-
5
- const CreateButton = styled(Button)`
6
- ${({ _theme }) => css`
7
- text-decoration: none;
8
-
9
- > div {
10
- display: flex;
11
- }
12
- `}
13
- `;
14
-
15
- const CreatePageButtonStyles = {
16
- CreateButton
17
- };
18
-
19
- export default CreatePageButtonStyles;
1
+ import styled, { css } from 'styled-components';
2
+
3
+ import { Button } from '@strapi/design-system';
4
+
5
+ const CreateButton = styled(Button)`
6
+ ${({ _theme }) => css`
7
+ text-decoration: none;
8
+
9
+ > div {
10
+ display: flex;
11
+ }
12
+ `}
13
+ `;
14
+
15
+ const CreatePageButtonStyles = {
16
+ CreateButton
17
+ };
18
+
19
+ export default CreatePageButtonStyles;
@@ -1,74 +1,74 @@
1
- import React, { useEffect, useState } 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, modifiedData, onChange } = useCMEditViewDataManager();
14
-
15
- const isUserCreatedContentType = layout.uid.startsWith('api::');
16
- const [linkedPage, setLinkedPage] = useState<Record<string, any> | undefined>(initialData.page?.[0]);
17
-
18
- const showCreatePageButton = isUserCreatedContentType && !isCreatingEntry && !linkedPage;
19
- const url = generateLink(linkedPage?.id, initialData?.locale);
20
-
21
- useEffect(() => {
22
- if (modifiedData.page?.[0]) {
23
- setLinkedPage(modifiedData.page?.[0]);
24
- }
25
-
26
- if (modifiedData.page === null) {
27
- setLinkedPage(undefined);
28
- }
29
- }, [modifiedData.page?.[0]]);
30
-
31
- useEffect(() => {
32
- if (isCreatingEntry) {
33
- onChange({
34
- target: {
35
- name: 'page',
36
- value: null
37
- }
38
- });
39
- }
40
- }, []);
41
-
42
- if (isCreatingEntry) {
43
- return null;
44
- }
45
-
46
- return (
47
- <Wrapper title="Gekoppelde pagina">
48
- <Flex direction="column" gap={4} width="100%" alignItems="start">
49
- {showCreatePageButton && <CreatePageButton />}
50
-
51
- {url && (
52
- <Flex direction="column" alignItems="start" width="100%" gap={1}>
53
- <S.SubtleType variant="omega" fontWeight="bold" textColor="neutral800">
54
- {PAGE_TYPE_PAGE}
55
- </S.SubtleType>
56
- <S.EntityLinkWrapper variant="pi" textColor="neutral800">
57
- <S.EntityLink title={linkedPage?.title || '-'} to={url} variant="pi">
58
- <Link />
59
- {linkedPage?.title || '-'}
60
- </S.EntityLink>
61
- </S.EntityLinkWrapper>
62
- </Flex>
63
- )}
64
- </Flex>
65
- </Wrapper>
66
- );
67
- };
68
-
69
- const generateLink = (entityId?: string, locale?: string) => {
70
- if (!entityId) {
71
- return '';
72
- }
73
- return `/content-manager/collectionType/${PAGE_UID}/${entityId}?plugins[i18n][locale]=${locale}`;
74
- };
1
+ import React, { useEffect, useState } 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, modifiedData, onChange } = useCMEditViewDataManager() as any;
14
+
15
+ const isUserCreatedContentType = layout.uid.startsWith('api::');
16
+ const [linkedPage, setLinkedPage] = useState<Record<string, any> | undefined>(initialData.page?.[0]);
17
+
18
+ const showCreatePageButton = isUserCreatedContentType && !isCreatingEntry && !linkedPage;
19
+ const url = generateLink(linkedPage?.id, initialData?.locale);
20
+
21
+ useEffect(() => {
22
+ if (modifiedData.page?.[0]) {
23
+ setLinkedPage(modifiedData.page?.[0]);
24
+ }
25
+
26
+ if (modifiedData.page === null) {
27
+ setLinkedPage(undefined);
28
+ }
29
+ }, [modifiedData.page?.[0]]);
30
+
31
+ useEffect(() => {
32
+ if (isCreatingEntry) {
33
+ onChange({
34
+ target: {
35
+ name: 'page',
36
+ value: null
37
+ }
38
+ });
39
+ }
40
+ }, []);
41
+
42
+ if (isCreatingEntry) {
43
+ return null;
44
+ }
45
+
46
+ return (
47
+ <Wrapper title="Gekoppelde pagina">
48
+ <Flex direction="column" gap={4} width="100%" alignItems="start">
49
+ {showCreatePageButton && <CreatePageButton />}
50
+
51
+ {url && (
52
+ <Flex direction="column" alignItems="start" width="100%" gap={1}>
53
+ <S.SubtleType variant="omega" fontWeight="bold" textColor="neutral800">
54
+ {PAGE_TYPE_PAGE}
55
+ </S.SubtleType>
56
+ <S.EntityLinkWrapper variant="pi" textColor="neutral800">
57
+ <S.EntityLink title={linkedPage?.title || '-'} to={url} variant="pi">
58
+ <Link />
59
+ {linkedPage?.title || '-'}
60
+ </S.EntityLink>
61
+ </S.EntityLinkWrapper>
62
+ </Flex>
63
+ )}
64
+ </Flex>
65
+ </Wrapper>
66
+ );
67
+ };
68
+
69
+ const generateLink = (entityId?: string, locale?: string) => {
70
+ if (!entityId) {
71
+ return '';
72
+ }
73
+ return `/content-manager/collectionType/${PAGE_UID}/${entityId}?plugins[i18n][locale]=${locale}`;
74
+ };