@cratis/components 0.1.9 → 0.1.10

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 (101) hide show
  1. package/dist/cjs/PivotViewer/PivotViewer.css +1258 -0
  2. package/dist/cjs/PivotViewer/components/Spinner.css +77 -0
  3. package/dist/cjs/TimeMachine/EventsView.css +213 -0
  4. package/dist/cjs/TimeMachine/TimeMachine.css +567 -0
  5. package/dist/esm/PivotViewer/PivotViewer.css +1258 -0
  6. package/dist/esm/PivotViewer/components/Spinner.css +77 -0
  7. package/dist/esm/TimeMachine/EventsView.css +213 -0
  8. package/dist/esm/TimeMachine/TimeMachine.css +567 -0
  9. package/package.json +3 -4
  10. package/.storybook/main.ts +0 -24
  11. package/CommandDialog/CommandDialog.stories.tsx +0 -25
  12. package/CommandDialog/CommandDialog.tsx +0 -161
  13. package/CommandDialog/index.ts +0 -4
  14. package/CommandForm/CommandForm.stories.tsx +0 -24
  15. package/CommandForm/CommandForm.tsx +0 -266
  16. package/CommandForm/CommandFormField.tsx +0 -27
  17. package/CommandForm/CommandFormFields.tsx +0 -142
  18. package/CommandForm/DatePickerField.tsx +0 -57
  19. package/CommandForm/DropdownField.tsx +0 -65
  20. package/CommandForm/InputTextField.tsx +0 -62
  21. package/CommandForm/SliderField.tsx +0 -68
  22. package/CommandForm/index.ts +0 -10
  23. package/Common/ErrorBoundary.stories.tsx +0 -10
  24. package/Common/ErrorBoundary.tsx +0 -41
  25. package/Common/FormElement.stories.tsx +0 -10
  26. package/Common/FormElement.tsx +0 -20
  27. package/Common/Page.stories.tsx +0 -10
  28. package/Common/Page.tsx +0 -21
  29. package/Common/index.ts +0 -6
  30. package/DataPage/DataPage.stories.tsx +0 -10
  31. package/DataPage/DataPage.tsx +0 -191
  32. package/DataPage/index.ts +0 -4
  33. package/DataTables/DataTableForObservableQuery.stories.tsx +0 -10
  34. package/DataTables/DataTableForObservableQuery.tsx +0 -97
  35. package/DataTables/DataTableForQuery.stories.tsx +0 -10
  36. package/DataTables/DataTableForQuery.tsx +0 -97
  37. package/DataTables/index.ts +0 -5
  38. package/Dialogs/BusyIndicatorDialog.stories.tsx +0 -26
  39. package/Dialogs/BusyIndicatorDialog.tsx +0 -26
  40. package/Dialogs/ConfirmationDialog.stories.tsx +0 -36
  41. package/Dialogs/ConfirmationDialog.tsx +0 -75
  42. package/Dialogs/index.ts +0 -5
  43. package/Dropdown/Dropdown.tsx +0 -23
  44. package/Dropdown/index.ts +0 -4
  45. package/PivotViewer/PivotViewer.stories.tsx +0 -24
  46. package/PivotViewer/PivotViewer.tsx +0 -791
  47. package/PivotViewer/components/AxisLabels.tsx +0 -69
  48. package/PivotViewer/components/DetailPanel.tsx +0 -108
  49. package/PivotViewer/components/FilterPanel.tsx +0 -189
  50. package/PivotViewer/components/FilterPanelContainer.tsx +0 -10
  51. package/PivotViewer/components/PivotCanvas.tsx +0 -660
  52. package/PivotViewer/components/PivotViewerMain.tsx +0 -229
  53. package/PivotViewer/components/RangeHistogramFilter.tsx +0 -220
  54. package/PivotViewer/components/Spinner.tsx +0 -21
  55. package/PivotViewer/components/Toolbar.tsx +0 -130
  56. package/PivotViewer/components/ToolbarContainer.tsx +0 -10
  57. package/PivotViewer/components/index.ts +0 -12
  58. package/PivotViewer/components/pivot/animation.ts +0 -108
  59. package/PivotViewer/components/pivot/buckets.ts +0 -152
  60. package/PivotViewer/components/pivot/colorResolver.ts +0 -67
  61. package/PivotViewer/components/pivot/constants.ts +0 -46
  62. package/PivotViewer/components/pivot/sprites.ts +0 -265
  63. package/PivotViewer/components/pivot/visibility.ts +0 -319
  64. package/PivotViewer/constants.ts +0 -9
  65. package/PivotViewer/engine/layout.ts +0 -149
  66. package/PivotViewer/engine/pivot.worker.ts +0 -86
  67. package/PivotViewer/engine/store.ts +0 -437
  68. package/PivotViewer/engine/types.ts +0 -255
  69. package/PivotViewer/hooks/index.ts +0 -13
  70. package/PivotViewer/hooks/useContainerDimensions.ts +0 -45
  71. package/PivotViewer/hooks/useDimensionState.ts +0 -53
  72. package/PivotViewer/hooks/useFilterOptions.ts +0 -36
  73. package/PivotViewer/hooks/useFilterPanelDrag.ts +0 -49
  74. package/PivotViewer/hooks/useFilterState.ts +0 -106
  75. package/PivotViewer/hooks/useFilteredData.ts +0 -119
  76. package/PivotViewer/hooks/usePanning.ts +0 -163
  77. package/PivotViewer/hooks/usePivotEngine.ts +0 -252
  78. package/PivotViewer/hooks/useSelectedItem.ts +0 -402
  79. package/PivotViewer/hooks/useWheelZoom.ts +0 -114
  80. package/PivotViewer/hooks/useZoomState.ts +0 -34
  81. package/PivotViewer/index.ts +0 -7
  82. package/PivotViewer/types.ts +0 -59
  83. package/PivotViewer/utils/animations.ts +0 -249
  84. package/PivotViewer/utils/constants.ts +0 -20
  85. package/PivotViewer/utils/index.ts +0 -6
  86. package/PivotViewer/utils/selection.ts +0 -292
  87. package/PivotViewer/utils/utils.ts +0 -259
  88. package/TimeMachine/EventsView.stories.tsx +0 -10
  89. package/TimeMachine/EventsView.tsx +0 -119
  90. package/TimeMachine/Properties.stories.tsx +0 -10
  91. package/TimeMachine/Properties.tsx +0 -98
  92. package/TimeMachine/ReadModelView.stories.tsx +0 -10
  93. package/TimeMachine/ReadModelView.tsx +0 -143
  94. package/TimeMachine/TimeMachine.stories.tsx +0 -10
  95. package/TimeMachine/TimeMachine.tsx +0 -244
  96. package/TimeMachine/index.ts +0 -8
  97. package/TimeMachine/types.ts +0 -23
  98. package/global.d.ts +0 -11
  99. package/index.ts +0 -22
  100. package/useOverlayZIndex.ts +0 -32
  101. package/vite.config.ts +0 -80
