@webbio/strapi-plugin-page-builder 0.9.2-platform → 0.9.4-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-page-types.ts +2 -2
- package/admin/src/api/platform-relation.ts +3 -6
- package/admin/src/api/platform.ts +0 -3
- package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +14 -5
- package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +3 -3
- package/admin/src/components/EditView/PageSettings/index.tsx +11 -21
- package/admin/src/components/PageTypeEditView/index.tsx +18 -14
- package/admin/src/components/PlatformFilteredSelectField/Multi/index.tsx +5 -2
- package/admin/src/components/PlatformFilteredSelectField/Single/index.tsx +12 -5
- package/admin/src/components/PlatformFilteredSelectField/index.tsx +10 -2
- package/admin/src/utils/hooks/usePlatformFormData.ts +11 -7
- package/dist/package.json +1 -1
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/server/middlewares/mikkel.js +0 -35
- package/dist/server/policies/platformSelector.js +0 -18
- package/dist/server/utils/graphql.js +0 -100
- package/dist/server/utils/paginationValidation.js +0 -31
|
@@ -21,7 +21,7 @@ const fetchPageTypesForPlatform = async ({ fetchClient, id }: Record<string, any
|
|
|
21
21
|
const pageTypesResult = await get(`/content-manager/collection-types/api::page-type.page-type?page=1&pageSize=999`);
|
|
22
22
|
|
|
23
23
|
return pageTypesResult?.data?.results
|
|
24
|
-
?.filter((x) => x?.platform?.id === id)
|
|
24
|
+
?.filter((x: Record<string, any>) => x?.platform?.id === id)
|
|
25
25
|
?.map((pageType: Record<string, any>) => ({
|
|
26
26
|
id: pageType.id,
|
|
27
27
|
uid: pageType.uid,
|
|
@@ -36,7 +36,7 @@ const fetchPageTypesForPlatform = async ({ fetchClient, id }: Record<string, any
|
|
|
36
36
|
export const useGetPageTypesForPlatform = (params: Record<string, any>) => {
|
|
37
37
|
const fetchClient = useFetchClient();
|
|
38
38
|
|
|
39
|
-
return useQuery<PageType[], Error>([QUERY_KEY, params], () =>
|
|
39
|
+
return useQuery<PageType[], Error>([QUERY_KEY, params.id], () =>
|
|
40
40
|
fetchPageTypesForPlatform({
|
|
41
41
|
...params,
|
|
42
42
|
fetchClient
|
|
@@ -2,10 +2,7 @@ import { useQuery } from 'react-query';
|
|
|
2
2
|
|
|
3
3
|
import { useFetchClient } from '@strapi/helper-plugin';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
id: number;
|
|
7
|
-
title?: string;
|
|
8
|
-
};
|
|
5
|
+
import { Platform } from './platform';
|
|
9
6
|
|
|
10
7
|
const QUERY_KEY = 'platformRelations';
|
|
11
8
|
|
|
@@ -13,7 +10,7 @@ const fetchPlatformRelation = async ({
|
|
|
13
10
|
fetchClient,
|
|
14
11
|
id,
|
|
15
12
|
uid
|
|
16
|
-
}: Record<string, any> & UseGetPlatformRelationParams): Promise<Platform
|
|
13
|
+
}: Record<string, any> & UseGetPlatformRelationParams): Promise<Platform | undefined> => {
|
|
17
14
|
try {
|
|
18
15
|
if (!uid || !id) {
|
|
19
16
|
throw new Error('No uid or id');
|
|
@@ -36,7 +33,7 @@ type UseGetPlatformRelationParams = {
|
|
|
36
33
|
export const useGetPlatformRelation = (params: Record<string, any> & UseGetPlatformRelationParams) => {
|
|
37
34
|
const fetchClient = useFetchClient();
|
|
38
35
|
|
|
39
|
-
return useQuery<Platform
|
|
36
|
+
return useQuery<Platform | undefined, Error>([QUERY_KEY, params], () =>
|
|
40
37
|
fetchPlatformRelation({
|
|
41
38
|
...params,
|
|
42
39
|
fetchClient
|
|
@@ -2,12 +2,9 @@ import { useQuery } from 'react-query';
|
|
|
2
2
|
|
|
3
3
|
import { useFetchClient } from '@strapi/helper-plugin';
|
|
4
4
|
|
|
5
|
-
import { PageType } from './platform-page-types';
|
|
6
|
-
|
|
7
5
|
export type Platform = {
|
|
8
6
|
id: number;
|
|
9
7
|
title?: string;
|
|
10
|
-
pageTypes?: PageType[];
|
|
11
8
|
};
|
|
12
9
|
|
|
13
10
|
const QUERY_KEY = 'platforms';
|
|
@@ -10,12 +10,20 @@ import getRequestUrl from '../../../../utils/getRequestUrl';
|
|
|
10
10
|
import { sanitizeModules } from '../../../../utils/sanitizeModules';
|
|
11
11
|
import { PAGE_UID } from '../../../../../../shared/utils/constants';
|
|
12
12
|
import { IGetTranslationPageLinks } from '../../../../../../server/controllers/collection-types';
|
|
13
|
+
import { usePlatformFormData } from '../../../../utils/hooks/usePlatformFormData';
|
|
13
14
|
|
|
14
15
|
import S from './styles';
|
|
16
|
+
import { Platform } from '../../../../api/platform';
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
interface ICreatePageButtonProps {
|
|
19
|
+
selectedPlatform: Platform;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const CreatePageButton = ({ selectedPlatform }: ICreatePageButtonProps) => {
|
|
17
23
|
const history = useHistory();
|
|
18
|
-
const
|
|
24
|
+
const form = (useCMEditViewDataManager() || {}) as Record<string, any>;
|
|
25
|
+
const { layout, initialData } = form;
|
|
26
|
+
|
|
19
27
|
const { locales } = useSelector((state: any) => state.i18n_locales);
|
|
20
28
|
|
|
21
29
|
const { post, get, put } = useFetchClient();
|
|
@@ -23,8 +31,9 @@ export const CreatePageButton = () => {
|
|
|
23
31
|
|
|
24
32
|
const handleCreatePage = async (e: React.MouseEvent<HTMLAnchorElement>) => {
|
|
25
33
|
e.preventDefault();
|
|
34
|
+
|
|
26
35
|
try {
|
|
27
|
-
const pageTypeUrl = getRequestUrl(`/page-types/${layout.uid}/${
|
|
36
|
+
const pageTypeUrl = getRequestUrl(`/page-types/${layout.uid}/${selectedPlatform.id}`);
|
|
28
37
|
const { data: pageType } = await get(pageTypeUrl);
|
|
29
38
|
const mappedLocalizations = (initialData?.localizations || []).map((x: any) => x?.id).join(',');
|
|
30
39
|
const linkedPages: { data: IGetTranslationPageLinks[] } = await get(
|
|
@@ -49,7 +58,7 @@ export const CreatePageButton = () => {
|
|
|
49
58
|
post,
|
|
50
59
|
locale,
|
|
51
60
|
pageTypeId: pageType.id,
|
|
52
|
-
platformId:
|
|
61
|
+
platformId: selectedPlatform.id,
|
|
53
62
|
parentId: pageType?.defaultParent?.id,
|
|
54
63
|
collectionTypeId: initialData.id,
|
|
55
64
|
layoutUid: layout.uid,
|
|
@@ -107,7 +116,7 @@ const createNewPage = async ({
|
|
|
107
116
|
lower: true,
|
|
108
117
|
trim: true
|
|
109
118
|
})
|
|
110
|
-
|
|
119
|
+
}
|
|
111
120
|
: {};
|
|
112
121
|
|
|
113
122
|
const { data: page } = await post(url, {
|
|
@@ -16,12 +16,12 @@ interface CollectionTypeSettingsProps {
|
|
|
16
16
|
|
|
17
17
|
export const CollectionTypeSettings = ({ onlyPlatform }: CollectionTypeSettingsProps) => {
|
|
18
18
|
const form = (useCMEditViewDataManager() || {}) as Record<string, any>;
|
|
19
|
-
usePlatformFormData(form);
|
|
19
|
+
const { selectedPlatform, isLoadingPlatform } = usePlatformFormData(form);
|
|
20
20
|
const { layout, isCreatingEntry, initialData, modifiedData, onChange } = form;
|
|
21
21
|
const isUserCreatedContentType = layout.uid.startsWith('api::');
|
|
22
22
|
const [linkedPage, setLinkedPage] = useState<Record<string, any> | undefined>(initialData.page?.[0]);
|
|
23
23
|
|
|
24
|
-
const showCreatePageButton = isUserCreatedContentType && !isCreatingEntry && !linkedPage;
|
|
24
|
+
const showCreatePageButton = isUserCreatedContentType && !isCreatingEntry && !linkedPage && !isLoadingPlatform;
|
|
25
25
|
const url = generateLink(linkedPage?.id, initialData?.locale);
|
|
26
26
|
|
|
27
27
|
useEffect(() => {
|
|
@@ -50,7 +50,7 @@ export const CollectionTypeSettings = ({ onlyPlatform }: CollectionTypeSettingsP
|
|
|
50
50
|
{!isCreatingEntry && !onlyPlatform && (
|
|
51
51
|
<Wrapper title="Gekoppelde pagina">
|
|
52
52
|
<Flex direction="column" gap={4} width="100%" alignItems="start">
|
|
53
|
-
{showCreatePageButton && <CreatePageButton />}
|
|
53
|
+
{showCreatePageButton && selectedPlatform && <CreatePageButton selectedPlatform={selectedPlatform} />}
|
|
54
54
|
|
|
55
55
|
{url && (
|
|
56
56
|
<Flex direction="column" alignItems="start" width="100%" gap={1}>
|
|
@@ -7,9 +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/platform-page-types';
|
|
11
10
|
import { Details } from '../Details';
|
|
12
|
-
import { Platform } from '../../../api/platform';
|
|
13
11
|
import { usePlatformFormData } from '../../../utils/hooks/usePlatformFormData';
|
|
14
12
|
import { useGetPageTypesForPlatform } from '../../../api/platform-page-types';
|
|
15
13
|
import S from '../Details/styles';
|
|
@@ -17,17 +15,19 @@ import S from '../Details/styles';
|
|
|
17
15
|
export const PageSettings = () => {
|
|
18
16
|
const form = (useCMEditViewDataManager() || {}) as Record<string, any>;
|
|
19
17
|
const { isCreatingEntry, initialData, onChange, modifiedData } = form;
|
|
20
|
-
const {
|
|
21
|
-
|
|
22
|
-
const [selectedPlatform, setSelectedPlatform] = useState<Platform | undefined | null>(initialData?.platform?.[0]);
|
|
18
|
+
const { selectedPlatform, isLoadingPlatform } = usePlatformFormData(form);
|
|
19
|
+
|
|
23
20
|
const { data: pageTypesForPlatform } = useGetPageTypesForPlatform({
|
|
24
21
|
id: selectedPlatform?.id
|
|
25
22
|
});
|
|
23
|
+
const selectedPageType = pageTypesForPlatform?.find(
|
|
24
|
+
(pageType) => pageType.id === Number(modifiedData?.pageType?.[0]?.id)
|
|
25
|
+
);
|
|
26
26
|
const noPlatformSelected = useMemo(() => !Boolean(selectedPlatform), [selectedPlatform]);
|
|
27
27
|
const [isEditting, setIsEditting] = useState(false);
|
|
28
28
|
const showEditFields = useMemo(
|
|
29
|
-
() => isCreatingEntry || !
|
|
30
|
-
[isCreatingEntry, isEditting,
|
|
29
|
+
() => isCreatingEntry || !initialData?.initialPageType?.id || !initialData.collectionTypeTitle || isEditting,
|
|
30
|
+
[isCreatingEntry, isEditting, initialData?.initialPageType, initialData]
|
|
31
31
|
);
|
|
32
32
|
|
|
33
33
|
const setFormValue = (name: string, value?: string | Record<string, any>[]) => {
|
|
@@ -41,29 +41,20 @@ export const PageSettings = () => {
|
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
useEffect(() => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
setIsEditting(false);
|
|
47
|
-
}, [initialData]);
|
|
48
|
-
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
if (!initialData?.platform?.[0] && defaultPlatform) {
|
|
51
|
-
setSelectedPlatform(defaultPlatform);
|
|
44
|
+
if (!isLoadingPlatform) {
|
|
45
|
+
setIsEditting(false);
|
|
52
46
|
}
|
|
53
|
-
}, [
|
|
47
|
+
}, [isLoadingPlatform]);
|
|
54
48
|
|
|
55
49
|
const cancelEdit = () => {
|
|
56
50
|
setIsEditting(false);
|
|
57
|
-
setSelectedPageType(initialData?.initialPageType || []);
|
|
58
|
-
setSelectedPlatform(initialData?.platform?.[0]);
|
|
59
51
|
setFormValue('pageType', initialData?.initialPageType || []);
|
|
60
52
|
setFormValue('collectionTypeTitle', initialData?.collectionTypeTitle);
|
|
61
53
|
setFormValue('collectionTypeId', initialData?.collectionTypeId);
|
|
62
|
-
setFormValue('platform',
|
|
54
|
+
setFormValue('platform', modifiedData?.platform);
|
|
63
55
|
};
|
|
64
56
|
|
|
65
57
|
const removePageType = () => {
|
|
66
|
-
setSelectedPageType(undefined);
|
|
67
58
|
setFormValue('pageType', []);
|
|
68
59
|
setFormValue('collectionTypeTitle', undefined);
|
|
69
60
|
setFormValue('collectionTypeId', undefined);
|
|
@@ -73,7 +64,6 @@ export const PageSettings = () => {
|
|
|
73
64
|
const pageType = pageTypesForPlatform?.find((pageType) => pageType.id === Number(pageTypeId));
|
|
74
65
|
|
|
75
66
|
if (pageType) {
|
|
76
|
-
setSelectedPageType(pageType);
|
|
77
67
|
const formPageType = {
|
|
78
68
|
...pageType,
|
|
79
69
|
mainField: pageType.uid,
|
|
@@ -7,25 +7,29 @@ import { PAGE_TYPE_UID } from '../../../../shared/utils/constants';
|
|
|
7
7
|
import { TemplatePlatformSelect } from './TemplatePlatformSelect';
|
|
8
8
|
import { Wrapper } from '../EditView/wrapper';
|
|
9
9
|
import SinglePlatformFilteredSelectField from '../PlatformFilteredSelectField/Single';
|
|
10
|
+
import { usePlatformFormData } from '../../utils/hooks/usePlatformFormData';
|
|
10
11
|
|
|
11
12
|
export const PageTypeEditView = () => {
|
|
12
|
-
const
|
|
13
|
+
const form = useCMEditViewDataManager() as any;
|
|
14
|
+
const { layout } = form;
|
|
15
|
+
const { selectedPlatform } = usePlatformFormData(form);
|
|
13
16
|
|
|
14
17
|
const isPageTypeCollectionType = layout.uid === PAGE_TYPE_UID;
|
|
15
18
|
|
|
16
|
-
if (isPageTypeCollectionType) {
|
|
17
|
-
return
|
|
18
|
-
<Wrapper title="Instellingen">
|
|
19
|
-
<Stack spacing={4} width="100%">
|
|
20
|
-
<TemplatePlatformSelect />
|
|
21
|
-
<SinglePlatformFilteredSelectField
|
|
22
|
-
name="defaultParent"
|
|
23
|
-
attribute={{ pluginOptions: { filteredSelect: { targetField: 'defaultParent' } } }}
|
|
24
|
-
/>
|
|
25
|
-
</Stack>
|
|
26
|
-
</Wrapper>
|
|
27
|
-
);
|
|
19
|
+
if (!isPageTypeCollectionType || !selectedPlatform) {
|
|
20
|
+
return null;
|
|
28
21
|
}
|
|
29
22
|
|
|
30
|
-
return
|
|
23
|
+
return (
|
|
24
|
+
<Wrapper title="Instellingen">
|
|
25
|
+
<Stack spacing={4} width="100%">
|
|
26
|
+
<TemplatePlatformSelect />
|
|
27
|
+
<SinglePlatformFilteredSelectField
|
|
28
|
+
name="defaultParent"
|
|
29
|
+
attribute={{ pluginOptions: { filteredSelect: { targetField: 'defaultParent' } } }}
|
|
30
|
+
selectedPlatform={selectedPlatform}
|
|
31
|
+
/>
|
|
32
|
+
</Stack>
|
|
33
|
+
</Wrapper>
|
|
34
|
+
);
|
|
31
35
|
};
|
|
@@ -14,6 +14,7 @@ import { useGetLocaleFromUrl } from '../../../utils/hooks/useGetLocaleFromUrl';
|
|
|
14
14
|
import { getSearchFilteredEntities } from '../../../api/search-filtered-entity';
|
|
15
15
|
import RelationHelper, { IPlatformFilteredSelectFieldProps } from '../utils/relation-helper';
|
|
16
16
|
import { getTranslation } from '../utils/get-translations';
|
|
17
|
+
import { Platform } from '../../../api/platform';
|
|
17
18
|
|
|
18
19
|
const PAGE = 1;
|
|
19
20
|
|
|
@@ -24,6 +25,7 @@ export interface IMultiPlatformFilteredSelectFieldProps extends IPlatformFiltere
|
|
|
24
25
|
isCloningEntry?: boolean;
|
|
25
26
|
totalRelations: number;
|
|
26
27
|
relationsFromModifiedData?: Record<string, any>[];
|
|
28
|
+
selectedPlatform: Platform;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
const MultiPlatformFilteredSelectField = ({
|
|
@@ -38,7 +40,8 @@ const MultiPlatformFilteredSelectField = ({
|
|
|
38
40
|
relations,
|
|
39
41
|
isCloningEntry,
|
|
40
42
|
totalRelations,
|
|
41
|
-
relationsFromModifiedData
|
|
43
|
+
relationsFromModifiedData,
|
|
44
|
+
selectedPlatform
|
|
42
45
|
}: IMultiPlatformFilteredSelectFieldProps) => {
|
|
43
46
|
const fetchClient = useFetchClient();
|
|
44
47
|
const {
|
|
@@ -95,7 +98,7 @@ const MultiPlatformFilteredSelectField = ({
|
|
|
95
98
|
uid: targetAttributes?.target || '',
|
|
96
99
|
locale: selectedLocale,
|
|
97
100
|
searchQuery: inputValue,
|
|
98
|
-
platformTitle:
|
|
101
|
+
platformTitle: selectedPlatform?.title,
|
|
99
102
|
notIds: selectedResults?.data?.map((x: Record<string, any>) => x.id)
|
|
100
103
|
});
|
|
101
104
|
|
|
@@ -14,6 +14,11 @@ import { getSearchFilteredEntities } from '../../../api/search-filtered-entity';
|
|
|
14
14
|
import S from './../styles';
|
|
15
15
|
import getTrad from '../../../utils/getTrad';
|
|
16
16
|
import RelationHelper, { IPlatformFilteredSelectFieldProps } from '../utils/relation-helper';
|
|
17
|
+
import { Platform } from '../../../api/platform';
|
|
18
|
+
|
|
19
|
+
export interface ISinglePlatformFilteredSelectFieldProps extends IPlatformFilteredSelectFieldProps {
|
|
20
|
+
selectedPlatform: Platform;
|
|
21
|
+
}
|
|
17
22
|
|
|
18
23
|
interface CustomReactSelectValue extends Omit<IReactSelectValue, 'initialSelected'> {
|
|
19
24
|
href?: string;
|
|
@@ -30,11 +35,13 @@ const SinglePlatformFilteredSelectField = ({
|
|
|
30
35
|
labelAction,
|
|
31
36
|
error,
|
|
32
37
|
intlLabel,
|
|
33
|
-
name
|
|
34
|
-
|
|
38
|
+
name,
|
|
39
|
+
selectedPlatform
|
|
40
|
+
}: ISinglePlatformFilteredSelectFieldProps) => {
|
|
35
41
|
const fetchClient = useFetchClient();
|
|
36
42
|
const { onChange, initialData, modifiedData, isCreatingEntry, layout, allLayoutData } =
|
|
37
43
|
useCMEditViewDataManager() as any;
|
|
44
|
+
|
|
38
45
|
const { locales } = useSelector((state: any) => state.i18n_locales);
|
|
39
46
|
const urlLocale = useGetLocaleFromUrl();
|
|
40
47
|
const defaultLocale = locales.find((locale: any) => locale.isDefault);
|
|
@@ -133,10 +140,10 @@ const SinglePlatformFilteredSelectField = ({
|
|
|
133
140
|
{targetAttributes?.type === 'relation' && (
|
|
134
141
|
<S.FieldWrapper>
|
|
135
142
|
<Combobox
|
|
136
|
-
key={`rerenderOnPlatformChange-${
|
|
143
|
+
key={`rerenderOnPlatformChange-${selectedPlatform?.title}`}
|
|
137
144
|
id="pagesSearch"
|
|
138
145
|
label={label}
|
|
139
|
-
loadOptions={(i, c) => debouncedFetch(i, c,
|
|
146
|
+
loadOptions={(i, c) => debouncedFetch(i, c, selectedPlatform?.title)}
|
|
140
147
|
cacheOptions
|
|
141
148
|
customOption={CustomOption}
|
|
142
149
|
onChange={handleChange}
|
|
@@ -178,7 +185,7 @@ const getInitialSelectItem = (initialValue?: Record<string, any>): SingleValue<C
|
|
|
178
185
|
href: initialValue?.href,
|
|
179
186
|
publicationState: initialValue.publicationState,
|
|
180
187
|
publishedAt: initialValue.publishedAt
|
|
181
|
-
|
|
188
|
+
}
|
|
182
189
|
: null;
|
|
183
190
|
|
|
184
191
|
export default SinglePlatformFilteredSelectField;
|
|
@@ -5,22 +5,30 @@ import RelationHelper, { IPlatformFilteredSelectFieldProps } from './utils/relat
|
|
|
5
5
|
import MultiPlatformFilteredSelectField from './Multi';
|
|
6
6
|
import SinglePlatformFilteredSelectField from './Single';
|
|
7
7
|
import { useRelationLoad } from './hooks/useRelationLoad';
|
|
8
|
+
import { usePlatformFormData } from '../../utils/hooks/usePlatformFormData';
|
|
8
9
|
|
|
9
10
|
const PlatformFilteredSelectField = (props: IPlatformFilteredSelectFieldProps) => {
|
|
10
11
|
const { name, attribute } = props;
|
|
11
|
-
const
|
|
12
|
+
const form = useCMEditViewDataManager() as any;
|
|
13
|
+
const { modifiedData, layout, allLayoutData } = form;
|
|
14
|
+
const { selectedPlatform } = usePlatformFormData(form);
|
|
12
15
|
const { relations, isCloningEntry, totalRelations, relationsFromModifiedData } = useRelationLoad(props);
|
|
13
16
|
const { targetAttributes } = RelationHelper.getTargetAttributes(name, attribute, modifiedData, layout, allLayoutData);
|
|
14
17
|
const toOneRelation = ['oneWay', 'oneToOne', 'manyToOne', 'oneToManyMorph', 'oneToOneMorph'].includes(
|
|
15
18
|
targetAttributes?.relation || ''
|
|
16
19
|
);
|
|
17
20
|
|
|
21
|
+
if (!selectedPlatform) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
18
25
|
if (toOneRelation) {
|
|
19
|
-
return <SinglePlatformFilteredSelectField {...props} />;
|
|
26
|
+
return <SinglePlatformFilteredSelectField selectedPlatform={selectedPlatform} {...props} />;
|
|
20
27
|
}
|
|
21
28
|
|
|
22
29
|
return (
|
|
23
30
|
<MultiPlatformFilteredSelectField
|
|
31
|
+
selectedPlatform={selectedPlatform}
|
|
24
32
|
relations={relations}
|
|
25
33
|
isCloningEntry={isCloningEntry}
|
|
26
34
|
totalRelations={totalRelations}
|
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
import { Platform } from '../../api/platform';
|
|
2
1
|
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Platform } from '../../api/platform';
|
|
3
4
|
import { useDefaultPlatformFromLocalStorage } from './useDefaultPlatformFromLocalStorage';
|
|
4
5
|
import { useGetPlatformRelation } from '../../api/platform-relation';
|
|
5
6
|
|
|
6
7
|
const usePlatformFormData = (form?: Record<string, any>, onPlatformChange?: (platform: Platform) => void) => {
|
|
7
8
|
const { onChange, initialData, layout } = form || {};
|
|
8
|
-
const { isLoading } = useGetPlatformRelation({
|
|
9
|
+
const { isLoading: isLoadingPlatform, data: selectedPlatform } = useGetPlatformRelation({
|
|
10
|
+
id: initialData?.id,
|
|
11
|
+
uid: layout.uid
|
|
12
|
+
});
|
|
9
13
|
|
|
10
14
|
const { selectedPlatform: defaultPlatform, setSelectedPlatform: setDefaultPlatform } =
|
|
11
15
|
useDefaultPlatformFromLocalStorage();
|
|
12
16
|
|
|
13
17
|
useEffect(() => {
|
|
14
|
-
if (!
|
|
18
|
+
if (!isLoadingPlatform && !selectedPlatform?.id && defaultPlatform) {
|
|
15
19
|
handleSelectPlatform(defaultPlatform);
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
if (
|
|
19
|
-
setDefaultPlatform(
|
|
22
|
+
if (selectedPlatform?.id && defaultPlatform?.id && selectedPlatform.id !== defaultPlatform.id) {
|
|
23
|
+
setDefaultPlatform(selectedPlatform);
|
|
20
24
|
}
|
|
21
|
-
}, [
|
|
25
|
+
}, [isLoadingPlatform, defaultPlatform]);
|
|
22
26
|
|
|
23
27
|
const setFormValue = (name: string, value?: string | Record<string, any>[]) => {
|
|
24
28
|
onChange({
|
|
@@ -44,7 +48,7 @@ const usePlatformFormData = (form?: Record<string, any>, onPlatformChange?: (pla
|
|
|
44
48
|
}
|
|
45
49
|
};
|
|
46
50
|
|
|
47
|
-
return { defaultPlatform };
|
|
51
|
+
return { defaultPlatform, selectedPlatform, isLoadingPlatform };
|
|
48
52
|
};
|
|
49
53
|
|
|
50
54
|
export { usePlatformFormData };
|