Skip to content

Commit 4edabc4

Browse files
committed
refactor: improve naming and autoselect logic, update config position
1 parent 4301865 commit 4edabc4

File tree

6 files changed

+39
-15
lines changed

6 files changed

+39
-15
lines changed

packages/pluggableWidgets/datagrid-web/src/Datagrid.editorConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function hideSelectionProperties(defaultProperties: Properties, values: Datagrid
143143
}
144144

145145
if (itemSelection !== "Single") {
146-
hidePropertyIn(defaultProperties, values, "selectFirstRow");
146+
hidePropertyIn(defaultProperties, values, "autoSelect");
147147
}
148148

149149
if (itemSelection !== "Multi" || itemSelectionMethod !== "checkbox") {

packages/pluggableWidgets/datagrid-web/src/Datagrid.xml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<enumerationValue key="rowClick">Row click</enumerationValue>
3434
</enumerationValues>
3535
</property>
36-
<property key="selectFirstRow" type="boolean" defaultValue="false">
36+
<property key="autoSelect" type="boolean" defaultValue="false">
3737
<caption>Auto select first row</caption>
3838
<description>Automatically select the first row</description>
3939
</property>
@@ -53,15 +53,6 @@
5353
<caption>Keep selection</caption>
5454
<description>If enabled, selected items will stay selected unless cleared by the user or a Nanoflow.</description>
5555
</property>
56-
<property key="selectionCountPosition" type="enumeration" defaultValue="bottom" required="true">
57-
<caption>Show selection count</caption>
58-
<description />
59-
<enumerationValues>
60-
<enumerationValue key="top">Top</enumerationValue>
61-
<enumerationValue key="bottom">Bottom</enumerationValue>
62-
<enumerationValue key="off">Off</enumerationValue>
63-
</enumerationValues>
64-
</property>
6556
<property key="clearSelectionButtonLabel" type="textTemplate" required="false">
6657
<caption>Clear selection label</caption>
6758
<description>Customize the label of the 'Clear section' button</description>

packages/pluggableWidgets/datagrid-web/src/model/configs/Datagrid.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface DatagridConfig {
1919
settingsStorageEnabled: boolean;
2020
enableSelectAll: boolean;
2121
keepSelection: boolean;
22+
autoSelect: boolean;
2223
pagingPosition: PagingPositionEnum;
2324
multiselectable: true | undefined;
2425
loadingType: LoadingTypeEnum;
@@ -48,6 +49,7 @@ export function datagridConfig(props: DatagridContainerProps): DatagridConfig {
4849
settingsStorageEnabled: isSettingsStorageEnabled(props),
4950
enableSelectAll: props.enableSelectAll,
5051
keepSelection: props.keepSelection,
52+
autoSelect: props.autoSelect,
5153
pagingPosition: props.pagingPosition,
5254
multiselectable: isMultiselectable(props),
5355
loadingType: props.loadingType,

packages/pluggableWidgets/datagrid-web/src/utils/test-utils.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export function mockContainerProps(overrides?: Partial<DatagridContainerProps>):
6464
columnsResizable: true,
6565
columns: [column("Col1"), column("Col2")],
6666
itemSelectionMethod: "checkbox",
67+
autoSelect: false,
6768
itemSelectionMode: "clear",
6869
enableSelectAll: false,
6970
keepSelection: false,

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import { ComponentType, CSSProperties, ReactNode } from "react";
77
import { ActionValue, DynamicValue, EditableValue, ListValue, ListActionValue, ListAttributeValue, ListAttributeListValue, ListExpressionValue, ListWidgetValue, SelectionSingleValue, SelectionMultiValue } from "mendix";
88
import { Big } from "big.js";
99

10+
export type ItemSelectionMethodEnum = "checkbox" | "rowClick";
11+
12+
export type ItemSelectionModeEnum = "toggle" | "clear";
13+
14+
export type LoadingTypeEnum = "spinner" | "skeleton";
15+
1016
export type ShowContentAsEnum = "attribute" | "dynamicText" | "customContent";
1117

1218
export type ExportTypeEnum = "default" | "number" | "date" | "boolean";
@@ -100,6 +106,15 @@ export interface DatagridContainerProps {
100106
tabIndex?: number;
101107
datasource: ListValue;
102108
refreshInterval: number;
109+
itemSelection?: SelectionSingleValue | SelectionMultiValue;
110+
itemSelectionMethod: ItemSelectionMethodEnum;
111+
autoSelect: boolean;
112+
itemSelectionMode: ItemSelectionModeEnum;
113+
showSelectAllToggle: boolean;
114+
keepSelection: boolean;
115+
clearSelectionButtonLabel?: DynamicValue<string>;
116+
loadingType: LoadingTypeEnum;
117+
refreshIndicator: boolean;
103118
columns: ColumnsType[];
104119
columnsFilterable: boolean;
105120
onClickTrigger: OnClickTriggerEnum;
@@ -108,7 +123,6 @@ export interface DatagridContainerProps {
108123
filtersPlaceholder?: ReactNode;
109124
itemSelection?: SelectionSingleValue | SelectionMultiValue;
110125
itemSelectionMethod: ItemSelectionMethodEnum;
111-
selectFirstRow: boolean;
112126
itemSelectionMode: ItemSelectionModeEnum;
113127
showSelectAllToggle: boolean;
114128
enableSelectAll: boolean;
@@ -160,6 +174,15 @@ export interface DatagridPreviewProps {
160174
translate: (text: string) => string;
161175
datasource: {} | { caption: string } | { type: string } | null;
162176
refreshInterval: number | null;
177+
itemSelection: "None" | "Single" | "Multi";
178+
itemSelectionMethod: ItemSelectionMethodEnum;
179+
autoSelect: boolean;
180+
itemSelectionMode: ItemSelectionModeEnum;
181+
showSelectAllToggle: boolean;
182+
keepSelection: boolean;
183+
clearSelectionButtonLabel: string;
184+
loadingType: LoadingTypeEnum;
185+
refreshIndicator: boolean;
163186
columns: ColumnsPreviewType[];
164187
columnsFilterable: boolean;
165188
onClickTrigger: OnClickTriggerEnum;
@@ -168,7 +191,6 @@ export interface DatagridPreviewProps {
168191
filtersPlaceholder: { widgetCount: number; renderer: ComponentType<{ children: ReactNode; caption?: string }> };
169192
itemSelection: "None" | "Single" | "Multi";
170193
itemSelectionMethod: ItemSelectionMethodEnum;
171-
selectFirstRow: boolean;
172194
itemSelectionMode: ItemSelectionModeEnum;
173195
showSelectAllToggle: boolean;
174196
enableSelectAll: boolean;

packages/shared/widget-plugin-grid/src/selection/createSelectionHelper.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { MultiSelectionHelper, SingleSelectionHelper } from "./helpers";
99
export function createSelectionHelper(
1010
host: SetupComponentHost,
1111
gate: DerivedPropsGate<SelectionDynamicProps>,
12-
config: { keepSelection: boolean } = { keepSelection: false }
12+
config: { keepSelection: boolean; autoSelect: boolean } = { keepSelection: false, autoSelect: false }
1313
): SelectionHelperService {
1414
const { selection, datasource } = gate.props;
1515

@@ -58,7 +58,15 @@ export function createSelectionHelper(
5858
);
5959
add(cleanup);
6060
}
61-
61+
if (helper.type === "Single" && config.autoSelect) {
62+
const dispose = autorun(() => {
63+
const firstItem = gate.props.datasource.items?.[0];
64+
if (!firstItem) return;
65+
helper.reduceTo(firstItem);
66+
dispose();
67+
});
68+
add(dispose);
69+
}
6270
return disposeAll;
6371
}
6472

0 commit comments

Comments
 (0)