@webbio/strapi-plugin-page-builder 0.12.1-platform → 0.12.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.
Files changed (173) hide show
  1. package/README.md +166 -166
  2. package/admin/src/api/collection-type.ts +111 -111
  3. package/admin/src/api/entity-relation.ts +42 -42
  4. package/admin/src/api/has-page-relation.ts +37 -37
  5. package/admin/src/api/has-platform-relation.ts +40 -40
  6. package/admin/src/api/page-type-relation.ts +41 -41
  7. package/admin/src/api/platform-page-types.ts +45 -45
  8. package/admin/src/api/platform-relation.ts +42 -42
  9. package/admin/src/api/platform.ts +35 -35
  10. package/admin/src/api/search-filtered-entity.ts +114 -114
  11. package/admin/src/api/template.ts +39 -39
  12. package/admin/src/components/Combobox/index.tsx +83 -83
  13. package/admin/src/components/Combobox/react-select-custom-styles.tsx +121 -121
  14. package/admin/src/components/Combobox/styles.ts +46 -46
  15. package/admin/src/components/ConfirmModal/index.tsx +90 -90
  16. package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +127 -127
  17. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +149 -149
  18. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/styles.ts +19 -19
  19. package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +82 -82
  20. package/admin/src/components/EditView/Details/index.tsx +48 -48
  21. package/admin/src/components/EditView/Details/styles.ts +51 -51
  22. package/admin/src/components/EditView/PageSettings/index.tsx +124 -124
  23. package/admin/src/components/EditView/Platform/platform-select.tsx +30 -30
  24. package/admin/src/components/EditView/Template/TemplateConfirmModal/index.tsx +36 -36
  25. package/admin/src/components/EditView/Template/TemplateSelect/index.tsx +70 -70
  26. package/admin/src/components/EditView/Template/TemplateSelect/use-template-modules.ts +41 -41
  27. package/admin/src/components/EditView/index.tsx +35 -35
  28. package/admin/src/components/EditView/page-type-select.tsx +32 -32
  29. package/admin/src/components/EditView/wrapper.tsx +41 -41
  30. package/admin/src/components/GlobalPlatformSelect/index.tsx +40 -40
  31. package/admin/src/components/GlobalPlatformSelect/styles.ts +27 -27
  32. package/admin/src/components/Initializer/index.tsx +24 -24
  33. package/admin/src/components/PageFilters/PageTypeFilter/index.tsx +39 -39
  34. package/admin/src/components/PageFilters/PlatformFilter/index.tsx +32 -32
  35. package/admin/src/components/PageFilters/filters.tsx +189 -189
  36. package/admin/src/components/PageFilters/index.tsx +35 -35
  37. package/admin/src/components/PageTypeEditView/TemplatePlatformSelect/index.tsx +76 -76
  38. package/admin/src/components/PageTypeEditView/index.tsx +53 -53
  39. package/admin/src/components/PlatformFilteredSelectField/InputIcon/index.tsx +23 -23
  40. package/admin/src/components/PlatformFilteredSelectField/Multi/index.tsx +210 -210
  41. package/admin/src/components/PlatformFilteredSelectField/Single/index.tsx +197 -197
  42. package/admin/src/components/PlatformFilteredSelectField/hooks/useRelationLoad.tsx +128 -128
  43. package/admin/src/components/PlatformFilteredSelectField/index.tsx +85 -85
  44. package/admin/src/components/PlatformFilteredSelectField/styles.tsx +77 -77
  45. package/admin/src/components/PlatformFilteredSelectField/utils/get-translations.ts +3 -3
  46. package/admin/src/components/PlatformFilteredSelectField/utils/relation-helper.ts +147 -147
  47. package/admin/src/components/PluginIcon/index.tsx +94 -94
  48. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/RelationInput.tsx +689 -689
  49. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/RelationInputDataManager.tsx +6 -6
  50. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/useRelation.ts +170 -170
  51. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/utils/getRelationLink.ts +5 -5
  52. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/utils/normalizeRelations.ts +52 -52
  53. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/constants/attributes.ts +3 -3
  54. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/hooks/useDragAndDrop.ts +253 -253
  55. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/hooks/useKeyboardDragAndDrop.ts +96 -96
  56. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/hooks/usePrev.ts +11 -11
  57. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/dragAndDrop.ts +8 -8
  58. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/paths.ts +29 -29
  59. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/refs.ts +19 -19
  60. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/translations.ts +3 -3
  61. package/admin/src/components/StrapiCore/content-manager/shared/contracts/collection-types.ts +300 -300
  62. package/admin/src/components/StrapiCore/content-manager/shared/contracts/components.ts +72 -72
  63. package/admin/src/components/StrapiCore/content-manager/shared/contracts/content-types.ts +116 -116
  64. package/admin/src/components/StrapiCore/content-manager/shared/contracts/index.ts +8 -8
  65. package/admin/src/components/StrapiCore/content-manager/shared/contracts/init.ts +22 -22
  66. package/admin/src/components/StrapiCore/content-manager/shared/contracts/relations.ts +80 -80
  67. package/admin/src/components/StrapiCore/content-manager/shared/contracts/review-workflows.ts +88 -88
  68. package/admin/src/components/StrapiCore/content-manager/shared/contracts/single-types.ts +112 -112
  69. package/admin/src/components/StrapiCore/content-manager/shared/contracts/uid.ts +48 -48
  70. package/admin/src/components/StrapiCore/content-manager/shared/index.ts +1 -1
  71. package/admin/src/constants.ts +3 -3
  72. package/admin/src/index.tsx +101 -101
  73. package/admin/src/middlewares/index.tsx +37 -37
  74. package/admin/src/pages/app/index.tsx +14 -14
  75. package/admin/src/pluginId.ts +5 -5
  76. package/admin/src/translations/en.json +9 -9
  77. package/admin/src/translations/nl.json +9 -9
  78. package/admin/src/utils/findDomElement.ts +6 -6
  79. package/admin/src/utils/findElementParent.ts +20 -20
  80. package/admin/src/utils/getObjectFromFormName.ts +42 -42
  81. package/admin/src/utils/getRequestUrl.ts +11 -11
  82. package/admin/src/utils/getTrad.ts +5 -5
  83. package/admin/src/utils/hooks/useDebounce.ts +17 -17
  84. package/admin/src/utils/hooks/useDefaultPlatformFromLocalStorage.ts +61 -61
  85. package/admin/src/utils/hooks/useGetLocaleFromUrl.ts +9 -9
  86. package/admin/src/utils/hooks/useHideOverviewFilterTags.ts +34 -34
  87. package/admin/src/utils/hooks/usePlatformFormData.ts +64 -64
  88. package/admin/src/utils/hooks/usePrevious.ts +12 -12
  89. package/admin/src/utils/sanitizeModules.ts +93 -93
  90. package/custom.d.ts +6 -6
  91. package/dist/package.json +1 -1
  92. package/dist/server/bootstrap.js +1 -0
  93. package/dist/server/graphql/page-by-path.js +9 -9
  94. package/dist/server/graphql/page-by-slug.js +89 -0
  95. package/dist/server/graphql/pages-by-uid.js +5 -5
  96. package/dist/server/services/private-content/graphql/index.js +27 -27
  97. package/dist/server/services/private-content/graphql/types/index.js +74 -74
  98. package/dist/server/utils/graphql.js +100 -0
  99. package/dist/server/utils/paginationValidation.js +31 -0
  100. package/dist/tsconfig.server.tsbuildinfo +1 -1
  101. package/package.json +78 -78
  102. package/server/bootstrap/collection-type-lifecycles.ts +47 -47
  103. package/server/bootstrap/permissions.ts +161 -161
  104. package/server/bootstrap.ts +261 -260
  105. package/server/config/index.ts +4 -4
  106. package/server/content-types/index.ts +7 -7
  107. package/server/content-types/user-category/schema.json +23 -23
  108. package/server/controllers/collection-types.ts +32 -32
  109. package/server/controllers/index.ts +19 -19
  110. package/server/controllers/page-type.ts +18 -18
  111. package/server/controllers/page.ts +9 -9
  112. package/server/controllers/platform.ts +21 -21
  113. package/server/controllers/private-content.ts +17 -17
  114. package/server/controllers/sitemap.ts +32 -32
  115. package/server/controllers/template.ts +16 -16
  116. package/server/controllers/user-category.ts +3 -3
  117. package/server/destroy.ts +5 -5
  118. package/server/graphql/index.ts +9 -9
  119. package/server/graphql/page-by-path.ts +132 -132
  120. package/server/graphql/page-type.ts +67 -67
  121. package/server/graphql/pages-by-uid.ts +89 -89
  122. package/server/index.ts +23 -23
  123. package/server/middlewares/index.ts +1 -1
  124. package/server/policies/index.ts +5 -5
  125. package/server/policies/isAuthorizedPage.ts +11 -11
  126. package/server/register.ts +22 -22
  127. package/server/routes/index.ts +115 -115
  128. package/server/routes/user-category.ts +3 -3
  129. package/server/schema/page-end.json +96 -96
  130. package/server/schema/page-start.json +87 -87
  131. package/server/schema/page-type-end.json +53 -53
  132. package/server/schema/page-type-start.json +38 -38
  133. package/server/schema/platform-start.json +21 -21
  134. package/server/schema/template-end.json +40 -40
  135. package/server/schema/template-start.json +35 -35
  136. package/server/services/builder.ts +232 -232
  137. package/server/services/collection-types.ts +95 -95
  138. package/server/services/email.ts +127 -127
  139. package/server/services/index.ts +23 -23
  140. package/server/services/page-type.ts +30 -30
  141. package/server/services/page.ts +24 -24
  142. package/server/services/platform.ts +30 -30
  143. package/server/services/private-content/components/admin-email.json +22 -22
  144. package/server/services/private-content/components/email.json +22 -22
  145. package/server/services/private-content/components/platform-email.json +30 -30
  146. package/server/services/private-content/constants/index.ts +13 -13
  147. package/server/services/private-content/graphql/index.ts +88 -88
  148. package/server/services/private-content/graphql/resolvers/findOnePage.ts +40 -40
  149. package/server/services/private-content/graphql/resolvers/findPage.ts +45 -45
  150. package/server/services/private-content/graphql/resolvers/forgot-password.ts +34 -34
  151. package/server/services/private-content/graphql/resolvers/login.ts +56 -56
  152. package/server/services/private-content/graphql/resolvers/register.ts +78 -78
  153. package/server/services/private-content/graphql/resolvers/reset-password.ts +44 -44
  154. package/server/services/private-content/graphql/types/index.ts +96 -96
  155. package/server/services/private-content/index.ts +95 -95
  156. package/server/services/private-content/mail-template/txtMail.email.template.text.ts +6 -6
  157. package/server/services/private-content/page.ts +20 -20
  158. package/server/services/private-content/platform.ts +19 -19
  159. package/server/services/private-content/schemas/index.ts +28 -28
  160. package/server/services/private-content/user.ts +197 -197
  161. package/server/services/sitemap.ts +83 -83
  162. package/server/services/template.ts +13 -13
  163. package/server/services/user-category.ts +3 -3
  164. package/server/utils/filter-underscore-arguments.ts +12 -12
  165. package/server/utils/reload-strapi-on-load.ts +13 -13
  166. package/server/utils/strapi.ts +50 -50
  167. package/shared/utils/constants.ts +8 -8
  168. package/shared/utils/sleep.ts +1 -1
  169. package/strapi-admin.js +3 -3
  170. package/strapi-server.js +3 -3
  171. package/tsconfig.json +20 -20
  172. package/tsconfig.server.json +25 -25
  173. package/dist/server/content-types/user-categories/schema.json +0 -18
