@strato-admin/cloudscape 0.1.0

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 (255) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/dist/Admin.d.ts +17 -0
  4. package/dist/Admin.js +69 -0
  5. package/dist/RecordLink.d.ts +9 -0
  6. package/dist/RecordLink.js +43 -0
  7. package/dist/__mocks__/strato-core.js +50 -0
  8. package/dist/__mocks__to__delete/strato-core.js +50 -0
  9. package/dist/button/BulkDeleteButton.d.ts +7 -0
  10. package/dist/button/BulkDeleteButton.js +17 -0
  11. package/dist/button/Button.d.ts +6 -0
  12. package/dist/button/Button.js +6 -0
  13. package/dist/button/CreateButton.d.ts +6 -0
  14. package/dist/button/CreateButton.js +24 -0
  15. package/dist/button/EditButton.d.ts +8 -0
  16. package/dist/button/EditButton.js +24 -0
  17. package/dist/button/SaveButton.d.ts +6 -0
  18. package/dist/button/SaveButton.js +8 -0
  19. package/dist/button/index.d.ts +5 -0
  20. package/dist/button/index.js +5 -0
  21. package/dist/collection-hooks/index.d.ts +2 -0
  22. package/dist/collection-hooks/index.js +2 -0
  23. package/dist/collection-hooks/interfaces.d.ts +93 -0
  24. package/dist/collection-hooks/interfaces.js +1 -0
  25. package/dist/collection-hooks/useCollection.d.ts +3 -0
  26. package/dist/collection-hooks/useCollection.js +102 -0
  27. package/dist/create/Create.d.ts +40 -0
  28. package/dist/create/Create.js +34 -0
  29. package/dist/create/CreateHeader.d.ts +7 -0
  30. package/dist/create/CreateHeader.js +18 -0
  31. package/dist/create/index.d.ts +2 -0
  32. package/dist/create/index.js +2 -0
  33. package/dist/detail/KeyValuePairs.d.ts +36 -0
  34. package/dist/detail/KeyValuePairs.js +58 -0
  35. package/dist/detail/Show.d.ts +39 -0
  36. package/dist/detail/Show.js +40 -0
  37. package/dist/detail/ShowHeader.d.ts +7 -0
  38. package/dist/detail/ShowHeader.js +19 -0
  39. package/dist/detail/index.d.ts +3 -0
  40. package/dist/detail/index.js +3 -0
  41. package/dist/edit/Edit.d.ts +42 -0
  42. package/dist/edit/Edit.js +38 -0
  43. package/dist/edit/EditHeader.d.ts +7 -0
  44. package/dist/edit/EditHeader.js +18 -0
  45. package/dist/edit/index.d.ts +2 -0
  46. package/dist/edit/index.js +2 -0
  47. package/dist/field/ArrayField.d.ts +29 -0
  48. package/dist/field/ArrayField.js +30 -0
  49. package/dist/field/BadgeField.d.ts +12 -0
  50. package/dist/field/BadgeField.js +15 -0
  51. package/dist/field/BooleanField.d.ts +18 -0
  52. package/dist/field/BooleanField.js +14 -0
  53. package/dist/field/CurrencyField.d.ts +19 -0
  54. package/dist/field/CurrencyField.js +23 -0
  55. package/dist/field/DateField.d.ts +14 -0
  56. package/dist/field/DateField.js +17 -0
  57. package/dist/field/IdField.d.ts +17 -0
  58. package/dist/field/IdField.js +21 -0
  59. package/dist/field/NumberField.d.ts +14 -0
  60. package/dist/field/NumberField.js +18 -0
  61. package/dist/field/ReferenceField.d.ts +16 -0
  62. package/dist/field/ReferenceField.js +23 -0
  63. package/dist/field/ReferenceManyField.d.ts +55 -0
  64. package/dist/field/ReferenceManyField.js +19 -0
  65. package/dist/field/StatusIndicatorField.d.ts +56 -0
  66. package/dist/field/StatusIndicatorField.js +48 -0
  67. package/dist/field/TextField.d.ts +5 -0
  68. package/dist/field/TextField.js +11 -0
  69. package/dist/field/index.d.ts +23 -0
  70. package/dist/field/index.js +23 -0
  71. package/dist/field/types.d.ts +56 -0
  72. package/dist/field/types.js +1 -0
  73. package/dist/form/Form.d.ts +13 -0
  74. package/dist/form/Form.js +33 -0
  75. package/dist/form/index.d.ts +2 -0
  76. package/dist/form/index.js +2 -0
  77. package/dist/index.d.ts +22 -0
  78. package/dist/index.js +22 -0
  79. package/dist/input/AttributeEditor.d.ts +25 -0
  80. package/dist/input/AttributeEditor.js +80 -0
  81. package/dist/input/AutocompleteInput.d.ts +10 -0
  82. package/dist/input/AutocompleteInput.js +67 -0
  83. package/dist/input/FieldTitle.d.ts +8 -0
  84. package/dist/input/FieldTitle.js +29 -0
  85. package/dist/input/FormField.d.ts +7 -0
  86. package/dist/input/FormField.js +35 -0
  87. package/dist/input/FormFieldContext.d.ts +6 -0
  88. package/dist/input/FormFieldContext.js +3 -0
  89. package/dist/input/NumberInput.d.ts +7 -0
  90. package/dist/input/NumberInput.js +27 -0
  91. package/dist/input/ReferenceInput.d.ts +3 -0
  92. package/dist/input/ReferenceInput.js +25 -0
  93. package/dist/input/SelectInput.d.ts +15 -0
  94. package/dist/input/SelectInput.js +47 -0
  95. package/dist/input/SliderInput.d.ts +6 -0
  96. package/dist/input/SliderInput.js +25 -0
  97. package/dist/input/TextAreaInput.d.ts +6 -0
  98. package/dist/input/TextAreaInput.js +23 -0
  99. package/dist/input/TextInput.d.ts +7 -0
  100. package/dist/input/TextInput.js +23 -0
  101. package/dist/input/index.d.ts +11 -0
  102. package/dist/input/index.js +11 -0
  103. package/dist/input/types.d.ts +6 -0
  104. package/dist/input/types.js +1 -0
  105. package/dist/layout/AppLayout.d.ts +8 -0
  106. package/dist/layout/AppLayout.js +38 -0
  107. package/dist/layout/TopNavigation.d.ts +6 -0
  108. package/dist/layout/TopNavigation.js +53 -0
  109. package/dist/layout/index.d.ts +2 -0
  110. package/dist/layout/index.js +2 -0
  111. package/dist/list/Cards.d.ts +11 -0
  112. package/dist/list/Cards.js +27 -0
  113. package/dist/list/List.d.ts +43 -0
  114. package/dist/list/List.js +28 -0
  115. package/dist/list/Table.d.ts +112 -0
  116. package/dist/list/Table.examples.d.ts +1 -0
  117. package/dist/list/Table.examples.js +3 -0
  118. package/dist/list/Table.js +218 -0
  119. package/dist/list/TableHeader.d.ts +7 -0
  120. package/dist/list/TableHeader.js +22 -0
  121. package/dist/list/index.d.ts +4 -0
  122. package/dist/list/index.js +4 -0
  123. package/dist/preferences/index.d.ts +0 -0
  124. package/dist/preferences/index.js +1 -0
  125. package/dist/theme/ThemeManager.d.ts +2 -0
  126. package/dist/theme/ThemeManager.js +11 -0
  127. package/dist/theme/index.d.ts +2 -0
  128. package/dist/theme/index.js +2 -0
  129. package/package.json +73 -0
  130. package/src/Admin.test.tsx +32 -0
  131. package/src/Admin.tsx +123 -0
  132. package/src/RecordLink.stories.tsx +56 -0
  133. package/src/RecordLink.tsx +67 -0
  134. package/src/__mocks__/strato-core.tsx +52 -0
  135. package/src/button/BulkDeleteButton.stories.tsx +59 -0
  136. package/src/button/BulkDeleteButton.test.tsx +64 -0
  137. package/src/button/BulkDeleteButton.tsx +41 -0
  138. package/src/button/Button.stories.tsx +31 -0
  139. package/src/button/Button.tsx +12 -0
  140. package/src/button/CreateButton.stories.tsx +42 -0
  141. package/src/button/CreateButton.tsx +38 -0
  142. package/src/button/EditButton.stories.tsx +29 -0
  143. package/src/button/EditButton.tsx +38 -0
  144. package/src/button/SaveButton.stories.tsx +35 -0
  145. package/src/button/SaveButton.tsx +19 -0
  146. package/src/button/index.ts +5 -0
  147. package/src/collection-hooks/index.ts +2 -0
  148. package/src/collection-hooks/interfaces.ts +80 -0
  149. package/src/collection-hooks/useCollection.test.ts +413 -0
  150. package/src/collection-hooks/useCollection.ts +125 -0
  151. package/src/create/Create.test.tsx +63 -0
  152. package/src/create/Create.tsx +93 -0
  153. package/src/create/CreateHeader.tsx +34 -0
  154. package/src/create/index.ts +2 -0
  155. package/src/detail/KeyValuePairs.test.tsx +98 -0
  156. package/src/detail/KeyValuePairs.tsx +107 -0
  157. package/src/detail/Show.test.tsx +96 -0
  158. package/src/detail/Show.tsx +104 -0
  159. package/src/detail/ShowHeader.test.tsx +80 -0
  160. package/src/detail/ShowHeader.tsx +35 -0
  161. package/src/detail/index.ts +3 -0
  162. package/src/edit/Edit.test.tsx +91 -0
  163. package/src/edit/Edit.tsx +102 -0
  164. package/src/edit/EditHeader.tsx +34 -0
  165. package/src/edit/index.ts +2 -0
  166. package/src/field/ArrayField.tsx +51 -0
  167. package/src/field/BadgeField.tsx +33 -0
  168. package/src/field/BooleanField.stories.tsx +56 -0
  169. package/src/field/BooleanField.test.tsx +63 -0
  170. package/src/field/BooleanField.tsx +42 -0
  171. package/src/field/CurrencyField.stories.tsx +67 -0
  172. package/src/field/CurrencyField.tsx +45 -0
  173. package/src/field/DateField.stories.tsx +67 -0
  174. package/src/field/DateField.tsx +33 -0
  175. package/src/field/IdField.test.tsx +88 -0
  176. package/src/field/IdField.tsx +40 -0
  177. package/src/field/NumberField.stories.tsx +75 -0
  178. package/src/field/NumberField.tsx +35 -0
  179. package/src/field/ReferenceField.test.tsx +88 -0
  180. package/src/field/ReferenceField.tsx +64 -0
  181. package/src/field/ReferenceManyField.test.tsx +41 -0
  182. package/src/field/ReferenceManyField.tsx +73 -0
  183. package/src/field/StatusIndicatorField.stories.tsx +93 -0
  184. package/src/field/StatusIndicatorField.test.tsx +143 -0
  185. package/src/field/StatusIndicatorField.tsx +119 -0
  186. package/src/field/TextField.stories.tsx +45 -0
  187. package/src/field/TextField.tsx +17 -0
  188. package/src/field/index.ts +23 -0
  189. package/src/field/types.ts +58 -0
  190. package/src/form/Form.test.tsx +55 -0
  191. package/src/form/Form.tsx +66 -0
  192. package/src/form/index.ts +2 -0
  193. package/src/index.ts +25 -0
  194. package/src/input/AttributeEditor.test.tsx +147 -0
  195. package/src/input/AttributeEditor.tsx +185 -0
  196. package/src/input/AutocompleteInput.test.tsx +178 -0
  197. package/src/input/AutocompleteInput.tsx +116 -0
  198. package/src/input/FieldTitle.tsx +53 -0
  199. package/src/input/FormField.tsx +87 -0
  200. package/src/input/FormFieldContext.ts +9 -0
  201. package/src/input/NumberInput.tsx +56 -0
  202. package/src/input/ReferenceInput.test.tsx +35 -0
  203. package/src/input/ReferenceInput.tsx +36 -0
  204. package/src/input/SelectInput.tsx +91 -0
  205. package/src/input/SliderInput.test.tsx +103 -0
  206. package/src/input/SliderInput.tsx +49 -0
  207. package/src/input/TextAreaInput.tsx +48 -0
  208. package/src/input/TextInput.test.tsx +91 -0
  209. package/src/input/TextInput.tsx +51 -0
  210. package/src/input/index.ts +11 -0
  211. package/src/input/types.ts +14 -0
  212. package/src/layout/AppLayout.test.tsx +87 -0
  213. package/src/layout/AppLayout.tsx +60 -0
  214. package/src/layout/TopNavigation.test.tsx +78 -0
  215. package/src/layout/TopNavigation.tsx +84 -0
  216. package/src/layout/index.ts +2 -0
  217. package/src/list/Cards.tsx +58 -0
  218. package/src/list/List.tsx +76 -0
  219. package/src/list/Table.examples.tsx +11 -0
  220. package/src/list/Table.stories.tsx +73 -0
  221. package/src/list/Table.test.tsx +255 -0
  222. package/src/list/Table.tsx +438 -0
  223. package/src/list/TableHeader.test.tsx +114 -0
  224. package/src/list/TableHeader.tsx +44 -0
  225. package/src/list/index.ts +4 -0
  226. package/src/preferences/index.ts +0 -0
  227. package/src/stories/Button.stories.ts +54 -0
  228. package/src/stories/Button.tsx +31 -0
  229. package/src/stories/Configure.mdx +369 -0
  230. package/src/stories/Header.stories.ts +34 -0
  231. package/src/stories/Header.tsx +47 -0
  232. package/src/stories/Page.stories.ts +33 -0
  233. package/src/stories/Page.tsx +71 -0
  234. package/src/stories/RaStoryDecorator.tsx +38 -0
  235. package/src/stories/assets/accessibility.png +0 -0
  236. package/src/stories/assets/accessibility.svg +1 -0
  237. package/src/stories/assets/addon-library.png +0 -0
  238. package/src/stories/assets/assets.png +0 -0
  239. package/src/stories/assets/avif-test-image.avif +0 -0
  240. package/src/stories/assets/context.png +0 -0
  241. package/src/stories/assets/discord.svg +1 -0
  242. package/src/stories/assets/docs.png +0 -0
  243. package/src/stories/assets/figma-plugin.png +0 -0
  244. package/src/stories/assets/github.svg +1 -0
  245. package/src/stories/assets/share.png +0 -0
  246. package/src/stories/assets/styling.png +0 -0
  247. package/src/stories/assets/testing.png +0 -0
  248. package/src/stories/assets/theming.png +0 -0
  249. package/src/stories/assets/tutorials.svg +1 -0
  250. package/src/stories/assets/youtube.svg +1 -0
  251. package/src/stories/button.css +30 -0
  252. package/src/stories/header.css +32 -0
  253. package/src/stories/page.css +68 -0
  254. package/src/theme/ThemeManager.tsx +15 -0
  255. package/src/theme/index.ts +2 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vadim Gubergrits
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @strato-admin/cloudscape
2
+
3
+ Strato Admin Cloudscape implementation - UI component library and theme for React Admin based on AWS Cloudscape Design System.
@@ -0,0 +1,17 @@
1
+ import { type CoreAdminProps, type AdminChildren } from '@strato-admin/core';
2
+ export interface AdminProps extends CoreAdminProps {
3
+ children?: AdminChildren;
4
+ title?: string;
5
+ }
6
+ /**
7
+ * The root component of a Strato Admin application.
8
+ *
9
+ * It sets up the data fetching context, authentication, and layout using Cloudscape.
10
+ *
11
+ * @example
12
+ * <Admin dataProvider={myDataProvider} title="My App">
13
+ * <Resource name="posts" list={PostList} />
14
+ * </Admin>
15
+ */
16
+ export declare const Admin: ({ children, title, layout: Layout, i18nProvider, store, ...props }: AdminProps) => import("react/jsx-runtime").JSX.Element;
17
+ export default Admin;
package/dist/Admin.js ADDED
@@ -0,0 +1,69 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState, useEffect } from 'react';
3
+ import { CoreAdmin, SchemaRegistryProvider, localStorageStore, useLocaleState, registerDefaultResourceComponents, registerFieldInputMapping, } from '@strato-admin/core';
4
+ import { icuI18nProvider } from '@strato-admin/i18n';
5
+ import englishMessages from '@strato-admin/language-en';
6
+ import AppLayout from './layout/AppLayout';
7
+ import { List } from './list';
8
+ import { Create } from './create';
9
+ import { Edit } from './edit';
10
+ import { Show } from './detail';
11
+ import { TextField, NumberField, CurrencyField, ReferenceField } from './field';
12
+ import { TextInput, NumberInput, ReferenceInput } from './input';
13
+ import { I18nProvider, importMessages } from '@cloudscape-design/components/i18n';
14
+ // Register Cloudscape themed components as defaults for ResourceSchema.
15
+ // This is done once, here, to avoid circular dependencies at the module level.
16
+ registerDefaultResourceComponents({
17
+ list: List,
18
+ create: Create,
19
+ edit: Edit,
20
+ show: Show,
21
+ });
22
+ registerFieldInputMapping(new Map([
23
+ [TextField, TextInput],
24
+ [NumberField, NumberInput],
25
+ [CurrencyField, NumberInput],
26
+ [ReferenceField, ReferenceInput],
27
+ ]));
28
+ const defaultI18nProvider = icuI18nProvider(() => englishMessages);
29
+ const defaultStore = localStorageStore();
30
+ /**
31
+ * Syncs Cloudscape I18n with React-Admin locale.
32
+ */
33
+ const CloudscapeI18n = ({ children }) => {
34
+ const [locale] = useLocaleState();
35
+ const [messages, setMessages] = useState([]);
36
+ useEffect(() => {
37
+ let active = true;
38
+ importMessages(locale).then((msgs) => {
39
+ if (active) {
40
+ setMessages(msgs);
41
+ }
42
+ });
43
+ return () => {
44
+ active = false;
45
+ };
46
+ }, [locale]);
47
+ if (messages.length === 0) {
48
+ return null;
49
+ }
50
+ return (_jsx(I18nProvider, { locale: locale, messages: messages, children: children }));
51
+ };
52
+ const CloudscapeLayout = (props) => {
53
+ const { children, layout: Layout = AppLayout, ...rest } = props;
54
+ return (_jsx(CloudscapeI18n, { children: _jsx(Layout, { ...rest, children: children }) }));
55
+ };
56
+ /**
57
+ * The root component of a Strato Admin application.
58
+ *
59
+ * It sets up the data fetching context, authentication, and layout using Cloudscape.
60
+ *
61
+ * @example
62
+ * <Admin dataProvider={myDataProvider} title="My App">
63
+ * <Resource name="posts" list={PostList} />
64
+ * </Admin>
65
+ */
66
+ export const Admin = ({ children, title, layout: Layout = AppLayout, i18nProvider = defaultI18nProvider, store = defaultStore, ...props }) => {
67
+ return (_jsx(SchemaRegistryProvider, { children: _jsx(CoreAdmin, { ...props, layout: (layoutProps) => _jsx(CloudscapeLayout, { ...layoutProps, layout: Layout }), title: title, i18nProvider: i18nProvider, store: store, children: children }) }));
68
+ };
69
+ export default Admin;
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ export type RecordLinkType = string | boolean | ((record: any, reference?: string) => string);
3
+ export interface RecordLinkProps {
4
+ link?: RecordLinkType;
5
+ resource?: string;
6
+ children: React.ReactNode;
7
+ }
8
+ declare const RecordLink: ({ link, resource, children }: RecordLinkProps) => import("react/jsx-runtime").JSX.Element;
9
+ export default RecordLink;
@@ -0,0 +1,43 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import Link from '@cloudscape-design/components/link';
3
+ import { useCreatePath, useResourceContext, useRecordContext } from '@strato-admin/core';
4
+ import { useNavigate } from 'react-router-dom';
5
+ const RecordLinkImpl = ({ link, resource, children }) => {
6
+ const contextResource = useResourceContext();
7
+ const record = useRecordContext();
8
+ const createPath = useCreatePath();
9
+ const navigate = useNavigate();
10
+ const finalResource = resource ?? contextResource;
11
+ if (!record || !finalResource) {
12
+ return _jsx(_Fragment, { children: children });
13
+ }
14
+ let href = '';
15
+ if (typeof link === 'function') {
16
+ href = link(record, finalResource);
17
+ }
18
+ else if (link === true) {
19
+ href = createPath({ resource: finalResource, id: record.id, type: 'edit' });
20
+ }
21
+ else if (link === 'edit' || link === 'show') {
22
+ href = createPath({ resource: finalResource, id: record.id, type: link });
23
+ }
24
+ else if (typeof link === 'string') {
25
+ href = link;
26
+ }
27
+ if (!href) {
28
+ return _jsx(_Fragment, { children: children });
29
+ }
30
+ return (_jsx(Link, { href: href, onFollow: (event) => {
31
+ if (!event.detail.external) {
32
+ event.preventDefault();
33
+ navigate(href);
34
+ }
35
+ }, children: children }));
36
+ };
37
+ const RecordLink = ({ link, resource, children }) => {
38
+ if (!link) {
39
+ return _jsx(_Fragment, { children: children });
40
+ }
41
+ return (_jsx(RecordLinkImpl, { link: link, resource: resource, children: children }));
42
+ };
43
+ export default RecordLink;
@@ -0,0 +1,50 @@
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { vi } from 'vitest';
3
+ export const useTranslate = vi.fn(() => (key, options) => options?._ || key);
4
+ export const useTranslateLabel = vi.fn(() => (label) => typeof label === 'string' ? label : label?.source || '');
5
+ export const useGetResourceLabel = vi.fn(() => (resource) => {
6
+ if (resource === 'products')
7
+ return 'Products';
8
+ if (resource === 'categories')
9
+ return 'Categories';
10
+ return resource;
11
+ });
12
+ export const useResourceDefinitions = vi.fn(() => ({}));
13
+ export const useResourceDefinition = vi.fn(() => ({
14
+ name: 'products',
15
+ options: { label: 'Products' },
16
+ }));
17
+ export const useResourceContext = vi.fn();
18
+ export const useRecordContext = vi.fn((record) => record || {});
19
+ export const useDefaultTitle = vi.fn(() => '');
20
+ export const useInput = vi.fn();
21
+ export const useChoicesContext = vi.fn(() => ({ allChoices: [], isPending: false }));
22
+ export const useGetRecordRepresentation = vi.fn(() => (record) => record?.name || record?.id || record);
23
+ export const useFieldSchema = vi.fn(() => []);
24
+ export const useInputSchema = vi.fn(() => []);
25
+ export const ResourceSchemaProvider = vi.fn(({ children }) => children);
26
+ export const ValidationError = vi.fn(({ error }) => _jsx("span", { children: error }));
27
+ export const useStore = vi.fn(() => ['light', vi.fn()]);
28
+ export const useSaveContext = vi.fn(() => ({ save: vi.fn(), saving: false }));
29
+ export const useNotify = vi.fn(() => vi.fn());
30
+ export const useRedirect = vi.fn(() => vi.fn());
31
+ export const useRefresh = vi.fn(() => vi.fn());
32
+ export const useFieldValue = vi.fn(({ source, record }) => record?.[source]);
33
+ export const useCreatePath = vi.fn(() => (params) => `/${params.resource}/${params.id}/${params.type}`);
34
+ export const useLocale = vi.fn(() => 'en');
35
+ export const useBulkDeleteController = vi.fn(() => ({
36
+ handleDelete: vi.fn(),
37
+ isPending: false,
38
+ isLoading: false,
39
+ }));
40
+ export const CreateBase = vi.fn(({ children }) => _jsx("div", { "data-testid": "create-base", children: children }));
41
+ export const EditBase = vi.fn(({ children }) => _jsx("div", { "data-testid": "edit-base", children: children }));
42
+ export const ShowBase = vi.fn(({ children }) => _jsx("div", { "data-testid": "show-base", children: children }));
43
+ export const ListBase = vi.fn(({ children }) => _jsx("div", { "data-testid": "list-base", children: children }));
44
+ export const useShowContext = vi.fn(() => ({ isLoading: false, record: {}, defaultTitle: 'Products' }));
45
+ export const useEditContext = vi.fn(() => ({ isLoading: false, record: {}, defaultTitle: 'Products' }));
46
+ export const useCreateContext = vi.fn(() => ({ isLoading: false, record: {}, defaultTitle: 'Products' }));
47
+ export const useListContext = vi.fn(() => ({ total: 0, isPending: false, selectedIds: [], defaultTitle: 'Products' }));
48
+ export const Form = vi.fn(({ children }) => _jsx("div", { "data-testid": "ra-form", children: children }));
49
+ export const FieldTitle = vi.fn(({ label, source }) => _jsx("span", { "data-testid": "field-title", children: label || source }));
50
+ export const RecordContextProvider = vi.fn(({ children }) => _jsx(_Fragment, { children: children }));
@@ -0,0 +1,50 @@
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { vi } from 'vitest';
3
+ export const useTranslate = vi.fn(() => (key, options) => options?._ || key);
4
+ export const useTranslateLabel = vi.fn(() => (label) => typeof label === 'string' ? label : label?.source || '');
5
+ export const useGetResourceLabel = vi.fn(() => (resource) => {
6
+ if (resource === 'products')
7
+ return 'Products';
8
+ if (resource === 'categories')
9
+ return 'Categories';
10
+ return resource;
11
+ });
12
+ export const useResourceDefinitions = vi.fn(() => ({}));
13
+ export const useResourceDefinition = vi.fn(() => ({
14
+ name: 'products',
15
+ options: { label: 'Products' },
16
+ }));
17
+ export const useResourceContext = vi.fn();
18
+ export const useRecordContext = vi.fn((record) => record || {});
19
+ export const useDefaultTitle = vi.fn(() => '');
20
+ export const useInput = vi.fn();
21
+ export const useChoicesContext = vi.fn(() => ({ allChoices: [], isPending: false }));
22
+ export const useGetRecordRepresentation = vi.fn(() => (record) => record?.name || record?.id || record);
23
+ export const useFieldSchema = vi.fn(() => []);
24
+ export const useInputSchema = vi.fn(() => []);
25
+ export const ResourceSchemaProvider = vi.fn(({ children }) => children);
26
+ export const ValidationError = vi.fn(({ error }) => _jsx("span", { children: error }));
27
+ export const useStore = vi.fn(() => ['light', vi.fn()]);
28
+ export const useSaveContext = vi.fn(() => ({ save: vi.fn(), saving: false }));
29
+ export const useNotify = vi.fn(() => vi.fn());
30
+ export const useRedirect = vi.fn(() => vi.fn());
31
+ export const useRefresh = vi.fn(() => vi.fn());
32
+ export const useFieldValue = vi.fn(({ source, record }) => record?.[source]);
33
+ export const useCreatePath = vi.fn(() => (params) => `/${params.resource}/${params.id}/${params.type}`);
34
+ export const useLocale = vi.fn(() => 'en');
35
+ export const useBulkDeleteController = vi.fn(() => ({
36
+ handleDelete: vi.fn(),
37
+ isPending: false,
38
+ isLoading: false,
39
+ }));
40
+ export const CreateBase = vi.fn(({ children }) => _jsx("div", { "data-testid": "create-base", children: children }));
41
+ export const EditBase = vi.fn(({ children }) => _jsx("div", { "data-testid": "edit-base", children: children }));
42
+ export const ShowBase = vi.fn(({ children }) => _jsx("div", { "data-testid": "show-base", children: children }));
43
+ export const ListBase = vi.fn(({ children }) => _jsx("div", { "data-testid": "list-base", children: children }));
44
+ export const useShowContext = vi.fn(() => ({ isLoading: false, record: {}, defaultTitle: 'Products' }));
45
+ export const useEditContext = vi.fn(() => ({ isLoading: false, record: {}, defaultTitle: 'Products' }));
46
+ export const useCreateContext = vi.fn(() => ({ isLoading: false, record: {}, defaultTitle: 'Products' }));
47
+ export const useListContext = vi.fn(() => ({ total: 0, isPending: false, selectedIds: [], defaultTitle: 'Products' }));
48
+ export const Form = vi.fn(({ children }) => _jsx("div", { "data-testid": "ra-form", children: children }));
49
+ export const FieldTitle = vi.fn(({ label, source }) => _jsx("span", { "data-testid": "field-title", children: label || source }));
50
+ export const RecordContextProvider = vi.fn(({ children }) => _jsx(_Fragment, { children: children }));
@@ -0,0 +1,7 @@
1
+ export interface BulkDeleteButtonProps {
2
+ label?: string;
3
+ variant?: 'primary' | 'normal' | 'link';
4
+ mutationMode?: 'undoable' | 'optimistic' | 'pessimistic';
5
+ }
6
+ export declare const BulkDeleteButton: ({ label, variant, mutationMode, }: BulkDeleteButtonProps) => import("react/jsx-runtime").JSX.Element | null;
7
+ export default BulkDeleteButton;
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useBulkDeleteController, useTranslate, useListContext, useResourceDefinition } from '@strato-admin/core';
3
+ import { Button } from './Button';
4
+ export const BulkDeleteButton = ({ label, variant = 'normal', mutationMode = 'pessimistic', }) => {
5
+ const translate = useTranslate();
6
+ const { selectedIds } = useListContext();
7
+ const { options } = useResourceDefinition();
8
+ const { handleDelete, isPending, isLoading } = useBulkDeleteController({
9
+ mutationMode,
10
+ });
11
+ if (options?.canDelete === false) {
12
+ return null;
13
+ }
14
+ const isBusy = isPending || isLoading;
15
+ return (_jsx(Button, { variant: variant, onClick: handleDelete, loading: isBusy, disabled: isBusy || !selectedIds || selectedIds.length === 0, children: label || translate('ra.action.delete', { _: 'Delete' }) }));
16
+ };
17
+ export default BulkDeleteButton;
@@ -0,0 +1,6 @@
1
+ import { ButtonProps as CloudscapeButtonProps } from '@cloudscape-design/components/button';
2
+ export interface ButtonProps extends CloudscapeButtonProps {
3
+ children: React.ReactNode;
4
+ }
5
+ export declare const Button: ({ children, ...props }: ButtonProps) => import("react/jsx-runtime").JSX.Element;
6
+ export default Button;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import CloudscapeButton from '@cloudscape-design/components/button';
3
+ export const Button = ({ children, ...props }) => {
4
+ return _jsx(CloudscapeButton, { ...props, children: children });
5
+ };
6
+ export default Button;
@@ -0,0 +1,6 @@
1
+ import { ButtonProps } from './Button';
2
+ export interface CreateButtonProps extends Omit<ButtonProps, 'children'> {
3
+ label?: string;
4
+ }
5
+ export declare const CreateButton: ({ label, variant, ...props }: CreateButtonProps) => import("react/jsx-runtime").JSX.Element | null;
6
+ export default CreateButton;
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useResourceContext, useTranslate, useCreatePath, useResourceDefinitions } from '@strato-admin/core';
3
+ import { useNavigate } from 'react-router-dom';
4
+ import { Button } from './Button';
5
+ export const CreateButton = ({ label, variant = 'primary', ...props }) => {
6
+ const resource = useResourceContext();
7
+ const translate = useTranslate();
8
+ const createPath = useCreatePath();
9
+ const navigate = useNavigate();
10
+ const definitions = useResourceDefinitions();
11
+ const definition = resource ? definitions[resource] : undefined;
12
+ if (!definition || !definition.hasCreate) {
13
+ return null;
14
+ }
15
+ const handleClick = () => {
16
+ const path = createPath({
17
+ resource,
18
+ type: 'create',
19
+ });
20
+ navigate(path);
21
+ };
22
+ return (_jsx(Button, { variant: variant, onClick: handleClick, iconName: "add-plus", ...props, children: label || translate('ra.action.create', { _: 'Create' }) }));
23
+ };
24
+ export default CreateButton;
@@ -0,0 +1,8 @@
1
+ import { RaRecord } from '@strato-admin/core';
2
+ import { ButtonProps } from './Button';
3
+ export interface EditButtonProps extends Omit<ButtonProps, 'children'> {
4
+ label?: string;
5
+ record?: RaRecord;
6
+ }
7
+ export declare const EditButton: ({ label, record: recordProp, variant, ...props }: EditButtonProps) => import("react/jsx-runtime").JSX.Element | null;
8
+ export default EditButton;
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useResourceContext, useRecordContext, useTranslate, useCreatePath } from '@strato-admin/core';
3
+ import { useNavigate } from 'react-router-dom';
4
+ import { Button } from './Button';
5
+ export const EditButton = ({ label, record: recordProp, variant = 'primary', ...props }) => {
6
+ const resource = useResourceContext();
7
+ const record = useRecordContext(recordProp);
8
+ const translate = useTranslate();
9
+ const createPath = useCreatePath();
10
+ const navigate = useNavigate();
11
+ if (!record) {
12
+ return null;
13
+ }
14
+ const handleClick = () => {
15
+ const path = createPath({
16
+ resource,
17
+ id: record.id,
18
+ type: 'edit',
19
+ });
20
+ navigate(path);
21
+ };
22
+ return (_jsx(Button, { variant: variant, onClick: handleClick, ...props, children: label || translate('ra.action.edit', { _: 'Edit' }) }));
23
+ };
24
+ export default EditButton;
@@ -0,0 +1,6 @@
1
+ import { ButtonProps } from './Button';
2
+ export interface SaveButtonProps extends Omit<ButtonProps, 'children'> {
3
+ label?: string;
4
+ }
5
+ export declare const SaveButton: ({ label, variant, ...props }: SaveButtonProps) => import("react/jsx-runtime").JSX.Element;
6
+ export default SaveButton;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useTranslate } from '@strato-admin/core';
3
+ import { Button } from './Button';
4
+ export const SaveButton = ({ label, variant = 'primary', ...props }) => {
5
+ const translate = useTranslate();
6
+ return (_jsx(Button, { variant: variant, formAction: "submit", nativeButtonAttributes: { type: 'submit' }, ...props, children: label || translate('ra.action.save', { _: 'Save' }) }));
7
+ };
8
+ export default SaveButton;
@@ -0,0 +1,5 @@
1
+ export * from './Button';
2
+ export * from './EditButton';
3
+ export * from './BulkDeleteButton';
4
+ export * from './SaveButton';
5
+ export * from './CreateButton';
@@ -0,0 +1,5 @@
1
+ export * from './Button';
2
+ export * from './EditButton';
3
+ export * from './BulkDeleteButton';
4
+ export * from './SaveButton';
5
+ export * from './CreateButton';
@@ -0,0 +1,2 @@
1
+ export * from './useCollection';
2
+ export * from './interfaces';
@@ -0,0 +1,2 @@
1
+ export * from './useCollection';
2
+ export * from './interfaces';
@@ -0,0 +1,93 @@
1
+ interface CustomEventLike<T> {
2
+ detail: T;
3
+ }
4
+ export interface TableColumnDisplay {
5
+ id: string;
6
+ visible: boolean;
7
+ }
8
+ export interface CollectionPreferences {
9
+ pageSize?: number;
10
+ wrapLines?: boolean;
11
+ stripedRows?: boolean;
12
+ visibleContent?: ReadonlyArray<string>;
13
+ contentDisplay?: ReadonlyArray<TableColumnDisplay>;
14
+ contentDensity?: 'comfortable' | 'compact';
15
+ }
16
+ export interface UseCollectionOptions<_T> {
17
+ filtering?: any;
18
+ pagination?: any;
19
+ sorting?: any;
20
+ preferences?: {
21
+ pageSizeOptions?: ReadonlyArray<{
22
+ value: number;
23
+ label?: string;
24
+ }>;
25
+ visibleContentOptions?: ReadonlyArray<{
26
+ id: string;
27
+ label: string;
28
+ editable?: boolean;
29
+ }>;
30
+ contentDisplayOptions?: ReadonlyArray<{
31
+ id: string;
32
+ label: string;
33
+ alwaysVisible?: boolean;
34
+ }>;
35
+ wrapLines?: boolean;
36
+ stripedRows?: boolean;
37
+ visibleContent?: ReadonlyArray<string>;
38
+ contentDisplay?: ReadonlyArray<TableColumnDisplay>;
39
+ };
40
+ }
41
+ export interface UseCollectionResult<T> {
42
+ items: ReadonlyArray<T> | undefined;
43
+ collectionProps: {
44
+ selectedItems: T[];
45
+ onSelectionChange(event: CustomEventLike<{
46
+ selectedItems: T[];
47
+ }>): void;
48
+ trackBy: string | ((item: T) => string);
49
+ sortingColumn?: {
50
+ sortingField?: string;
51
+ };
52
+ sortingDescending?: boolean;
53
+ onSortingChange?(event: CustomEventLike<{
54
+ sortingColumn: {
55
+ sortingField?: string;
56
+ };
57
+ isDescending?: boolean;
58
+ }>): void;
59
+ };
60
+ paginationProps: {
61
+ disabled?: boolean;
62
+ currentPageIndex: number;
63
+ pagesCount: number;
64
+ onChange(event: CustomEventLike<{
65
+ currentPageIndex: number;
66
+ }>): void;
67
+ };
68
+ filterProps: {
69
+ filteringText: string;
70
+ onChange(event: CustomEventLike<{
71
+ filteringText: string;
72
+ }>): void;
73
+ };
74
+ preferencesProps: {
75
+ preferences: CollectionPreferences;
76
+ onConfirm(event: CustomEventLike<CollectionPreferences>): void;
77
+ pageSizeOptions?: ReadonlyArray<{
78
+ value: number;
79
+ label?: string;
80
+ }>;
81
+ visibleContentOptions?: ReadonlyArray<{
82
+ id: string;
83
+ label: string;
84
+ editable?: boolean;
85
+ }>;
86
+ contentDisplayOptions?: ReadonlyArray<{
87
+ id: string;
88
+ label: string;
89
+ alwaysVisible?: boolean;
90
+ }>;
91
+ };
92
+ }
93
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { RaRecord } from '@strato-admin/core';
2
+ import { UseCollectionOptions, UseCollectionResult } from './interfaces';
3
+ export declare function useCollection<T extends RaRecord>(options: UseCollectionOptions<T>): UseCollectionResult<T>;
@@ -0,0 +1,102 @@
1
+ import { useState, useMemo } from 'react';
2
+ import { useListContext } from '@strato-admin/core';
3
+ export function useCollection(options) {
4
+ const { data, // Array of the list records, e.g. [{ id: 123, title: 'hello world' }, { ... }
5
+ total, // Total number of results for the current filters, excluding pagination. Useful to build the pagination controls, e.g. 23
6
+ isPending, // Boolean, true until the data is available
7
+ isFetching, // Boolean, true while the data is being fetched, false once the data is fetched
8
+ isLoading, // Boolean, true until the data is fetched for the first time
9
+ // Pagination
10
+ page, // Current page. Starts at 1
11
+ perPage, // Number of results per page. Defaults to 25
12
+ setPage, // Callback to change the page, e.g. setPage(3)
13
+ setPerPage, // Callback to change the number of results per page, e.g. setPerPage(50)
14
+ // Selection
15
+ selectedIds, // Array of the selected record IDs
16
+ onSelect, // Callback to change the selection, e.g. onSelect([123, 456])
17
+ // Sorting
18
+ sort, // Current sort. E.g. { field: 'id', order: 'ASC' }
19
+ setSort, // Callback to change the sort. E.g. setSort({ field: 'id', order: 'ASC' })
20
+ // Filtering
21
+ filterValues, setFilters, } = useListContext();
22
+ const [wrapLines, setWrapLines] = useState(options.preferences?.wrapLines);
23
+ const [stripedRows, setStripedRows] = useState(options.preferences?.stripedRows);
24
+ const [visibleContent, setVisibleContent] = useState(options.preferences?.visibleContent ?? options.preferences?.visibleContentOptions?.map((o) => o.id));
25
+ const [contentDisplay, setContentDisplay] = useState(options.preferences?.contentDisplay ?? options.preferences?.contentDisplayOptions?.map((o) => ({ id: o.id, visible: true })));
26
+ useMemo(() => {
27
+ setVisibleContent(options.preferences?.visibleContent ?? options.preferences?.visibleContentOptions?.map((o) => o.id));
28
+ setContentDisplay(options.preferences?.contentDisplay ?? options.preferences?.contentDisplayOptions?.map((o) => ({ id: o.id, visible: true })));
29
+ }, [options.preferences?.visibleContent, options.preferences?.visibleContentOptions, options.preferences?.contentDisplay, options.preferences?.contentDisplayOptions]);
30
+ const selectedItems = (selectedIds || []).map((id) => {
31
+ const item = data?.find((i) => i.id === id);
32
+ if (item)
33
+ return item;
34
+ return { id };
35
+ });
36
+ const items = useMemo(() => {
37
+ // If it's a client-side list (data contains all records), we need to slice it for pagination.
38
+ // We detect this by checking if data.length equals total and if data.length is greater than perPage.
39
+ if (data && total === data.length && data.length > (perPage || 0)) {
40
+ const p = page || 1;
41
+ const pp = perPage || 25;
42
+ return data.slice((p - 1) * pp, p * pp);
43
+ }
44
+ return data;
45
+ }, [data, total, page, perPage]);
46
+ return {
47
+ items,
48
+ collectionProps: {
49
+ selectedItems,
50
+ onSelectionChange: (event) => onSelect(event.detail.selectedItems.map((item) => item.id)),
51
+ trackBy: 'id',
52
+ sortingColumn: sort ? { sortingField: sort.field } : undefined,
53
+ sortingDescending: sort?.order === 'DESC',
54
+ onSortingChange: (event) => {
55
+ const { sortingColumn, isDescending } = event.detail;
56
+ if (sortingColumn?.sortingField) {
57
+ setSort({ field: sortingColumn.sortingField, order: isDescending ? 'DESC' : 'ASC' });
58
+ }
59
+ },
60
+ },
61
+ paginationProps: {
62
+ disabled: isPending || isFetching || isLoading,
63
+ currentPageIndex: page,
64
+ pagesCount: total !== undefined && perPage ? Math.ceil(total / perPage) : 1,
65
+ onChange: (event) => setPage(event.detail.currentPageIndex),
66
+ },
67
+ filterProps: {
68
+ filteringText: filterValues?.q || '',
69
+ onChange: (event) => {
70
+ setFilters({ ...filterValues, q: event.detail.filteringText });
71
+ },
72
+ },
73
+ preferencesProps: {
74
+ preferences: {
75
+ pageSize: perPage,
76
+ wrapLines,
77
+ stripedRows,
78
+ visibleContent,
79
+ contentDisplay,
80
+ },
81
+ onConfirm: (event) => {
82
+ const { pageSize, wrapLines: newWrapLines, stripedRows: newStripedRows, visibleContent: newVisibleContent, contentDisplay: newContentDisplay, } = event.detail;
83
+ if (pageSize !== undefined && pageSize !== perPage) {
84
+ setPerPage(pageSize);
85
+ }
86
+ if (newWrapLines !== undefined) {
87
+ setWrapLines(newWrapLines);
88
+ }
89
+ if (newStripedRows !== undefined) {
90
+ setStripedRows(newStripedRows);
91
+ }
92
+ if (newVisibleContent !== undefined) {
93
+ setVisibleContent(newVisibleContent);
94
+ }
95
+ if (newContentDisplay !== undefined) {
96
+ setContentDisplay(newContentDisplay);
97
+ }
98
+ },
99
+ ...options.preferences,
100
+ },
101
+ };
102
+ }