Skip to content

Commit 6bdd659

Browse files
committed
chore: update changelog
1 parent fa440fb commit 6bdd659

File tree

6 files changed

+39
-2
lines changed

6 files changed

+39
-2
lines changed

packages/pluggableWidgets/datagrid-web/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
99
### Added
1010

1111
- We added configurable selection count visibility and clear selection button label template for improved row selection management.
12+
- We added the possiblity to configure the first row of a DataGrid to be auto-selected on first load, facilitating master-detail views.
13+
14+
### Fixed
1215

1316
- We fixed an issue where missing consistency checks for the captions were causing runtime errors instead of in Studio Pro
1417

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ function hideSelectionProperties(defaultProperties: Properties, values: Datagrid
165165
hidePropertyIn(defaultProperties, values, "itemSelectionMode");
166166
}
167167

168+
if (itemSelection !== "Single") {
169+
hidePropertyIn(defaultProperties, values, "selectFirstRow");
170+
}
171+
168172
if (itemSelection !== "Multi" || itemSelectionMethod !== "checkbox") {
169173
hidePropertyIn(defaultProperties, values, "showSelectAllToggle");
170174
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ const Container = observer((props: Props): ReactElement => {
3838
props.itemSelection,
3939
props.datasource,
4040
props.onSelectionChange,
41-
props.keepSelection ? "always keep" : "always clear"
41+
props.keepSelection || props.selectFirstRow ? "always keep" : "always clear",
42+
props.selectFirstRow
4243
);
4344

4445
const selectActionHelper = useSelectActionHelper(props, selectionHelper);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
<enumerationValue key="rowClick">Row click</enumerationValue>
3838
</enumerationValues>
3939
</property>
40+
<property key="selectFirstRow" type="boolean" defaultValue="false">
41+
<caption>Auto select first row</caption>
42+
<description>Automatically select the first row</description>
43+
</property>
4044
<property key="itemSelectionMode" type="enumeration" defaultValue="clear">
4145
<caption>Toggle on click</caption>
4246
<description>Defines item selection behavior.</description>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export interface DatagridContainerProps {
9595
refreshInterval: number;
9696
itemSelection?: SelectionSingleValue | SelectionMultiValue;
9797
itemSelectionMethod: ItemSelectionMethodEnum;
98+
selectFirstRow: boolean;
9899
itemSelectionMode: ItemSelectionModeEnum;
99100
showSelectAllToggle: boolean;
100101
keepSelection: boolean;
@@ -149,6 +150,7 @@ export interface DatagridPreviewProps {
149150
refreshInterval: number | null;
150151
itemSelection: "None" | "Single" | "Multi";
151152
itemSelectionMethod: ItemSelectionMethodEnum;
153+
selectFirstRow: boolean;
152154
itemSelectionMode: ItemSelectionModeEnum;
153155
showSelectAllToggle: boolean;
154156
keepSelection: boolean;

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,17 +343,40 @@ export function useSelectionHelper(
343343
selection: SelectionSingleValue | SelectionMultiValue | undefined,
344344
dataSource: ListValue,
345345
onSelectionChange: ActionValue | undefined,
346-
keepSelection: Parameters<typeof selectionStateHandler>[0]
346+
keepSelection: Parameters<typeof selectionStateHandler>[0],
347+
selectFirstRow?: boolean
347348
): SelectionHelper | undefined {
348349
const prevObjectListRef = useRef<ObjectItem[]>([]);
349350
const firstLoadDone = useRef(false);
351+
const hasAutoSelected = useRef(false);
350352
useState(() => {
351353
if (selection) {
352354
selection.setKeepSelection(selectionStateHandler(keepSelection));
353355
}
354356
});
355357
firstLoadDone.current ||= dataSource?.status !== "loading";
356358

359+
useEffect(() => {
360+
if (
361+
selectFirstRow &&
362+
dataSource.status === "available" &&
363+
dataSource.items &&
364+
dataSource.items.length > 0 &&
365+
selection &&
366+
selection.type === "Single" &&
367+
!selection.selection &&
368+
!hasAutoSelected.current
369+
) {
370+
setTimeout(() => {
371+
if (!selection.selection) {
372+
const firstItem = dataSource.items![0];
373+
selection.setSelection(firstItem);
374+
hasAutoSelected.current = true;
375+
}
376+
}, 100);
377+
}
378+
}, [dataSource.status, dataSource.items, selectFirstRow, selection]);
379+
357380
useEffect(() => {
358381
const prevObjectList = prevObjectListRef.current;
359382
const current = selection?.selection ?? [];

0 commit comments

Comments
 (0)