@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,34 @@
|
|
|
1
|
+
import { useLayoutEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useQueryParams } from '@strapi/helper-plugin';
|
|
4
|
+
|
|
5
|
+
import { findElementParent } from '../../utils/findElementParent';
|
|
6
|
+
import { findDomElement } from '../../utils/findDomElement';
|
|
7
|
+
import { useGetPlatforms } from '../../api/platform';
|
|
8
|
+
|
|
9
|
+
const filtersToRemove = ['platform', 'pageType'];
|
|
10
|
+
|
|
11
|
+
export const useHideOverviewFilterTags = () => {
|
|
12
|
+
const [{ query }] = useQueryParams() as any;
|
|
13
|
+
const { data: platforms } = useGetPlatforms({});
|
|
14
|
+
|
|
15
|
+
useLayoutEffect(() => {
|
|
16
|
+
filtersToRemove.forEach((filter) => removeFilterElement(filter, query));
|
|
17
|
+
}, [query, platforms]);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const removeFilterElement = (filterToRemove?: string, query?: Record<string, any>): void => {
|
|
21
|
+
if (!filterToRemove || !query || !(JSON.stringify(query.filters || {}) || '').includes(filterToRemove)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const filterTag = findDomElement(`//button//span[contains(., '${filterToRemove} is')]`);
|
|
26
|
+
|
|
27
|
+
if (filterTag) {
|
|
28
|
+
const parent = findElementParent(filterTag, 'DIV', 2);
|
|
29
|
+
|
|
30
|
+
if (parent?.remove) {
|
|
31
|
+
parent.style.display = 'none';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Platform } from '../../api/platform';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { useDefaultPlatformFromLocalStorage } from './useDefaultPlatformFromLocalStorage';
|
|
4
|
+
import { useGetPlatformRelation } from '../../api/platform-relation';
|
|
5
|
+
|
|
6
|
+
const usePlatformFormData = (form?: Record<string, any>, onPlatformChange?: (platform: Platform) => void) => {
|
|
7
|
+
const { onChange, initialData, layout } = form || {};
|
|
8
|
+
const { isLoading } = useGetPlatformRelation({ id: initialData?.id, uid: layout.uid });
|
|
9
|
+
const { selectedPlatform: defaultPlatform, setSelectedPlatform: setDefaultPlatform } =
|
|
10
|
+
useDefaultPlatformFromLocalStorage();
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!isLoading && !initialData.platform[0]?.id && defaultPlatform) {
|
|
14
|
+
handleSelectPlatform(defaultPlatform);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (initialData.platform[0]?.id && defaultPlatform?.id && initialData.platform[0].id !== defaultPlatform.id) {
|
|
18
|
+
setDefaultPlatform(initialData.platform[0]);
|
|
19
|
+
}
|
|
20
|
+
}, [isLoading, defaultPlatform, initialData]);
|
|
21
|
+
|
|
22
|
+
const setFormValue = (name: string, value?: string | Record<string, any>[]) => {
|
|
23
|
+
onChange({
|
|
24
|
+
target: {
|
|
25
|
+
name,
|
|
26
|
+
value
|
|
27
|
+
},
|
|
28
|
+
shouldSetInitialValue: true
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const handleSelectPlatform = async (platform: Platform) => {
|
|
33
|
+
onPlatformChange?.(platform);
|
|
34
|
+
if (platform?.title) {
|
|
35
|
+
const formPlatform = {
|
|
36
|
+
...platform,
|
|
37
|
+
label: platform.title,
|
|
38
|
+
value: platform.id
|
|
39
|
+
};
|
|
40
|
+
setFormValue('platform', [formPlatform]);
|
|
41
|
+
} else {
|
|
42
|
+
setFormValue('platform', []);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return { defaultPlatform };
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export { usePlatformFormData };
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webbio/strapi-plugin-page-builder",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2-platform",
|
|
4
4
|
"description": "This is the description of the plugin.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"develop": "tsc -p tsconfig.server.json -w",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"url": "https://github.com/webbio/strapi-plugin-page-builder.git"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"@mantine/hooks": "^7.2.2",
|
|
23
24
|
"@strapi/design-system": "^1.11.0",
|
|
24
25
|
"@strapi/helper-plugin": "^4.15.0",
|
|
25
26
|
"@strapi/icons": "^1.11.0",
|
|
@@ -4,13 +4,13 @@ exports.default = {
|
|
|
4
4
|
async findAll() {
|
|
5
5
|
return await strapi.service('plugin::page-builder.platform').findAll();
|
|
6
6
|
},
|
|
7
|
-
async
|
|
7
|
+
async findOneById(ctx) {
|
|
8
8
|
var _a;
|
|
9
|
-
const
|
|
10
|
-
if (!
|
|
11
|
-
return ctx.badRequest('
|
|
9
|
+
const id = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.params) === null || _a === void 0 ? void 0 : _a.id;
|
|
10
|
+
if (!id) {
|
|
11
|
+
return ctx.badRequest('id is missing.');
|
|
12
12
|
}
|
|
13
|
-
return await strapi.service('plugin::page-builder.platform').
|
|
13
|
+
return await strapi.service('plugin::page-builder.platform').findOneById(id);
|
|
14
14
|
},
|
|
15
15
|
async findPageTypesByPlatform(ctx) {
|
|
16
16
|
var _a;
|
|
@@ -5,24 +5,19 @@ exports.default = {
|
|
|
5
5
|
async findAll() {
|
|
6
6
|
return await strapi.entityService.findMany(constants_1.PLATFORM_UID, { populate: '*' });
|
|
7
7
|
},
|
|
8
|
-
async
|
|
9
|
-
return await strapi.entityService.
|
|
10
|
-
populate: '*'
|
|
11
|
-
filters: {
|
|
12
|
-
pagetype: {
|
|
13
|
-
uid
|
|
14
|
-
}
|
|
15
|
-
}
|
|
8
|
+
async findOneById(id) {
|
|
9
|
+
return await strapi.entityService.findOne(constants_1.PLATFORM_UID, id, {
|
|
10
|
+
populate: '*'
|
|
16
11
|
});
|
|
17
12
|
},
|
|
18
|
-
async findPageTypesByPlatform(
|
|
13
|
+
async findPageTypesByPlatform(id) {
|
|
19
14
|
const results = await strapi.entityService.findMany(constants_1.PLATFORM_UID, {
|
|
20
15
|
populate: {
|
|
21
16
|
pagetype: true
|
|
22
17
|
},
|
|
23
18
|
filters: {
|
|
24
|
-
|
|
25
|
-
$eq:
|
|
19
|
+
id: {
|
|
20
|
+
$eq: id
|
|
26
21
|
}
|
|
27
22
|
}
|
|
28
23
|
});
|