@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.
@@ -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.0-platform",
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 findOneByUid(ctx) {
7
+ async findOneById(ctx) {
8
8
  var _a;
9
- const uid = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.params) === null || _a === void 0 ? void 0 : _a.uid;
10
- if (!uid) {
11
- return ctx.badRequest('uid is missing.');
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').findOneByUid(uid);
13
+ return await strapi.service('plugin::page-builder.platform').findOneById(id);
14
14
  },
15
15
  async findPageTypesByPlatform(ctx) {
16
16
  var _a;
@@ -71,8 +71,8 @@ const routes = {
71
71
  },
72
72
  {
73
73
  method: 'GET',
74
- path: '/platform/:uid',
75
- handler: 'platform.findOneByUid'
74
+ path: '/platform/:id',
75
+ handler: 'platform.findOneById'
76
76
  },
77
77
  {
78
78
  method: 'GET',
@@ -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 findOneByUid(uid) {
9
- return await strapi.entityService.findMany(constants_1.PLATFORM_UID, {
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(platform) {
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
- title: {
25
- $eq: platform
19
+ id: {
20
+ $eq: id
26
21
  }
27
22
  }
28
23
  });