Skip to content

Commit 4301865

Browse files
committed
chore: update changelog
1 parent e3a73dd commit 4301865

File tree

5 files changed

+98
-1
lines changed

5 files changed

+98
-1
lines changed

packages/pluggableWidgets/datagrid-web/CHANGELOG.md

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

1717
- We added configurable selection count visibility and clear selection button label template for improved row selection management.
18+
- We added the possiblity to configure the first row of a DataGrid to be auto-selected on first load, facilitating master-detail views.
19+
20+
### Fixed
1821

1922
### Fixed
2023

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

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

145+
if (itemSelection !== "Single") {
146+
hidePropertyIn(defaultProperties, values, "selectFirstRow");
147+
}
148+
145149
if (itemSelection !== "Multi" || itemSelectionMethod !== "checkbox") {
146150
hidePropertyIn(defaultProperties, values, "showSelectAllToggle");
147151
}

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,71 @@
1616
<caption>Refresh time (in seconds)</caption>
1717
<description />
1818
</property>
19+
<property key="itemSelection" type="selection" dataSource="datasource">
20+
<caption>Selection</caption>
21+
<description />
22+
<selectionTypes>
23+
<selectionType name="None" />
24+
<selectionType name="Single" />
25+
<selectionType name="Multi" />
26+
</selectionTypes>
27+
</property>
28+
<property key="itemSelectionMethod" type="enumeration" defaultValue="checkbox">
29+
<caption>Selection method</caption>
30+
<description />
31+
<enumerationValues>
32+
<enumerationValue key="checkbox">Checkbox</enumerationValue>
33+
<enumerationValue key="rowClick">Row click</enumerationValue>
34+
</enumerationValues>
35+
</property>
36+
<property key="selectFirstRow" type="boolean" defaultValue="false">
37+
<caption>Auto select first row</caption>
38+
<description>Automatically select the first row</description>
39+
</property>
40+
<property key="itemSelectionMode" type="enumeration" defaultValue="clear">
41+
<caption>Toggle on click</caption>
42+
<description>Defines item selection behavior.</description>
43+
<enumerationValues>
44+
<enumerationValue key="toggle">Yes</enumerationValue>
45+
<enumerationValue key="clear">No</enumerationValue>
46+
</enumerationValues>
47+
</property>
48+
<property key="showSelectAllToggle" type="boolean" defaultValue="true">
49+
<caption>Show (un)check all toggle</caption>
50+
<description>Show a checkbox in the grid header to check or uncheck multiple items.</description>
51+
</property>
52+
<property key="keepSelection" type="boolean" defaultValue="false">
53+
<caption>Keep selection</caption>
54+
<description>If enabled, selected items will stay selected unless cleared by the user or a Nanoflow.</description>
55+
</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>
65+
<property key="clearSelectionButtonLabel" type="textTemplate" required="false">
66+
<caption>Clear selection label</caption>
67+
<description>Customize the label of the 'Clear section' button</description>
68+
<translations>
69+
<translation lang="en_US">Clear selection</translation>
70+
</translations>
71+
</property>
72+
<property key="loadingType" type="enumeration" defaultValue="spinner" required="true">
73+
<caption>Loading type</caption>
74+
<description />
75+
<enumerationValues>
76+
<enumerationValue key="spinner">Spinner</enumerationValue>
77+
<enumerationValue key="skeleton">Skeleton</enumerationValue>
78+
</enumerationValues>
79+
</property>
80+
<property key="refreshIndicator" type="boolean" defaultValue="false">
81+
<caption>Show refresh indicator</caption>
82+
<description>Show a refresh indicator when the data is being loaded.</description>
83+
</property>
1984
</propertyGroup>
2085
<propertyGroup caption="Columns">
2186
<property key="columns" type="object" isList="true">

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export interface DatagridContainerProps {
108108
filtersPlaceholder?: ReactNode;
109109
itemSelection?: SelectionSingleValue | SelectionMultiValue;
110110
itemSelectionMethod: ItemSelectionMethodEnum;
111+
selectFirstRow: boolean;
111112
itemSelectionMode: ItemSelectionModeEnum;
112113
showSelectAllToggle: boolean;
113114
enableSelectAll: boolean;
@@ -167,6 +168,7 @@ export interface DatagridPreviewProps {
167168
filtersPlaceholder: { widgetCount: number; renderer: ComponentType<{ children: ReactNode; caption?: string }> };
168169
itemSelection: "None" | "Single" | "Multi";
169170
itemSelectionMethod: ItemSelectionMethodEnum;
171+
selectFirstRow: boolean;
170172
itemSelectionMode: ItemSelectionModeEnum;
171173
showSelectAllToggle: boolean;
172174
enableSelectAll: boolean;

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,40 @@ export function useSelectionHelper(
346346
selection: SelectionSingleValue | SelectionMultiValue | undefined,
347347
dataSource: ListValue,
348348
onSelectionChange: ActionValue | undefined,
349-
keepSelection: Parameters<typeof selectionStateHandler>[0]
349+
keepSelection: Parameters<typeof selectionStateHandler>[0],
350+
selectFirstRow?: boolean
350351
): SelectionHelper | undefined {
351352
const prevObjectListRef = useRef<ObjectItem[]>([]);
352353
const firstLoadDone = useRef(false);
354+
const hasAutoSelected = useRef(false);
353355
useState(() => {
354356
if (selection) {
355357
selection.setKeepSelection(selectionStateHandler(keepSelection));
356358
}
357359
});
358360
firstLoadDone.current ||= dataSource?.status !== "loading";
359361

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

0 commit comments

Comments
 (0)