@webbio/strapi-plugin-page-builder 0.4.0-platform → 0.4.2-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/platform-relation.ts +40 -0
- package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +5 -54
- package/admin/src/components/EditView/Details/index.tsx +1 -11
- package/admin/src/components/EditView/PageSettings/index.tsx +15 -47
- package/admin/src/components/EditView/Platform/platform-select.tsx +1 -2
- package/admin/src/components/GlobalPlatformSelect/index.tsx +40 -0
- package/admin/src/components/GlobalPlatformSelect/styles.ts +27 -0
- package/admin/src/components/PageFilters/PlatformFilter/index.tsx +12 -8
- package/admin/src/components/PageFilters/filters.tsx +20 -11
- package/admin/src/components/PluginIcon/index.tsx +83 -3
- package/admin/src/index.tsx +7 -3
- package/admin/src/pages/app/index.tsx +14 -0
- package/admin/src/utils/findDomElement.ts +6 -0
- package/admin/src/utils/findElementParent.ts +20 -0
- package/admin/src/utils/hooks/useDefaultPlatformFromLocalStorage.ts +30 -0
- package/admin/src/utils/hooks/useHideOverviewFilterTags.ts +34 -0
- package/admin/src/utils/hooks/usePlatformFormData.ts +49 -0
- package/dist/package.json +2 -1
- package/dist/server/controllers/platform.js +5 -5
- package/dist/server/routes/index.js +2 -2
- package/dist/server/services/platform.js +6 -11
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/server/controllers/platform.ts +5 -5
- package/server/routes/index.ts +2 -2
- package/server/services/platform.ts +6 -12
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useQuery } from 'react-query';
|
|
2
|
+
|
|
3
|
+
import { useFetchClient } from '@strapi/helper-plugin';
|
|
4
|
+
|
|
5
|
+
export type Platform = {
|
|
6
|
+
id: number;
|
|
7
|
+
title?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const QUERY_KEY = 'platformRelations';
|
|
11
|
+
|
|
12
|
+
const fetchPlatformRelation = async ({
|
|
13
|
+
fetchClient,
|
|
14
|
+
id,
|
|
15
|
+
uid
|
|
16
|
+
}: Record<string, any> & UseGetPlatformRelationParams): Promise<Platform | undefined> => {
|
|
17
|
+
try {
|
|
18
|
+
const { get } = fetchClient;
|
|
19
|
+
const result = await get(`/content-manager/relations/${uid}/${id}/platform?page=1&pageSize=5`);
|
|
20
|
+
|
|
21
|
+
return result?.data?.data;
|
|
22
|
+
} catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type UseGetPlatformRelationParams = {
|
|
28
|
+
uid: string;
|
|
29
|
+
id: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const useGetPlatformRelation = (params: Record<string, any> & UseGetPlatformRelationParams) => {
|
|
33
|
+
const fetchClient = useFetchClient();
|
|
34
|
+
params = {
|
|
35
|
+
...params,
|
|
36
|
+
fetchClient
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return useQuery<Platform | undefined, Error>([QUERY_KEY, params.uid, params.id], () => fetchPlatformRelation(params));
|
|
40
|
+
};
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
|
4
|
-
import { Flex
|
|
4
|
+
import { Flex } from '@strapi/design-system';
|
|
5
5
|
import { Link } from '@strapi/icons';
|
|
6
6
|
|
|
7
7
|
import { Wrapper } from '../wrapper';
|
|
8
8
|
import { CreatePageButton } from './CreatePageButton';
|
|
9
9
|
import { PAGE_TYPE_PAGE, PAGE_UID } from '../../../../../shared/utils/constants';
|
|
10
|
+
import { usePlatformFormData } from '../../../utils/hooks/usePlatformFormData';
|
|
10
11
|
import S from '../Details/styles';
|
|
11
|
-
import { PlatformSelect } from '../Platform/platform-select';
|
|
12
|
-
import { Platform, useGetPlatforms } from '../../../api/platform';
|
|
13
12
|
|
|
14
13
|
interface CollectionTypeSettingsProps {
|
|
15
14
|
onlyPlatform?: boolean;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
export const CollectionTypeSettings = ({ onlyPlatform }: CollectionTypeSettingsProps) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const
|
|
18
|
+
const form = (useCMEditViewDataManager() || {}) as Record<string, any>;
|
|
19
|
+
usePlatformFormData(form);
|
|
20
|
+
const { layout, isCreatingEntry, initialData, modifiedData, onChange } = form;
|
|
22
21
|
const isUserCreatedContentType = layout.uid.startsWith('api::');
|
|
23
22
|
const [linkedPage, setLinkedPage] = useState<Record<string, any> | undefined>(initialData.page?.[0]);
|
|
24
23
|
|
|
@@ -46,59 +45,11 @@ export const CollectionTypeSettings = ({ onlyPlatform }: CollectionTypeSettingsP
|
|
|
46
45
|
}
|
|
47
46
|
}, []);
|
|
48
47
|
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
setSelectedPlatform(initialData?.platform?.[0]);
|
|
51
|
-
}, [initialData]);
|
|
52
|
-
|
|
53
|
-
const setFormValue = (name: string, value?: string | Record<string, any>[]) => {
|
|
54
|
-
onChange({
|
|
55
|
-
target: {
|
|
56
|
-
name,
|
|
57
|
-
value
|
|
58
|
-
},
|
|
59
|
-
shouldSetInitialValue: true
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const handleSelectPlatform = async (platformId: string) => {
|
|
64
|
-
const platform = platforms?.find((platform) => platform.id === Number(platformId));
|
|
65
|
-
|
|
66
|
-
if (platform && platform.title) {
|
|
67
|
-
setSelectedPlatform(platform);
|
|
68
|
-
const formPlatform = {
|
|
69
|
-
...platform,
|
|
70
|
-
label: platform.title,
|
|
71
|
-
value: platform.id
|
|
72
|
-
};
|
|
73
|
-
setFormValue('platform', [formPlatform]);
|
|
74
|
-
} else {
|
|
75
|
-
setFormValue('platform', []);
|
|
76
|
-
setSelectedPlatform(null);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
|
|
80
48
|
return (
|
|
81
49
|
<>
|
|
82
|
-
{(isCreatingEntry || onlyPlatform) && (
|
|
83
|
-
<Wrapper title="Platform">
|
|
84
|
-
<PlatformSelect
|
|
85
|
-
platforms={platforms}
|
|
86
|
-
selectedPlatform={selectedPlatform}
|
|
87
|
-
onChange={handleSelectPlatform}
|
|
88
|
-
noLabel
|
|
89
|
-
/>
|
|
90
|
-
</Wrapper>
|
|
91
|
-
)}
|
|
92
50
|
{!isCreatingEntry && !onlyPlatform && (
|
|
93
51
|
<Wrapper title="Gekoppelde pagina">
|
|
94
52
|
<Flex direction="column" gap={4} width="100%" alignItems="start">
|
|
95
|
-
<Box width="100%">
|
|
96
|
-
<PlatformSelect
|
|
97
|
-
platforms={platforms}
|
|
98
|
-
selectedPlatform={selectedPlatform}
|
|
99
|
-
onChange={handleSelectPlatform}
|
|
100
|
-
/>
|
|
101
|
-
</Box>
|
|
102
53
|
{showCreatePageButton && <CreatePageButton />}
|
|
103
54
|
|
|
104
55
|
{url && (
|
|
@@ -16,22 +16,12 @@ interface Props {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const Details = (props: Props) => {
|
|
19
|
-
const { entityTitle, pageType
|
|
19
|
+
const { entityTitle, pageType } = props;
|
|
20
20
|
|
|
21
21
|
const url = generateLink(props);
|
|
22
22
|
|
|
23
23
|
return (
|
|
24
24
|
<Flex gap={4} width="100%" direction="column">
|
|
25
|
-
{platformTitle && (
|
|
26
|
-
<Flex direction="column" alignItems="start" width="100%" gap={1}>
|
|
27
|
-
<S.SubtleType variant="omega" fontWeight="bold" textColor="neutral800">
|
|
28
|
-
Platform
|
|
29
|
-
</S.SubtleType>
|
|
30
|
-
<S.SubtleType variant="pi" textColor="neutral600">
|
|
31
|
-
{platformTitle}
|
|
32
|
-
</S.SubtleType>
|
|
33
|
-
</Flex>
|
|
34
|
-
)}
|
|
35
25
|
<Flex direction="column" alignItems="start" width="100%" gap={1}>
|
|
36
26
|
<S.SubtleType variant="omega" fontWeight="bold" textColor="neutral800">
|
|
37
27
|
{pageType?.title || PAGE_TYPE_PAGE}
|
|
@@ -3,25 +3,26 @@ import React, { useEffect, useMemo, useState } from 'react';
|
|
|
3
3
|
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
|
4
4
|
import { Stack, Flex } from '@strapi/design-system';
|
|
5
5
|
import { Cog, Cross } from '@strapi/icons';
|
|
6
|
-
import { getFetchClient } from '@strapi/helper-plugin';
|
|
7
6
|
import { TemplateSelect } from '../Template/TemplateSelect';
|
|
8
7
|
import { PageTypeSelect } from '../page-type-select';
|
|
9
8
|
import { CollectionTypeSearch } from '../CollectionTypeSearch';
|
|
10
9
|
import { Wrapper } from '../wrapper';
|
|
11
|
-
import { PageType
|
|
10
|
+
import { PageType } from '../../../api/page-type';
|
|
12
11
|
import { Details } from '../Details';
|
|
12
|
+
import { Platform } from '../../../api/platform';
|
|
13
|
+
import { usePlatformFormData } from '../../../utils/hooks/usePlatformFormData';
|
|
14
|
+
import { useGetPageTypesForPlatform } from '../../../api/platform-page-types';
|
|
13
15
|
import S from '../Details/styles';
|
|
14
|
-
import { Platform, useGetPlatforms } from '../../../api/platform';
|
|
15
|
-
import { PlatformSelect } from '../Platform/platform-select';
|
|
16
|
-
import getRequestUrl from '../../../utils/getRequestUrl';
|
|
17
16
|
|
|
18
17
|
export const PageSettings = () => {
|
|
19
|
-
const
|
|
20
|
-
const {
|
|
21
|
-
const {
|
|
22
|
-
const [pageTypes, setPageTypes] = useState(allPageTypes);
|
|
18
|
+
const form = (useCMEditViewDataManager() || {}) as Record<string, any>;
|
|
19
|
+
const { isCreatingEntry, initialData, onChange, modifiedData } = form;
|
|
20
|
+
const { defaultPlatform } = usePlatformFormData(form);
|
|
23
21
|
const [selectedPageType, setSelectedPageType] = useState<PageType | undefined | null>(initialData?.initialPageType);
|
|
24
22
|
const [selectedPlatform, setSelectedPlatform] = useState<Platform | undefined | null>(initialData?.platform?.[0]);
|
|
23
|
+
const { data: pageTypesForPlatform } = useGetPageTypesForPlatform({
|
|
24
|
+
id: selectedPlatform?.id
|
|
25
|
+
});
|
|
25
26
|
const noPlatformSelected = useMemo(() => !Boolean(selectedPlatform), [selectedPlatform]);
|
|
26
27
|
const [isEditting, setIsEditting] = useState(false);
|
|
27
28
|
const showEditFields = useMemo(
|
|
@@ -41,16 +42,15 @@ export const PageSettings = () => {
|
|
|
41
42
|
|
|
42
43
|
useEffect(() => {
|
|
43
44
|
setSelectedPageType(initialData?.initialPageType);
|
|
44
|
-
|
|
45
45
|
setSelectedPlatform(initialData?.platform?.[0]);
|
|
46
46
|
setIsEditting(false);
|
|
47
47
|
}, [initialData]);
|
|
48
48
|
|
|
49
49
|
useEffect(() => {
|
|
50
|
-
if (
|
|
51
|
-
|
|
50
|
+
if (!initialData?.platform?.[0] && defaultPlatform) {
|
|
51
|
+
setSelectedPlatform(defaultPlatform);
|
|
52
52
|
}
|
|
53
|
-
}, [
|
|
53
|
+
}, [initialData, defaultPlatform]);
|
|
54
54
|
|
|
55
55
|
const cancelEdit = () => {
|
|
56
56
|
setIsEditting(false);
|
|
@@ -70,7 +70,7 @@ export const PageSettings = () => {
|
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
const handleSelectPageType = (pageTypeId: string) => {
|
|
73
|
-
const pageType =
|
|
73
|
+
const pageType = pageTypesForPlatform?.find((pageType) => pageType.id === Number(pageTypeId));
|
|
74
74
|
|
|
75
75
|
if (pageType) {
|
|
76
76
|
setSelectedPageType(pageType);
|
|
@@ -86,45 +86,13 @@ export const PageSettings = () => {
|
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
const handleSelectPlatform = async (platformId: string) => {
|
|
90
|
-
const platform = platforms?.find((platform) => platform.id === Number(platformId));
|
|
91
|
-
|
|
92
|
-
if (platform && platform.title) {
|
|
93
|
-
setSelectedPlatform(platform);
|
|
94
|
-
const formPlatform = {
|
|
95
|
-
...platform,
|
|
96
|
-
label: platform.title,
|
|
97
|
-
value: platform.id
|
|
98
|
-
};
|
|
99
|
-
setFormValue('platform', [formPlatform]);
|
|
100
|
-
setPageTypesByPlatform(platform.title);
|
|
101
|
-
} else {
|
|
102
|
-
setFormValue('platform', []);
|
|
103
|
-
setSelectedPlatform(null);
|
|
104
|
-
removePageType();
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const setPageTypesByPlatform = async (platform: string) => {
|
|
109
|
-
const pageTypeUrl = getRequestUrl(`/platform/${platform}`);
|
|
110
|
-
const { get } = getFetchClient();
|
|
111
|
-
const { data: platFormData } = await get(pageTypeUrl);
|
|
112
|
-
|
|
113
|
-
const filterPageTypeByPlatform = platFormData[0].pageTypes.filter(
|
|
114
|
-
(data) => allPageTypes?.find((pageData) => pageData.uid === data.uid)
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
setPageTypes(filterPageTypeByPlatform);
|
|
118
|
-
};
|
|
119
|
-
|
|
120
89
|
return (
|
|
121
90
|
<Wrapper title="Gekoppelde type">
|
|
122
91
|
<Flex direction="column" gap={4} width="100%">
|
|
123
92
|
{showEditFields ? (
|
|
124
93
|
<Stack spacing={4} width="100%">
|
|
125
|
-
<PlatformSelect platforms={platforms} selectedPlatform={selectedPlatform} onChange={handleSelectPlatform} />
|
|
126
94
|
<PageTypeSelect
|
|
127
|
-
pageTypes={
|
|
95
|
+
pageTypes={pageTypesForPlatform}
|
|
128
96
|
selectedPageType={selectedPageType}
|
|
129
97
|
onChange={handleSelectPageType}
|
|
130
98
|
disabled={noPlatformSelected}
|
|
@@ -16,11 +16,10 @@ export const PlatformSelect = ({ onChange, platforms, selectedPlatform, noLabel
|
|
|
16
16
|
return (
|
|
17
17
|
<SingleSelect
|
|
18
18
|
label={!noLabel && 'Platform'}
|
|
19
|
-
placeholder="
|
|
19
|
+
placeholder="Kies een platform"
|
|
20
20
|
value={selectedPlatform?.id || PLATFORM}
|
|
21
21
|
onChange={onChange}
|
|
22
22
|
>
|
|
23
|
-
<SingleSelectOption value={PLATFORM}>Platform</SingleSelectOption>
|
|
24
23
|
{platforms?.map((pageType: Platform) => (
|
|
25
24
|
<SingleSelectOption key={pageType?.id} value={pageType?.id}>
|
|
26
25
|
{pageType?.title}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useHistory, useLocation } from 'react-router-dom';
|
|
3
|
+
|
|
4
|
+
import PlatformFilter from '../PageFilters/PlatformFilter';
|
|
5
|
+
import { Platform, useGetPlatforms } from '../../api/platform';
|
|
6
|
+
import { useDefaultPlatformFromLocalStorage } from '../../utils/hooks/useDefaultPlatformFromLocalStorage';
|
|
7
|
+
|
|
8
|
+
import S from './styles';
|
|
9
|
+
|
|
10
|
+
export interface IGlobalPlatformSelectProps {
|
|
11
|
+
small?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const GlobalPlatformSelect = ({ small }: IGlobalPlatformSelectProps) => {
|
|
15
|
+
const { pathname } = useLocation();
|
|
16
|
+
const { push } = useHistory();
|
|
17
|
+
|
|
18
|
+
const { data: platforms, isLoading } = useGetPlatforms({});
|
|
19
|
+
const { selectedPlatform, setSelectedPlatform } = useDefaultPlatformFromLocalStorage();
|
|
20
|
+
|
|
21
|
+
const handlePlatformChange = (platform: Platform) => {
|
|
22
|
+
setSelectedPlatform(platform);
|
|
23
|
+
|
|
24
|
+
if (typeof window !== 'undefined' && pathname.split('/').filter(Boolean).length > 3) {
|
|
25
|
+
push('/');
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
if (isLoading || (platforms || [])?.length < 2) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<S.Wrapper small={small}>
|
|
35
|
+
<PlatformFilter platforms={platforms} onChange={handlePlatformChange} selectedPlatform={selectedPlatform} />
|
|
36
|
+
</S.Wrapper>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { GlobalPlatformSelect };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import styled, { css } from 'styled-components';
|
|
2
|
+
|
|
3
|
+
const Wrapper = styled.div<{ small?: boolean }>`
|
|
4
|
+
${({ theme, small }) => {
|
|
5
|
+
return css`
|
|
6
|
+
width: ${small ? '72px' : '224px'};
|
|
7
|
+
&:hover {
|
|
8
|
+
width: 224px;
|
|
9
|
+
transition: ${small ? 'width 0.15s ease-in-out' : 'none'};
|
|
10
|
+
}
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
gap: 4px;
|
|
14
|
+
position: fixed;
|
|
15
|
+
top: 64px;
|
|
16
|
+
left: 0;
|
|
17
|
+
z-index: 1000;
|
|
18
|
+
padding: 0 8px 0 12px;
|
|
19
|
+
`;
|
|
20
|
+
}}
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
const GlobalPlatformSelectStyles = {
|
|
24
|
+
Wrapper
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default GlobalPlatformSelectStyles;
|
|
@@ -2,22 +2,26 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { SingleSelectOption, SingleSelect } from '@strapi/design-system';
|
|
4
4
|
import { Platform } from '../../../api/platform';
|
|
5
|
-
import { PLATFORM_NO_FILTER } from '../../../constants';
|
|
6
5
|
|
|
7
6
|
interface Props {
|
|
8
|
-
onChange?: (
|
|
9
|
-
selectedPlatform?:
|
|
7
|
+
onChange?: (platform: Platform) => void;
|
|
8
|
+
selectedPlatform?: Platform;
|
|
10
9
|
platforms?: Platform[];
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
const PlatformFilter = ({ onChange, platforms, selectedPlatform }: Props) => {
|
|
13
|
+
const handleChange = (platformId?: string) => {
|
|
14
|
+
const foundPlatform = platforms?.find((platform) => platform?.id === Number(platformId));
|
|
15
|
+
|
|
16
|
+
if (foundPlatform) {
|
|
17
|
+
onChange?.(foundPlatform);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
14
21
|
return (
|
|
15
|
-
<SingleSelect placeholder="
|
|
16
|
-
<SingleSelectOption key={PLATFORM_NO_FILTER} value={PLATFORM_NO_FILTER}>
|
|
17
|
-
All Platforms
|
|
18
|
-
</SingleSelectOption>
|
|
22
|
+
<SingleSelect placeholder="Selecteer platform" onChange={handleChange} size="S" value={selectedPlatform?.id}>
|
|
19
23
|
{platforms?.map((platform: Platform) => (
|
|
20
|
-
<SingleSelectOption key={platform?.id} value={platform?.
|
|
24
|
+
<SingleSelectOption key={platform?.id} value={platform?.id}>
|
|
21
25
|
{platform?.title}
|
|
22
26
|
</SingleSelectOption>
|
|
23
27
|
))}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
1
|
+
import { useEffect, useMemo } from 'react';
|
|
2
2
|
import set from 'lodash/set';
|
|
3
3
|
|
|
4
4
|
import { Stack } from '@strapi/design-system';
|
|
@@ -6,11 +6,12 @@ import { useQueryParams } from '@strapi/helper-plugin';
|
|
|
6
6
|
|
|
7
7
|
import PageTypeFilter from './PageTypeFilter';
|
|
8
8
|
import { PAGE_TYPE_PAGE, PLATFORM } from '../../../../shared/utils/constants';
|
|
9
|
-
import PlatformFilter from './PlatformFilter';
|
|
10
9
|
import { Platform, useGetPlatforms } from '../../api/platform';
|
|
11
10
|
import { PAGE_TYPE, PAGE_TYPE_NO_FILTER, PLATFORM_NO_FILTER } from '../../constants';
|
|
12
11
|
import { PageType } from '../../api/page-type';
|
|
13
12
|
import { useGetPageTypesForPlatform } from '../../api/platform-page-types';
|
|
13
|
+
import { useDefaultPlatformFromLocalStorage } from '../../utils/hooks/useDefaultPlatformFromLocalStorage';
|
|
14
|
+
import { useHideOverviewFilterTags } from '../../utils/hooks/useHideOverviewFilterTags';
|
|
14
15
|
|
|
15
16
|
interface PageFiltersProps {
|
|
16
17
|
hidePageType?: boolean;
|
|
@@ -18,16 +19,18 @@ interface PageFiltersProps {
|
|
|
18
19
|
|
|
19
20
|
const PageFilters = ({ hidePageType }: PageFiltersProps) => {
|
|
20
21
|
const [{ query }, setQuery] = useQueryParams() as any;
|
|
21
|
-
|
|
22
|
+
const { selectedPlatform: globalSelectedPlatform } = useDefaultPlatformFromLocalStorage();
|
|
23
|
+
useHideOverviewFilterTags();
|
|
22
24
|
const { data: platforms } = useGetPlatforms({});
|
|
23
25
|
|
|
24
|
-
const selectedPlatformTitle = useMemo(() => getPlatformFromQuery(query, platforms), [query, platforms]);
|
|
25
|
-
|
|
26
26
|
const { data: pageTypesForPlatform } = useGetPageTypesForPlatform({
|
|
27
|
-
id:
|
|
27
|
+
id: globalSelectedPlatform?.id
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
const selectedPageTypeUid = useMemo(
|
|
30
|
+
const selectedPageTypeUid = useMemo(
|
|
31
|
+
() => getPageTypeFromQuery(query, []),
|
|
32
|
+
[query, platforms, globalSelectedPlatform]
|
|
33
|
+
);
|
|
31
34
|
|
|
32
35
|
const handleFilterChange = (
|
|
33
36
|
filters: Record<string, any>,
|
|
@@ -62,13 +65,13 @@ const PageFilters = ({ hidePageType }: PageFiltersProps) => {
|
|
|
62
65
|
});
|
|
63
66
|
};
|
|
64
67
|
|
|
65
|
-
const handlePlatformSelect = (
|
|
66
|
-
if (
|
|
68
|
+
const handlePlatformSelect = (platformTitle: string) => {
|
|
69
|
+
if (platformTitle === PLATFORM_NO_FILTER) {
|
|
67
70
|
removeFilters(PLATFORM);
|
|
68
71
|
return;
|
|
69
72
|
}
|
|
70
73
|
|
|
71
|
-
handleFilterChange(getPlatformQueryFilter(
|
|
74
|
+
handleFilterChange(getPlatformQueryFilter(platformTitle), PLATFORM, PAGE_TYPE);
|
|
72
75
|
};
|
|
73
76
|
|
|
74
77
|
const handlePageTypeSelect = (pageType: string) => {
|
|
@@ -85,9 +88,15 @@ const PageFilters = ({ hidePageType }: PageFiltersProps) => {
|
|
|
85
88
|
handleFilterChange(getPageTypeQueryFilter(pageType), PAGE_TYPE);
|
|
86
89
|
};
|
|
87
90
|
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
const selectedPlatformFromQuery = getPlatformFromQuery(query, platforms);
|
|
93
|
+
if (globalSelectedPlatform?.title && globalSelectedPlatform.title !== selectedPlatformFromQuery) {
|
|
94
|
+
handlePlatformSelect(globalSelectedPlatform.title);
|
|
95
|
+
}
|
|
96
|
+
}, [query, platforms, globalSelectedPlatform]);
|
|
97
|
+
|
|
88
98
|
return (
|
|
89
99
|
<Stack horizontal spacing={2}>
|
|
90
|
-
<PlatformFilter onChange={handlePlatformSelect} platforms={platforms} selectedPlatform={selectedPlatformTitle} />
|
|
91
100
|
{!hidePageType && (
|
|
92
101
|
<PageTypeFilter
|
|
93
102
|
onChange={handlePageTypeSelect}
|
|
@@ -4,11 +4,91 @@
|
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import React from 'react';
|
|
8
|
-
|
|
7
|
+
import React, { useLayoutEffect, useRef } from 'react';
|
|
8
|
+
|
|
9
|
+
import { GlobalPlatformSelect } from '../GlobalPlatformSelect';
|
|
10
|
+
import { Portal } from '@strapi/design-system';
|
|
11
|
+
import { findElementParent } from '../../utils/findElementParent';
|
|
12
|
+
import { findDomElement } from '../../utils/findDomElement';
|
|
13
|
+
import { useDefaultPlatformFromLocalStorage } from '../../utils/hooks/useDefaultPlatformFromLocalStorage';
|
|
9
14
|
|
|
10
15
|
const PluginIcon = () => {
|
|
11
|
-
|
|
16
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
17
|
+
const [smallNav, setSmallNav] = React.useState<boolean>();
|
|
18
|
+
const { selectedPlatform, platforms } = useDefaultPlatformFromLocalStorage();
|
|
19
|
+
|
|
20
|
+
const setHrStyles = () => {
|
|
21
|
+
const hr = findNavHr();
|
|
22
|
+
|
|
23
|
+
if (hr) {
|
|
24
|
+
hr.style.marginTop = '40px';
|
|
25
|
+
const navW = hr?.getBoundingClientRect().width;
|
|
26
|
+
setSmallNav(navW < 100 ? true : false);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
useLayoutEffect(() => {
|
|
31
|
+
if (platforms && platforms.length > 1) {
|
|
32
|
+
setHrStyles();
|
|
33
|
+
}
|
|
34
|
+
}, [platforms]);
|
|
35
|
+
|
|
36
|
+
useLayoutEffect(() => {
|
|
37
|
+
removePluginLink(ref);
|
|
38
|
+
}, [ref]);
|
|
39
|
+
|
|
40
|
+
useLayoutEffect(() => {
|
|
41
|
+
changeStrapiTitle(selectedPlatform?.title);
|
|
42
|
+
}, [selectedPlatform]);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div ref={ref}>
|
|
46
|
+
<Portal>
|
|
47
|
+
<GlobalPlatformSelect small={smallNav} />
|
|
48
|
+
</Portal>
|
|
49
|
+
</div>
|
|
50
|
+
);
|
|
12
51
|
};
|
|
13
52
|
|
|
14
53
|
export default PluginIcon;
|
|
54
|
+
|
|
55
|
+
const changeStrapiTitle = (selectedPlatformTitle?: string) => {
|
|
56
|
+
let element = findDomElement(`//nav//a//p[contains(., 'Workplace')]`);
|
|
57
|
+
|
|
58
|
+
if (element) {
|
|
59
|
+
// If element is found, make sure to add a data attribute, so we can find it later
|
|
60
|
+
element.dataset.strapiWorkplace = 'platformTitle';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!element) {
|
|
64
|
+
element = findDomElement(`//nav//a//p[@data-strapi-workplace="platformTitle"]`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (element && selectedPlatformTitle) {
|
|
68
|
+
element.textContent = selectedPlatformTitle;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const removePluginLink = (ref?: React.RefObject<HTMLDivElement>) => {
|
|
73
|
+
if (ref?.current) {
|
|
74
|
+
const anchorParent = findElementParent(ref.current, 'LI');
|
|
75
|
+
if (anchorParent) {
|
|
76
|
+
anchorParent?.remove();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const findNavHr = (): HTMLElement | undefined => {
|
|
82
|
+
if (typeof window === 'undefined') {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let hrNode: HTMLElement | undefined;
|
|
87
|
+
document.querySelector('nav')?.childNodes.forEach((node) => {
|
|
88
|
+
if (node?.nodeName === 'HR') {
|
|
89
|
+
hrNode = node as HTMLElement;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return hrNode;
|
|
94
|
+
};
|
package/admin/src/index.tsx
CHANGED
|
@@ -22,12 +22,16 @@ export default {
|
|
|
22
22
|
|
|
23
23
|
app.addMenuLink({
|
|
24
24
|
to: '/plugins/strapi-plugin-page-builder',
|
|
25
|
-
icon: PluginIcon,
|
|
25
|
+
icon: PluginIcon, // This really is a plugin icon, I promise!
|
|
26
26
|
intlLabel: {
|
|
27
27
|
id: pluginId,
|
|
28
|
-
defaultMessage: '
|
|
28
|
+
defaultMessage: ' '
|
|
29
|
+
},
|
|
30
|
+
Component: async () => {
|
|
31
|
+
const component = await import(/* webpackChunkName: "[request]" */ './pages/app');
|
|
32
|
+
|
|
33
|
+
return component;
|
|
29
34
|
},
|
|
30
|
-
Component: PluginIcon,
|
|
31
35
|
permissions: [] // permissions to apply to the link
|
|
32
36
|
});
|
|
33
37
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const findElementParent = (rootEl: HTMLElement, element?: string, maxDepth = 10): HTMLElement | undefined => {
|
|
2
|
+
let found = false;
|
|
3
|
+
let el = rootEl;
|
|
4
|
+
let depth = 0;
|
|
5
|
+
|
|
6
|
+
while (!found && depth <= maxDepth) {
|
|
7
|
+
if (el?.tagName === element) {
|
|
8
|
+
found = true;
|
|
9
|
+
} else {
|
|
10
|
+
el = el?.parentElement as HTMLElement;
|
|
11
|
+
depth++;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (!found) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return el;
|
|
20
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useLocalStorage } from '@mantine/hooks';
|
|
2
|
+
import { Platform, useGetPlatforms } from '../../api/platform';
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
|
|
5
|
+
const useDefaultPlatformFromLocalStorage = () => {
|
|
6
|
+
const { data: platforms, isLoading } = useGetPlatforms({});
|
|
7
|
+
const [selectedPlatform, setSelectedPlatform] = useLocalStorage<Platform | undefined>({
|
|
8
|
+
key: 'selectedPlatform',
|
|
9
|
+
defaultValue: undefined,
|
|
10
|
+
getInitialValueInEffect: false
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (
|
|
15
|
+
!isLoading &&
|
|
16
|
+
platforms?.[0]?.title &&
|
|
17
|
+
(!selectedPlatform?.id || !platforms.find((platform) => platform.id === selectedPlatform.id))
|
|
18
|
+
) {
|
|
19
|
+
setSelectedPlatform(platforms[0]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!isLoading && (platforms || []).length === 0) {
|
|
23
|
+
setSelectedPlatform(undefined);
|
|
24
|
+
}
|
|
25
|
+
}, [isLoading, selectedPlatform]);
|
|
26
|
+
|
|
27
|
+
return { selectedPlatform, setSelectedPlatform, platforms };
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { useDefaultPlatformFromLocalStorage };
|