Skip to content

Commit 2318f04

Browse files
committed
feat: add selection count visibility to config
1 parent 5d1d596 commit 2318f04

File tree

7 files changed

+80
-58
lines changed

7 files changed

+80
-58
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ const Container = observer((props: Props): ReactElement => {
118118
paginationType={props.pagination}
119119
loadMoreButtonCaption={props.loadMoreButtonCaption?.value}
120120
clearSelectionButtonLabel={props.clearSelectionButtonLabel?.value}
121+
selectionCountVisibility={props.selectionCountVisibility}
121122
paging={paginationCtrl.showPagination}
122123
pagingPosition={props.pagingPosition}
123124
showPagingButtons={props.showPagingButtons}

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@
6565
<caption>Show refresh indicator</caption>
6666
<description>Show a refresh indicator when the data is being loaded.</description>
6767
</property>
68-
<property key="clearSelectionButtonLabel" type="textTemplate" required="false">
69-
<caption>Clear selection</caption>
70-
<description>Customize the label of the 'Clear section' button</description>
71-
<translations>
72-
<translation lang="en_US">Clear selection</translation>
73-
</translations>
74-
</property>
7568
</propertyGroup>
7669
<propertyGroup caption="Columns">
7770
<property key="columns" type="object" isList="true">
@@ -251,6 +244,22 @@
251244
<enumerationValue key="both">Both</enumerationValue>
252245
</enumerationValues>
253246
</property>
247+
<property key="selectionCountVisibility" type="enumeration" defaultValue="bottom" required="true">
248+
<caption>Show selection count</caption>
249+
<description />
250+
<enumerationValues>
251+
<enumerationValue key="top">Top</enumerationValue>
252+
<enumerationValue key="bottom">Bottom</enumerationValue>
253+
<enumerationValue key="off">Off</enumerationValue>
254+
</enumerationValues>
255+
</property>
256+
<property key="clearSelectionButtonLabel" type="textTemplate" required="false">
257+
<caption>Clear selection label</caption>
258+
<description>Customize the label of the 'Clear section' button</description>
259+
<translations>
260+
<translation lang="en_US">Clear selection</translation>
261+
</translations>
262+
</property>
254263
<property key="loadMoreButtonCaption" type="textTemplate" required="false">
255264
<caption>Load more caption</caption>
256265
<description />
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { If } from "@mendix/widget-plugin-component-kit/If";
2+
import { observer } from "mobx-react-lite";
3+
import { createElement } from "react";
4+
import { useDatagridRootScope } from "../helpers/root-context";
5+
6+
export const SelectionCounter = observer(function SelectionCounter({
7+
clearSelectionButtonLabel
8+
}: {
9+
clearSelectionButtonLabel?: string;
10+
}) {
11+
const { selectionCountStore, selectActionHelper } = useDatagridRootScope();
12+
13+
return (
14+
<If condition={selectionCountStore.displayCount !== ""}>
15+
<span className="widget-datagrid-selection-count">{selectionCountStore.displayCount}</span>&nbsp;|&nbsp;
16+
<button className="widget-datagrid-clear-selection" onClick={selectActionHelper.onClearSelection}>
17+
{clearSelectionButtonLabel || "Clear selection"}
18+
</button>
19+
</If>
20+
);
21+
});

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
LoadingTypeEnum,
1010
PaginationEnum,
1111
PagingPositionEnum,
12-
ShowPagingButtonsEnum
12+
ShowPagingButtonsEnum,
13+
SelectionCountVisibilityEnum
1314
} from "../../typings/DatagridProps";
1415
import { SelectActionHelper } from "../helpers/SelectActionHelper";
1516
import { useDatagridRootScope } from "../helpers/root-context";
@@ -49,6 +50,7 @@ export interface WidgetProps<C extends GridColumn, T extends ObjectItem = Object
4950
paginationType: PaginationEnum;
5051
loadMoreButtonCaption?: string;
5152
clearSelectionButtonLabel?: string;
53+
selectionCountVisibility?: SelectionCountVisibilityEnum;
5254
pageSize: number;
5355
paging: boolean;
5456
pagingPosition: PagingPositionEnum;
@@ -120,6 +122,7 @@ const Main = observer(<C extends GridColumn>(props: WidgetProps<C>): ReactElemen
120122
headerTitle,
121123
loadMoreButtonCaption,
122124
clearSelectionButtonLabel,
125+
selectionCountVisibility,
123126
numberOfItems,
124127
page,
125128
pageSize,
@@ -162,7 +165,14 @@ const Main = observer(<C extends GridColumn>(props: WidgetProps<C>): ReactElemen
162165

163166
return (
164167
<Fragment>
165-
{showTopBar && <WidgetTopBar>{pagination}</WidgetTopBar>}
168+
{showTopBar && (
169+
<WidgetTopBar
170+
selectionCountVisibility={selectionCountVisibility}
171+
clearSelectionButtonLabel={clearSelectionButtonLabel}
172+
>
173+
{pagination}
174+
</WidgetTopBar>
175+
)}
166176
{showHeader && <WidgetHeader headerTitle={headerTitle}>{headerContent}</WidgetHeader>}
167177
<WidgetContent>
168178
<Grid
@@ -238,6 +248,7 @@ const Main = observer(<C extends GridColumn>(props: WidgetProps<C>): ReactElemen
238248
paginationType={paginationType}
239249
loadMoreButtonCaption={loadMoreButtonCaption}
240250
clearSelectionButtonLabel={clearSelectionButtonLabel}
251+
selectionCountVisibility={selectionCountVisibility}
241252
hasMoreItems={hasMoreItems}
242253
setPage={setPage}
243254
/>
Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,35 @@
1-
import { If } from "@mendix/widget-plugin-component-kit/If";
2-
import { observer } from "mobx-react-lite";
3-
import { JSX, ReactElement, ReactNode } from "react";
4-
import { PaginationEnum, PagingPositionEnum } from "../../typings/DatagridProps";
5-
import { useDatagridRootScope } from "../helpers/root-context";
1+
import { ReactElement, ReactNode } from "react";
2+
import { PaginationEnum } from "../../typings/DatagridProps";
63

74
type WidgetFooterProps = {
8-
pagingPosition: PagingPositionEnum;
95
pagination: ReactNode;
6+
selectionCount: ReactNode;
107
paginationType: PaginationEnum;
118
loadMoreButtonCaption?: string;
12-
clearSelectionButtonLabel?: string;
139
hasMoreItems: boolean;
1410
setPage?: (computePage: (prevPage: number) => number) => void;
1511
} & JSX.IntrinsicElements["div"];
1612

1713
export function WidgetFooter(props: WidgetFooterProps): ReactElement | null {
18-
const {
19-
pagingPosition,
20-
pagination,
21-
paginationType,
22-
loadMoreButtonCaption,
23-
clearSelectionButtonLabel,
24-
hasMoreItems,
25-
setPage,
26-
...rest
27-
} = props;
14+
const { pagination, selectionCount, paginationType, loadMoreButtonCaption, hasMoreItems, setPage, ...rest } = props;
2815

2916
return (
3017
<div {...rest} className="widget-datagrid-footer table-footer">
3118
<div className="widget-datagrid-paging-bottom">
32-
<div className="widget-datagrid-pb-start">
33-
<SelectionCounter clearSelectionButtonLabel={clearSelectionButtonLabel} />
34-
</div>
35-
{hasMoreItems && paginationType === "loadMore" && (
36-
<div className="widget-datagrid-pb-middle">
19+
{selectionCount}
20+
<div className="widget-datagrid-pb-end">
21+
{pagination}
22+
{hasMoreItems && paginationType === "loadMore" && (
3723
<button
3824
className="btn btn-primary widget-datagrid-load-more"
3925
onClick={() => setPage && setPage(prev => prev + 1)}
4026
tabIndex={0}
4127
>
4228
{loadMoreButtonCaption}
4329
</button>
44-
</div>
45-
)}
46-
<div className="widget-datagrid-pb-end">
47-
{(pagingPosition === "bottom" || pagingPosition === "both") && pagination}
30+
)}
4831
</div>
4932
</div>
5033
</div>
5134
);
5235
}
53-
54-
const SelectionCounter = observer(function SelectionCounter({
55-
clearSelectionButtonLabel
56-
}: {
57-
clearSelectionButtonLabel?: string;
58-
}) {
59-
const { selectionCountStore, selectActionHelper } = useDatagridRootScope();
60-
61-
return (
62-
<If condition={selectionCountStore.displayCount !== ""}>
63-
<span className="widget-datagrid-selection-count">{selectionCountStore.displayCount}</span>&nbsp;|&nbsp;
64-
<button className="widget-datagrid-clear-selection" onClick={selectActionHelper.onClearSelection}>
65-
{clearSelectionButtonLabel || "Clear selection"}
66-
</button>
67-
</If>
68-
);
69-
});
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
import { JSX, ReactElement } from "react";
1+
import { ReactElement, ReactNode } from "react";
2+
3+
type WidgetTopBarProps = {
4+
pagination: ReactNode;
5+
selectionCount: ReactNode;
6+
} & JSX.IntrinsicElements["div"];
7+
8+
export function WidgetTopBar(props: WidgetTopBarProps): ReactElement {
9+
const { pagination, selectionCount, ...rest } = props;
210

3-
export function WidgetTopBar(props: JSX.IntrinsicElements["div"]): ReactElement {
411
return (
5-
<div {...props} className="widget-datagrid-top-bar table-header">
6-
{props.children}
12+
<div {...rest} className="widget-datagrid-top-bar table-header">
13+
<div className="widget-datagrid-padding-top">
14+
{selectionCount}
15+
{pagination && <div className="widget-datagrid-tb-end">{pagination}</div>}
16+
</div>
717
</div>
818
);
919
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export type ShowPagingButtonsEnum = "always" | "auto";
5353

5454
export type PagingPositionEnum = "bottom" | "top" | "both";
5555

56+
export type SelectionCountVisibilityEnum = "top" | "bottom" | "off";
57+
5658
export type ShowEmptyPlaceholderEnum = "none" | "custom";
5759

5860
export type OnClickTriggerEnum = "single" | "double";
@@ -98,14 +100,15 @@ export interface DatagridContainerProps {
98100
keepSelection: boolean;
99101
loadingType: LoadingTypeEnum;
100102
refreshIndicator: boolean;
101-
clearSelectionButtonLabel?: DynamicValue<string>;
102103
columns: ColumnsType[];
103104
columnsFilterable: boolean;
104105
pageSize: number;
105106
pagination: PaginationEnum;
106107
showPagingButtons: ShowPagingButtonsEnum;
107108
showNumberOfRows: boolean;
108109
pagingPosition: PagingPositionEnum;
110+
selectionCountVisibility: SelectionCountVisibilityEnum;
111+
clearSelectionButtonLabel?: DynamicValue<string>;
109112
loadMoreButtonCaption?: DynamicValue<string>;
110113
showEmptyPlaceholder: ShowEmptyPlaceholderEnum;
111114
emptyPlaceholder?: ReactNode;
@@ -151,14 +154,15 @@ export interface DatagridPreviewProps {
151154
keepSelection: boolean;
152155
loadingType: LoadingTypeEnum;
153156
refreshIndicator: boolean;
154-
clearSelectionButtonLabel: string;
155157
columns: ColumnsPreviewType[];
156158
columnsFilterable: boolean;
157159
pageSize: number | null;
158160
pagination: PaginationEnum;
159161
showPagingButtons: ShowPagingButtonsEnum;
160162
showNumberOfRows: boolean;
161163
pagingPosition: PagingPositionEnum;
164+
selectionCountVisibility: SelectionCountVisibilityEnum;
165+
clearSelectionButtonLabel: string;
162166
loadMoreButtonCaption: string;
163167
showEmptyPlaceholder: ShowEmptyPlaceholderEnum;
164168
emptyPlaceholder: { widgetCount: number; renderer: ComponentType<{ children: ReactNode; caption?: string }> };

0 commit comments

Comments
 (0)