Skip to content

Commit cce5535

Browse files
committed
feat: add spd vm
1 parent b2c9f9a commit cce5535

File tree

7 files changed

+86
-68
lines changed

7 files changed

+86
-68
lines changed

packages/pluggableWidgets/datagrid-web/src/components/SelectAllBar.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@ import { createElement } from "react";
44
import { useDatagridRootScope } from "../helpers/root-context";
55

66
export const SelectAllBar = observer(function SelectAllBar(): React.ReactNode {
7-
const { selectAllBarViewModel } = useDatagridRootScope();
8-
const { barVisible, selectionCountText, clearVisible, clearSelectionLabel, selectAllVisible, selectAllLabel } =
9-
selectAllBarViewModel;
7+
const { selectAllBarViewModel: vm } = useDatagridRootScope();
108

11-
if (!barVisible) return null;
9+
if (!vm.barVisible) return null;
1210

1311
return (
1412
<div className="widget-datagrid-select-all-bar">
15-
{selectionCountText}&nbsp;
16-
<If condition={selectAllVisible}>
17-
<button className="btn" onClick={() => selectAllBarViewModel.onSelectAll()}>
18-
{selectAllLabel}
13+
{vm.selectionCountText}&nbsp;
14+
<If condition={vm.selectAllVisible}>
15+
<button className="btn" onClick={() => vm.onSelectAll()}>
16+
{vm.selectAllLabel}
1917
</button>
2018
</If>
21-
<If condition={clearVisible}>
22-
<button className="btn" onClick={() => selectAllBarViewModel.onClear()}>
23-
{clearSelectionLabel}
19+
<If condition={vm.clearVisible}>
20+
<button className="btn" onClick={() => vm.onClear()}>
21+
{vm.clearSelectionLabel}
2422
</button>
2523
</If>
2624
</div>

packages/pluggableWidgets/datagrid-web/src/components/SelectionProgressDialog.tsx

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
11
import { createElement, ReactElement } from "react";
2-
import { PseudoModal } from "./PseudoModal";
2+
import { useDatagridRootScope } from "../helpers/root-context";
33
import { ExportAlert } from "./ExportAlert";
4+
import { PseudoModal } from "./PseudoModal";
45

5-
export type SelectionProgressDialogProps = {
6-
open: boolean;
7-
selectingLabel: string;
8-
cancelLabel: string;
9-
onCancel: () => void;
10-
progress: number;
11-
total: number;
12-
};
13-
14-
export function SelectionProgressDialog({
15-
open,
16-
selectingLabel,
17-
cancelLabel,
18-
onCancel,
19-
progress,
20-
total
21-
}: SelectionProgressDialogProps): ReactElement | null {
22-
if (!open) return null;
6+
export function SelectionProgressDialog(): ReactElement | null {
7+
const { selectionProgressDialogViewModel: vm } = useDatagridRootScope();
8+
if (!vm.open) return null;
239
return (
2410
<PseudoModal>
2511
<ExportAlert
26-
alertLabel={selectingLabel}
27-
cancelLabel={cancelLabel}
12+
alertLabel={vm.selectingAllLabel}
13+
cancelLabel={vm.cancelSelectionLabel}
2814
failed={false}
29-
onCancel={onCancel}
30-
progress={progress}
31-
total={total}
15+
onCancel={() => vm.onCancel()}
16+
progress={vm.progress}
17+
total={vm.total}
3218
/>
3319
</PseudoModal>
3420
);

packages/pluggableWidgets/datagrid-web/src/components/Widget.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export interface WidgetProps<C extends GridColumn, T extends ObjectItem = Object
8282

8383
export const Widget = observer(<C extends GridColumn>(props: WidgetProps<C>): ReactElement => {
8484
const { className, exporting, numberOfItems, onExportCancel, selectActionHelper } = props;
85-
const { basicData, selectAllProgressStore, selectAllController } = useDatagridRootScope();
85+
const { basicData, selectAllProgressStore } = useDatagridRootScope();
8686

8787
const selectionEnabled = selectActionHelper.selectionType !== "None";
8888

@@ -96,14 +96,7 @@ export const Widget = observer(<C extends GridColumn>(props: WidgetProps<C>): Re
9696
selectingAllPages={selectAllProgressStore.inProgress}
9797
>
9898
<Main {...props} data={exporting ? [] : props.data} />
99-
<SelectionProgressDialog
100-
open={selectAllProgressStore.inProgress}
101-
selectingLabel={basicData.selectingAllLabel ?? "Selecting all items..."}
102-
cancelLabel={basicData.cancelSelectionLabel ?? "Cancel selection"}
103-
onCancel={() => selectAllController.abort()}
104-
progress={selectAllProgressStore.loaded}
105-
total={selectAllProgressStore.total}
106-
/>
99+
<SelectionProgressDialog />
107100
{exporting && (
108101
<ExportWidget
109102
alertLabel={basicData.exportDialogLabel ?? "Export progress"}

packages/pluggableWidgets/datagrid-web/src/helpers/root-context.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { FocusTargetController } from "@mendix/widget-plugin-grid/keyboard-navigation/FocusTargetController";
2-
import { SelectAllController, SelectionHelper } from "@mendix/widget-plugin-grid/selection";
2+
import { SelectionHelper } from "@mendix/widget-plugin-grid/selection";
33
import { ProgressStore } from "@mendix/widget-plugin-grid/stores/ProgressStore";
44
import { SelectionCountStore } from "@mendix/widget-plugin-grid/stores/SelectionCountStore";
55
import { createContext, useContext } from "react";
66
import { GridBasicData } from "../helpers/state/GridBasicData";
77
import { EventsController } from "../typings/CellComponent";
88
import { SelectActionHelper } from "./SelectActionHelper";
99
import { SelectAllBarViewModel } from "./state/SelectAllBarViewModel";
10+
import { SelectionProgressDialogViewModel } from "./state/SelectionProgressDialogViewModel";
1011

1112
export interface DatagridRootScope {
1213
basicData: GridBasicData;
@@ -15,11 +16,11 @@ export interface DatagridRootScope {
1516
selectActionHelper: SelectActionHelper;
1617
cellEventsController: EventsController;
1718
checkboxEventsController: EventsController;
18-
selectAllController: SelectAllController;
1919
focusController: FocusTargetController;
2020
selectionCountStore: SelectionCountStore;
2121
selectAllProgressStore: ProgressStore;
2222
selectAllBarViewModel: SelectAllBarViewModel;
23+
selectionProgressDialogViewModel: SelectionProgressDialogViewModel;
2324
}
2425

2526
export const DatagridContext = createContext<DatagridRootScope | null>(null);

packages/pluggableWidgets/datagrid-web/src/helpers/state/GridBasicData.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,7 @@ import { DatagridContainerProps } from "../../../typings/DatagridProps";
55

66
type Props = Pick<
77
DatagridContainerProps,
8-
| "exportDialogLabel"
9-
| "cancelExportLabel"
10-
| "selectRowLabel"
11-
| "selectAllRowsLabel"
12-
| "itemSelection"
13-
| "onClick"
14-
| "selectingAllLabel"
15-
| "cancelSelectionLabel"
16-
| "selectAllTemplate"
17-
| "selectRemainingTemplate"
18-
| "clearSelectionCaption"
8+
"exportDialogLabel" | "cancelExportLabel" | "selectRowLabel" | "selectAllRowsLabel" | "itemSelection" | "onClick"
199
>;
2010

2111
type Gate = DerivedPropsGate<Props>;
@@ -50,14 +40,6 @@ export class GridBasicData {
5040
return this.gate.props.selectAllRowsLabel?.value;
5141
}
5242

53-
get selectingAllLabel(): string | undefined {
54-
return this.gate.props.selectingAllLabel?.value;
55-
}
56-
57-
get cancelSelectionLabel(): string | undefined {
58-
return this.gate.props.cancelSelectionLabel?.value;
59-
}
60-
6143
get gridInteractive(): boolean {
6244
return !!(this.gate.props.itemSelection || this.gate.props.onClick);
6345
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { SelectAllController } from "@mendix/widget-plugin-grid/selection";
2+
import { ProgressStore } from "@mendix/widget-plugin-grid/stores/ProgressStore";
3+
import { DerivedPropsGate } from "@mendix/widget-plugin-mobx-kit/props-gate";
4+
import { DynamicValue } from "mendix";
5+
import { makeAutoObservable } from "mobx";
6+
7+
type Gate = DerivedPropsGate<{
8+
selectingAllLabel?: DynamicValue<string>;
9+
cancelSelectionLabel?: DynamicValue<string>;
10+
}>;
11+
12+
export class SelectionProgressDialogViewModel {
13+
constructor(
14+
private gate: Gate,
15+
private progressStore: ProgressStore,
16+
private selectAllController: SelectAllController
17+
) {
18+
makeAutoObservable(this);
19+
}
20+
21+
get open(): boolean {
22+
return this.progressStore.inProgress;
23+
}
24+
25+
get progress(): number {
26+
return this.progressStore.loaded;
27+
}
28+
29+
get total(): number {
30+
return this.progressStore.total;
31+
}
32+
33+
get selectingAllLabel(): string {
34+
return this.gate.props.selectingAllLabel?.value ?? "Selecting all items...";
35+
}
36+
37+
get cancelSelectionLabel(): string {
38+
return this.gate.props.cancelSelectionLabel?.value ?? "Cancel selection";
39+
}
40+
41+
onCancel(): void {
42+
this.selectAllController.abort();
43+
}
44+
}

packages/pluggableWidgets/datagrid-web/typings/DatagridProps.d.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@
33
* WARNING: All changes made to this file will be overwritten
44
* @author Mendix Widgets Framework Team
55
*/
6-
import { ComponentType, CSSProperties, ReactNode } from "react";
7-
import { ActionValue, DynamicValue, EditableValue, ListValue, ListActionValue, ListAttributeValue, ListAttributeListValue, ListExpressionValue, ListWidgetValue, SelectionSingleValue, SelectionMultiValue } from "mendix";
86
import { Big } from "big.js";
7+
import {
8+
ActionValue,
9+
DynamicValue,
10+
EditableValue,
11+
ListActionValue,
12+
ListAttributeListValue,
13+
ListAttributeValue,
14+
ListExpressionValue,
15+
ListValue,
16+
ListWidgetValue,
17+
SelectionMultiValue,
18+
SelectionSingleValue
19+
} from "mendix";
20+
import { ComponentType, CSSProperties, ReactNode } from "react";
921

1022
export type ShowContentAsEnum = "attribute" | "dynamicText" | "customContent";
1123

@@ -19,7 +31,9 @@ export type AlignmentEnum = "left" | "center" | "right";
1931

2032
export interface ColumnsType {
2133
showContentAs: ShowContentAsEnum;
22-
attribute?: ListAttributeValue<string | Big | boolean | Date> | ListAttributeListValue<string | Big | boolean | Date>;
34+
attribute?:
35+
| ListAttributeValue<string | Big | boolean | Date>
36+
| ListAttributeListValue<string | Big | boolean | Date>;
2337
content?: ListWidgetValue;
2438
dynamicText?: ListExpressionValue<string>;
2539
exportValue?: ListExpressionValue<string>;

0 commit comments

Comments
 (0)