@webbio/strapi-plugin-page-builder 0.6.0-platform → 0.7.0-platform
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/admin/src/api/has-page-relation.ts +1 -1
- package/admin/src/api/has-platform-relation.ts +1 -1
- package/admin/src/api/page.ts +94 -0
- package/admin/src/api/platform-page-types.ts +17 -19
- package/admin/src/api/platform.ts +2 -2
- package/admin/src/api/template.ts +10 -7
- package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +6 -2
- package/admin/src/components/EditView/Details/index.tsx +1 -1
- package/admin/src/components/EditView/PageSettings/index.tsx +1 -1
- package/admin/src/components/EditView/Template/TemplateSelect/index.tsx +3 -2
- package/admin/src/components/EditView/Template/TemplateSelect/use-template-modules.ts +5 -2
- package/admin/src/components/EditView/page-type-select.tsx +1 -1
- package/admin/src/components/EditView/wrapper.tsx +13 -7
- package/admin/src/components/GlobalPlatformSelect/index.tsx +0 -1
- package/admin/src/components/PageFilters/PageTypeFilter/index.tsx +1 -1
- package/admin/src/components/PageFilters/filters.tsx +1 -1
- package/admin/src/components/PageFilters/index.tsx +6 -1
- package/admin/src/components/PageTypeEditView/PageByPlatformSelect/index.tsx +112 -0
- package/admin/src/components/PageTypeEditView/TemplatePlatformSelect/index.tsx +55 -0
- package/admin/src/components/PageTypeEditView/index.tsx +28 -0
- package/admin/src/index.tsx +5 -0
- package/admin/src/utils/hooks/usePlatformFormData.ts +1 -0
- package/dist/package.json +1 -1
- package/dist/server/controllers/page-type.js +6 -2
- package/dist/server/routes/index.js +1 -1
- package/dist/server/schema/page-type-end.json +15 -5
- package/dist/server/schema/platform-start.json +0 -10
- package/dist/server/schema/template-end.json +40 -0
- package/dist/server/services/builder.js +4 -3
- package/dist/server/services/page-type.js +7 -3
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/server/controllers/page-type.ts +6 -1
- package/server/routes/index.ts +1 -1
- package/server/schema/page-type-end.json +15 -5
- package/server/schema/platform-start.json +0 -10
- package/server/schema/template-end.json +40 -0
- package/server/services/builder.ts +4 -3
- package/server/services/page-type.ts +7 -3
- package/admin/src/api/page-type.ts +0 -32
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useQuery, UseQueryOptions } from 'react-query';
|
|
2
|
+
import orderBy from 'lodash/orderBy';
|
|
3
|
+
|
|
4
|
+
import { useFetchClient } from '@strapi/helper-plugin';
|
|
5
|
+
import { PAGE_UID } from '../../../shared/utils/constants';
|
|
6
|
+
|
|
7
|
+
export type PageSearchResult = {
|
|
8
|
+
pagination: {
|
|
9
|
+
page: number;
|
|
10
|
+
pageCount: number;
|
|
11
|
+
pageSize: number;
|
|
12
|
+
total: number;
|
|
13
|
+
};
|
|
14
|
+
results: {
|
|
15
|
+
id: number;
|
|
16
|
+
title: string;
|
|
17
|
+
isCurrentSelected?: boolean;
|
|
18
|
+
}[];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type SearchPageQueryParams = {
|
|
22
|
+
fetchClient?: any;
|
|
23
|
+
page: number;
|
|
24
|
+
locale: string;
|
|
25
|
+
searchQuery?: string;
|
|
26
|
+
currentCollectionTypeId?: number;
|
|
27
|
+
platformTitle?: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const QUERY_KEY = ['pages'];
|
|
31
|
+
|
|
32
|
+
export const getSearchPages = async ({
|
|
33
|
+
fetchClient,
|
|
34
|
+
page,
|
|
35
|
+
locale,
|
|
36
|
+
searchQuery,
|
|
37
|
+
currentCollectionTypeId,
|
|
38
|
+
platformTitle
|
|
39
|
+
}: SearchPageQueryParams): Promise<PageSearchResult> => {
|
|
40
|
+
try {
|
|
41
|
+
const { get } = fetchClient;
|
|
42
|
+
const searchParams = new URLSearchParams();
|
|
43
|
+
searchParams.append('page', String(page));
|
|
44
|
+
searchParams.append('pageSize', '20');
|
|
45
|
+
searchParams.append('locale', locale);
|
|
46
|
+
|
|
47
|
+
if (searchQuery) {
|
|
48
|
+
searchParams.delete('sort');
|
|
49
|
+
searchParams.append('sort', 'title:ASC');
|
|
50
|
+
searchParams.append('_q', searchQuery);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (platformTitle) {
|
|
54
|
+
searchParams.append('filters[$and][0][platform][title][$contains]', String(platformTitle));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const { data } = await get(`/content-manager/collection-types/${PAGE_UID}?${searchParams.toString()}`);
|
|
58
|
+
|
|
59
|
+
const mapResults = data.results.map((result: Record<string, any>) => ({
|
|
60
|
+
id: result.id,
|
|
61
|
+
title: result.title,
|
|
62
|
+
isCurrentSelected: result?.id === currentCollectionTypeId
|
|
63
|
+
}));
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
pagination: data.pagination,
|
|
67
|
+
results: orderBy(mapResults, ['title'], ['asc'])
|
|
68
|
+
};
|
|
69
|
+
} catch (e) {
|
|
70
|
+
return {
|
|
71
|
+
pagination: { page: 1, pageCount: 0, pageSize: 0, total: 0 },
|
|
72
|
+
results: []
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const useSearchPages = (params: SearchPageQueryParams, options?: UseQueryOptions<PageSearchResult, Error>) => {
|
|
78
|
+
const fetchClient = useFetchClient();
|
|
79
|
+
|
|
80
|
+
return useQuery<PageSearchResult, Error>(
|
|
81
|
+
[
|
|
82
|
+
QUERY_KEY,
|
|
83
|
+
{
|
|
84
|
+
...params
|
|
85
|
+
}
|
|
86
|
+
],
|
|
87
|
+
() =>
|
|
88
|
+
getSearchPages({
|
|
89
|
+
...params,
|
|
90
|
+
fetchClient
|
|
91
|
+
}),
|
|
92
|
+
options
|
|
93
|
+
);
|
|
94
|
+
};
|
|
@@ -2,31 +2,29 @@ import { useQuery } from 'react-query';
|
|
|
2
2
|
|
|
3
3
|
import { useFetchClient } from '@strapi/helper-plugin';
|
|
4
4
|
|
|
5
|
-
import { PageType } from './page-type';
|
|
6
|
-
|
|
7
5
|
const QUERY_KEY = 'pageTypesForPlatform';
|
|
8
6
|
|
|
7
|
+
export type PageType = {
|
|
8
|
+
id: number;
|
|
9
|
+
uid: string;
|
|
10
|
+
title?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
9
13
|
const fetchPageTypesForPlatform = async ({ fetchClient, id }: Record<string, any>): Promise<PageType[]> => {
|
|
10
14
|
if (!id) return [];
|
|
11
15
|
|
|
12
16
|
const { get } = fetchClient;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
id: entity.id,
|
|
25
|
-
uid: fullPageType.uid,
|
|
26
|
-
title: fullPageType.title,
|
|
27
|
-
templateId: fullPageType?.template?.id
|
|
28
|
-
};
|
|
29
|
-
});
|
|
17
|
+
|
|
18
|
+
const pageTypesResult = await get(`/content-manager/collection-types/api::page-type.page-type?page=1&pageSize=999`);
|
|
19
|
+
|
|
20
|
+
return pageTypesResult?.data?.results
|
|
21
|
+
?.filter((x) => x?.platform?.id === id)
|
|
22
|
+
?.map((pageType: Record<string, any>) => ({
|
|
23
|
+
id: pageType.id,
|
|
24
|
+
uid: pageType.uid,
|
|
25
|
+
title: pageType.title,
|
|
26
|
+
templateId: pageType?.template?.id
|
|
27
|
+
}));
|
|
30
28
|
};
|
|
31
29
|
|
|
32
30
|
export const useGetPageTypesForPlatform = (params: Record<string, any>) => {
|
|
@@ -2,7 +2,7 @@ import { useQuery } from 'react-query';
|
|
|
2
2
|
|
|
3
3
|
import { useFetchClient } from '@strapi/helper-plugin';
|
|
4
4
|
|
|
5
|
-
import { PageType } from './page-
|
|
5
|
+
import { PageType } from './platform-page-types';
|
|
6
6
|
|
|
7
7
|
export type Platform = {
|
|
8
8
|
id: number;
|
|
@@ -14,7 +14,7 @@ const QUERY_KEY = 'platforms';
|
|
|
14
14
|
|
|
15
15
|
const fetchPlatforms = async ({ fetchClient }: Record<string, any>): Promise<Platform[]> => {
|
|
16
16
|
const { get } = fetchClient;
|
|
17
|
-
const result = await get('/content-manager/collection-types/api::platform.platform?page=1&pageSize=
|
|
17
|
+
const result = await get('/content-manager/collection-types/api::platform.platform?page=1&pageSize=999');
|
|
18
18
|
|
|
19
19
|
return result?.data?.results.map((entity: Record<string, any>) => ({
|
|
20
20
|
id: entity.id,
|
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
import { useQuery } from 'react-query';
|
|
2
|
+
|
|
2
3
|
import { useFetchClient } from '@strapi/helper-plugin';
|
|
3
|
-
import getRequestUrl from '../utils/getRequestUrl';
|
|
4
4
|
|
|
5
5
|
export type Template = {
|
|
6
6
|
id: number;
|
|
7
7
|
title: string;
|
|
8
|
-
modules: any[];
|
|
8
|
+
modules: Record<string, any>[];
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
const QUERY_KEY = ['templates'];
|
|
12
12
|
|
|
13
|
-
const fetchTemplates = async ({ fetchClient }: any): Promise<Template[]> => {
|
|
13
|
+
const fetchTemplates = async ({ fetchClient, id }: Record<string, any>): Promise<Template[]> => {
|
|
14
14
|
const { get } = fetchClient;
|
|
15
|
-
const result = await get(
|
|
15
|
+
const result = await get(`/content-manager/collection-types/api::template.template?page=1&pageSize=999`);
|
|
16
16
|
|
|
17
|
-
return result?.data
|
|
17
|
+
return result?.data?.results
|
|
18
|
+
?.filter((x?: Record<string, any>) => x?.platform?.id === id)
|
|
19
|
+
?.map((template: Record<string, any>) => ({ id: template.id, title: template.title, modules: template.modules }));
|
|
18
20
|
};
|
|
19
21
|
|
|
20
|
-
export const useGetTemplates = (params: any) => {
|
|
22
|
+
export const useGetTemplates = (params: Record<string, any>) => {
|
|
21
23
|
const fetchClient = useFetchClient();
|
|
22
24
|
params = {
|
|
23
25
|
...params,
|
|
24
26
|
fetchClient
|
|
25
27
|
};
|
|
26
|
-
|
|
28
|
+
|
|
29
|
+
return useQuery<Template[], Error>([QUERY_KEY, params?.id], () => fetchTemplates(params));
|
|
27
30
|
};
|
|
@@ -24,7 +24,7 @@ export const CreatePageButton = () => {
|
|
|
24
24
|
const handleCreatePage = async (e: React.MouseEvent<HTMLAnchorElement>) => {
|
|
25
25
|
e.preventDefault();
|
|
26
26
|
try {
|
|
27
|
-
const pageTypeUrl = getRequestUrl(`/page-types/${layout.uid}`);
|
|
27
|
+
const pageTypeUrl = getRequestUrl(`/page-types/${layout.uid}/${initialData.platform[0]?.id}`);
|
|
28
28
|
const { data: pageType } = await get(pageTypeUrl);
|
|
29
29
|
const mappedLocalizations = (initialData?.localizations || []).map((x: any) => x?.id).join(',');
|
|
30
30
|
const linkedPages: { data: IGetTranslationPageLinks[] } = await get(
|
|
@@ -50,6 +50,7 @@ export const CreatePageButton = () => {
|
|
|
50
50
|
locale,
|
|
51
51
|
pageTypeId: pageType.id,
|
|
52
52
|
platformId: initialData.platform[0]?.id,
|
|
53
|
+
parentId: pageType?.defaultParent?.id,
|
|
53
54
|
collectionTypeId: initialData.id,
|
|
54
55
|
layoutUid: layout.uid,
|
|
55
56
|
relatedEntityId: createLocalizedPage ? linkedPages.data?.[0]?.id : undefined
|
|
@@ -82,6 +83,7 @@ interface ICreateNewPageProps {
|
|
|
82
83
|
pageTypeId: number;
|
|
83
84
|
platformId: number;
|
|
84
85
|
relatedEntityId?: number;
|
|
86
|
+
parentId?: number;
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
const createNewPage = async ({
|
|
@@ -93,7 +95,8 @@ const createNewPage = async ({
|
|
|
93
95
|
modules,
|
|
94
96
|
pageTypeId,
|
|
95
97
|
platformId,
|
|
96
|
-
relatedEntityId
|
|
98
|
+
relatedEntityId,
|
|
99
|
+
parentId
|
|
97
100
|
}: ICreateNewPageProps) => {
|
|
98
101
|
// Including locale in url is neccesary.
|
|
99
102
|
const relatedEntityIdQuery = relatedEntityId ? `&plugins[i18n][relatedEntityId]=${relatedEntityId}` : '';
|
|
@@ -113,6 +116,7 @@ const createNewPage = async ({
|
|
|
113
116
|
locale,
|
|
114
117
|
pageType: { connect: [{ id: pageTypeId }] },
|
|
115
118
|
platform: { connect: [{ id: platformId }] },
|
|
119
|
+
...(parentId && { parent: { connect: [{ id: parentId }] } }),
|
|
116
120
|
collectionTypeData: {
|
|
117
121
|
id: collectionTypeId,
|
|
118
122
|
__type: layoutUid,
|
|
@@ -3,7 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import { Flex } from '@strapi/design-system';
|
|
4
4
|
import { Link } from '@strapi/icons';
|
|
5
5
|
|
|
6
|
-
import { PageType } from '../../../api/page-
|
|
6
|
+
import { PageType } from '../../../api/platform-page-types';
|
|
7
7
|
import { PAGE_TYPE_PAGE } from '../../../../../shared/utils/constants';
|
|
8
8
|
import S from './styles';
|
|
9
9
|
|
|
@@ -7,7 +7,7 @@ import { TemplateSelect } from '../Template/TemplateSelect';
|
|
|
7
7
|
import { PageTypeSelect } from '../page-type-select';
|
|
8
8
|
import { CollectionTypeSearch } from '../CollectionTypeSearch';
|
|
9
9
|
import { Wrapper } from '../wrapper';
|
|
10
|
-
import { PageType } from '../../../api/page-
|
|
10
|
+
import { PageType } from '../../../api/platform-page-types';
|
|
11
11
|
import { Details } from '../Details';
|
|
12
12
|
import { Platform } from '../../../api/platform';
|
|
13
13
|
import { usePlatformFormData } from '../../../utils/hooks/usePlatformFormData';
|
|
@@ -21,7 +21,8 @@ export const TemplateSelect = ({ disabled }: Props) => {
|
|
|
21
21
|
|
|
22
22
|
const handleSelectTemplate = (templateId?: string) => {
|
|
23
23
|
const template = templates?.find((template) => template.id === Number(templateId));
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
setSelectedTemplate(template || null);
|
|
25
26
|
|
|
26
27
|
setTemplateIdToSelect(undefined);
|
|
27
28
|
};
|
|
@@ -50,7 +51,7 @@ export const TemplateSelect = ({ disabled }: Props) => {
|
|
|
50
51
|
onChange={handleSelectChange}
|
|
51
52
|
disabled={Boolean(disabled)}
|
|
52
53
|
>
|
|
53
|
-
<SingleSelectOption value={0}>
|
|
54
|
+
<SingleSelectOption value={0}>Kies een template om in te laden</SingleSelectOption>
|
|
54
55
|
{templates?.map((template) => (
|
|
55
56
|
<SingleSelectOption key={template.id} value={template.id}>
|
|
56
57
|
{template.title}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { useFetchClient } from '@strapi/helper-plugin';
|
|
2
|
+
|
|
1
3
|
import { Template, useGetTemplates } from '../../../../api/template';
|
|
2
4
|
import { sanitizeModules } from '../../../../utils/sanitizeModules';
|
|
3
|
-
import { useFetchClient } from '@strapi/helper-plugin';
|
|
4
5
|
import getRequestUrl from '../../../../utils/getRequestUrl';
|
|
6
|
+
import { useDefaultPlatformFromLocalStorage } from '../../../../utils/hooks/useDefaultPlatformFromLocalStorage';
|
|
5
7
|
|
|
6
8
|
type OnChangeFormType = (props: { target: Record<string, any>; shouldSetInitialValue: boolean }) => void;
|
|
7
9
|
|
|
8
10
|
export const useTemplateModules = (onChange: OnChangeFormType) => {
|
|
9
|
-
const {
|
|
11
|
+
const { selectedPlatform } = useDefaultPlatformFromLocalStorage();
|
|
12
|
+
const { data: templates } = useGetTemplates({ id: selectedPlatform?.id });
|
|
10
13
|
const fetchClient = useFetchClient();
|
|
11
14
|
|
|
12
15
|
return {
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { SingleSelect, SingleSelectOption } from '@strapi/design-system';
|
|
4
4
|
|
|
5
|
-
import { PageType } from '../../api/page-
|
|
5
|
+
import { PageType } from '../../api/platform-page-types';
|
|
6
6
|
import { PAGE_TYPE_PAGE } from '../../../../shared/utils/constants';
|
|
7
7
|
|
|
8
8
|
interface Props {
|
|
@@ -2,8 +2,9 @@ import React from 'react';
|
|
|
2
2
|
import { Flex, Box, Divider, Typography } from '@strapi/design-system';
|
|
3
3
|
|
|
4
4
|
interface Props {
|
|
5
|
-
title
|
|
5
|
+
title?: string;
|
|
6
6
|
children: React.ReactNode;
|
|
7
|
+
flexProps?: Record<string, any>;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export const Wrapper = (props: Props) => {
|
|
@@ -20,14 +21,19 @@ export const Wrapper = (props: Props) => {
|
|
|
20
21
|
paddingLeft={4}
|
|
21
22
|
shadow="tableShadow"
|
|
22
23
|
alignItems="left"
|
|
24
|
+
{...props.flexProps}
|
|
23
25
|
>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
{props.title && (
|
|
27
|
+
<>
|
|
28
|
+
<Typography variant="sigma" textColor="neutral600" id="additional-information">
|
|
29
|
+
{props.title}
|
|
30
|
+
</Typography>
|
|
27
31
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
<Box paddingTop={2} paddingBottom={4}>
|
|
33
|
+
<Divider />
|
|
34
|
+
</Box>
|
|
35
|
+
</>
|
|
36
|
+
)}
|
|
31
37
|
|
|
32
38
|
{props.children}
|
|
33
39
|
</Flex>
|
|
@@ -19,7 +19,6 @@ const GlobalPlatformSelect = ({ small }: IGlobalPlatformSelectProps) => {
|
|
|
19
19
|
const { selectedPlatform, setSelectedPlatform } = useDefaultPlatformFromLocalStorage();
|
|
20
20
|
|
|
21
21
|
const handlePlatformChange = (platform: Platform) => {
|
|
22
|
-
console.log('handlePlatformChange', platform);
|
|
23
22
|
setSelectedPlatform(platform);
|
|
24
23
|
|
|
25
24
|
if (typeof window !== 'undefined' && pathname.split('/').filter(Boolean).length > 3) {
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { SingleSelectOption, SingleSelect } from '@strapi/design-system';
|
|
4
4
|
|
|
5
|
-
import { PageType } from '../../../api/page-
|
|
5
|
+
import { PageType } from '../../../api/platform-page-types';
|
|
6
6
|
import { PAGE_TYPE_NO_FILTER } from '../../../constants';
|
|
7
7
|
import { PAGE_TYPE_PAGE } from '../../../../../shared/utils/constants';
|
|
8
8
|
|
|
@@ -8,7 +8,7 @@ import PageTypeFilter from './PageTypeFilter';
|
|
|
8
8
|
import { PAGE_TYPE_PAGE, PLATFORM } from '../../../../shared/utils/constants';
|
|
9
9
|
import { Platform, useGetPlatforms } from '../../api/platform';
|
|
10
10
|
import { PAGE_TYPE, PAGE_TYPE_NO_FILTER, PLATFORM_NO_FILTER } from '../../constants';
|
|
11
|
-
import { PageType } from '../../api/page-
|
|
11
|
+
import { PageType } from '../../api/platform-page-types';
|
|
12
12
|
import { useGetPageTypesForPlatform } from '../../api/platform-page-types';
|
|
13
13
|
import { useDefaultPlatformFromLocalStorage } from '../../utils/hooks/useDefaultPlatformFromLocalStorage';
|
|
14
14
|
import { useHideOverviewFilterTags } from '../../utils/hooks/useHideOverviewFilterTags';
|
|
@@ -6,6 +6,7 @@ import { PAGE_UID } from '../../../../shared/utils/constants';
|
|
|
6
6
|
|
|
7
7
|
import PageFilters from './filters';
|
|
8
8
|
import { useHasPageRelation } from '../../api/has-page-relation';
|
|
9
|
+
import { useHasPlatformRelation } from '../../api/has-platform-relation';
|
|
9
10
|
|
|
10
11
|
const PageFiltersContainer = () => {
|
|
11
12
|
const { pathname } = useLocation();
|
|
@@ -16,11 +17,15 @@ const PageFiltersContainer = () => {
|
|
|
16
17
|
uid
|
|
17
18
|
});
|
|
18
19
|
|
|
20
|
+
const { data: hasPlatformRelation, isLoading: isLoadingPlatformRelation } = useHasPlatformRelation({
|
|
21
|
+
uid
|
|
22
|
+
});
|
|
23
|
+
|
|
19
24
|
if (isPageCollectionType) {
|
|
20
25
|
return <PageFilters />;
|
|
21
26
|
}
|
|
22
27
|
|
|
23
|
-
if (!isPageCollectionType &&
|
|
28
|
+
if (!isPageCollectionType && !isLoading && !isLoadingPlatformRelation && (hasPageRelation || hasPlatformRelation)) {
|
|
24
29
|
return <PageFilters hidePageType />;
|
|
25
30
|
}
|
|
26
31
|
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
import { useGetLocaleFromUrl } from '../../../utils/hooks/useGetLocaleFromUrl';
|
|
7
|
+
import { IReactSelectValue, Combobox } from '../../Combobox';
|
|
8
|
+
import { getSearchPages } from '../../../api/page';
|
|
9
|
+
|
|
10
|
+
const SEARCH_DEBOUNCE_MS = 150;
|
|
11
|
+
const PAGE = 1;
|
|
12
|
+
|
|
13
|
+
export const PageByPlatformSearch = () => {
|
|
14
|
+
const fetchClient = useFetchClient();
|
|
15
|
+
const { onChange, initialData, modifiedData, isCreatingEntry } = useCMEditViewDataManager() as any;
|
|
16
|
+
const { locales } = useSelector((state: any) => state.i18n_locales);
|
|
17
|
+
const urlLocale = useGetLocaleFromUrl();
|
|
18
|
+
const defaultLocale = locales.find((locale: any) => locale.isDefault);
|
|
19
|
+
const selectedLocale = initialData?.locale ?? urlLocale ?? defaultLocale.code;
|
|
20
|
+
|
|
21
|
+
const [selected, setSelected] = useState<SingleValue<IReactSelectValue | null>>();
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const initialSelect = getInitialSelectItem(
|
|
25
|
+
modifiedData?.defaultParent?.[0]?.id,
|
|
26
|
+
modifiedData?.defaultParent?.[0]?.title
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
setSelected(initialSelect);
|
|
30
|
+
}, [modifiedData?.defaultParent]);
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (isCreatingEntry) {
|
|
34
|
+
setSelected(null);
|
|
35
|
+
}
|
|
36
|
+
}, []);
|
|
37
|
+
|
|
38
|
+
const setFormValue = (name: string, value?: string | Record<string, any>[]) => {
|
|
39
|
+
onChange({
|
|
40
|
+
target: {
|
|
41
|
+
name,
|
|
42
|
+
value
|
|
43
|
+
},
|
|
44
|
+
shouldSetInitialValue: true
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const handleSelectDefaultParent = (value?: SingleValue<IReactSelectValue>) => {
|
|
49
|
+
if (value) {
|
|
50
|
+
const defaultParent = {
|
|
51
|
+
id: value.value,
|
|
52
|
+
title: value.label,
|
|
53
|
+
mainField: value.label,
|
|
54
|
+
label: value.label,
|
|
55
|
+
value: value.value
|
|
56
|
+
};
|
|
57
|
+
setFormValue('defaultParent', [defaultParent]);
|
|
58
|
+
} else {
|
|
59
|
+
setFormValue('defaultParent', []);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const getItems = async (inputValue?: string, platformTitle?: string): Promise<IReactSelectValue[]> => {
|
|
64
|
+
const pages = await getSearchPages({
|
|
65
|
+
fetchClient,
|
|
66
|
+
page: PAGE,
|
|
67
|
+
locale: selectedLocale,
|
|
68
|
+
searchQuery: inputValue,
|
|
69
|
+
currentCollectionTypeId: initialData?.collectionTypeId,
|
|
70
|
+
platformTitle
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return pages?.results.map((x) => ({
|
|
74
|
+
value: String(x.id),
|
|
75
|
+
label: x.title,
|
|
76
|
+
initialSelected: x.isCurrentSelected
|
|
77
|
+
}));
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const debouncedFetch = debounce((searchTerm, callback, selectedPlatformTitle?: string) => {
|
|
81
|
+
promiseOptions(searchTerm, selectedPlatformTitle).then((result) => {
|
|
82
|
+
return callback(result || []);
|
|
83
|
+
});
|
|
84
|
+
}, SEARCH_DEBOUNCE_MS);
|
|
85
|
+
|
|
86
|
+
const promiseOptions = (inputValue: string, selectedPlatformTitle?: string): Promise<IReactSelectValue[]> =>
|
|
87
|
+
new Promise<IReactSelectValue[]>((resolve) => {
|
|
88
|
+
resolve(getItems(inputValue, selectedPlatformTitle));
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<Combobox
|
|
93
|
+
key={`rerenderOnUidOrPlatformChange-${initialData?.platform?.[0]?.id}`}
|
|
94
|
+
id="pagesSearch"
|
|
95
|
+
label="Standaard overzichtspagina"
|
|
96
|
+
loadOptions={(i, c) => debouncedFetch(i, c, initialData?.platform?.[0]?.title)}
|
|
97
|
+
cacheOptions
|
|
98
|
+
onChange={handleSelectDefaultParent}
|
|
99
|
+
value={selected}
|
|
100
|
+
defaultOptions
|
|
101
|
+
/>
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const getInitialSelectItem = (id?: string, title?: string): SingleValue<IReactSelectValue | null> =>
|
|
106
|
+
id
|
|
107
|
+
? {
|
|
108
|
+
value: String(id),
|
|
109
|
+
label: title ?? '',
|
|
110
|
+
initialSelected: true
|
|
111
|
+
}
|
|
112
|
+
: null;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
|
4
|
+
import { SingleSelect, SingleSelectOption } from '@strapi/design-system';
|
|
5
|
+
|
|
6
|
+
import { useGetTemplates } from '../../../api/template';
|
|
7
|
+
|
|
8
|
+
export const TemplatePlatformSelect = () => {
|
|
9
|
+
const { onChange, modifiedData } = (useCMEditViewDataManager() || {}) as Record<string, any>;
|
|
10
|
+
const { data: templates } = useGetTemplates({ id: modifiedData?.platform?.[0]?.id });
|
|
11
|
+
|
|
12
|
+
const setFormValue = (name: string, value?: string | Record<string, any>[]) => {
|
|
13
|
+
onChange({
|
|
14
|
+
target: {
|
|
15
|
+
name,
|
|
16
|
+
value
|
|
17
|
+
},
|
|
18
|
+
shouldSetInitialValue: true
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const handleSelectTemplate = (templateId: string) => {
|
|
23
|
+
const template = templates?.find((pageType) => pageType.id === Number(templateId));
|
|
24
|
+
|
|
25
|
+
if (template) {
|
|
26
|
+
const formTemplate = {
|
|
27
|
+
...template,
|
|
28
|
+
mainField: template.title,
|
|
29
|
+
label: template.title,
|
|
30
|
+
value: template.id
|
|
31
|
+
};
|
|
32
|
+
setFormValue('template', [formTemplate]);
|
|
33
|
+
} else {
|
|
34
|
+
setFormValue('template', []);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<SingleSelect
|
|
40
|
+
width="100%"
|
|
41
|
+
label="Template"
|
|
42
|
+
placeholder="Kies een template"
|
|
43
|
+
value={modifiedData?.template?.[0]?.id || 0}
|
|
44
|
+
onChange={handleSelectTemplate}
|
|
45
|
+
disabled={Boolean(!modifiedData?.platform?.[0]?.id)}
|
|
46
|
+
>
|
|
47
|
+
<SingleSelectOption value={0}>Geen template geselecteerd</SingleSelectOption>
|
|
48
|
+
{templates?.map((template) => (
|
|
49
|
+
<SingleSelectOption key={template.id} value={template.id}>
|
|
50
|
+
{template.title}
|
|
51
|
+
</SingleSelectOption>
|
|
52
|
+
))}
|
|
53
|
+
</SingleSelect>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
|
4
|
+
import { Stack } from '@strapi/design-system';
|
|
5
|
+
|
|
6
|
+
import { PAGE_TYPE_UID } from '../../../../shared/utils/constants';
|
|
7
|
+
import { TemplatePlatformSelect } from './TemplatePlatformSelect';
|
|
8
|
+
import { Wrapper } from '../EditView/wrapper';
|
|
9
|
+
import { PageByPlatformSearch } from './PageByPlatformSelect';
|
|
10
|
+
|
|
11
|
+
export const PageTypeEditView = () => {
|
|
12
|
+
const { layout } = useCMEditViewDataManager() as any;
|
|
13
|
+
|
|
14
|
+
const isPageTypeCollectionType = layout.uid === PAGE_TYPE_UID;
|
|
15
|
+
|
|
16
|
+
if (isPageTypeCollectionType) {
|
|
17
|
+
return (
|
|
18
|
+
<Wrapper title="Instellingen">
|
|
19
|
+
<Stack spacing={4} width="100%">
|
|
20
|
+
<TemplatePlatformSelect />
|
|
21
|
+
<PageByPlatformSearch />
|
|
22
|
+
</Stack>
|
|
23
|
+
</Wrapper>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return null;
|
|
28
|
+
};
|
package/admin/src/index.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import pluginId from './pluginId';
|
|
|
5
5
|
import Initializer from './components/Initializer';
|
|
6
6
|
import PageFiltersContainer from './components/PageFilters';
|
|
7
7
|
import { EditView } from './components/EditView';
|
|
8
|
+
import { PageTypeEditView } from './components/PageTypeEditView';
|
|
8
9
|
import middlewares from './middlewares';
|
|
9
10
|
import PluginIcon from './components/PluginIcon';
|
|
10
11
|
|
|
@@ -43,6 +44,10 @@ export default {
|
|
|
43
44
|
name: 'collection-type-picker',
|
|
44
45
|
Component: EditView
|
|
45
46
|
});
|
|
47
|
+
app.injectContentManagerComponent('editView', 'right-links', {
|
|
48
|
+
name: 'page-type-edit-view',
|
|
49
|
+
Component: PageTypeEditView
|
|
50
|
+
});
|
|
46
51
|
app.injectContentManagerComponent('listView', 'actions', {
|
|
47
52
|
name: 'page-filters',
|
|
48
53
|
Component: PageFiltersContainer
|
|
@@ -6,6 +6,7 @@ import { useGetPlatformRelation } from '../../api/platform-relation';
|
|
|
6
6
|
const usePlatformFormData = (form?: Record<string, any>, onPlatformChange?: (platform: Platform) => void) => {
|
|
7
7
|
const { onChange, initialData, layout } = form || {};
|
|
8
8
|
const { isLoading } = useGetPlatformRelation({ id: initialData?.id, uid: layout.uid });
|
|
9
|
+
|
|
9
10
|
const { selectedPlatform: defaultPlatform, setSelectedPlatform: setDefaultPlatform } =
|
|
10
11
|
useDefaultPlatformFromLocalStorage();
|
|
11
12
|
|