@@ -1,65 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import { PropertyAccessor } from '@cratis/fundamentals';
5
- import { PropertyDescriptor } from '@cratis/arc/reflection';
6
- import React, { useState, useEffect } from 'react';
7
- import { DropdownChangeEvent } from 'primereact/dropdown';
8
- import { Dropdown } from '../Dropdown';
9
- import { useCommandFormContext } from './CommandForm';
10
-
11
- export interface DropdownFieldProps<TCommand, TOption> {
12
- icon?: React.ReactElement;
13
- value: PropertyAccessor<TCommand>;
14
- options: TOption[];
15
- optionIdField: keyof TOption;
16
- optionLabelField: keyof TOption;
17
- placeholder?: string;
18
- onChange?: (value: unknown) => void;
19
- currentValue?: unknown;
20
- onValueChange?: (value: unknown) => void;
21
- required?: boolean;
22
- title?: string;
23
- description?: string;
24
- propertyDescriptor?: PropertyDescriptor;
25
- fieldName?: string;
26
- }
27
-
28
- export const DropdownField = <TCommand, TOption>(props: DropdownFieldProps<TCommand, TOption>) => {
29
- const [localValue, setLocalValue] = useState(props.currentValue);
30
- const required = props.required ?? true;
31
- const isValid = !required || localValue !== null && localValue !== undefined;
32
- const { setFieldValidity } = useCommandFormContext();
33
-
34
- useEffect(() => {
35
- setLocalValue(props.currentValue);
36
- }, [props.currentValue]);
37
-
38
- useEffect(() => {
39
- if (props.fieldName) {
40
- setFieldValidity(props.fieldName, isValid);
41
- }
42
- }, [isValid, props.fieldName, setFieldValidity]);
43
-
44
- const handleChange = (e: DropdownChangeEvent) => {
45
- const newValue = e.value;
46
- setLocalValue(newValue);
47
- props.onValueChange?.(newValue);
48
- };
49
-
50
- return (
51
- <Dropdown
52
- value={localValue}
53
- onChange={handleChange}
54
- options={props.options}
55
- optionLabel={props.optionLabelField as string}
56
- optionValue={props.optionIdField as string}
57
- placeholder={props.placeholder || props.title}
58
- required={required}
59
- invalid={!isValid}
60
- className="w-full"
61
- />
62
- );
63
- };
64
-
65
- DropdownField.displayName = 'CommandFormField';
@@ -1,62 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import { PropertyAccessor } from '@cratis/fundamentals';
5
- import { PropertyDescriptor } from '@cratis/arc/reflection';
6
- import React, { useState, useEffect } from 'react';
7
- import { InputText } from 'primereact/inputtext';
8
- import { useCommandFormContext } from './CommandForm';
9
-
10
- export interface InputTextFieldProps<TCommand> {
11
- icon?: React.ReactElement;
12
- value: PropertyAccessor<TCommand>;
13
- onChange?: (value: unknown) => void;
14
- currentValue?: string;
15
- onValueChange?: (value: string) => void;
16
- required?: boolean;
17
- title?: string;
18
- description?: string;
19
- propertyDescriptor?: PropertyDescriptor;
20
- fieldName?: string;
21
- }
22
-
23
- export const InputTextField = <TCommand,>(props: InputTextFieldProps<TCommand>) => {
24
- const [localValue, setLocalValue] = useState(props.currentValue || '');
25
- const required = props.required ?? true;
26
- const isValid = !required || localValue.trim().length > 0;
27
- const { setFieldValidity } = useCommandFormContext();
28
-
29
- // Determine input type based on property descriptor
30
- const inputType = props.propertyDescriptor?.type === Number ? 'number' : 'text';
31
-
32
- // Update local value when prop changes from outside
33
- useEffect(() => {
34
- setLocalValue(props.currentValue || '');
35
- }, [props.currentValue]);
36
-
37
- // Report validity changes
38
- useEffect(() => {
39
- if (props.fieldName) {
40
- setFieldValidity(props.fieldName, isValid);
41
- }
42
- }, [isValid, props.fieldName, setFieldValidity]);
43
-
44
- const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
45
- const newValue = e.target.value;
46
- setLocalValue(newValue);
47
- props.onValueChange?.(newValue);
48
- };
49
-
50
- return (
51
- <InputText
52
- type={inputType}
53
- value={localValue}
54
- onChange={handleChange}
55
- required={required}
56
- invalid={!isValid}
57
- placeholder={props.title}
58
- />
59
- );
60
- };
61
-
62
- InputTextField.displayName = 'CommandFormField';
@@ -1,68 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import { PropertyAccessor } from '@cratis/fundamentals';
5
- import { PropertyDescriptor } from '@cratis/arc/reflection';
6
- import React, { useState, useEffect } from 'react';
7
- import { Slider, SliderChangeEvent } from 'primereact/slider';
8
- import { useCommandFormContext } from './CommandForm';
9
-
10
- export interface SliderFieldProps<TCommand> {
11
- icon?: React.ReactElement;
12
- value: PropertyAccessor<TCommand>;
13
- onChange?: (value: unknown) => void;
14
- currentValue?: number;
15
- onValueChange?: (value: number) => void;
16
- required?: boolean;
17
- title?: string;
18
- description?: string;
19
- propertyDescriptor?: PropertyDescriptor;
20
- fieldName?: string;
21
- min?: number;
22
- max?: number;
23
- step?: number;
24
- }
25
-
26
- export const SliderField = <TCommand,>(props: SliderFieldProps<TCommand>) => {
27
- const [localValue, setLocalValue] = useState(props.currentValue ?? 0);
28
- const required = props.required ?? true;
29
- const min = props.min ?? 0;
30
- const max = props.max ?? 1;
31
- const step = props.step ?? 0.01;
32
- const isValid = !required || (localValue >= min && localValue <= max);
33
- const { setFieldValidity } = useCommandFormContext();
34
-
35
- useEffect(() => {
36
- setLocalValue(props.currentValue ?? 0);
37
- }, [props.currentValue]);
38
-
39
- useEffect(() => {
40
- if (props.fieldName) {
41
- setFieldValidity(props.fieldName, isValid);
42
- }
43
- }, [isValid, props.fieldName, setFieldValidity]);
44
-
45
- const handleChange = (e: SliderChangeEvent) => {
46
- const newValue = e.value as number;
47
- setLocalValue(newValue);
48
- props.onValueChange?.(newValue);
49
- };
50
-
51
- return (
52
- <div className="p-inputtext w-full flex align-items-center gap-3" style={{ display: 'flex', alignItems: 'center', borderTopLeftRadius: 0, borderBottomLeftRadius: 0 }}>
53
- <Slider
54
- value={localValue}
55
- onChange={handleChange}
56
- min={min}
57
- max={max}
58
- step={step}
59
- className="flex-1 ml-2"
60
- />
61
- <span className="font-semibold" style={{ minWidth: '3rem', textAlign: 'right' }}>
62
- {localValue.toFixed(2)}
63
- </span>
64
- </div>
65
- );
66
- };
67
-
68
- SliderField.displayName = 'CommandFormField';
@@ -1,10 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- export * from './CommandForm';
5
- export * from './CommandFormField';
6
- export * from './CommandFormFields';
7
- export * from './InputTextField';
8
- export * from './DatePickerField';
9
- export * from './DropdownField';
10
- export * from './SliderField';
@@ -1,10 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import React from 'react';
5
- import * as Comp from './ErrorBoundary';
6
- const Component: React.ComponentType<any> | undefined = (Comp as any).default || (Object.values(Comp)[0] as any);
7
-
8
- export default { title: 'Common/ErrorBoundary', component: Component };
9
-
10
- export const Default = () => (Component ? <Component /> : <div>Unable to render component</div>);
@@ -1,41 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import { Component, ErrorInfo, ReactNode } from 'react';
5
-
6
- interface Props {
7
- children: ReactNode;
8
- }
9
- interface State {
10
- hasError: boolean;
11
- error: Error;
12
- }
13
-
14
- export class ErrorBoundary extends Component<Props, State> {
15
- public state: State = {
16
- hasError: false,
17
- error: new Error(),
18
- };
19
-
20
- public static getDerivedStateFromError(error: Error): State {
21
- return { hasError: true, error: error };
22
- }
23
-
24
- public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
25
- console.error('Uncaught error:', error, errorInfo);
26
- }
27
-
28
- public render() {
29
- if (this.state.hasError) {
30
- return (
31
- <div className='p-4'>
32
- <h1 className='text-3xl m-3'>Error</h1>
33
- <p>{this.state.error.message}</p>
34
- <p>{this.state.error.stack}</p>
35
- </div>
36
- );
37
- }
38
-
39
- return this.props.children;
40
- }
41
- }
@@ -1,10 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import React from 'react';
5
- import * as Comp from './FormElement';
6
- const Component: React.ComponentType<any> | undefined = (Comp as any).default || (Object.values(Comp)[0] as any);
7
-
8
- export default { title: 'Common/FormElement', component: Component };
9
-
10
- export const Default = () => (Component ? <Component /> : <div>Unable to render component</div>);
@@ -1,20 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- export interface FormElementProps {
5
- children: React.ReactNode;
6
- icon: React.ReactNode;
7
- }
8
-
9
- export const FormElement = (props: FormElementProps) => {
10
- return (
11
- <div className="card flex flex-column md:flex-row gap-3">
12
- <div className="p-inputgroup flex-1">
13
- <span className="p-inputgroup-addon">
14
- {props.icon}
15
- </span>
16
- {props.children}
17
- </div>
18
- </div>
19
- );
20
- };
@@ -1,10 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import React from 'react';
5
- import * as Comp from './Page';
6
- const Component: React.ComponentType<any> | undefined = (Comp as any).default || (Object.values(Comp)[0] as any);
7
-
8
- export default { title: 'Common/Page', component: Component };
9
-
10
- export const Default = () => (Component ? <Component /> : <div>Unable to render component</div>);
package/Common/Page.tsx DELETED
@@ -1,21 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import { HTMLAttributes, ReactNode } from 'react';
5
-
6
- export interface PageProps extends HTMLAttributes<HTMLDivElement> {
7
- title: string;
8
- children?: ReactNode;
9
- panel?: boolean
10
- }
11
-
12
- export const Page = ({ title, children, panel, ...rest }: PageProps) => {
13
- return (
14
- <div className='flex flex-col h-full' {...rest}>
15
- <h1 className='text-3xl mt-3 mb-4'>{title}</h1>
16
- <main className={`overflow-hidden h-full flex flex-col flex-1 ${panel ? 'panel' : ''}`}>
17
- {children}
18
- </main>
19
- </div>
20
- );
21
- };
package/Common/index.ts DELETED
@@ -1,6 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- export * from './ErrorBoundary';
5
- export * from './Page';
6
- export * from './FormElement';
@@ -1,10 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import React from 'react';
5
- import * as Comp from './DataPage';
6
- const Component: React.ComponentType<any> | undefined = (Comp as any).default || (Object.values(Comp)[0] as any);
7
-
8
- export default { title: 'DataPage/DataPage', component: Component };
9
-
10
- export const Default = () => (Component ? <Component /> : <div>Unable to render component</div>);
@@ -1,191 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import { ReactNode, useMemo } from 'react';
5
- import { Page } from '../Common/Page';
6
- import React from 'react';
7
- import { MenuItem as PrimeMenuItem } from 'primereact/menuitem';
8
- import { Menubar } from 'primereact/menubar';
9
- import { IObservableQueryFor, IQueryFor, QueryFor } from '@cratis/arc/queries';
10
- import { DataTableForObservableQuery } from '../DataTables/DataTableForObservableQuery';
11
- import { DataTableFilterMeta, DataTableSelectionSingleChangeEvent } from 'primereact/datatable';
12
- import { DataTableForQuery } from '../DataTables/DataTableForQuery';
13
- import { Allotment } from 'allotment';
14
- import { Constructor } from '@cratis/fundamentals';
15
-
16
- /* eslint-disable @typescript-eslint/no-explicit-any */
17
-
18
- export interface MenuItemProps extends PrimeMenuItem {
19
- disableOnUnselected?: boolean;
20
- }
21
-
22
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
23
- export const MenuItem = (_: MenuItemProps) => {
24
- return null;
25
- };
26
-
27
- export interface MenuItemsProps {
28
- children: ReactNode;
29
- }
30
-
31
- export interface ColumnProps {
32
- children: ReactNode;
33
- }
34
-
35
- export const MenuItems = ({ children }: MenuItemsProps) => {
36
- const context = React.useContext(DataPageContext);
37
-
38
- const isDisabled = useMemo(() => {
39
- return !context.selectedItem;
40
- }, [context.selectedItem]);
41
-
42
- const items = useMemo(() => {
43
- const menuItems: PrimeMenuItem[] = [];
44
- React.Children.forEach(children, (child) => {
45
- if (React.isValidElement<MenuItemProps>(child) && child.type == MenuItem) {
46
- const Icon = child.props.icon;
47
- const menuItem = { ...child.props };
48
- menuItem.icon = <Icon className='mr-2' />;
49
- menuItem.disabled = isDisabled && child.props.disableOnUnselected;
50
- menuItems.push(menuItem);
51
- }
52
- });
53
-
54
- return menuItems;
55
- }, [children, context.selectedItem]);
56
-
57
- return (
58
- <div className="px-4 py-2">
59
- <Menubar aria-label="Actions" model={items} />
60
- </div>);
61
- };
62
-
63
- export const Columns = ({ children }: ColumnProps) => {
64
-
65
- const context = React.useContext(DataPageContext);
66
-
67
- if (context.query.prototype instanceof QueryFor) {
68
- return (
69
- <DataTableForQuery {...context} selection={context.selectedItem} onSelectionChange={context.onSelectionChanged}>
70
- {children}
71
- </DataTableForQuery>);
72
-
73
- } else {
74
- return (
75
- <DataTableForObservableQuery {...context} selection={context.selectedItem} onSelectionChange={context.onSelectionChanged}>
76
- {children}
77
- </DataTableForObservableQuery>);
78
- }
79
- };
80
-
81
- export interface IDetailsComponentProps<TDataType> {
82
- item: TDataType;
83
-
84
- }
85
-
86
- interface IDataPageContext extends DataPageProps<any, any, any> {
87
- selectedItem: any;
88
- onSelectionChanged: (e: DataTableSelectionSingleChangeEvent<any>) => void;
89
- }
90
-
91
- const DataPageContext = React.createContext<IDataPageContext>(null as any);
92
-
93
- /**
94
- * Props for the DataPage component
95
- */
96
- export interface DataPageProps<TQuery extends IQueryFor<TDataType> | IObservableQueryFor<TDataType>, TDataType, TArguments> {
97
- /**
98
- * The title of the page
99
- */
100
- title: string;
101
-
102
- /**
103
- * Children to render, for this it means menu items and columns. Use <DataPage.MenuItems> and <DataPage.Columns> for this.
104
- */
105
- children: ReactNode;
106
-
107
- /**
108
- * Component to render when the selection changes
109
- */
110
- detailsComponent?: React.FC<IDetailsComponentProps<any>>;
111
-
112
- /**
113
- * The type of query to use
114
- */
115
- query: Constructor<TQuery>;
116
-
117
- /**
118
- * Optional arguments to pass to the query
119
- */
120
- queryArguments?: TArguments;
121
-
122
- /**
123
- * The message to show when there is no data
124
- */
125
- emptyMessage: string;
126
-
127
- /**
128
- * The key to use for the data
129
- */
130
- dataKey?: string | undefined;
131
-
132
- /**
133
- * The current selection.
134
- */
135
- selection?: any | undefined | null;
136
-
137
- /**
138
- * Callback for when the selection changes
139
- */
140
- onSelectionChange?(event: DataTableSelectionSingleChangeEvent<any>): void;
141
-
142
- /**
143
- * Fields to use for global filtering
144
- */
145
- globalFilterFields?: string[] | undefined;
146
-
147
- /**
148
- * Default filters to use
149
- */
150
- defaultFilters?: DataTableFilterMeta;
151
- }
152
-
153
- /**
154
- * Represents a data driven page with a menu and custom defined columns for the data table.
155
- * @param props Props for the DataPage component
156
- * @returns Function to render the DataPage component
157
- */
158
- const DataPage = <TQuery extends IQueryFor<TDataType> | IObservableQueryFor<TDataType, TArguments>, TDataType, TArguments extends object>(props: DataPageProps<TQuery, TDataType, TArguments>) => {
159
- const [selectedItem, setSelectedItem] = React.useState(undefined);
160
-
161
- const selectionChanged = (e: DataTableSelectionSingleChangeEvent<any>) => {
162
- setSelectedItem(e.value);
163
- if (props.onSelectionChange) {
164
- props.onSelectionChange(e);
165
- }
166
- };
167
-
168
- const context = { ...props, selectedItem, onSelectionChanged: selectionChanged };
169
-
170
- return (
171
- <DataPageContext.Provider value={context}>
172
- <Page title={props.title} panel={true}>
173
- <Allotment className="h-full" proportionalLayout={false}>
174
- <Allotment.Pane className="flex-grow">
175
- {props.children}
176
- </Allotment.Pane>
177
- {props.detailsComponent && selectedItem &&
178
- <Allotment.Pane preferredSize="450px">
179
- <props.detailsComponent item={selectedItem} />
180
- </Allotment.Pane>
181
- }
182
- </Allotment>
183
- </Page>
184
- </DataPageContext.Provider>
185
- );
186
- };
187
-
188
- DataPage.MenuItems = MenuItems;
189
- DataPage.Columns = Columns;
190
-
191
- export { DataPage };
package/DataPage/index.ts DELETED
@@ -1,4 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- export * from './DataPage';
@@ -1,10 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import React from 'react';
5
- import * as Comp from './DataTableForObservableQuery';
6
- const Component: React.ComponentType<any> | undefined = (Comp as any).default || (Object.values(Comp)[0] as any);
7
-
8
- export default { title: 'DataTables/DataTableForObservableQuery', component: Component };
9
-
10
- export const Default = () => (Component ? <Component /> : <div>Unable to render component</div>);
@@ -1,97 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import { DataTable, DataTableFilterMeta, DataTableSelectionSingleChangeEvent } from 'primereact/datatable';
5
- import { Constructor } from '@cratis/fundamentals';
6
- import { IObservableQueryFor, Paging } from '@cratis/arc/queries';
7
- import { useObservableQueryWithPaging } from '@cratis/arc.react/queries';
8
- import { ReactNode, useState } from 'react';
9
-
10
-
11
-
12
- /**
13
- * Props for the DataTableForQuery component
14
- */
15
- export interface DataTableForObservableQueryProps<TQuery extends IObservableQueryFor<TDataType>, TDataType, TArguments> {
16
- /**
17
- * Children to render
18
- */
19
- children?: ReactNode;
20
-
21
- /**
22
- * The type of query to use
23
- */
24
- query: Constructor<TQuery>;
25
-
26
- /**
27
- * Optional arguments to pass to the query
28
- */
29
- queryArguments?: TArguments;
30
-
31
- /**
32
- * The message to show when there is no data
33
- */
34
- emptyMessage: string;
35
-
36
- /**
37
- * The key to use for the data
38
- */
39
- dataKey?: string | undefined;
40
-
41
- /**
42
- * The current selection.
43
- */
44
- selection?: any | undefined | null;
45
-
46
- /**
47
- * Callback for when the selection changes
48
- */
49
- onSelectionChange?(event: DataTableSelectionSingleChangeEvent<any>): void;
50
-
51
- /**
52
- * Fields to use for global filtering
53
- */
54
- globalFilterFields?: string[] | undefined;
55
-
56
- /**
57
- * Default filters to use
58
- */
59
- defaultFilters?: DataTableFilterMeta;
60
- }
61
-
62
- const paging = new Paging(0, 20);
63
-
64
- /**
65
- * Represents a DataTable for a query.
66
- * @param props Props for the component
67
- * @returns Function to render the DataTableForQuery component
68
- */
69
- export const DataTableForObservableQuery = <TQuery extends IObservableQueryFor<TDataType, TArguments>, TDataType, TArguments extends object>(props: DataTableForObservableQueryProps<TQuery, TDataType, TArguments>) => {
70
- const [filters, setFilters] = useState<DataTableFilterMeta>(props.defaultFilters ?? {});
71
- const [result, , setPage] = useObservableQueryWithPaging(props.query, paging, props.queryArguments);
72
-
73
- return (
74
- <DataTable
75
- value={result.data}
76
- lazy
77
- rows={paging.pageSize}
78
- totalRecords={result.paging.totalItems}
79
- paginator
80
- alwaysShowPaginator={false}
81
- first={result.paging.page * paging.pageSize}
82
- onPage={(e) => setPage(e.page ?? 0)}
83
- scrollable
84
- scrollHeight={'flex'}
85
- selectionMode='single'
86
- selection={props.selection}
87
- onSelectionChange={props.onSelectionChange}
88
- dataKey={props.dataKey}
89
- filters={filters}
90
- filterDisplay='menu'
91
- onFilter={(e) => setFilters(e.filters)}
92
- globalFilterFields={props.globalFilterFields}
93
- emptyMessage={props.emptyMessage}>
94
- {props.children}
95
- </DataTable>
96
- );
97
- };
@@ -1,10 +0,0 @@
1
- // Copyright (c) Cratis. All rights reserved.
2
- // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
-
4
- import React from 'react';
5
- import * as Comp from './DataTableForQuery';
6
- const Component: React.ComponentType<any> | undefined = (Comp as any).default || (Object.values(Comp)[0] as any);
7
-
8
- export default { title: 'DataTables/DataTableForQuery', component: Component };
9
-
10
- export const Default = () => (Component ? <Component /> : <div>Unable to render component</div>);