@@ -1,6 +1,6 @@
1
- const PUBLICATION_STATES = {
2
- DRAFT: 'draft',
3
- PUBLISHED: 'published'
4
- } as const;
5
-
6
- export { PUBLICATION_STATES };
1
+ const PUBLICATION_STATES = {
2
+ DRAFT: 'draft',
3
+ PUBLISHED: 'published'
4
+ } as const;
5
+
6
+ export { PUBLICATION_STATES };
@@ -1,170 +1,170 @@
1
- // @ts-nocheck build compiler thinks differently than runtime compiler
2
- import { useEffect, useState } from 'react';
3
-
4
- import { useCallbackRef, useFetchClient } from '@strapi/helper-plugin';
5
- import { useInfiniteQuery } from 'react-query';
6
-
7
- import { NormalizeRelationArgs, NormalizedRelation, normalizeRelations } from './utils/normalizeRelations';
8
-
9
- import type { Contracts } from '../../../../../../content-manager/shared';
10
-
11
- interface UseRelationArgs {
12
- relation: {
13
- enabled: boolean;
14
- endpoint: string;
15
- normalizeArguments: NormalizeRelationArgs;
16
- onLoad: (data: NormalizedRelation[]) => void;
17
- pageParams?: Record<string, any>;
18
- pageGoal?: number;
19
- };
20
- search: {
21
- endpoint: string;
22
- pageParams?: Record<string, any>;
23
- };
24
- }
25
-
26
- const useRelation = (cacheKey: any[] = [], { relation, search }: UseRelationArgs) => {
27
- const [searchParams, setSearchParams] = useState({});
28
- const [currentPage, setCurrentPage] = useState(0);
29
- const { get } = useFetchClient();
30
-
31
- const { onLoad: onLoadRelations, normalizeArguments } = relation;
32
-
33
- const relationsRes = useInfiniteQuery(
34
- ['relation', ...cacheKey],
35
- async ({ pageParam = 1 }) => {
36
- try {
37
- const { data } = await get<Contracts.Relations.FindExisting.Response>(relation?.endpoint, {
38
- params: {
39
- ...(relation.pageParams ?? {}),
40
- page: pageParam
41
- }
42
- });
43
-
44
- setCurrentPage(pageParam);
45
-
46
- return data;
47
- } catch (err) {
48
- return null;
49
- }
50
- },
51
- {
52
- cacheTime: 0,
53
- enabled: relation.enabled,
54
- getNextPageParam(lastPage) {
55
- const isXToOneRelation = lastPage && !('pagination' in lastPage);
56
-
57
- if (
58
- !lastPage || // the API may send an empty 204 response
59
- isXToOneRelation || // xToOne relations do not have a pagination
60
- lastPage?.pagination.page >= lastPage?.pagination.pageCount
61
- ) {
62
- return undefined;
63
- }
64
-
65
- // eslint-disable-next-line consistent-return
66
- return lastPage.pagination.page + 1;
67
- },
68
- select: (data) => ({
69
- ...data,
70
- pages: data.pages.map((page) => {
71
- if (!page) {
72
- return page;
73
- }
74
-
75
- let normalizedResults: Contracts.Relations.RelationResult[] = [];
76
-
77
- // xToOne relations return an object, which we normalize so that relations
78
- // always have the same shape
79
- if ('data' in page && page.data) {
80
- normalizedResults = [page.data];
81
- } else if ('results' in page && page.results) {
82
- normalizedResults = [...page.results].reverse();
83
- }
84
-
85
- return {
86
- pagination: 'pagination' in page ? page.pagination : undefined,
87
- results: normalizedResults
88
- };
89
- })
90
- })
91
- }
92
- );
93
-
94
- const { pageGoal } = relation;
95
-
96
- const { status, data, fetchNextPage, hasNextPage } = relationsRes;
97
-
98
- useEffect(() => {
99
- /**
100
- * This ensures the infiniteQuery hook fetching has caught-up with the modifiedData
101
- * state i.e. in circumstances where you add 10 relations, the browserState knows this,
102
- * but the hook would think it could fetch more, when in reality, it can't.
103
- */
104
- if (pageGoal && pageGoal > currentPage && hasNextPage && status === 'success') {
105
- fetchNextPage({
106
- pageParam: currentPage + 1
107
- });
108
- }
109
- }, [pageGoal, currentPage, fetchNextPage, hasNextPage, status]);
110
-
111
- const onLoadRelationsCallback = useCallbackRef(onLoadRelations);
112
-
113
- useEffect(() => {
114
- if (status === 'success' && data && data.pages?.at(-1)?.results && onLoadRelationsCallback) {
115
- // everytime we fetch, we normalize prior to adding to redux
116
- const normalizedResults = normalizeRelations(data.pages.at(-1)?.results ?? [], normalizeArguments);
117
-
118
- // this is loadRelation from EditViewDataManagerProvider
119
- onLoadRelationsCallback(normalizedResults);
120
- }
121
-
122
- // eslint-disable-next-line react-hooks/exhaustive-deps
123
- }, [status, onLoadRelationsCallback, data]);
124
-
125
- const searchRes = useInfiniteQuery(
126
- ['relation', ...cacheKey, 'search', JSON.stringify(searchParams)],
127
- async ({ pageParam = 1 }) => {
128
- try {
129
- const { data } = await get<Contracts.Relations.FindAvailable.Response>(search.endpoint, {
130
- params: {
131
- ...(search.pageParams ?? {}),
132
- ...searchParams,
133
- page: pageParam
134
- }
135
- });
136
-
137
- return data;
138
- } catch (err) {
139
- return null;
140
- }
141
- },
142
- {
143
- enabled: Object.keys(searchParams).length > 0,
144
- getNextPageParam(lastPage) {
145
- if (
146
- !lastPage?.pagination ||
147
- (lastPage.pagination && lastPage.pagination.page >= lastPage.pagination.pageCount)
148
- ) {
149
- return undefined;
150
- }
151
-
152
- // eslint-disable-next-line consistent-return
153
- return lastPage.pagination.page + 1;
154
- }
155
- }
156
- );
157
-
158
- const searchFor = (term: string, options: object = {}) => {
159
- setSearchParams({
160
- ...options,
161
- _q: term,
162
- _filter: '$containsi'
163
- });
164
- };
165
-
166
- return { relations: relationsRes, search: searchRes, searchFor };
167
- };
168
-
169
- export { useRelation };
170
- export type { UseRelationArgs };
1
+ // @ts-nocheck build compiler thinks differently than runtime compiler
2
+ import { useEffect, useState } from 'react';
3
+
4
+ import { useCallbackRef, useFetchClient } from '@strapi/helper-plugin';
5
+ import { useInfiniteQuery } from 'react-query';
6
+
7
+ import { NormalizeRelationArgs, NormalizedRelation, normalizeRelations } from './utils/normalizeRelations';
8
+
9
+ import type { Contracts } from '../../../../../../content-manager/shared';
10
+
11
+ interface UseRelationArgs {
12
+ relation: {
13
+ enabled: boolean;
14
+ endpoint: string;
15
+ normalizeArguments: NormalizeRelationArgs;
16
+ onLoad: (data: NormalizedRelation[]) => void;
17
+ pageParams?: Record<string, any>;
18
+ pageGoal?: number;
19
+ };
20
+ search: {
21
+ endpoint: string;
22
+ pageParams?: Record<string, any>;
23
+ };
24
+ }
25
+
26
+ const useRelation = (cacheKey: any[] = [], { relation, search }: UseRelationArgs) => {
27
+ const [searchParams, setSearchParams] = useState({});
28
+ const [currentPage, setCurrentPage] = useState(0);
29
+ const { get } = useFetchClient();
30
+
31
+ const { onLoad: onLoadRelations, normalizeArguments } = relation;
32
+
33
+ const relationsRes = useInfiniteQuery(
34
+ ['relation', ...cacheKey],
35
+ async ({ pageParam = 1 }) => {
36
+ try {
37
+ const { data } = await get<Contracts.Relations.FindExisting.Response>(relation?.endpoint, {
38
+ params: {
39
+ ...(relation.pageParams ?? {}),
40
+ page: pageParam
41
+ }
42
+ });
43
+
44
+ setCurrentPage(pageParam);
45
+
46
+ return data;
47
+ } catch (err) {
48
+ return null;
49
+ }
50
+ },
51
+ {
52
+ cacheTime: 0,
53
+ enabled: relation.enabled,
54
+ getNextPageParam(lastPage) {
55
+ const isXToOneRelation = lastPage && !('pagination' in lastPage);
56
+
57
+ if (
58
+ !lastPage || // the API may send an empty 204 response
59
+ isXToOneRelation || // xToOne relations do not have a pagination
60
+ lastPage?.pagination.page >= lastPage?.pagination.pageCount
61
+ ) {
62
+ return undefined;
63
+ }
64
+
65
+ // eslint-disable-next-line consistent-return
66
+ return lastPage.pagination.page + 1;
67
+ },
68
+ select: (data) => ({
69
+ ...data,
70
+ pages: data.pages.map((page) => {
71
+ if (!page) {
72
+ return page;
73
+ }
74
+
75
+ let normalizedResults: Contracts.Relations.RelationResult[] = [];
76
+
77
+ // xToOne relations return an object, which we normalize so that relations
78
+ // always have the same shape
79
+ if ('data' in page && page.data) {
80
+ normalizedResults = [page.data];
81
+ } else if ('results' in page && page.results) {
82
+ normalizedResults = [...page.results].reverse();
83
+ }
84
+
85
+ return {
86
+ pagination: 'pagination' in page ? page.pagination : undefined,
87
+ results: normalizedResults
88
+ };
89
+ })
90
+ })
91
+ }
92
+ );
93
+
94
+ const { pageGoal } = relation;
95
+
96
+ const { status, data, fetchNextPage, hasNextPage } = relationsRes;
97
+
98
+ useEffect(() => {
99
+ /**
100
+ * This ensures the infiniteQuery hook fetching has caught-up with the modifiedData
101
+ * state i.e. in circumstances where you add 10 relations, the browserState knows this,
102
+ * but the hook would think it could fetch more, when in reality, it can't.
103
+ */
104
+ if (pageGoal && pageGoal > currentPage && hasNextPage && status === 'success') {
105
+ fetchNextPage({
106
+ pageParam: currentPage + 1
107
+ });
108
+ }
109
+ }, [pageGoal, currentPage, fetchNextPage, hasNextPage, status]);
110
+
111
+ const onLoadRelationsCallback = useCallbackRef(onLoadRelations);
112
+
113
+ useEffect(() => {
114
+ if (status === 'success' && data && data.pages?.at(-1)?.results && onLoadRelationsCallback) {
115
+ // everytime we fetch, we normalize prior to adding to redux
116
+ const normalizedResults = normalizeRelations(data.pages.at(-1)?.results ?? [], normalizeArguments);
117
+
118
+ // this is loadRelation from EditViewDataManagerProvider
119
+ onLoadRelationsCallback(normalizedResults);
120
+ }
121
+
122
+ // eslint-disable-next-line react-hooks/exhaustive-deps
123
+ }, [status, onLoadRelationsCallback, data]);
124
+
125
+ const searchRes = useInfiniteQuery(
126
+ ['relation', ...cacheKey, 'search', JSON.stringify(searchParams)],
127
+ async ({ pageParam = 1 }) => {
128
+ try {
129
+ const { data } = await get<Contracts.Relations.FindAvailable.Response>(search.endpoint, {
130
+ params: {
131
+ ...(search.pageParams ?? {}),
132
+ ...searchParams,
133
+ page: pageParam
134
+ }
135
+ });
136
+
137
+ return data;
138
+ } catch (err) {
139
+ return null;
140
+ }
141
+ },
142
+ {
143
+ enabled: Object.keys(searchParams).length > 0,
144
+ getNextPageParam(lastPage) {
145
+ if (
146
+ !lastPage?.pagination ||
147
+ (lastPage.pagination && lastPage.pagination.page >= lastPage.pagination.pageCount)
148
+ ) {
149
+ return undefined;
150
+ }
151
+
152
+ // eslint-disable-next-line consistent-return
153
+ return lastPage.pagination.page + 1;
154
+ }
155
+ }
156
+ );
157
+
158
+ const searchFor = (term: string, options: object = {}) => {
159
+ setSearchParams({
160
+ ...options,
161
+ _q: term,
162
+ _filter: '$containsi'
163
+ });
164
+ };
165
+
166
+ return { relations: relationsRes, search: searchRes, searchFor };
167
+ };
168
+
169
+ export { useRelation };
170
+ export type { UseRelationArgs };
@@ -1,5 +1,5 @@
1
- import { Entity } from '@strapi/types';
2
-
3
- export function getRelationLink(targetModel: string, id?: Entity.ID) {
4
- return `/content-manager/collectionType/${targetModel}/${id ?? ''}`;
5
- }
1
+ import { Entity } from '@strapi/types';
2
+
3
+ export function getRelationLink(targetModel: string, id?: Entity.ID) {
4
+ return `/content-manager/collectionType/${targetModel}/${id ?? ''}`;
5
+ }
@@ -1,52 +1,52 @@
1
- // @ts-nocheck build compiler thinks differently than runtime compiler
2
- import type { Contracts } from '../../../../../../../content-manager/shared';
3
-
4
- import { PUBLICATION_STATES } from '../RelationInputDataManager';
5
-
6
- import { getRelationLink } from './getRelationLink';
7
-
8
- export interface NormalizeRelationArgs {
9
- shouldAddLink: boolean;
10
- mainFieldName: string;
11
- targetModel: string;
12
- }
13
-
14
- export type NormalizedRelation = Contracts.Relations.RelationResult & {
15
- href?: string;
16
- mainField: string;
17
- publicationState?: false | 'published' | 'draft';
18
- };
19
-
20
- export const normalizeRelation = (
21
- relation: Contracts.Relations.RelationResult,
22
- { shouldAddLink, mainFieldName, targetModel }: NormalizeRelationArgs
23
- ) => {
24
- const nextRelation: NormalizedRelation = {
25
- ...relation,
26
- mainField: relation[mainFieldName]
27
- };
28
-
29
- if (shouldAddLink) {
30
- nextRelation.href = getRelationLink(targetModel, nextRelation.id);
31
- }
32
-
33
- nextRelation.publicationState = false;
34
-
35
- if (nextRelation?.publishedAt !== undefined) {
36
- nextRelation.publicationState = nextRelation.publishedAt ? PUBLICATION_STATES.PUBLISHED : PUBLICATION_STATES.DRAFT;
37
- }
38
-
39
- return nextRelation;
40
- };
41
-
42
- /*
43
- * Applies some transformations to existing and new relations in order to display them correctly
44
- * relations: raw relations data coming from useRelations
45
- * shouldAddLink: comes from generateRelationQueryInfos, if true we display a link to the relation (TO FIX: explanation)
46
- * mainFieldName: name of the main field inside the relation (e.g. text field), if no displayable main field exists (e.g. date field) we use the id of the entry
47
- * targetModel: the model on which the relation is based on, used to create an URL link
48
- */
49
-
50
- export const normalizeRelations = (relations: Contracts.Relations.RelationResult[], args: NormalizeRelationArgs) => {
51
- return [...relations].map((relation) => normalizeRelation(relation, args));
52
- };
1
+ // @ts-nocheck build compiler thinks differently than runtime compiler
2
+ import type { Contracts } from '../../../../../../../content-manager/shared';
3
+
4
+ import { PUBLICATION_STATES } from '../RelationInputDataManager';
5
+
6
+ import { getRelationLink } from './getRelationLink';
7
+
8
+ export interface NormalizeRelationArgs {
9
+ shouldAddLink: boolean;
10
+ mainFieldName: string;
11
+ targetModel: string;
12
+ }
13
+
14
+ export type NormalizedRelation = Contracts.Relations.RelationResult & {
15
+ href?: string;
16
+ mainField: string;
17
+ publicationState?: false | 'published' | 'draft';
18
+ };
19
+
20
+ export const normalizeRelation = (
21
+ relation: Contracts.Relations.RelationResult,
22
+ { shouldAddLink, mainFieldName, targetModel }: NormalizeRelationArgs
23
+ ) => {
24
+ const nextRelation: NormalizedRelation = {
25
+ ...relation,
26
+ mainField: relation[mainFieldName]
27
+ };
28
+
29
+ if (shouldAddLink) {
30
+ nextRelation.href = getRelationLink(targetModel, nextRelation.id);
31
+ }
32
+
33
+ nextRelation.publicationState = false;
34
+
35
+ if (nextRelation?.publishedAt !== undefined) {
36
+ nextRelation.publicationState = nextRelation.publishedAt ? PUBLICATION_STATES.PUBLISHED : PUBLICATION_STATES.DRAFT;
37
+ }
38
+
39
+ return nextRelation;
40
+ };
41
+
42
+ /*
43
+ * Applies some transformations to existing and new relations in order to display them correctly
44
+ * relations: raw relations data coming from useRelations
45
+ * shouldAddLink: comes from generateRelationQueryInfos, if true we display a link to the relation (TO FIX: explanation)
46
+ * mainFieldName: name of the main field inside the relation (e.g. text field), if no displayable main field exists (e.g. date field) we use the id of the entry
47
+ * targetModel: the model on which the relation is based on, used to create an URL link
48
+ */
49
+
50
+ export const normalizeRelations = (relations: Contracts.Relations.RelationResult[], args: NormalizeRelationArgs) => {
51
+ return [...relations].map((relation) => normalizeRelation(relation, args));
52
+ };
@@ -1,3 +1,3 @@
1
- const CREATOR_FIELDS = ['createdBy', 'updatedBy'];
2
-
3
- export { CREATOR_FIELDS };
1
+ const CREATOR_FIELDS = ['createdBy', 'updatedBy'];
2
+
3
+ export { CREATOR_FIELDS };