@databiosphere/findable-ui 2.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/Detail/components/DetailViewTable/detailViewTable.js +1 -1
- package/lib/components/Filter/components/FilterLabel/filterLabel.styles.d.ts +1 -1
- package/lib/components/Filter/components/Filters/filters.d.ts +1 -1
- package/lib/components/Filter/components/Filters/filters.styles.js +1 -1
- package/lib/components/Filter/components/VariableSizeListItem/variableSizeListItem.js +2 -1
- package/lib/components/Index/index.d.ts +2 -1
- package/lib/components/Index/index.js +2 -2
- package/lib/components/Layout/components/Header/components/Content/components/Actions/components/Authentication/components/AuthenticationMenu/authenticationMenu.styles.d.ts +3 -3
- package/lib/components/Layout/components/Header/components/Content/components/Actions/components/Authentication/components/RequestAuthentication/requestAuthentication.styles.d.ts +1 -1
- package/lib/components/Layout/components/Header/components/Content/components/Actions/components/Search/components/SearchBar/searchBar.styles.d.ts +1 -1
- package/lib/components/Layout/components/Header/components/Content/components/Actions/components/Search/components/SearchButton/searchButton.styles.d.ts +1 -1
- package/lib/components/Layout/components/Outline/components/ContentsTab/contentsTab.styles.d.ts +1 -1
- package/lib/components/Layout/components/Outline/outline.styles.d.ts +1 -1
- package/lib/components/Table/common/utils.d.ts +6 -0
- package/lib/components/Table/common/utils.js +12 -1
- package/lib/components/Table/components/CheckboxMenu/checkboxMenu.js +2 -2
- package/lib/components/Table/components/CheckboxMenu/checkboxMenu.styles.d.ts +1 -1
- package/lib/components/Table/components/CheckboxMenu/checkboxMenu.styles.js +3 -3
- package/lib/components/Table/components/TableCell/common/utils.d.ts +8 -0
- package/lib/components/Table/components/TableCell/common/utils.js +15 -0
- package/lib/components/Table/components/TableCell/components/RowSelectionCell/rowSelectionCell.d.ts +6 -0
- package/lib/components/Table/components/TableCell/components/RowSelectionCell/rowSelectionCell.js +15 -0
- package/lib/components/Table/components/TableHead/components/HeadSelectionCell/headSelectionCell.d.ts +6 -0
- package/lib/components/Table/components/TableHead/components/HeadSelectionCell/headSelectionCell.js +16 -0
- package/lib/components/Table/components/TableHead/tableHead.js +2 -2
- package/lib/components/Table/components/TableRows/tableRows.js +2 -3
- package/lib/components/Table/components/TableToolbar/components/RowSelection/components/DropdownMenu/dropdownMenu.d.ts +10 -0
- package/lib/components/Table/components/TableToolbar/components/RowSelection/components/DropdownMenu/dropdownMenu.js +37 -0
- package/lib/components/Table/components/TableToolbar/components/RowSelection/components/DropdownMenu/dropdownMenu.styles.d.ts +3 -0
- package/lib/components/Table/components/TableToolbar/components/RowSelection/components/DropdownMenu/dropdownMenu.styles.js +13 -0
- package/lib/components/Table/components/TableToolbar/components/RowSelection/rowSelection.d.ts +9 -0
- package/lib/components/Table/components/TableToolbar/components/RowSelection/rowSelection.js +19 -0
- package/lib/components/Table/components/TableToolbar/components/RowSelection/rowSelection.styles.d.ts +5 -0
- package/lib/components/Table/components/TableToolbar/components/RowSelection/rowSelection.styles.js +13 -0
- package/lib/components/Table/components/TableToolbar/tableToolbar.js +5 -5
- package/lib/components/Table/components/TableToolbar/tableToolbar.styles.d.ts +1 -5
- package/lib/components/Table/components/TableToolbar/tableToolbar.styles.js +10 -7
- package/lib/components/Table/table.d.ts +5 -2
- package/lib/components/Table/table.js +13 -2
- package/lib/components/TableCreator/common/constants.d.ts +6 -0
- package/lib/components/TableCreator/common/constants.js +22 -0
- package/lib/components/TableCreator/common/entities.d.ts +5 -0
- package/lib/components/TableCreator/common/entities.js +2 -0
- package/lib/components/TableCreator/common/utils.d.ts +8 -0
- package/lib/components/TableCreator/common/utils.js +24 -0
- package/lib/components/TableCreator/tableCreator.d.ts +3 -1
- package/lib/components/TableCreator/tableCreator.js +19 -34
- package/lib/components/common/Alert/components/AlertText/alertText.styles.d.ts +5 -0
- package/lib/components/common/Alert/components/AlertText/alertText.styles.js +25 -0
- package/lib/components/common/Button/components/DropdownButton/dropdownButton.d.ts +4 -2
- package/lib/components/common/Button/components/DropdownButton/dropdownButton.js +2 -2
- package/lib/components/common/Button/components/DropdownButton/dropdownButton.styles.d.ts +5 -1
- package/lib/components/common/Button/components/DropdownButton/dropdownButton.styles.js +24 -1
- package/lib/components/common/CustomIcon/components/IndeterminateIcon/indeterminateIcon.d.ts +6 -0
- package/lib/components/common/CustomIcon/components/IndeterminateIcon/indeterminateIcon.js +29 -0
- package/lib/components/common/Dialog/dialog.d.ts +7 -0
- package/lib/components/common/Dialog/dialog.js +24 -0
- package/lib/components/common/DropdownMenu/common/constants.d.ts +2 -0
- package/lib/components/common/DropdownMenu/common/constants.js +8 -0
- package/lib/components/common/DropdownMenu/common/entities.d.ts +10 -0
- package/lib/components/common/DropdownMenu/common/entities.js +2 -0
- package/lib/components/common/DropdownMenu/components/MenuItem/menuItem.d.ts +7 -0
- package/lib/components/common/DropdownMenu/components/MenuItem/menuItem.js +25 -0
- package/lib/components/common/DropdownMenu/dropdownMenu.d.ts +9 -0
- package/lib/components/common/DropdownMenu/dropdownMenu.js +49 -0
- package/lib/components/common/DropdownMenu/dropdownMenu.styles.d.ts +3 -0
- package/lib/components/common/DropdownMenu/dropdownMenu.styles.js +13 -0
- package/lib/components/common/IconButton/iconButton.d.ts +4 -3
- package/lib/components/common/IconButton/iconButton.js +4 -4
- package/lib/components/common/IconButton/iconButton.styles.d.ts +34 -0
- package/lib/components/common/IconButton/iconButton.styles.js +27 -1
- package/lib/components/common/Tabs/tabs.styles.d.ts +1 -1
- package/lib/config/entities.d.ts +9 -1
- package/lib/providers/exploreState/constants.d.ts +3 -3
- package/lib/providers/exploreState/constants.js +3 -26
- package/lib/providers/exploreState/entities.d.ts +16 -5
- package/lib/providers/exploreState/initializer/constants.js +2 -0
- package/lib/providers/exploreState/initializer/utils.js +77 -5
- package/lib/providers/exploreState/payloads/entities.d.ts +32 -6
- package/lib/providers/exploreState/utils.d.ts +65 -11
- package/lib/providers/exploreState/utils.js +126 -15
- package/lib/providers/exploreState.d.ts +39 -7
- package/lib/providers/exploreState.js +58 -11
- package/lib/theme/common/components.js +4 -0
- package/lib/views/ExploreView/exploreView.d.ts +3 -1
- package/lib/views/ExploreView/exploreView.js +17 -11
- package/package.json +1 -1
- package/src/components/Detail/components/DetailViewTable/detailViewTable.tsx +2 -2
- package/src/components/Filter/components/Filters/filters.styles.ts +1 -1
- package/src/components/Filter/components/Filters/filters.tsx +1 -1
- package/src/components/Filter/components/VariableSizeListItem/variableSizeListItem.tsx +6 -3
- package/src/components/Index/index.tsx +3 -1
- package/src/components/Table/common/utils.ts +17 -0
- package/src/components/Table/components/CheckboxMenu/checkboxMenu.styles.ts +3 -3
- package/src/components/Table/components/CheckboxMenu/checkboxMenu.tsx +4 -2
- package/src/components/Table/components/TableCell/common/utils.ts +16 -0
- package/src/components/Table/components/TableCell/components/RowSelectionCell/rowSelectionCell.tsx +24 -0
- package/src/components/Table/components/TableHead/components/HeadSelectionCell/headSelectionCell.tsx +31 -0
- package/src/components/Table/components/TableHead/tableHead.tsx +18 -7
- package/src/components/Table/components/TableRows/tableRows.tsx +10 -8
- package/src/components/Table/components/TableToolbar/components/RowSelection/components/DropdownMenu/dropdownMenu.styles.ts +8 -0
- package/src/components/Table/components/TableToolbar/components/RowSelection/components/DropdownMenu/dropdownMenu.tsx +50 -0
- package/src/components/Table/components/TableToolbar/components/RowSelection/rowSelection.styles.ts +8 -0
- package/src/components/Table/components/TableToolbar/components/RowSelection/rowSelection.tsx +30 -0
- package/src/components/Table/components/TableToolbar/tableToolbar.styles.ts +10 -7
- package/src/components/Table/components/TableToolbar/tableToolbar.tsx +11 -8
- package/src/components/Table/table.tsx +18 -1
- package/src/components/TableCreator/common/constants.ts +26 -0
- package/src/components/TableCreator/common/entities.ts +6 -0
- package/src/components/TableCreator/common/utils.ts +33 -0
- package/src/components/TableCreator/tableCreator.tsx +38 -17
- package/src/components/common/Alert/components/AlertText/alertText.styles.ts +20 -0
- package/src/components/common/Button/components/DropdownButton/dropdownButton.styles.ts +15 -1
- package/src/components/common/Button/components/DropdownButton/dropdownButton.tsx +10 -2
- package/src/components/common/CustomIcon/components/IndeterminateIcon/indeterminateIcon.tsx +23 -0
- package/src/components/common/Dialog/dialog.tsx +21 -0
- package/src/components/common/DropdownMenu/common/constants.ts +7 -0
- package/src/components/common/DropdownMenu/common/entities.ts +11 -0
- package/src/components/common/DropdownMenu/components/MenuItem/menuItem.tsx +24 -0
- package/src/components/common/DropdownMenu/dropdownMenu.styles.ts +8 -0
- package/src/components/common/DropdownMenu/dropdownMenu.tsx +48 -0
- package/src/components/common/IconButton/iconButton.styles.ts +18 -0
- package/src/components/common/IconButton/iconButton.tsx +10 -11
- package/src/config/entities.ts +13 -1
- package/src/providers/exploreState/constants.ts +3 -0
- package/src/providers/exploreState/entities.ts +28 -4
- package/src/providers/exploreState/initializer/constants.ts +2 -0
- package/src/providers/exploreState/initializer/utils.ts +94 -3
- package/src/providers/exploreState/payloads/entities.ts +41 -7
- package/src/providers/exploreState/utils.ts +185 -21
- package/src/providers/exploreState.tsx +155 -21
- package/src/theme/common/components.ts +4 -0
- package/src/views/ExploreView/exploreView.tsx +22 -10
- package/types/data-explorer-ui.d.ts +10 -0
- package/src/components/Table/components/EntityViewToggle/entityViewToggle.tsx +0 -36
|
@@ -334,6 +334,23 @@ function getVisibleRowsTableData<T>(rows: Row<T>[]): TableData[][] {
|
|
|
334
334
|
);
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
+
/**
|
|
338
|
+
* Returns true if any or all table rows are selected.
|
|
339
|
+
* @param table - Table.
|
|
340
|
+
* @returns true if a row is selected.
|
|
341
|
+
*/
|
|
342
|
+
export function isAnyRowSelected<T>(table: Table<T>): boolean {
|
|
343
|
+
const {
|
|
344
|
+
getIsAllPageRowsSelected,
|
|
345
|
+
getIsSomePageRowsSelected,
|
|
346
|
+
options: { enableRowSelection },
|
|
347
|
+
} = table;
|
|
348
|
+
return Boolean(
|
|
349
|
+
enableRowSelection &&
|
|
350
|
+
(getIsSomePageRowsSelected() || getIsAllPageRowsSelected())
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
337
354
|
/**
|
|
338
355
|
* Returns true if client-side filtering is enabled.
|
|
339
356
|
* @param exploreMode - Explore mode.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import styled from "@emotion/styled";
|
|
2
|
-
import { Menu } from "@mui/material";
|
|
2
|
+
import { Menu as MMenu } from "@mui/material";
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const Menu = styled(MMenu)`
|
|
5
5
|
.MuiPaper-menu {
|
|
6
|
-
margin:
|
|
6
|
+
margin: 4px 0;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
// List item button
|
|
@@ -9,7 +9,7 @@ import { ButtonTextPrimary } from "../../../common/Button/components/ButtonTextP
|
|
|
9
9
|
import { DropdownButton } from "../../../common/Button/components/DropdownButton/dropdownButton";
|
|
10
10
|
import { CheckedIcon } from "../../../common/CustomIcon/components/CheckedIcon/checkedIcon";
|
|
11
11
|
import { UncheckedIcon } from "../../../common/CustomIcon/components/UncheckedIcon/uncheckedIcon";
|
|
12
|
-
import {
|
|
12
|
+
import { Menu } from "./checkboxMenu.styles";
|
|
13
13
|
|
|
14
14
|
type MenuListItemOnChangeFn = (event: unknown) => void; // see React Table VisibilityColumn "getToggleVisibilityHandler".
|
|
15
15
|
type onResetFn = () => void; // see React Table VisibilityInstance "resetColumnVisibility".
|
|
@@ -46,7 +46,9 @@ export const CheckboxMenu = ({
|
|
|
46
46
|
|
|
47
47
|
return (
|
|
48
48
|
<>
|
|
49
|
-
<DropdownButton onClick={onOpenMenu}
|
|
49
|
+
<DropdownButton onClick={onOpenMenu} open={open}>
|
|
50
|
+
{buttonLabel}
|
|
51
|
+
</DropdownButton>
|
|
50
52
|
<Menu
|
|
51
53
|
anchorEl={anchorEl}
|
|
52
54
|
anchorOrigin={{ horizontal: "right", vertical: "bottom" }}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TableCellProps as MTableCellProps } from "@mui/material/TableCell/TableCell";
|
|
2
|
+
import { CoreCell, CoreHeader } from "@tanstack/table-core";
|
|
3
|
+
import { ACCESSOR_KEYS } from "../../../../TableCreator/common/constants";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns table cell padding based on the cell ID.
|
|
7
|
+
* @param id - Cell ID.
|
|
8
|
+
* @returns table cell padding.
|
|
9
|
+
*/
|
|
10
|
+
export function getTableCellPadding<T extends object, TValue>(
|
|
11
|
+
id: CoreHeader<T, TValue>["id"] | CoreCell<T, TValue>["id"]
|
|
12
|
+
): MTableCellProps["padding"] {
|
|
13
|
+
if (id === ACCESSOR_KEYS.SELECT) {
|
|
14
|
+
return "checkbox";
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/components/Table/components/TableCell/components/RowSelectionCell/rowSelectionCell.tsx
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Checkbox as MCheckbox } from "@mui/material";
|
|
2
|
+
import { Row } from "@tanstack/react-table";
|
|
3
|
+
import { RowData } from "@tanstack/table-core";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { CheckedIcon } from "../../../../../common/CustomIcon/components/CheckedIcon/checkedIcon";
|
|
6
|
+
import { UncheckedIcon } from "../../../../../common/CustomIcon/components/UncheckedIcon/uncheckedIcon";
|
|
7
|
+
|
|
8
|
+
export interface RowSelectionCellProps<T> {
|
|
9
|
+
row: Row<T>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const RowSelectionCell = <T extends RowData>({
|
|
13
|
+
row,
|
|
14
|
+
}: RowSelectionCellProps<T>): JSX.Element => {
|
|
15
|
+
const { getIsSelected, getToggleSelectedHandler } = row;
|
|
16
|
+
return (
|
|
17
|
+
<MCheckbox
|
|
18
|
+
checked={getIsSelected()}
|
|
19
|
+
checkedIcon={<CheckedIcon />}
|
|
20
|
+
icon={<UncheckedIcon />}
|
|
21
|
+
onChange={getToggleSelectedHandler()}
|
|
22
|
+
/>
|
|
23
|
+
);
|
|
24
|
+
};
|
package/src/components/Table/components/TableHead/components/HeadSelectionCell/headSelectionCell.tsx
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Checkbox } from "@mui/material";
|
|
2
|
+
import { Table } from "@tanstack/react-table";
|
|
3
|
+
import { RowData } from "@tanstack/table-core";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { CheckedIcon } from "../../../../../common/CustomIcon/components/CheckedIcon/checkedIcon";
|
|
6
|
+
import { IndeterminateIcon } from "../../../../../common/CustomIcon/components/IndeterminateIcon/indeterminateIcon";
|
|
7
|
+
import { UncheckedIcon } from "../../../../../common/CustomIcon/components/UncheckedIcon/uncheckedIcon";
|
|
8
|
+
|
|
9
|
+
export interface HeadSelectionCellProps<T> {
|
|
10
|
+
tableInstance: Table<T>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const HeadSelectionCell = <T extends RowData>({
|
|
14
|
+
tableInstance,
|
|
15
|
+
}: HeadSelectionCellProps<T>): JSX.Element => {
|
|
16
|
+
const {
|
|
17
|
+
getIsAllPageRowsSelected,
|
|
18
|
+
getIsSomePageRowsSelected,
|
|
19
|
+
getToggleAllRowsSelectedHandler,
|
|
20
|
+
} = tableInstance;
|
|
21
|
+
return (
|
|
22
|
+
<Checkbox
|
|
23
|
+
checked={getIsAllPageRowsSelected()}
|
|
24
|
+
checkedIcon={<CheckedIcon />}
|
|
25
|
+
icon={<UncheckedIcon />}
|
|
26
|
+
indeterminate={getIsSomePageRowsSelected()}
|
|
27
|
+
indeterminateIcon={<IndeterminateIcon />}
|
|
28
|
+
onChange={getToggleAllRowsSelectedHandler()}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
TableCell,
|
|
2
|
+
TableCell as MTableCell,
|
|
3
3
|
TableHead as MTableHead,
|
|
4
4
|
TableRow,
|
|
5
5
|
TableSortLabel,
|
|
@@ -8,6 +8,7 @@ import { flexRender, Table } from "@tanstack/react-table";
|
|
|
8
8
|
import React, { Fragment } from "react";
|
|
9
9
|
import { ROW_DIRECTION } from "../../common/entities";
|
|
10
10
|
import { getTableSortLabelProps } from "../../common/utils";
|
|
11
|
+
import { getTableCellPadding } from "../TableCell/common/utils";
|
|
11
12
|
|
|
12
13
|
export interface TableHeadProps<T> {
|
|
13
14
|
rowDirection: ROW_DIRECTION;
|
|
@@ -25,14 +26,24 @@ export const TableHead = <T extends object>({
|
|
|
25
26
|
<MTableHead key={headerGroup.id}>
|
|
26
27
|
<TableRow>
|
|
27
28
|
{headerGroup.headers.map((header) => (
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
<MTableCell
|
|
30
|
+
key={header.id}
|
|
31
|
+
padding={getTableCellPadding(header.id)}
|
|
32
|
+
>
|
|
33
|
+
{header.column.getCanSort() ? (
|
|
34
|
+
<TableSortLabel {...getTableSortLabelProps(header.column)}>
|
|
35
|
+
{flexRender(
|
|
36
|
+
header.column.columnDef.header,
|
|
37
|
+
header.getContext()
|
|
38
|
+
)}
|
|
39
|
+
</TableSortLabel>
|
|
40
|
+
) : (
|
|
41
|
+
flexRender(
|
|
31
42
|
header.column.columnDef.header,
|
|
32
43
|
header.getContext()
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
</
|
|
44
|
+
)
|
|
45
|
+
)}
|
|
46
|
+
</MTableCell>
|
|
36
47
|
))}
|
|
37
48
|
</TableRow>
|
|
38
49
|
</MTableHead>
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { TableCell, TableRow as MTableRow } from "@mui/material";
|
|
1
|
+
import { TableCell as MTableCell, TableRow as MTableRow } from "@mui/material";
|
|
2
2
|
import { flexRender, Row, Table } from "@tanstack/react-table";
|
|
3
3
|
import { Virtualizer } from "@tanstack/react-virtual";
|
|
4
4
|
import React, { Fragment } from "react";
|
|
5
|
+
import { getTableCellPadding } from "../TableCell/common/utils";
|
|
5
6
|
|
|
6
7
|
export interface TableRowsProps<T> {
|
|
7
8
|
tableInstance: Table<T>;
|
|
@@ -25,13 +26,14 @@ export const TableRows = <T extends object>({
|
|
|
25
26
|
data-index={virtualRow.index}
|
|
26
27
|
ref={virtualizer.measureElement}
|
|
27
28
|
>
|
|
28
|
-
{row.getVisibleCells().map((cell) =>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
{row.getVisibleCells().map((cell) => (
|
|
30
|
+
<MTableCell
|
|
31
|
+
key={cell.id}
|
|
32
|
+
padding={getTableCellPadding(cell.column.id)}
|
|
33
|
+
>
|
|
34
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
35
|
+
</MTableCell>
|
|
36
|
+
))}
|
|
35
37
|
</MTableRow>
|
|
36
38
|
);
|
|
37
39
|
})}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { MenuProps as MMenuProps } from "@mui/material";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { DropdownButton as DXDropdownButton } from "../../../../../../../common/Button/components/DropdownButton/dropdownButton";
|
|
4
|
+
import {
|
|
5
|
+
DropdownMenuButtonProps,
|
|
6
|
+
DropdownMenuItemProps,
|
|
7
|
+
} from "../../../../../../../common/DropdownMenu/common/entities";
|
|
8
|
+
import { DropdownMenuProps as DXDropdownMenuProps } from "../../../../../../../common/DropdownMenu/dropdownMenu";
|
|
9
|
+
import { DropdownMenu as RowSelectionDropdownMenu } from "./dropdownMenu.styles";
|
|
10
|
+
|
|
11
|
+
const DEFAULT_MENU_PROPS: Partial<MMenuProps> = {
|
|
12
|
+
anchorOrigin: { horizontal: "left", vertical: "bottom" },
|
|
13
|
+
transformOrigin: { horizontal: "left", vertical: "top" },
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export interface DropdownMenuProps {
|
|
17
|
+
Button?: DXDropdownMenuProps["Button"];
|
|
18
|
+
buttonLabel?: string;
|
|
19
|
+
children: ({ closeMenu }: DropdownMenuItemProps) => JSX.Element[];
|
|
20
|
+
className?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const DropdownMenu = ({
|
|
24
|
+
Button = (props: DropdownMenuButtonProps): JSX.Element =>
|
|
25
|
+
renderButton({ children: buttonLabel, ...props }),
|
|
26
|
+
buttonLabel = "Edit",
|
|
27
|
+
children,
|
|
28
|
+
className,
|
|
29
|
+
...props /* Spread props to allow for Mui Menu specific prop overrides e.g. "anchorOrigin". */
|
|
30
|
+
}: DropdownMenuProps): JSX.Element => {
|
|
31
|
+
return (
|
|
32
|
+
<RowSelectionDropdownMenu
|
|
33
|
+
{...DEFAULT_MENU_PROPS}
|
|
34
|
+
className={className}
|
|
35
|
+
Button={Button}
|
|
36
|
+
{...props}
|
|
37
|
+
>
|
|
38
|
+
{({ closeMenu }): JSX.Element[] => children({ closeMenu })}
|
|
39
|
+
</RowSelectionDropdownMenu>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Return the dropdown button.
|
|
45
|
+
* @param props - Button props e.g. "onClick".
|
|
46
|
+
* @returns button element.
|
|
47
|
+
*/
|
|
48
|
+
function renderButton(props: DropdownMenuButtonProps): JSX.Element {
|
|
49
|
+
return <DXDropdownButton {...props} />;
|
|
50
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Typography } from "@mui/material";
|
|
2
|
+
import { Row } from "@tanstack/react-table";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { ComponentsConfig } from "../../../../../../config/entities";
|
|
5
|
+
import { TEXT_BODY_400 } from "../../../../../../theme/common/typography";
|
|
6
|
+
import { ComponentCreator } from "../../../../../ComponentCreator/ComponentCreator";
|
|
7
|
+
import { RowSelection as RowSelectionActions } from "./rowSelection.styles";
|
|
8
|
+
|
|
9
|
+
export interface RowSelectionProps<T> {
|
|
10
|
+
className?: string;
|
|
11
|
+
rows: Row<T>[];
|
|
12
|
+
rowSelectionView?: ComponentsConfig;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const RowSelection = <T extends object>({
|
|
16
|
+
className,
|
|
17
|
+
rows,
|
|
18
|
+
rowSelectionView,
|
|
19
|
+
}: RowSelectionProps<T>): JSX.Element | null => {
|
|
20
|
+
return (
|
|
21
|
+
<RowSelectionActions className={className}>
|
|
22
|
+
<Typography variant={TEXT_BODY_400}>
|
|
23
|
+
{rows.length} items selected:
|
|
24
|
+
</Typography>
|
|
25
|
+
{rowSelectionView ? (
|
|
26
|
+
<ComponentCreator components={rowSelectionView} response={rows} />
|
|
27
|
+
) : null}
|
|
28
|
+
</RowSelectionActions>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import styled from "@emotion/styled";
|
|
2
|
+
import { Toolbar as MToolbar } from "@mui/material";
|
|
2
3
|
import { white } from "../../../../styles/common/mixins/colors";
|
|
3
4
|
import { Grid } from "../../../common/Grid/grid";
|
|
4
5
|
|
|
5
|
-
export const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
export const Toolbar = styled(MToolbar)`
|
|
7
|
+
&.MuiToolbar-table {
|
|
8
|
+
align-items: center;
|
|
9
|
+
background-color: ${white};
|
|
10
|
+
display: flex;
|
|
11
|
+
justify-content: space-between;
|
|
12
|
+
padding: 20px;
|
|
13
|
+
}
|
|
14
|
+
` as typeof MToolbar;
|
|
12
15
|
|
|
13
16
|
export const ToolbarActions = styled(Grid)`
|
|
14
17
|
gap: 8px;
|
|
@@ -3,12 +3,12 @@ import React, { Fragment } from "react";
|
|
|
3
3
|
import { ListViewConfig } from "../../../../config/entities";
|
|
4
4
|
import { useExploreState } from "../../../../hooks/useExploreState";
|
|
5
5
|
import { ROW_DIRECTION } from "../../common/entities";
|
|
6
|
-
import { getEditColumnOptions } from "../../common/utils";
|
|
6
|
+
import { getEditColumnOptions, isAnyRowSelected } from "../../common/utils";
|
|
7
7
|
import { CheckboxMenu } from "../CheckboxMenu/checkboxMenu";
|
|
8
8
|
import { DownloadEntityResults } from "../DownloadEntityResults/downloadEntityResults";
|
|
9
|
-
import { EntityViewToggle } from "../EntityViewToggle/entityViewToggle";
|
|
10
9
|
import { PaginationSummary } from "../PaginationSummary/paginationSummary";
|
|
11
|
-
import {
|
|
10
|
+
import { RowSelection } from "./components/RowSelection/rowSelection";
|
|
11
|
+
import { Toolbar, ToolbarActions } from "./tableToolbar.styles";
|
|
12
12
|
|
|
13
13
|
export interface TableToolbarProps<T> {
|
|
14
14
|
listView?: ListViewConfig;
|
|
@@ -22,9 +22,9 @@ export const TableToolbar = <T extends object>({
|
|
|
22
22
|
tableInstance,
|
|
23
23
|
}: TableToolbarProps<T>): JSX.Element => {
|
|
24
24
|
const { exploreState } = useExploreState();
|
|
25
|
-
const { paginationState
|
|
25
|
+
const { paginationState } = exploreState;
|
|
26
26
|
const { currentPage, pages, pageSize, rows } = paginationState;
|
|
27
|
-
const { resetColumnVisibility } = tableInstance;
|
|
27
|
+
const { getSelectedRowModel, resetColumnVisibility } = tableInstance;
|
|
28
28
|
const { enableDownload } = listView || {};
|
|
29
29
|
const isLastPage = currentPage === pages;
|
|
30
30
|
const editColumnOptions = getEditColumnOptions(tableInstance);
|
|
@@ -42,9 +42,12 @@ export const TableToolbar = <T extends object>({
|
|
|
42
42
|
return (
|
|
43
43
|
<Fragment>
|
|
44
44
|
{showToolbar && (
|
|
45
|
-
<Toolbar>
|
|
46
|
-
{
|
|
47
|
-
<
|
|
45
|
+
<Toolbar variant="table">
|
|
46
|
+
{isAnyRowSelected(tableInstance) ? (
|
|
47
|
+
<RowSelection
|
|
48
|
+
rows={getSelectedRowModel().rows}
|
|
49
|
+
rowSelectionView={listView?.rowSelectionView}
|
|
50
|
+
/>
|
|
48
51
|
) : (
|
|
49
52
|
<PaginationSummary
|
|
50
53
|
firstResult={(currentPage - 1) * pageSize + 1}
|
|
@@ -8,11 +8,13 @@ import {
|
|
|
8
8
|
getPaginationRowModel,
|
|
9
9
|
getSortedRowModel,
|
|
10
10
|
InitialTableState,
|
|
11
|
+
RowSelectionState,
|
|
11
12
|
TableState,
|
|
12
13
|
Updater,
|
|
13
14
|
useReactTable,
|
|
14
15
|
VisibilityState,
|
|
15
16
|
} from "@tanstack/react-table";
|
|
17
|
+
import { CoreOptions } from "@tanstack/table-core";
|
|
16
18
|
import React, { useEffect } from "react";
|
|
17
19
|
import { track } from "../../common/analytics/analytics";
|
|
18
20
|
import {
|
|
@@ -51,6 +53,7 @@ import { GridTable } from "./table.styles";
|
|
|
51
53
|
export interface TableProps<T extends object> {
|
|
52
54
|
columns: ColumnDef<T>[];
|
|
53
55
|
count?: number;
|
|
56
|
+
getRowId?: CoreOptions<T>["getRowId"];
|
|
54
57
|
initialState: InitialTableState;
|
|
55
58
|
items: T[];
|
|
56
59
|
listView?: ListViewConfig;
|
|
@@ -67,6 +70,7 @@ export interface TableProps<T extends object> {
|
|
|
67
70
|
* Uncontrolled table will take advantage of React Table's state and will be used for static loads.
|
|
68
71
|
* @param tableProps - Set of props required for displaying the table.
|
|
69
72
|
* @param tableProps.columns - Set of columns to display.
|
|
73
|
+
* @param tableProps.getRowId - Function to customize the row ID.
|
|
70
74
|
* @param tableProps.initialState - Initial table state.
|
|
71
75
|
* @param tableProps.items - Row data to display.
|
|
72
76
|
* @param tableProps.listView - List view configuration.
|
|
@@ -75,6 +79,7 @@ export interface TableProps<T extends object> {
|
|
|
75
79
|
*/
|
|
76
80
|
export const TableComponent = <T extends object>({
|
|
77
81
|
columns,
|
|
82
|
+
getRowId,
|
|
78
83
|
initialState,
|
|
79
84
|
items,
|
|
80
85
|
listView,
|
|
@@ -93,7 +98,8 @@ TableProps<T>): JSX.Element => {
|
|
|
93
98
|
paginationState,
|
|
94
99
|
tabValue,
|
|
95
100
|
} = exploreState;
|
|
96
|
-
const { columnsVisibility, sorting } =
|
|
101
|
+
const { columnsVisibility, enableRowSelection, rowSelection, sorting } =
|
|
102
|
+
entityPageState[tabValue];
|
|
97
103
|
const { currentPage, pages, pageSize } = paginationState;
|
|
98
104
|
const { disablePagination = false } = listView || {};
|
|
99
105
|
const clientFiltering = isClientFilteringEnabled(exploreMode);
|
|
@@ -126,12 +132,20 @@ TableProps<T>): JSX.Element => {
|
|
|
126
132
|
});
|
|
127
133
|
};
|
|
128
134
|
|
|
135
|
+
const onRowSelectionChange = (updater: Updater<RowSelectionState>): void => {
|
|
136
|
+
exploreDispatch({
|
|
137
|
+
payload: typeof updater === "function" ? updater(rowSelection) : updater,
|
|
138
|
+
type: ExploreActionKind.UpdateRowSelection,
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
|
|
129
142
|
const state: Partial<TableState> = {
|
|
130
143
|
columnVisibility: columnsVisibility,
|
|
131
144
|
pagination: {
|
|
132
145
|
pageIndex: 0,
|
|
133
146
|
pageSize: disablePagination ? Number.MAX_SAFE_INTEGER : pageSize,
|
|
134
147
|
},
|
|
148
|
+
rowSelection,
|
|
135
149
|
sorting,
|
|
136
150
|
};
|
|
137
151
|
const tableInstance = useReactTable({
|
|
@@ -140,6 +154,7 @@ TableProps<T>): JSX.Element => {
|
|
|
140
154
|
enableColumnFilters: true, // client-side filtering.
|
|
141
155
|
enableFilters: true, // client-side filtering.
|
|
142
156
|
enableMultiSort: false,
|
|
157
|
+
enableRowSelection,
|
|
143
158
|
enableSorting: true, // client-side filtering.
|
|
144
159
|
enableSortingRemoval: false, // client-side filtering.
|
|
145
160
|
getCoreRowModel: getCoreRowModel(),
|
|
@@ -149,11 +164,13 @@ TableProps<T>): JSX.Element => {
|
|
|
149
164
|
: undefined,
|
|
150
165
|
getFilteredRowModel: clientFiltering ? getFilteredRowModel() : undefined,
|
|
151
166
|
getPaginationRowModel: getPaginationRowModel(),
|
|
167
|
+
getRowId,
|
|
152
168
|
getSortedRowModel: clientFiltering ? getSortedRowModel() : undefined,
|
|
153
169
|
initialState,
|
|
154
170
|
manualPagination: clientFiltering,
|
|
155
171
|
manualSorting: !clientFiltering,
|
|
156
172
|
onColumnVisibilityChange,
|
|
173
|
+
onRowSelectionChange,
|
|
157
174
|
onSortingChange,
|
|
158
175
|
pageCount: total,
|
|
159
176
|
state,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { RowData } from "@tanstack/react-table";
|
|
2
|
+
import { RowSelectionCell } from "../../Table/components/TableCell/components/RowSelectionCell/rowSelectionCell";
|
|
3
|
+
import { BaseColumnConfig } from "./entities";
|
|
4
|
+
|
|
5
|
+
export const ACCESSOR_KEYS = {
|
|
6
|
+
SELECT: "select",
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const COLUMN_CONFIGS: Record<
|
|
10
|
+
string,
|
|
11
|
+
BaseColumnConfig<RowData, unknown>
|
|
12
|
+
> = {
|
|
13
|
+
SELECT: {
|
|
14
|
+
columnPinned: false,
|
|
15
|
+
columnVisible: false,
|
|
16
|
+
componentConfig: { component: RowSelectionCell },
|
|
17
|
+
disableHiding: true,
|
|
18
|
+
disableSorting: true,
|
|
19
|
+
header: ACCESSOR_KEYS.SELECT,
|
|
20
|
+
id: ACCESSOR_KEYS.SELECT,
|
|
21
|
+
meta: {
|
|
22
|
+
header: "",
|
|
23
|
+
},
|
|
24
|
+
width: "max-content",
|
|
25
|
+
},
|
|
26
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ColumnDef } from "@tanstack/react-table";
|
|
2
|
+
import { BaseColumnConfig } from "./entities";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Builds a base column definition.
|
|
6
|
+
* @param baseColumnConfig - Base column configuration.
|
|
7
|
+
* @returns column definition.
|
|
8
|
+
*/
|
|
9
|
+
export function buildBaseColumnDef<T, TValue>(
|
|
10
|
+
baseColumnConfig: BaseColumnConfig<T, TValue>
|
|
11
|
+
): ColumnDef<T> {
|
|
12
|
+
const {
|
|
13
|
+
columnPinned,
|
|
14
|
+
disableHiding,
|
|
15
|
+
disableSorting,
|
|
16
|
+
header,
|
|
17
|
+
id,
|
|
18
|
+
meta,
|
|
19
|
+
width,
|
|
20
|
+
} = baseColumnConfig;
|
|
21
|
+
return {
|
|
22
|
+
accessorKey: id,
|
|
23
|
+
enableHiding: !disableHiding,
|
|
24
|
+
enableSorting: !disableSorting,
|
|
25
|
+
header,
|
|
26
|
+
id,
|
|
27
|
+
meta: {
|
|
28
|
+
columnPinned,
|
|
29
|
+
header: meta ? meta.header : header,
|
|
30
|
+
width,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CellContext, ColumnDef, ColumnSort } from "@tanstack/react-table";
|
|
2
|
+
import { CoreOptions, HeaderContext, RowData } from "@tanstack/table-core";
|
|
2
3
|
import React, { useMemo } from "react";
|
|
3
4
|
import { Pagination } from "../../common/entities";
|
|
4
5
|
import { ColumnConfig, ListViewConfig } from "../../config/entities";
|
|
@@ -10,12 +11,17 @@ import {
|
|
|
10
11
|
getInitialState,
|
|
11
12
|
sortingFn,
|
|
12
13
|
} from "../Table/common/utils";
|
|
14
|
+
import { RowSelectionCell } from "../Table/components/TableCell/components/RowSelectionCell/rowSelectionCell";
|
|
15
|
+
import { HeadSelectionCell } from "../Table/components/TableHead/components/HeadSelectionCell/headSelectionCell";
|
|
13
16
|
import { Table } from "../Table/table";
|
|
17
|
+
import { COLUMN_CONFIGS } from "./common/constants";
|
|
18
|
+
import { buildBaseColumnDef } from "./common/utils";
|
|
14
19
|
import { TableCreator as TableCreatorContainer } from "./tableCreator.styles";
|
|
15
20
|
|
|
16
21
|
export interface TableCreatorProps<T> {
|
|
17
22
|
columns: ColumnConfig<T>[];
|
|
18
23
|
defaultSort: ColumnSort | undefined;
|
|
24
|
+
getRowId?: CoreOptions<T>["getRowId"];
|
|
19
25
|
items: T[];
|
|
20
26
|
listView?: ListViewConfig;
|
|
21
27
|
loading?: boolean;
|
|
@@ -26,9 +32,8 @@ export interface TableCreatorProps<T> {
|
|
|
26
32
|
total?: number;
|
|
27
33
|
}
|
|
28
34
|
|
|
29
|
-
const createCell = <T extends
|
|
30
|
-
|
|
31
|
-
function CellCreator({ row }: CellContext<T, any>): JSX.Element {
|
|
35
|
+
const createCell = <T extends RowData>(config: ColumnConfig<T>) =>
|
|
36
|
+
function CellCreator({ row }: CellContext<T, unknown>): JSX.Element {
|
|
32
37
|
return (
|
|
33
38
|
<ComponentCreator
|
|
34
39
|
components={[config.componentConfig]}
|
|
@@ -37,9 +42,20 @@ const createCell = <T extends object>(config: ColumnConfig<T>) =>
|
|
|
37
42
|
);
|
|
38
43
|
};
|
|
39
44
|
|
|
45
|
+
const createHeaderSelectionCell = <T extends RowData>() =>
|
|
46
|
+
function CellCreator({ table }: HeaderContext<T, unknown>): JSX.Element {
|
|
47
|
+
return <HeadSelectionCell tableInstance={table} />;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const createRowSelectionCell = <T extends RowData>() =>
|
|
51
|
+
function CellCreator({ row }: CellContext<T, unknown>): JSX.Element {
|
|
52
|
+
return <RowSelectionCell row={row} />;
|
|
53
|
+
};
|
|
54
|
+
|
|
40
55
|
export const TableCreator = <T extends object>({
|
|
41
56
|
columns,
|
|
42
57
|
defaultSort,
|
|
58
|
+
getRowId,
|
|
43
59
|
items,
|
|
44
60
|
listView,
|
|
45
61
|
loading,
|
|
@@ -51,21 +67,25 @@ export const TableCreator = <T extends object>({
|
|
|
51
67
|
}: TableCreatorProps<T>): JSX.Element => {
|
|
52
68
|
const columnDefs: ColumnDef<T>[] = useMemo(
|
|
53
69
|
() =>
|
|
54
|
-
columns.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
columnPinned: columnConfig.columnPinned,
|
|
64
|
-
header: columnConfig.header,
|
|
65
|
-
width: columnConfig.width,
|
|
70
|
+
columns.reduce(
|
|
71
|
+
(acc, columnConfig) => {
|
|
72
|
+
acc.push({
|
|
73
|
+
...buildBaseColumnDef(columnConfig),
|
|
74
|
+
cell: createCell(columnConfig),
|
|
75
|
+
filterFn: arrIncludesSome,
|
|
76
|
+
sortingFn: sortingFn,
|
|
77
|
+
});
|
|
78
|
+
return acc;
|
|
66
79
|
},
|
|
67
|
-
|
|
68
|
-
|
|
80
|
+
[
|
|
81
|
+
/* Initialize column definitions with the "select" column */
|
|
82
|
+
{
|
|
83
|
+
...buildBaseColumnDef(COLUMN_CONFIGS.SELECT),
|
|
84
|
+
cell: createRowSelectionCell(),
|
|
85
|
+
header: createHeaderSelectionCell(),
|
|
86
|
+
},
|
|
87
|
+
] as ColumnDef<T>[]
|
|
88
|
+
),
|
|
69
89
|
[columns]
|
|
70
90
|
);
|
|
71
91
|
const initialState = getInitialState(columns, defaultSort);
|
|
@@ -79,6 +99,7 @@ export const TableCreator = <T extends object>({
|
|
|
79
99
|
<Table<T>
|
|
80
100
|
columns={columnDefs}
|
|
81
101
|
count={pageCount}
|
|
102
|
+
getRowId={getRowId}
|
|
82
103
|
initialState={initialState}
|
|
83
104
|
items={items}
|
|
84
105
|
listView={listView}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import styled from "@emotion/styled";
|
|
2
|
+
|
|
3
|
+
export const AlertText = styled.div`
|
|
4
|
+
ul {
|
|
5
|
+
padding-left: 24px;
|
|
6
|
+
margin: 8px 0;
|
|
7
|
+
|
|
8
|
+
li {
|
|
9
|
+
margin: 4px 0;
|
|
10
|
+
|
|
11
|
+
&:last-child {
|
|
12
|
+
margin-bottom: 0;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
*:last-child {
|
|
18
|
+
margin-bottom: 0;
|
|
19
|
+
}
|
|
20
|
+
`;
|