@strato-admin/cloudscape 0.1.1 → 0.3.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.
- package/dist/Admin.d.ts +6 -2
- package/dist/Admin.js +14 -8
- package/dist/RecordLink.js +5 -4
- package/dist/Settings.d.ts +17 -0
- package/dist/Settings.js +14 -0
- package/dist/button/BulkDeleteButton.d.ts +2 -1
- package/dist/button/BulkDeleteButton.js +17 -11
- package/dist/button/Button.d.ts +2 -1
- package/dist/button/CancelButton.d.ts +6 -0
- package/dist/button/CancelButton.js +10 -0
- package/dist/button/CreateButton.js +9 -8
- package/dist/button/DeleteButton.d.ts +13 -0
- package/dist/button/DeleteButton.js +36 -0
- package/dist/button/EditButton.d.ts +1 -1
- package/dist/button/EditButton.js +10 -10
- package/dist/button/SaveButton.js +2 -2
- package/dist/button/index.d.ts +2 -0
- package/dist/button/index.js +2 -0
- package/dist/collection-hooks/interfaces.d.ts +7 -3
- package/dist/collection-hooks/useCollection.d.ts +1 -1
- package/dist/collection-hooks/useCollection.js +15 -10
- package/dist/create/Create.d.ts +9 -17
- package/dist/create/Create.js +40 -12
- package/dist/create/CreateHeader.d.ts +2 -2
- package/dist/create/CreateHeader.js +4 -5
- package/dist/defaults.d.ts +6 -0
- package/dist/defaults.js +21 -0
- package/dist/detail/Detail.d.ts +33 -0
- package/dist/detail/Detail.js +22 -0
- package/dist/detail/DetailHeader.d.ts +11 -0
- package/dist/detail/{ShowHeader.js → DetailHeader.js} +7 -5
- package/dist/detail/DetailHub.d.ts +27 -0
- package/dist/detail/DetailHub.js +63 -0
- package/dist/detail/KeyValuePairs.d.ts +7 -1
- package/dist/detail/KeyValuePairs.js +14 -8
- package/dist/detail/index.d.ts +3 -2
- package/dist/detail/index.js +3 -2
- package/dist/edit/Edit.d.ts +8 -19
- package/dist/edit/Edit.js +48 -12
- package/dist/edit/EditHeader.d.ts +2 -2
- package/dist/edit/EditHeader.js +5 -4
- package/dist/field/ArrayField.d.ts +26 -10
- package/dist/field/ArrayField.js +38 -10
- package/dist/field/BadgeField.d.ts +1 -1
- package/dist/field/BadgeField.js +1 -1
- package/dist/field/BooleanField.d.ts +1 -1
- package/dist/field/BooleanField.js +2 -2
- package/dist/field/CurrencyField.d.ts +1 -1
- package/dist/field/CurrencyField.js +1 -1
- package/dist/field/DateField.d.ts +1 -1
- package/dist/field/DateField.js +1 -1
- package/dist/field/IdField.d.ts +1 -1
- package/dist/field/IdField.js +3 -3
- package/dist/field/NumberField.d.ts +1 -1
- package/dist/field/NumberField.js +1 -1
- package/dist/field/ReferenceField.d.ts +1 -1
- package/dist/field/ReferenceField.js +4 -2
- package/dist/field/ReferenceManyField.d.ts +35 -4
- package/dist/field/ReferenceManyField.js +17 -4
- package/dist/field/StatusIndicatorField.d.ts +1 -1
- package/dist/field/StatusIndicatorField.js +6 -5
- package/dist/field/TextField.d.ts +1 -1
- package/dist/field/TextField.js +1 -1
- package/dist/field/types.d.ts +9 -9
- package/dist/form/Form.d.ts +12 -2
- package/dist/form/Form.js +10 -16
- package/dist/form/index.d.ts +1 -1
- package/dist/form/index.js +1 -1
- package/dist/hooks/useSchemaFields.d.ts +22 -0
- package/dist/hooks/useSchemaFields.js +45 -0
- package/dist/i18n/Message.d.ts +15 -0
- package/dist/i18n/Message.js +19 -0
- package/dist/i18n/RecordMessage.d.ts +14 -0
- package/dist/i18n/RecordMessage.js +16 -0
- package/dist/i18n/index.d.ts +3 -0
- package/dist/i18n/index.js +2 -0
- package/dist/i18n/types.d.ts +19 -0
- package/dist/i18n/types.js +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +5 -1
- package/dist/input/ArrayInput.d.ts +33 -0
- package/dist/input/{AttributeEditor.js → ArrayInput.js} +18 -11
- package/dist/input/AutocompleteInput.d.ts +1 -1
- package/dist/input/AutocompleteInput.js +3 -3
- package/dist/input/BooleanInput.d.ts +6 -0
- package/dist/input/BooleanInput.js +23 -0
- package/dist/input/CommonInputProps.d.ts +6 -0
- package/dist/input/CommonInputProps.js +6 -0
- package/dist/input/FieldTitle.js +4 -4
- package/dist/input/FormField.js +12 -3
- package/dist/input/FormFieldContext.d.ts +1 -1
- package/dist/input/NumberInput.d.ts +1 -1
- package/dist/input/NumberInput.js +3 -3
- package/dist/input/ReferenceInput.d.ts +1 -1
- package/dist/input/ReferenceInput.js +22 -12
- package/dist/input/SelectInput.d.ts +1 -1
- package/dist/input/SelectInput.js +3 -3
- package/dist/input/SliderInput.d.ts +1 -1
- package/dist/input/SliderInput.js +4 -4
- package/dist/input/TextAreaInput.d.ts +1 -1
- package/dist/input/TextAreaInput.js +3 -3
- package/dist/input/TextInput.d.ts +1 -1
- package/dist/input/TextInput.js +6 -12
- package/dist/input/index.d.ts +2 -1
- package/dist/input/index.js +2 -1
- package/dist/input/types.d.ts +33 -2
- package/dist/layout/AppLayout.js +6 -3
- package/dist/layout/Notifications.d.ts +1 -0
- package/dist/layout/Notifications.js +51 -0
- package/dist/layout/Ready.d.ts +6 -0
- package/dist/layout/Ready.js +24 -0
- package/dist/layout/TopNavigation.d.ts +4 -2
- package/dist/layout/TopNavigation.js +7 -7
- package/dist/layout/index.d.ts +2 -0
- package/dist/layout/index.js +2 -0
- package/dist/list/Cards.d.ts +31 -4
- package/dist/list/Cards.js +81 -10
- package/dist/list/List.d.ts +9 -12
- package/dist/list/List.js +41 -11
- package/dist/list/Table.d.ts +8 -4
- package/dist/list/Table.js +55 -55
- package/dist/list/TableHeader.d.ts +2 -2
- package/dist/list/TableHeader.js +4 -5
- package/dist/theme/ThemeManager.js +1 -1
- package/package.json +8 -5
- package/src/Admin.tsx +35 -18
- package/src/RecordLink.stories.tsx +1 -1
- package/src/RecordLink.tsx +5 -4
- package/src/Settings.tsx +16 -0
- package/src/__mocks__/ra-core.tsx +83 -0
- package/src/__mocks__/strato-core.tsx +36 -42
- package/src/button/BulkDeleteButton.test.tsx +17 -4
- package/src/button/BulkDeleteButton.tsx +24 -29
- package/src/button/Button.tsx +31 -2
- package/src/button/CancelButton.tsx +20 -0
- package/src/button/CreateButton.tsx +12 -10
- package/src/button/DeleteButton.tsx +96 -0
- package/src/button/EditButton.tsx +13 -12
- package/src/button/SaveButton.tsx +2 -3
- package/src/button/index.ts +2 -0
- package/src/collection-hooks/interfaces.ts +7 -3
- package/src/collection-hooks/useCollection.test.ts +115 -2
- package/src/collection-hooks/useCollection.ts +15 -10
- package/src/create/Create.test.tsx +3 -3
- package/src/create/Create.tsx +68 -37
- package/src/create/CreateHeader.tsx +6 -10
- package/src/defaults.tsx +28 -0
- package/src/detail/Detail-CollectionFields.test.tsx +84 -0
- package/src/detail/Detail.test.tsx +91 -0
- package/src/detail/Detail.tsx +48 -0
- package/src/detail/{ShowHeader.test.tsx → DetailHeader.test.tsx} +11 -9
- package/src/detail/DetailHeader.tsx +42 -0
- package/src/detail/DetailHub.tsx +88 -0
- package/src/detail/KeyValuePairs.test.tsx +2 -2
- package/src/detail/KeyValuePairs.tsx +25 -18
- package/src/detail/index.ts +3 -2
- package/src/edit/Edit.test.tsx +7 -5
- package/src/edit/Edit.tsx +92 -40
- package/src/edit/EditHeader.tsx +7 -5
- package/src/field/ArrayField.tsx +57 -11
- package/src/field/BadgeField.tsx +2 -3
- package/src/field/BooleanField.test.tsx +2 -3
- package/src/field/BooleanField.tsx +3 -3
- package/src/field/CurrencyField.tsx +1 -1
- package/src/field/DateField.tsx +1 -1
- package/src/field/IdField.test.tsx +8 -20
- package/src/field/IdField.tsx +5 -20
- package/src/field/NumberField.tsx +1 -1
- package/src/field/ReferenceField.test.tsx +15 -6
- package/src/field/ReferenceField.tsx +10 -7
- package/src/field/ReferenceManyField.test.tsx +55 -10
- package/src/field/ReferenceManyField.tsx +84 -13
- package/src/field/StatusIndicatorField.test.tsx +7 -21
- package/src/field/StatusIndicatorField.tsx +8 -20
- package/src/field/TextField.tsx +1 -1
- package/src/field/types.ts +12 -13
- package/src/form/Form.test.tsx +8 -4
- package/src/form/Form.tsx +24 -19
- package/src/form/index.ts +1 -1
- package/src/hooks/useSchemaFields.ts +89 -0
- package/src/i18n/Message.tsx +22 -0
- package/src/i18n/RecordMessage.tsx +22 -0
- package/src/i18n/index.ts +3 -0
- package/src/i18n/types.ts +19 -0
- package/src/index.ts +5 -1
- package/src/input/ArrayInput.test.tsx +81 -0
- package/src/input/{AttributeEditor.tsx → ArrayInput.tsx} +36 -18
- package/src/input/AutocompleteInput.test.tsx +2 -4
- package/src/input/AutocompleteInput.tsx +9 -11
- package/src/input/BooleanInput.tsx +42 -0
- package/src/input/CommonInputProps.tsx +8 -0
- package/src/input/FieldTitle.tsx +3 -15
- package/src/input/FormField.tsx +78 -67
- package/src/input/FormFieldContext.ts +1 -1
- package/src/input/NumberInput.tsx +10 -7
- package/src/input/ReferenceInput.test.tsx +12 -2
- package/src/input/ReferenceInput.tsx +32 -14
- package/src/input/SelectInput.tsx +14 -17
- package/src/input/SliderInput.test.tsx +2 -3
- package/src/input/SliderInput.tsx +48 -38
- package/src/input/TextAreaInput.tsx +10 -6
- package/src/input/TextInput.test.tsx +2 -4
- package/src/input/TextInput.tsx +35 -20
- package/src/input/index.ts +2 -1
- package/src/input/types.ts +40 -8
- package/src/layout/AppLayout.test.tsx +23 -3
- package/src/layout/AppLayout.tsx +11 -8
- package/src/layout/Notifications.test.tsx +102 -0
- package/src/layout/Notifications.tsx +61 -0
- package/src/layout/Ready.tsx +123 -0
- package/src/layout/TopNavigation.test.tsx +2 -3
- package/src/layout/TopNavigation.tsx +9 -8
- package/src/layout/index.ts +2 -0
- package/src/list/Cards.test.tsx +320 -0
- package/src/list/Cards.tsx +146 -16
- package/src/list/List.tsx +87 -26
- package/src/list/Table.test.tsx +40 -5
- package/src/list/Table.tsx +89 -98
- package/src/list/TableHeader.test.tsx +15 -11
- package/src/list/TableHeader.tsx +6 -8
- package/src/theme/ThemeManager.tsx +1 -1
- package/dist/__mocks__/strato-core.js +0 -50
- package/dist/__mocks__to__delete/strato-core.js +0 -50
- package/dist/detail/Show.d.ts +0 -39
- package/dist/detail/Show.js +0 -40
- package/dist/detail/ShowHeader.d.ts +0 -7
- package/dist/input/AttributeEditor.d.ts +0 -25
- package/src/detail/Show.test.tsx +0 -96
- package/src/detail/Show.tsx +0 -104
- package/src/detail/ShowHeader.tsx +0 -35
- package/src/input/AttributeEditor.test.tsx +0 -147
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Button, Container, Header, SpaceBetween, Link, Icon, ContentLayout, ColumnLayout, } from '@cloudscape-design/components';
|
|
3
|
+
import { CodeView } from '@cloudscape-design/code-view';
|
|
4
|
+
import typescriptHighlight from '@cloudscape-design/code-view/highlight/typescript';
|
|
5
|
+
import { useDefaultTitle } from '@strato-admin/ra-core';
|
|
6
|
+
/**
|
|
7
|
+
* Default component to display when the admin has no resources.
|
|
8
|
+
* This is a Cloudscape-themed replacement for the default react-admin Ready component.
|
|
9
|
+
*/
|
|
10
|
+
export const Ready = () => {
|
|
11
|
+
const defaultTitle = useDefaultTitle();
|
|
12
|
+
const appTitle = typeof defaultTitle === 'string' ? defaultTitle : 'Strato Admin';
|
|
13
|
+
const codeSnippet = `import { Admin, ResourceSchema, TextField } from '@strato-admin/admin';
|
|
14
|
+
|
|
15
|
+
export const App = () => (
|
|
16
|
+
<Admin dataProvider={...}>
|
|
17
|
+
<ResourceSchema name="posts" >
|
|
18
|
+
<TextField source="id" />
|
|
19
|
+
</ResourceSchema>
|
|
20
|
+
</Admin>
|
|
21
|
+
);`;
|
|
22
|
+
return (_jsx(ContentLayout, { maxContentWidth: 1040, headerVariant: "high-contrast", header: _jsx(Box, { padding: { vertical: 'xxxl' }, textAlign: "center", children: _jsxs(SpaceBetween, { size: "l", children: [_jsxs(Header, { variant: "h1", description: "Your Strato Admin application is properly configured and ready to go.", children: ["Welcome to ", appTitle] }), _jsxs(Box, { variant: "p", children: ["Strato Admin uses a ", _jsx("strong", { children: "Schema First" }), " approach to build admin interfaces efficiently. Start by defining your resources and let us handle the rest."] }), _jsx(Box, { margin: { top: 'm' }, children: _jsxs(SpaceBetween, { direction: "horizontal", size: "xs", children: [_jsx(Button, { variant: "primary", href: "https://strato-admin.dev/docs/getting-started/tutorial", iconName: "external", iconAlign: "right", children: "Get started with the tutorial" }), _jsx(Button, { href: "https://github.com/vadimgu/strato-admin", iconName: "external", iconAlign: "right", children: "View on GitHub" })] }) })] }) }), children: _jsxs(SpaceBetween, { size: "xxl", children: [_jsxs(SpaceBetween, { size: "l", children: [_jsx(Container, { header: _jsx(Header, { variant: "h2", children: "How to add your first resource" }), children: _jsxs(SpaceBetween, { size: "m", children: [_jsxs(Box, { variant: "p", children: ["Add a ", _jsx("code", { children: "<ResourceSchema>" }), " component as a child of your ", _jsx("code", { children: "<Admin>" }), " to define your data model."] }), _jsx(CodeView, { content: codeSnippet, highlight: typescriptHighlight })] }) }), _jsx(Container, { header: _jsx(Header, { variant: "h2", children: "Next steps" }), children: _jsxs(ColumnLayout, { columns: 2, variant: "text-grid", children: [_jsxs("div", { children: [_jsxs(Box, { variant: "h3", fontWeight: "bold", children: [_jsx(Icon, { name: "status-info", variant: "link" }), " Core Concepts"] }), _jsxs(Box, { variant: "p", children: ["Learn how", ' ', _jsx(Link, { href: "https://strato-admin.dev/docs/core-concepts/schema", external: true, children: "Schemas" }), ' ', "work to automate your UI."] })] }), _jsxs("div", { children: [_jsxs(Box, { variant: "h3", fontWeight: "bold", children: [_jsx(Icon, { name: "star", variant: "warning" }), " Design System"] }), _jsxs(Box, { variant: "p", children: ["Explore the", ' ', _jsx(Link, { href: "https://cloudscape.design/", external: true, children: "Cloudscape design system" }), ' ', "components."] })] })] }) })] }), _jsxs(Box, { textAlign: "center", color: "text-label", margin: { top: 'xs' }, padding: { bottom: 'xxxl' }, children: ["Built with", ' ', _jsx(Link, { href: "https://www.strato-admin.dev", external: true, children: "Strato Admin" }), "."] })] }) }));
|
|
23
|
+
};
|
|
24
|
+
export default Ready;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { TopNavigationProps } from '@cloudscape-design/components/top-navigation';
|
|
2
|
-
export interface MyTopNavigationProps
|
|
2
|
+
export interface MyTopNavigationProps {
|
|
3
3
|
identity?: TopNavigationProps.Identity;
|
|
4
|
+
utilities?: ReadonlyArray<TopNavigationProps.Utility>;
|
|
5
|
+
extraUtilities?: ReadonlyArray<TopNavigationProps.Utility>;
|
|
4
6
|
}
|
|
5
|
-
export declare const TopNavigation: ({ utilities: providedUtilities, identity,
|
|
7
|
+
export declare const TopNavigation: ({ utilities: providedUtilities, identity, extraUtilities }: MyTopNavigationProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
8
|
export default TopNavigation;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import CloudscapeTopNavigation from '@cloudscape-design/components/top-navigation';
|
|
3
|
-
import { useLocale, useSetLocale, useLocales, useTranslate, useAuthProvider, useStore } from '@strato-admin/core';
|
|
3
|
+
import { useLocale, useSetLocale, useLocales, useTranslate, useAuthProvider, useStore } from '@strato-admin/ra-core';
|
|
4
4
|
const LightModeIcon = (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", focusable: "false", children: [_jsx("path", { d: "M8 1.5v13a6.5 6.5 0 0 0 0-13z", fill: "currentColor" }), _jsx("circle", { cx: "8", cy: "8", r: "7", fill: "none", stroke: "currentColor", "stroke-width": "1.5" })] }));
|
|
5
5
|
const DarkModeIcon = (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", focusable: "false", children: [_jsx("path", { d: "M8 1.5v13a6.5 6.5 0 0 1 0-13z", fill: "currentColor" }), _jsx("circle", { cx: "8", cy: "8", r: "7", fill: "none", stroke: "currentColor", "stroke-width": "1.5" })] }));
|
|
6
|
-
export const TopNavigation = ({ utilities: providedUtilities, identity,
|
|
6
|
+
export const TopNavigation = ({ utilities: providedUtilities, identity, extraUtilities }) => {
|
|
7
7
|
const locale = useLocale();
|
|
8
8
|
const setLocale = useSetLocale();
|
|
9
9
|
const locales = useLocales();
|
|
@@ -38,16 +38,16 @@ export const TopNavigation = ({ utilities: providedUtilities, identity, ...props
|
|
|
38
38
|
if (authProvider) {
|
|
39
39
|
autoUtilities.push({
|
|
40
40
|
type: 'menu-dropdown',
|
|
41
|
-
text: translate('
|
|
41
|
+
text: translate('strato.auth.user_menu', { _: 'User' }),
|
|
42
42
|
iconName: 'user-profile',
|
|
43
43
|
items: [
|
|
44
|
-
{ id: 'profile', text: translate('
|
|
45
|
-
{ id: 'signout', text: translate('
|
|
44
|
+
{ id: 'profile', text: translate('strato.auth.profile', { _: 'Profile' }) },
|
|
45
|
+
{ id: 'signout', text: translate('strato.auth.logout', { _: 'Sign out' }) },
|
|
46
46
|
],
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
utilities = autoUtilities;
|
|
49
|
+
utilities = extraUtilities ? [...autoUtilities, ...extraUtilities] : autoUtilities;
|
|
50
50
|
}
|
|
51
|
-
return (_jsx("div", { id: "header", children: _jsx(CloudscapeTopNavigation, { identity: identity || { title: 'Strato Admin', href: '/' }, utilities: utilities
|
|
51
|
+
return (_jsx("div", { id: "header", children: _jsx(CloudscapeTopNavigation, { identity: identity || { title: 'Strato Admin', href: '/' }, utilities: utilities }) }));
|
|
52
52
|
};
|
|
53
53
|
export default TopNavigation;
|
package/dist/layout/index.d.ts
CHANGED
package/dist/layout/index.js
CHANGED
package/dist/list/Cards.d.ts
CHANGED
|
@@ -1,11 +1,38 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { CardsProps } from '@cloudscape-design/components/cards';
|
|
3
|
-
import { RaRecord } from '@strato-admin/core';
|
|
4
|
-
export interface ListCardsProps<T extends RaRecord = any> extends Omit<CardsProps<T>, 'items' | 'cardDefinition'> {
|
|
3
|
+
import { RaRecord } from '@strato-admin/ra-core';
|
|
4
|
+
export interface ListCardsProps<T extends RaRecord = any> extends Omit<CardsProps<T>, 'items' | 'cardDefinition' | 'preferences'> {
|
|
5
5
|
renderItem?: (item: T) => React.ReactNode;
|
|
6
6
|
include?: string[];
|
|
7
7
|
exclude?: string[];
|
|
8
|
+
children?: React.ReactNode;
|
|
9
|
+
title?: React.ReactNode;
|
|
10
|
+
description?: string;
|
|
11
|
+
actions?: React.ReactNode;
|
|
12
|
+
selectionType?: 'single' | 'multi';
|
|
13
|
+
/**
|
|
14
|
+
* Whether to enable text filtering.
|
|
15
|
+
* @default true
|
|
16
|
+
*/
|
|
17
|
+
filtering?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Placeholder text for the filter input.
|
|
20
|
+
* @default "Search..."
|
|
21
|
+
*/
|
|
22
|
+
filteringPlaceholder?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Options for the page size selector.
|
|
25
|
+
*/
|
|
26
|
+
pageSizeOptions?: ReadonlyArray<{
|
|
27
|
+
value: number;
|
|
28
|
+
label?: string;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Whether to show the preferences button or custom preferences content.
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
preferences?: boolean | React.ReactNode;
|
|
8
35
|
}
|
|
9
|
-
export declare const ListCards: <T extends RaRecord = any>({ renderItem, include, exclude, ...props }: ListCardsProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
-
export declare const Cards: <T extends RaRecord = any>({ renderItem, include, exclude, ...props }: ListCardsProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
36
|
+
export declare const ListCards: <T extends RaRecord = any>({ renderItem, include, exclude, children, title, description, actions, selectionType, filtering, filteringPlaceholder, pageSizeOptions, preferences, ...props }: ListCardsProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
export declare const Cards: <T extends RaRecord = any>({ renderItem, include, exclude, children, title, description, actions, selectionType, filtering, filteringPlaceholder, pageSizeOptions, preferences, ...props }: ListCardsProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
11
38
|
export default ListCards;
|
package/dist/list/Cards.js
CHANGED
|
@@ -1,27 +1,98 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
2
3
|
import CloudscapeCards from '@cloudscape-design/components/cards';
|
|
3
4
|
import Pagination from '@cloudscape-design/components/pagination';
|
|
4
|
-
import
|
|
5
|
+
import TextFilter from '@cloudscape-design/components/text-filter';
|
|
6
|
+
import CollectionPreferences from '@cloudscape-design/components/collection-preferences';
|
|
7
|
+
import { RecordContextProvider, useTranslateLabel, useTranslate } from '@strato-admin/ra-core';
|
|
8
|
+
import { useResourceSchema, useSettings } from '@strato-admin/core';
|
|
5
9
|
import { useCollection } from '../collection-hooks';
|
|
10
|
+
import { useSchemaFields } from '../hooks/useSchemaFields';
|
|
6
11
|
import KeyValuePairs from '../detail/KeyValuePairs';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
import TableHeader from './TableHeader';
|
|
13
|
+
export const ListCards = ({ renderItem, include, exclude, children, title, description, actions, selectionType, filtering = true, filteringPlaceholder, pageSizeOptions, preferences = true, ...props }) => {
|
|
14
|
+
const translate = useTranslate();
|
|
15
|
+
const { listPageSizes, listPageSizeLabel } = useSettings();
|
|
16
|
+
const resolvedPageSizeOptions = pageSizeOptions ??
|
|
17
|
+
(listPageSizes && listPageSizeLabel
|
|
18
|
+
? listPageSizes.map((value) => ({ value, label: listPageSizeLabel(value) }))
|
|
19
|
+
: undefined);
|
|
20
|
+
const translateLabel = useTranslateLabel();
|
|
21
|
+
const { resource, label: schemaLabel, definition } = useResourceSchema();
|
|
22
|
+
const { getListFields } = useSchemaFields();
|
|
23
|
+
const finalSelectionType = selectionType ?? (definition?.options?.canDelete ? 'multi' : undefined);
|
|
24
|
+
const finalChildren = React.useMemo(() => getListFields(children, { include, exclude }), [getListFields, children, include, exclude]);
|
|
25
|
+
const visibleContentOptions = React.useMemo(() => {
|
|
26
|
+
const options = [];
|
|
27
|
+
finalChildren.forEach((child, index) => {
|
|
28
|
+
if (!React.isValidElement(child))
|
|
29
|
+
return;
|
|
30
|
+
const { source, label } = child.props;
|
|
31
|
+
const headerLabel = translateLabel({ label, resource, source });
|
|
32
|
+
if (typeof headerLabel === 'string') {
|
|
33
|
+
options.push({
|
|
34
|
+
id: source || `section-${index}`,
|
|
35
|
+
label: headerLabel,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return options;
|
|
40
|
+
}, [finalChildren, resource, translateLabel]);
|
|
41
|
+
const { items, paginationProps, collectionProps, filterProps, preferencesProps } = useCollection({
|
|
42
|
+
preferences: {
|
|
43
|
+
pageSizeOptions: resolvedPageSizeOptions,
|
|
44
|
+
visibleContentOptions: visibleContentOptions.length > 0 ? visibleContentOptions : undefined,
|
|
45
|
+
},
|
|
12
46
|
});
|
|
13
|
-
const
|
|
14
|
-
|
|
47
|
+
const displayedChildren = React.useMemo(() => {
|
|
48
|
+
const { visibleContent } = preferencesProps.preferences;
|
|
49
|
+
if (!visibleContent)
|
|
50
|
+
return finalChildren;
|
|
51
|
+
return finalChildren.filter((child) => {
|
|
52
|
+
if (!React.isValidElement(child))
|
|
53
|
+
return true;
|
|
54
|
+
const { source } = child.props;
|
|
55
|
+
// If the child doesn't have a source, we don't know how to toggle it, so we keep it.
|
|
56
|
+
if (!source)
|
|
57
|
+
return true;
|
|
58
|
+
// If it's not in the options, it's not toggleable, so we keep it.
|
|
59
|
+
if (!visibleContentOptions.some((opt) => opt.id === source))
|
|
60
|
+
return true;
|
|
61
|
+
return visibleContent.includes(source);
|
|
62
|
+
});
|
|
63
|
+
}, [finalChildren, preferencesProps.preferences.visibleContent, visibleContentOptions]);
|
|
64
|
+
const defaultRenderItem = (_item) => _jsx(KeyValuePairs, { children: displayedChildren });
|
|
15
65
|
const finalRenderItem = renderItem || defaultRenderItem;
|
|
16
66
|
const cardDefinition = {
|
|
17
67
|
sections: [
|
|
18
68
|
{
|
|
19
69
|
id: 'main',
|
|
20
|
-
content: (item) => _jsx(RecordContextProvider, { value: item, children: finalRenderItem(item) }),
|
|
70
|
+
content: (item) => (_jsx(RecordContextProvider, { value: item, children: finalRenderItem(item) })),
|
|
21
71
|
},
|
|
22
72
|
],
|
|
23
73
|
};
|
|
24
|
-
|
|
74
|
+
const cardsHeader = React.useMemo(() => {
|
|
75
|
+
if (React.isValidElement(title)) {
|
|
76
|
+
return title;
|
|
77
|
+
}
|
|
78
|
+
const finalTitle = title !== undefined ? title : schemaLabel;
|
|
79
|
+
return _jsx(TableHeader, { title: finalTitle, description: description, actions: actions });
|
|
80
|
+
}, [title, description, actions, schemaLabel]);
|
|
81
|
+
return (_jsx(CloudscapeCards, { ...collectionProps, ...props, items: items || [], cardDefinition: cardDefinition, pagination: _jsx(Pagination, { ...paginationProps }), header: cardsHeader, selectionType: finalSelectionType, filter: filtering && _jsx(TextFilter, { ...filterProps, filteringPlaceholder: filteringPlaceholder }), preferences: preferences === true || resolvedPageSizeOptions ? (_jsx(CollectionPreferences, { ...preferencesProps, pageSizePreference: resolvedPageSizeOptions
|
|
82
|
+
? {
|
|
83
|
+
options: resolvedPageSizeOptions,
|
|
84
|
+
}
|
|
85
|
+
: undefined, visibleContentPreference: visibleContentOptions.length > 0
|
|
86
|
+
? {
|
|
87
|
+
title: translate('strato.action.select_sections', { _: 'Select visible sections' }),
|
|
88
|
+
options: [
|
|
89
|
+
{
|
|
90
|
+
label: translate('strato.action.select_sections', { _: 'Select visible sections' }),
|
|
91
|
+
options: visibleContentOptions,
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
}
|
|
95
|
+
: undefined })) : React.isValidElement(preferences) ? (preferences) : undefined }));
|
|
25
96
|
};
|
|
26
97
|
export const Cards = ListCards;
|
|
27
98
|
export default ListCards;
|
package/dist/list/List.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { type RaRecord } from '@strato-admin/core';
|
|
3
|
-
export interface ListProps<
|
|
2
|
+
import { type RaRecord, type ListBaseProps } from '@strato-admin/ra-core';
|
|
3
|
+
export interface ListProps<RecordType extends RaRecord = any> extends ListBaseProps<RecordType> {
|
|
4
4
|
children?: React.ReactNode;
|
|
5
|
-
fieldSchema?: React.ReactNode;
|
|
6
5
|
include?: string[];
|
|
7
6
|
exclude?: string[];
|
|
8
|
-
title?: React.ReactNode;
|
|
7
|
+
title?: React.ReactNode | (() => React.ReactNode);
|
|
8
|
+
description?: React.ReactNode | (() => React.ReactNode);
|
|
9
9
|
actions?: React.ReactNode;
|
|
10
10
|
/**
|
|
11
11
|
* Whether to enable text filtering in the implicit Table.
|
|
@@ -17,7 +17,10 @@ export interface ListProps<_RecordType extends RaRecord = any> {
|
|
|
17
17
|
* @default true
|
|
18
18
|
*/
|
|
19
19
|
preferences?: boolean | React.ReactNode;
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* The fields to display by default.
|
|
22
|
+
*/
|
|
23
|
+
display?: string[];
|
|
21
24
|
}
|
|
22
25
|
/**
|
|
23
26
|
* A List component that provides a list context and a Cloudscape Table.
|
|
@@ -32,12 +35,6 @@ export interface ListProps<_RecordType extends RaRecord = any> {
|
|
|
32
35
|
* @example
|
|
33
36
|
* // Using FieldSchema from context
|
|
34
37
|
* <List include={['name', 'price']} />
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* // Passing a custom field schema
|
|
38
|
-
* <List fieldSchema={<FieldSchema>...</FieldSchema>}>
|
|
39
|
-
* <Table />
|
|
40
|
-
* </List>
|
|
41
38
|
*/
|
|
42
|
-
export declare const List: <RecordType extends RaRecord = any>({ children,
|
|
39
|
+
export declare const List: <RecordType extends RaRecord = any>({ children, include, exclude, title, actions, description, filtering, preferences, display, ...props }: ListProps<RecordType>) => import("react/jsx-runtime").JSX.Element;
|
|
43
40
|
export default List;
|
package/dist/list/List.js
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ListBase, useTranslate } from '@strato-admin/ra-core';
|
|
4
|
+
import { ResourceSchemaProvider, useResourceSchema, useConstructedPageTitle, useSettings } from '@strato-admin/core';
|
|
3
5
|
import Table from './Table';
|
|
6
|
+
const ListUI = ({ children, title, actions, description, include, exclude, filtering, preferences, display, }) => {
|
|
7
|
+
const { label, listTitle, listDescription, listComponent: ListComponent = Table } = useResourceSchema();
|
|
8
|
+
const translate = useTranslate();
|
|
9
|
+
const constructedTitle = useConstructedPageTitle('list', label);
|
|
10
|
+
const finalTitle = React.useMemo(() => {
|
|
11
|
+
if (typeof title === 'function')
|
|
12
|
+
return title();
|
|
13
|
+
if (React.isValidElement(title))
|
|
14
|
+
return title;
|
|
15
|
+
if (title)
|
|
16
|
+
return translate(title);
|
|
17
|
+
if (React.isValidElement(listTitle))
|
|
18
|
+
return listTitle;
|
|
19
|
+
if (listTitle)
|
|
20
|
+
return translate(listTitle);
|
|
21
|
+
return constructedTitle;
|
|
22
|
+
}, [title, listTitle, translate, constructedTitle]);
|
|
23
|
+
const finalDescription = React.useMemo(() => {
|
|
24
|
+
if (typeof description === 'function')
|
|
25
|
+
return description();
|
|
26
|
+
if (React.isValidElement(description))
|
|
27
|
+
return description;
|
|
28
|
+
if (description)
|
|
29
|
+
return translate(description);
|
|
30
|
+
if (React.isValidElement(listDescription))
|
|
31
|
+
return listDescription;
|
|
32
|
+
if (listDescription)
|
|
33
|
+
return translate(listDescription);
|
|
34
|
+
return undefined;
|
|
35
|
+
}, [description, listDescription, translate]);
|
|
36
|
+
const finalChildren = children || (_jsx(ListComponent, { include: include, exclude: exclude, display: display, title: finalTitle, description: finalDescription, actions: actions, filtering: filtering, preferences: preferences }));
|
|
37
|
+
return _jsx(_Fragment, { children: finalChildren });
|
|
38
|
+
};
|
|
4
39
|
/**
|
|
5
40
|
* A List component that provides a list context and a Cloudscape Table.
|
|
6
41
|
*
|
|
@@ -14,15 +49,10 @@ import Table from './Table';
|
|
|
14
49
|
* @example
|
|
15
50
|
* // Using FieldSchema from context
|
|
16
51
|
* <List include={['name', 'price']} />
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* // Passing a custom field schema
|
|
20
|
-
* <List fieldSchema={<FieldSchema>...</FieldSchema>}>
|
|
21
|
-
* <Table />
|
|
22
|
-
* </List>
|
|
23
52
|
*/
|
|
24
|
-
export const List = ({ children,
|
|
25
|
-
const
|
|
26
|
-
|
|
53
|
+
export const List = ({ children, include, exclude, title, actions, description, filtering = true, preferences = true, display, ...props }) => {
|
|
54
|
+
const { queryOptions } = useResourceSchema(props.resource);
|
|
55
|
+
const { listPageSize } = useSettings();
|
|
56
|
+
return (_jsx(ListBase, { queryOptions: queryOptions, ...props, perPage: props.perPage ?? listPageSize, children: _jsx(ResourceSchemaProvider, { resource: props.resource, children: _jsx(ListUI, { title: title, actions: actions, description: description, include: include, exclude: exclude, filtering: filtering, preferences: preferences, display: display, children: children }) }) }));
|
|
27
57
|
};
|
|
28
58
|
export default List;
|
package/dist/list/Table.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TableProps as CloudscapeTableProps } from '@cloudscape-design/components/table';
|
|
3
|
-
import { RaRecord } from '@strato-admin/core';
|
|
3
|
+
import { RaRecord } from '@strato-admin/ra-core';
|
|
4
4
|
import { type RecordLinkType } from '../RecordLink';
|
|
5
5
|
export type CloudscapeColumnDefinitionProps = Partial<Omit<CloudscapeTableProps.ColumnDefinition<any>, 'id' | 'header' | 'cell' | 'sortingField'>>;
|
|
6
6
|
export interface ColumnProps extends CloudscapeColumnDefinitionProps {
|
|
@@ -38,6 +38,10 @@ export interface TableProps<RecordType extends RaRecord = any> extends Partial<O
|
|
|
38
38
|
* The title content of the table. Can be a string or a React node.
|
|
39
39
|
*/
|
|
40
40
|
title?: React.ReactNode;
|
|
41
|
+
/**
|
|
42
|
+
* The description content of the table.
|
|
43
|
+
*/
|
|
44
|
+
description?: React.ReactNode;
|
|
41
45
|
/**
|
|
42
46
|
* Actions to display in the table header, typically a button group.
|
|
43
47
|
*/
|
|
@@ -86,7 +90,7 @@ export interface TableProps<RecordType extends RaRecord = any> extends Partial<O
|
|
|
86
90
|
* Can be an array of field sources/IDs.
|
|
87
91
|
* If not specified, the first 5 fields will be shown.
|
|
88
92
|
*/
|
|
89
|
-
|
|
93
|
+
display?: string[];
|
|
90
94
|
}
|
|
91
95
|
/**
|
|
92
96
|
* The Table component provides a declarative way to build data tables with Cloudscape components
|
|
@@ -101,12 +105,12 @@ export interface TableProps<RecordType extends RaRecord = any> extends Partial<O
|
|
|
101
105
|
* ```
|
|
102
106
|
*/
|
|
103
107
|
export declare const Table: {
|
|
104
|
-
<RecordType extends RaRecord = any>({ title, actions, children, include, exclude, filtering, filteringPlaceholder, pageSizeOptions, preferences, reorderable,
|
|
108
|
+
<RecordType extends RaRecord = any>({ title, description, actions, children, include, exclude, filtering, filteringPlaceholder, pageSizeOptions, preferences, reorderable, display, selectionType, pagination, ...props }: TableProps<RecordType>): import("react/jsx-runtime").JSX.Element;
|
|
105
109
|
Column: ({ children, source, link, field: FieldComponent }: ColumnProps) => import("react/jsx-runtime").JSX.Element;
|
|
106
110
|
NumberColumn: ({ children, source, link, field: FieldComponent }: NumberColumnProps) => import("react/jsx-runtime").JSX.Element;
|
|
107
111
|
DateColumn: ({ children, source, link, field: FieldComponent }: DateColumnProps) => import("react/jsx-runtime").JSX.Element;
|
|
108
112
|
BooleanColumn: ({ children, source, field: FieldComponent }: BooleanColumnProps) => import("react/jsx-runtime").JSX.Element;
|
|
109
113
|
ReferenceColumn: ({ children, source, reference, link, field: FieldComponent }: ReferenceColumnProps) => import("react/jsx-runtime").JSX.Element;
|
|
110
|
-
Header: ({ title, actions,
|
|
114
|
+
Header: ({ title, actions, description, counter, info, variant, headingTagOverride }: import("./TableHeader").TableHeaderProps) => import("react/jsx-runtime").JSX.Element;
|
|
111
115
|
};
|
|
112
116
|
export default Table;
|
package/dist/list/Table.js
CHANGED
|
@@ -5,8 +5,10 @@ import Pagination from '@cloudscape-design/components/pagination';
|
|
|
5
5
|
import Box from '@cloudscape-design/components/box';
|
|
6
6
|
import TextFilter from '@cloudscape-design/components/text-filter';
|
|
7
7
|
import CollectionPreferences from '@cloudscape-design/components/collection-preferences';
|
|
8
|
-
import { RecordContextProvider,
|
|
8
|
+
import { RecordContextProvider, useTranslateLabel, useTranslate } from '@strato-admin/ra-core';
|
|
9
|
+
import { useResourceSchema, useSettings } from '@strato-admin/core';
|
|
9
10
|
import { useCollection } from '../collection-hooks';
|
|
11
|
+
import { useSchemaFields } from '../hooks/useSchemaFields';
|
|
10
12
|
import TextField from '../field/TextField';
|
|
11
13
|
import NumberField from '../field/NumberField';
|
|
12
14
|
import DateField from '../field/DateField';
|
|
@@ -57,12 +59,6 @@ export const ReferenceColumn = ({ children, source, reference, link, field: Fiel
|
|
|
57
59
|
}
|
|
58
60
|
return (_jsx(ReferenceField, { reference: reference, link: link, source: source, children: children }));
|
|
59
61
|
};
|
|
60
|
-
const defaultPageSizeOptions = [
|
|
61
|
-
{ value: 10, label: '10 items' },
|
|
62
|
-
{ value: 25, label: '25 items' },
|
|
63
|
-
{ value: 50, label: '50 items' },
|
|
64
|
-
{ value: 100, label: '100 items' },
|
|
65
|
-
];
|
|
66
62
|
/**
|
|
67
63
|
* The Table component provides a declarative way to build data tables with Cloudscape components
|
|
68
64
|
* while integrating with React Admin's data fetching and state management.
|
|
@@ -75,24 +71,22 @@ const defaultPageSizeOptions = [
|
|
|
75
71
|
* </Table>
|
|
76
72
|
* ```
|
|
77
73
|
*/
|
|
78
|
-
export const Table = ({ title, actions, children, include, exclude, filtering = true, filteringPlaceholder, pageSizeOptions
|
|
79
|
-
const resource = useResourceContext();
|
|
74
|
+
export const Table = ({ title, description, actions, children, include, exclude, filtering = true, filteringPlaceholder, pageSizeOptions, preferences = true, reorderable = true, display, selectionType, pagination = true, ...props }) => {
|
|
80
75
|
const translate = useTranslate();
|
|
76
|
+
const { listPageSizes, listPageSizeLabel } = useSettings();
|
|
77
|
+
const resolvedPageSizeOptions = pageSizeOptions ??
|
|
78
|
+
(listPageSizes && listPageSizeLabel
|
|
79
|
+
? listPageSizes.map((value) => ({
|
|
80
|
+
value,
|
|
81
|
+
label: listPageSizeLabel(value),
|
|
82
|
+
}))
|
|
83
|
+
: undefined);
|
|
81
84
|
const translateLabel = useTranslateLabel();
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const finalSelectionType = selectionType ?? (
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
let result = React.Children.toArray(baseChildren);
|
|
88
|
-
if (include) {
|
|
89
|
-
result = result.filter((child) => React.isValidElement(child) && include.includes(child.props.source));
|
|
90
|
-
}
|
|
91
|
-
else if (exclude) {
|
|
92
|
-
result = result.filter((child) => React.isValidElement(child) && !exclude.includes(child.props.source));
|
|
93
|
-
}
|
|
94
|
-
return result;
|
|
95
|
-
}, [children, schemaChildren, include, exclude]);
|
|
85
|
+
const { resource, definition, label: schemaLabel, listDisplay } = useResourceSchema();
|
|
86
|
+
const { getListFields } = useSchemaFields();
|
|
87
|
+
const finalSelectionType = selectionType ?? (definition?.options?.canDelete ? 'multi' : undefined);
|
|
88
|
+
const finalDisplay = display || listDisplay;
|
|
89
|
+
const finalChildren = React.useMemo(() => getListFields(children, { include, exclude }), [getListFields, children, include, exclude]);
|
|
96
90
|
// 1. Extract columns and options before calling useCollection
|
|
97
91
|
const extractedColumns = React.useMemo(() => {
|
|
98
92
|
const columns = [];
|
|
@@ -130,19 +124,18 @@ export const Table = ({ title, actions, children, include, exclude, filtering =
|
|
|
130
124
|
const defaultVisibleContent = React.useMemo(() => {
|
|
131
125
|
if (extractedColumns.options.length === 0)
|
|
132
126
|
return undefined;
|
|
133
|
-
if (
|
|
127
|
+
if (finalDisplay) {
|
|
134
128
|
// Map user-provided fields to their actual IDs
|
|
135
129
|
return extractedColumns.options
|
|
136
130
|
.filter((opt) => {
|
|
137
131
|
const column = extractedColumns.columns.find((c) => c.id === opt.id);
|
|
138
|
-
return
|
|
139
|
-
(column?.sortingField && defaultVisibleFields.includes(column.sortingField)));
|
|
132
|
+
return finalDisplay.includes(opt.id) || (column?.sortingField && finalDisplay.includes(column.sortingField));
|
|
140
133
|
})
|
|
141
134
|
.map((opt) => opt.id);
|
|
142
135
|
}
|
|
143
136
|
// Default to first 5 toggleable columns
|
|
144
137
|
return extractedColumns.options.slice(0, 5).map((opt) => opt.id);
|
|
145
|
-
}, [extractedColumns,
|
|
138
|
+
}, [extractedColumns, finalDisplay]);
|
|
146
139
|
const defaultContentDisplay = React.useMemo(() => {
|
|
147
140
|
if (extractedColumns.options.length === 0)
|
|
148
141
|
return undefined;
|
|
@@ -153,11 +146,8 @@ export const Table = ({ title, actions, children, include, exclude, filtering =
|
|
|
153
146
|
}));
|
|
154
147
|
}, [extractedColumns.options, defaultVisibleContent]);
|
|
155
148
|
const { items, paginationProps, collectionProps, filterProps, preferencesProps } = useCollection({
|
|
156
|
-
filtering: {},
|
|
157
|
-
pagination: {},
|
|
158
|
-
sorting: {},
|
|
159
149
|
preferences: {
|
|
160
|
-
pageSizeOptions,
|
|
150
|
+
pageSizeOptions: resolvedPageSizeOptions,
|
|
161
151
|
visibleContentOptions: !reorderable && extractedColumns.options.length > 0 ? extractedColumns.options : undefined,
|
|
162
152
|
contentDisplayOptions: reorderable && extractedColumns.options.length > 0 ? extractedColumns.options : undefined,
|
|
163
153
|
visibleContent: defaultVisibleContent,
|
|
@@ -177,7 +167,6 @@ export const Table = ({ title, actions, children, include, exclude, filtering =
|
|
|
177
167
|
return preferencesProps.preferences.visibleContent?.includes(col.id);
|
|
178
168
|
});
|
|
179
169
|
}, [extractedColumns.columns, extractedColumns.options, preferencesProps.preferences.visibleContent, reorderable]);
|
|
180
|
-
const getResourceLabel = useGetResourceLabel();
|
|
181
170
|
const tableHeader = React.useMemo(() => {
|
|
182
171
|
if (title === null || title === false) {
|
|
183
172
|
return undefined;
|
|
@@ -185,29 +174,40 @@ export const Table = ({ title, actions, children, include, exclude, filtering =
|
|
|
185
174
|
if (React.isValidElement(title)) {
|
|
186
175
|
return title;
|
|
187
176
|
}
|
|
188
|
-
const finalTitle = title !== undefined ? title :
|
|
189
|
-
return _jsx(TableHeader, { title: finalTitle, actions: actions });
|
|
190
|
-
}, [title,
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
177
|
+
const finalTitle = title !== undefined ? title : schemaLabel;
|
|
178
|
+
return _jsx(TableHeader, { title: finalTitle, description: description, actions: actions });
|
|
179
|
+
}, [title, description, actions, schemaLabel]);
|
|
180
|
+
const finalPreferences = React.useMemo(() => {
|
|
181
|
+
if (preferences === false)
|
|
182
|
+
return undefined;
|
|
183
|
+
if (React.isValidElement(preferences))
|
|
184
|
+
return preferences;
|
|
185
|
+
// preferences is true or an object, or we have pageSizeOptions
|
|
186
|
+
if (preferences === true || resolvedPageSizeOptions) {
|
|
187
|
+
return (_jsx(CollectionPreferences, { ...preferencesProps, pageSizePreference: resolvedPageSizeOptions
|
|
188
|
+
? {
|
|
189
|
+
options: resolvedPageSizeOptions,
|
|
190
|
+
}
|
|
191
|
+
: undefined, visibleContentPreference: !reorderable && extractedColumns.options.length > 0
|
|
192
|
+
? {
|
|
193
|
+
title: translate('strato.action.select_columns', { _: 'Select visible columns' }),
|
|
194
|
+
options: [
|
|
195
|
+
{
|
|
196
|
+
label: translate('strato.action.select_columns', { _: 'Select visible columns' }),
|
|
197
|
+
options: extractedColumns.options,
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
}
|
|
201
|
+
: undefined, contentDisplayPreference: reorderable && extractedColumns.options.length > 0
|
|
202
|
+
? {
|
|
203
|
+
title: translate('strato.action.select_columns', { _: 'Select visible columns' }),
|
|
204
|
+
options: extractedColumns.options,
|
|
205
|
+
}
|
|
206
|
+
: undefined }));
|
|
207
|
+
}
|
|
208
|
+
return undefined;
|
|
209
|
+
}, [preferences, resolvedPageSizeOptions, preferencesProps, reorderable, extractedColumns.options, translate]);
|
|
210
|
+
return (_jsx(CloudscapeTable, { ...collectionProps, ...props, selectionType: finalSelectionType, stripedRows: preferencesProps.preferences.stripedRows, wrapLines: preferencesProps.preferences.wrapLines, columnDefinitions: columnDefinitions, columnDisplay: reorderable ? preferencesProps.preferences.contentDisplay : undefined, items: items || [], header: tableHeader, filter: filtering && _jsx(TextFilter, { ...filterProps }), pagination: pagination === true ? _jsx(Pagination, { ...paginationProps }) : pagination || undefined, preferences: finalPreferences }));
|
|
211
211
|
};
|
|
212
212
|
Table.Column = Column;
|
|
213
213
|
Table.NumberColumn = NumberColumn;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { HeaderProps } from '@cloudscape-design/components/header';
|
|
3
|
-
export interface TableHeaderProps extends
|
|
3
|
+
export interface TableHeaderProps extends Pick<HeaderProps, 'variant' | 'counter' | 'actions' | 'description' | 'info' | 'headingTagOverride'> {
|
|
4
4
|
title?: React.ReactNode;
|
|
5
5
|
}
|
|
6
|
-
export declare const TableHeader: ({ title, actions,
|
|
6
|
+
export declare const TableHeader: ({ title, actions, description, counter, info, variant, headingTagOverride }: TableHeaderProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
export default TableHeader;
|
package/dist/list/TableHeader.js
CHANGED
|
@@ -2,21 +2,20 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import Header from '@cloudscape-design/components/header';
|
|
4
4
|
import SpaceBetween from '@cloudscape-design/components/space-between';
|
|
5
|
-
import { useListContext, useTranslate, useLocale } from '@strato-admin/core';
|
|
5
|
+
import { useListContext, useTranslate, useLocale } from '@strato-admin/ra-core';
|
|
6
6
|
import { BulkDeleteButton } from '../button/BulkDeleteButton';
|
|
7
7
|
import { CreateButton } from '../button/CreateButton';
|
|
8
|
-
export const TableHeader = ({ title, actions,
|
|
8
|
+
export const TableHeader = ({ title, actions, description, counter, info, variant = 'h2', headingTagOverride }) => {
|
|
9
9
|
const translate = useTranslate();
|
|
10
10
|
const locale = useLocale();
|
|
11
|
-
const {
|
|
11
|
+
const { defaultTitle } = useListContext();
|
|
12
12
|
const headerTitle = React.useMemo(() => {
|
|
13
13
|
if (title !== undefined) {
|
|
14
14
|
return typeof title === 'string' ? translate(title, { _: title }) : title;
|
|
15
15
|
}
|
|
16
16
|
return defaultTitle;
|
|
17
17
|
}, [title, defaultTitle, translate, locale]);
|
|
18
|
-
const counter = props.counter !== undefined ? props.counter : !isPending && total !== undefined ? `(${total})` : undefined;
|
|
19
18
|
const headerActions = actions !== undefined ? (actions) : (_jsxs(SpaceBetween, { direction: "horizontal", size: "xs", children: [_jsx(BulkDeleteButton, {}), _jsx(CreateButton, {})] }));
|
|
20
|
-
return (_jsx(Header, { variant:
|
|
19
|
+
return (_jsx(Header, { variant: variant, actions: headerActions, counter: counter, description: description, info: info, headingTagOverride: headingTagOverride, children: headerTitle }));
|
|
21
20
|
};
|
|
22
21
|
export default TableHeader;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
-
import { useStore } from '@strato-admin/core';
|
|
2
|
+
import { useStore } from '@strato-admin/ra-core';
|
|
3
3
|
import { Mode, applyMode } from '@cloudscape-design/global-styles';
|
|
4
4
|
export const ThemeManager = () => {
|
|
5
5
|
const [theme] = useStore('theme', 'light');
|