@databiosphere/findable-ui 15.0.2 → 16.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/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +13 -0
- package/lib/components/Detail/components/Table/components/TableRows/tableRows.js +3 -3
- package/lib/components/Detail/components/Table/table.js +7 -2
- package/lib/components/Export/components/ExportForm/exportForm.styles.js +1 -3
- package/lib/components/Layout/components/ContentLayout/contentLayout.d.ts +2 -2
- package/lib/components/Layout/components/ContentLayout/contentLayout.js +1 -1
- package/lib/components/Layout/components/ContentLayout/contentLayout.styles.d.ts +1 -0
- package/lib/components/Layout/components/ContentLayout/contentLayout.styles.js +11 -4
- package/lib/components/Table/common/columnDef.d.ts +2 -0
- package/lib/components/Table/common/columnDef.js +17 -0
- package/lib/components/Table/common/gridTable.styles.js +1 -2
- package/lib/components/Table/components/TableCell/common/utils.d.ts +9 -3
- package/lib/components/Table/components/TableCell/common/utils.js +16 -2
- package/lib/components/Table/components/TableCell/components/RowPositionCell/constants.d.ts +2 -0
- package/lib/components/Table/components/TableCell/components/RowPositionCell/constants.js +5 -0
- package/lib/components/Table/components/TableCell/components/RowPositionCell/rowPositionCell.d.ts +3 -0
- package/lib/components/Table/components/TableCell/components/RowPositionCell/rowPositionCell.js +6 -0
- package/lib/components/Table/components/TableHead/tableHead.js +3 -3
- package/lib/components/Table/components/TableRows/tableRows.js +3 -3
- package/lib/components/Table/features/RowPosition/constants.d.ts +2 -0
- package/lib/components/Table/features/RowPosition/constants.js +17 -0
- package/lib/components/Table/features/RowPosition/types.d.ts +3 -0
- package/lib/components/Table/features/RowPosition/types.js +1 -0
- package/lib/components/Table/features/RowPosition/utils.d.ts +21 -0
- package/lib/components/Table/features/RowPosition/utils.js +55 -0
- package/lib/components/Table/features/constants.d.ts +6 -0
- package/lib/components/Table/features/constants.js +8 -0
- package/lib/components/Table/features/entities.d.ts +2 -1
- package/lib/components/Table/table.d.ts +4 -2
- package/lib/components/Table/table.js +21 -3
- package/lib/components/TableCreator/common/constants.d.ts +1 -0
- package/lib/components/TableCreator/common/constants.js +1 -0
- package/lib/components/TableCreator/tableCreator.d.ts +3 -2
- package/lib/components/TableCreator/tableCreator.js +5 -2
- package/lib/components/common/Breadcrumbs/breadcrumbs.js +2 -1
- package/lib/components/common/Breadcrumbs/constants.d.ts +2 -0
- package/lib/components/common/Breadcrumbs/constants.js +4 -0
- package/lib/config/entities.d.ts +5 -3
- package/lib/providers/exploreState/initializer/utils.js +3 -1
- package/lib/styles/common/mui/link.d.ts +7 -0
- package/lib/styles/common/mui/link.js +8 -0
- package/lib/styles/common/mui/tableCell.d.ts +13 -0
- package/lib/styles/common/mui/tableCell.js +27 -0
- package/lib/styles/common/mui/typography.d.ts +2 -0
- package/lib/styles/common/mui/typography.js +3 -0
- package/lib/theme/common/components.d.ts +0 -6
- package/lib/theme/common/components.js +0 -31
- package/lib/theme/components/index.d.ts +1 -0
- package/lib/theme/components/index.js +1 -0
- package/lib/theme/components/muiTableCell.d.ts +2 -0
- package/lib/theme/components/muiTableCell.js +48 -0
- package/lib/theme/theme.js +1 -1
- package/lib/views/ContentView/contentView.d.ts +2 -1
- package/lib/views/ContentView/contentView.js +2 -2
- package/lib/views/ExploreView/exploreView.js +2 -2
- package/package.json +1 -1
- package/src/components/Detail/components/Table/components/TableRows/tableRows.tsx +8 -4
- package/src/components/Detail/components/Table/table.tsx +7 -2
- package/src/components/Export/components/ExportForm/exportForm.styles.ts +1 -7
- package/src/components/Layout/components/ContentLayout/contentLayout.styles.ts +13 -4
- package/src/components/Layout/components/ContentLayout/contentLayout.tsx +7 -3
- package/src/components/Table/common/columnDef.ts +19 -0
- package/src/components/Table/common/gridTable.styles.ts +1 -2
- package/src/components/Table/components/TableCell/common/utils.ts +22 -5
- package/src/components/Table/components/TableCell/components/RowPositionCell/constants.ts +7 -0
- package/src/components/Table/components/TableCell/components/RowPositionCell/rowPositionCell.tsx +16 -0
- package/src/components/Table/components/TableHead/tableHead.tsx +8 -4
- package/src/components/Table/components/TableRows/tableRows.tsx +8 -4
- package/src/components/Table/features/RowPosition/constants.ts +34 -0
- package/src/components/Table/features/RowPosition/types.ts +3 -0
- package/src/components/Table/features/RowPosition/utils.ts +80 -0
- package/src/components/Table/features/constants.ts +10 -0
- package/src/components/Table/features/entities.ts +2 -1
- package/src/components/Table/table.tsx +24 -3
- package/src/components/TableCreator/common/constants.ts +1 -0
- package/src/components/TableCreator/tableCreator.tsx +11 -1
- package/src/components/common/Breadcrumbs/breadcrumbs.tsx +2 -1
- package/src/components/common/Breadcrumbs/constants.ts +6 -0
- package/src/config/entities.ts +12 -3
- package/src/providers/exploreState/initializer/utils.ts +6 -1
- package/src/styles/common/mui/link.ts +15 -0
- package/src/styles/common/mui/tableCell.ts +40 -0
- package/src/styles/common/mui/typography.ts +5 -0
- package/src/theme/common/components.ts +0 -32
- package/src/theme/components/index.ts +1 -0
- package/src/theme/components/muiTableCell.ts +50 -0
- package/src/theme/theme.ts +1 -1
- package/src/views/ContentView/contentView.tsx +4 -1
- package/src/views/ExploreView/exploreView.tsx +2 -1
- package/types/data-explorer-ui.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [16.0.0](https://github.com/DataBiosphere/findable-ui/compare/v15.0.2...v16.0.0) (2024-11-25)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### ⚠ BREAKING CHANGES
|
|
7
|
+
|
|
8
|
+
* option to add row count on tables ([#284](https://github.com/DataBiosphere/findable-ui/issues/284)) (#285)
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* breadcrumbs should not inherit the new link style ([#271](https://github.com/DataBiosphere/findable-ui/issues/271)) ([#280](https://github.com/DataBiosphere/findable-ui/issues/280)) ([bae0178](https://github.com/DataBiosphere/findable-ui/commit/bae017818f3c13aea39530e9e7a1a9dd63123f1a))
|
|
13
|
+
* option to add row count on tables ([#284](https://github.com/DataBiosphere/findable-ui/issues/284)) ([#285](https://github.com/DataBiosphere/findable-ui/issues/285)) ([1643efb](https://github.com/DataBiosphere/findable-ui/commit/1643efbf366546509a07b1a59ba00a131f081e13))
|
|
14
|
+
* update contentlayout to centre content when there is no navigation ([#282](https://github.com/DataBiosphere/findable-ui/issues/282)) ([#286](https://github.com/DataBiosphere/findable-ui/issues/286)) ([798312f](https://github.com/DataBiosphere/findable-ui/commit/798312f803038d52463698caf0f415914668d4be))
|
|
15
|
+
|
|
3
16
|
## [15.0.2](https://github.com/DataBiosphere/findable-ui/compare/v15.0.1...v15.0.2) (2024-11-20)
|
|
4
17
|
|
|
5
18
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { TableCell
|
|
1
|
+
import { TableCell } from "@mui/material";
|
|
2
2
|
import { flexRender } from "@tanstack/react-table";
|
|
3
3
|
import React, { Fragment } from "react";
|
|
4
|
-
import { getTableCellPadding } from "../../../../../Table/components/TableCell/common/utils";
|
|
4
|
+
import { getTableCellAlign, getTableCellPadding, } from "../../../../../Table/components/TableCell/common/utils";
|
|
5
5
|
import { TableRow } from "../../../../../Table/components/TableRow/tableRow.styles";
|
|
6
6
|
export const TableRows = ({ tableInstance, tableView, }) => {
|
|
7
7
|
const { getRowModel } = tableInstance;
|
|
@@ -14,7 +14,7 @@ export const TableRows = ({ tableInstance, tableView, }) => {
|
|
|
14
14
|
return null; // Display of aggregated cells is currently not supported.
|
|
15
15
|
if (cell.getIsPlaceholder())
|
|
16
16
|
return null; // Display of placeholder cells is currently not supported.
|
|
17
|
-
return (React.createElement(
|
|
17
|
+
return (React.createElement(TableCell, { key: cell.id, align: getTableCellAlign(cell.column), padding: getTableCellPadding(cell.column.id), size: tableCellSize }, flexRender(cell.column.columnDef.cell, cell.getContext())));
|
|
18
18
|
})));
|
|
19
19
|
})));
|
|
20
20
|
};
|
|
@@ -3,8 +3,10 @@ import { getCoreRowModel, useReactTable, } from "@tanstack/react-table";
|
|
|
3
3
|
import React from "react";
|
|
4
4
|
import { BREAKPOINT_FN_NAME, useBreakpointHelper, } from "../../../../hooks/useBreakpointHelper";
|
|
5
5
|
import { TABLET } from "../../../../theme/common/breakpoints";
|
|
6
|
+
import { COLUMN_DEF } from "../../../Table/common/columnDef";
|
|
6
7
|
import { ROW_DIRECTION } from "../../../Table/common/entities";
|
|
7
8
|
import { TableHead } from "../../../Table/components/TableHead/tableHead";
|
|
9
|
+
import { ROW_POSITION } from "../../../Table/features/RowPosition/constants";
|
|
8
10
|
import { ROW_PREVIEW } from "../../../Table/features/RowPreview/constants";
|
|
9
11
|
import { GridTable } from "../../../Table/table.styles";
|
|
10
12
|
import { generateColumnDefinitions } from "./common/utils";
|
|
@@ -16,8 +18,11 @@ export const Table = ({ className, collapsable = true, columns, gridTemplateColu
|
|
|
16
18
|
const { stickyHeader = false } = table || {};
|
|
17
19
|
const { sx: tableContainerSx } = tableContainer || {};
|
|
18
20
|
const tableInstance = useReactTable({
|
|
19
|
-
_features: [ROW_PREVIEW],
|
|
20
|
-
columns: generateColumnDefinitions(
|
|
21
|
+
_features: [ROW_POSITION, ROW_PREVIEW],
|
|
22
|
+
columns: generateColumnDefinitions([
|
|
23
|
+
COLUMN_DEF.ROW_POSITION,
|
|
24
|
+
...columns,
|
|
25
|
+
]),
|
|
21
26
|
data: items,
|
|
22
27
|
enableSorting: false,
|
|
23
28
|
getCoreRowModel: getCoreRowModel(),
|
|
@@ -2,7 +2,7 @@ import { css } from "@emotion/react";
|
|
|
2
2
|
import styled from "@emotion/styled";
|
|
3
3
|
import { FormControl as MFormControl } from "@mui/material";
|
|
4
4
|
import { mediaTabletUp } from "../../../../styles/common/mixins/breakpoints";
|
|
5
|
-
import { inkMain,
|
|
5
|
+
import { inkMain, smokeMain } from "../../../../styles/common/mixins/colors";
|
|
6
6
|
import { textBodyLarge500 } from "../../../../styles/common/mixins/fonts";
|
|
7
7
|
import { sectionMargin, sectionMarginSm, } from "../../../common/Section/section.styles";
|
|
8
8
|
export const margin = ({ theme }) => css `
|
|
@@ -64,8 +64,6 @@ export const TableFormControl = styled(FormControl) `
|
|
|
64
64
|
|
|
65
65
|
.MuiTable-root {
|
|
66
66
|
th {
|
|
67
|
-
background-color: ${smokeLightest};
|
|
68
|
-
|
|
69
67
|
.MuiFormControlLabel-label {
|
|
70
68
|
font: inherit;
|
|
71
69
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
|
+
import { BaseComponentProps } from "../../../types";
|
|
2
3
|
import { LayoutStyle } from "./common/entities";
|
|
3
4
|
export interface ContentLayoutProps {
|
|
4
|
-
className?: string;
|
|
5
5
|
content: ReactNode;
|
|
6
6
|
layoutStyle?: LayoutStyle;
|
|
7
7
|
navigation?: ReactNode;
|
|
8
8
|
outline?: ReactNode;
|
|
9
9
|
}
|
|
10
|
-
export declare const ContentLayout: ({ className, content, layoutStyle, navigation, outline, }: ContentLayoutProps) => JSX.Element;
|
|
10
|
+
export declare const ContentLayout: ({ className, content, layoutStyle, navigation, outline, }: BaseComponentProps & ContentLayoutProps) => JSX.Element;
|
|
@@ -5,7 +5,7 @@ import { Content, ContentGrid, ContentLayout as Layout, Navigation, NavigationGr
|
|
|
5
5
|
export const ContentLayout = ({ className, content, layoutStyle, navigation, outline, }) => {
|
|
6
6
|
const { asPath } = useRouter();
|
|
7
7
|
const { layoutState: { headerHeight }, } = useLayoutState();
|
|
8
|
-
return (React.createElement(Layout, { className: className, panelColor: layoutStyle?.content },
|
|
8
|
+
return (React.createElement(Layout, { className: className, hasNavigation: Boolean(navigation), panelColor: layoutStyle?.content },
|
|
9
9
|
navigation && (React.createElement(NavigationGrid, { headerHeight: headerHeight, panelColor: layoutStyle?.navigation },
|
|
10
10
|
React.createElement(Positioner, { headerHeight: headerHeight },
|
|
11
11
|
React.createElement(Navigation, null, navigation)))),
|
|
@@ -22,10 +22,17 @@ export const ContentLayout = styled.div `
|
|
|
22
22
|
margin: 0 auto;
|
|
23
23
|
|
|
24
24
|
${mediaDesktopSmallUp} {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
${({ hasNavigation }) => hasNavigation
|
|
26
|
+
? css `
|
|
27
|
+
grid-template-areas: "navigation content";
|
|
28
|
+
grid-template-columns:
|
|
29
|
+
${NAV_GRID_WIDTH}px
|
|
30
|
+
1fr;
|
|
31
|
+
`
|
|
32
|
+
: css `
|
|
33
|
+
grid-template-areas: "content";
|
|
34
|
+
grid-template-columns: 1fr;
|
|
35
|
+
`};
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
${media1366Up} {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TABLE_CELL_PROPS } from "../../../styles/common/mui/tableCell";
|
|
2
|
+
import { ACCESSOR_KEYS } from "../../TableCreator/common/constants";
|
|
3
|
+
import { RowPositionCell } from "../components/TableCell/components/RowPositionCell/rowPositionCell";
|
|
4
|
+
export const COLUMN_DEF = {
|
|
5
|
+
ROW_POSITION: {
|
|
6
|
+
cell: RowPositionCell,
|
|
7
|
+
enableHiding: false,
|
|
8
|
+
enableSorting: false,
|
|
9
|
+
header: "",
|
|
10
|
+
id: ACCESSOR_KEYS.ROW_POSITION,
|
|
11
|
+
meta: {
|
|
12
|
+
align: TABLE_CELL_PROPS.ALIGN.RIGHT,
|
|
13
|
+
header: "",
|
|
14
|
+
width: "max-content",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import { TableCellProps
|
|
2
|
-
import { CoreCell, CoreHeader, RowData } from "@tanstack/react-table";
|
|
1
|
+
import { TableCellProps } from "@mui/material";
|
|
2
|
+
import { Column, CoreCell, CoreHeader, RowData } from "@tanstack/react-table";
|
|
3
|
+
/**
|
|
4
|
+
* Returns table cell alignment based on the cell.
|
|
5
|
+
* @param column - Column.
|
|
6
|
+
* @returns table cell alignment.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getTableCellAlign<T extends RowData, TValue>(column: Column<T, TValue>): TableCellProps["align"];
|
|
3
9
|
/**
|
|
4
10
|
* Returns table cell padding based on the cell ID.
|
|
5
11
|
* @param id - Cell ID.
|
|
6
12
|
* @returns table cell padding.
|
|
7
13
|
*/
|
|
8
|
-
export declare function getTableCellPadding<T extends RowData, TValue>(id: CoreHeader<T, TValue>["id"] | CoreCell<T, TValue>["id"]):
|
|
14
|
+
export declare function getTableCellPadding<T extends RowData, TValue>(id: CoreHeader<T, TValue>["id"] | CoreCell<T, TValue>["id"]): TableCellProps["padding"];
|
|
@@ -1,11 +1,25 @@
|
|
|
1
|
+
import { TABLE_CELL_PROPS } from "../../../../../styles/common/mui/tableCell";
|
|
1
2
|
import { ACCESSOR_KEYS } from "../../../../TableCreator/common/constants";
|
|
3
|
+
/**
|
|
4
|
+
* Returns table cell alignment based on the cell.
|
|
5
|
+
* @param column - Column.
|
|
6
|
+
* @returns table cell alignment.
|
|
7
|
+
*/
|
|
8
|
+
export function getTableCellAlign(column) {
|
|
9
|
+
return column.columnDef.meta?.align;
|
|
10
|
+
}
|
|
2
11
|
/**
|
|
3
12
|
* Returns table cell padding based on the cell ID.
|
|
4
13
|
* @param id - Cell ID.
|
|
5
14
|
* @returns table cell padding.
|
|
6
15
|
*/
|
|
7
16
|
export function getTableCellPadding(id) {
|
|
8
|
-
|
|
9
|
-
|
|
17
|
+
switch (id) {
|
|
18
|
+
case ACCESSOR_KEYS.ROW_POSITION:
|
|
19
|
+
return TABLE_CELL_PROPS.PADDING.NORMAL;
|
|
20
|
+
case ACCESSOR_KEYS.SELECT:
|
|
21
|
+
return TABLE_CELL_PROPS.PADDING.CHECKBOX;
|
|
22
|
+
default:
|
|
23
|
+
return TABLE_CELL_PROPS.PADDING.NORMAL;
|
|
10
24
|
}
|
|
11
25
|
}
|
package/lib/components/Table/components/TableCell/components/RowPositionCell/rowPositionCell.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CellContext, RowData } from "@tanstack/react-table";
|
|
2
|
+
import { BaseComponentProps } from "../../../../../types";
|
|
3
|
+
export declare const RowPositionCell: <TData extends RowData, TValue>({ className, ...cellContext }: BaseComponentProps & CellContext<TData, TValue>) => JSX.Element;
|
package/lib/components/Table/components/TableCell/components/RowPositionCell/rowPositionCell.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Typography } from "@mui/material";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { TYPOGRAPHY_PROPS } from "./constants";
|
|
4
|
+
export const RowPositionCell = ({ className, ...cellContext }) => {
|
|
5
|
+
return (React.createElement(Typography, { ...TYPOGRAPHY_PROPS, className: className, component: "div" }, cellContext.row.getRowPosition()));
|
|
6
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TableHead as MTableHead, TableRow as MTableRow, TableCell, TableSortLabel, } from "@mui/material";
|
|
2
2
|
import { flexRender } from "@tanstack/react-table";
|
|
3
3
|
import React, { Fragment } from "react";
|
|
4
4
|
import { ROW_DIRECTION } from "../../common/entities";
|
|
5
5
|
import { getTableSortLabelProps } from "../../common/utils";
|
|
6
|
-
import { getTableCellPadding } from "../TableCell/common/utils";
|
|
6
|
+
import { getTableCellAlign, getTableCellPadding, } from "../TableCell/common/utils";
|
|
7
7
|
export const TableHead = ({ rowDirection, tableInstance, }) => {
|
|
8
8
|
return (React.createElement(Fragment, null, rowDirection === ROW_DIRECTION.DEFAULT &&
|
|
9
9
|
tableInstance.getHeaderGroups().map((headerGroup) => (React.createElement(MTableHead, { key: headerGroup.id },
|
|
10
10
|
React.createElement(MTableRow, null, headerGroup.headers.map((header) => {
|
|
11
11
|
const { column: { columnDef: { meta: { enableSortingInteraction = true } = {}, }, }, } = header;
|
|
12
|
-
return header.column.getIsGrouped() ? null : (React.createElement(
|
|
12
|
+
return header.column.getIsGrouped() ? null : (React.createElement(TableCell, { key: header.id, align: getTableCellAlign(header.column), padding: getTableCellPadding(header.id) }, header.column.getCanSort() && enableSortingInteraction ? (React.createElement(TableSortLabel, { ...getTableSortLabelProps(header.column) }, flexRender(header.column.columnDef.header, header.getContext()))) : (flexRender(header.column.columnDef.header, header.getContext()))));
|
|
13
13
|
})))))));
|
|
14
14
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { TableCell
|
|
1
|
+
import { TableCell } from "@mui/material";
|
|
2
2
|
import { flexRender } from "@tanstack/react-table";
|
|
3
3
|
import React, { Fragment } from "react";
|
|
4
|
-
import { getTableCellPadding } from "../TableCell/common/utils";
|
|
4
|
+
import { getTableCellAlign, getTableCellPadding, } from "../TableCell/common/utils";
|
|
5
5
|
import { TableRow } from "../TableRow/tableRow.styles";
|
|
6
6
|
export const TableRows = ({ tableInstance, virtualizer, }) => {
|
|
7
7
|
const { getRowModel } = tableInstance;
|
|
@@ -10,6 +10,6 @@ export const TableRows = ({ tableInstance, virtualizer, }) => {
|
|
|
10
10
|
return (React.createElement(Fragment, null, virtualItems.map((virtualRow) => {
|
|
11
11
|
const row = rows[virtualRow.index];
|
|
12
12
|
const { getIsPreview } = row;
|
|
13
|
-
return (React.createElement(TableRow, { key: row.id, "data-index": virtualRow.index, isPreview: getIsPreview(), ref: virtualizer.measureElement }, row.getVisibleCells().map((cell) => (React.createElement(
|
|
13
|
+
return (React.createElement(TableRow, { key: row.id, "data-index": virtualRow.index, isPreview: getIsPreview(), ref: virtualizer.measureElement }, row.getVisibleCells().map((cell) => (React.createElement(TableCell, { key: cell.id, align: getTableCellAlign(cell.column), padding: getTableCellPadding(cell.column.id) }, flexRender(cell.column.columnDef.cell, cell.getContext()))))));
|
|
14
14
|
})));
|
|
15
15
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getRowModel, getRowPosition, initInitialState } from "./utils";
|
|
2
|
+
export const ROW_POSITION = {
|
|
3
|
+
createCell: (cell, column, row, table) => {
|
|
4
|
+
row.getRowPosition = () => {
|
|
5
|
+
return getRowPosition(row.id, table);
|
|
6
|
+
};
|
|
7
|
+
},
|
|
8
|
+
createTable: (table) => {
|
|
9
|
+
const originalGetRowModel = table.getRowModel.bind(table);
|
|
10
|
+
table.getRowModel = () => {
|
|
11
|
+
return getRowModel(table, originalGetRowModel);
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
getInitialState: (initialState) => {
|
|
15
|
+
return initInitialState(initialState);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { InitialTableState, RowData, RowModel, Table, TableState } from "@tanstack/react-table";
|
|
2
|
+
/**
|
|
3
|
+
* Returns row model, with getter for row position.
|
|
4
|
+
* @param table - Table.
|
|
5
|
+
* @param getRowModel - Table getRowModel function.
|
|
6
|
+
* @returns row model.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getRowModel<T extends RowData>(table: Table<T>, getRowModel: Table<T>[`getRowModel`]): RowModel<T>;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the position of the row in the table.
|
|
11
|
+
* @param rowId - Row ID.
|
|
12
|
+
* @param table - Table.
|
|
13
|
+
* @returns row position.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getRowPosition<T extends RowData>(rowId: string, table: Table<T>): number;
|
|
16
|
+
/**
|
|
17
|
+
* Returns the initial table state.
|
|
18
|
+
* @param initialState - Initial state.
|
|
19
|
+
* @returns initial state.
|
|
20
|
+
*/
|
|
21
|
+
export declare function initInitialState(initialState?: InitialTableState): Partial<TableState>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ACCESSOR_KEYS } from "../../../TableCreator/common/constants";
|
|
2
|
+
import { DEFAULT_PAGINATION } from "../constants";
|
|
3
|
+
/**
|
|
4
|
+
* Returns row model, with getter for row position.
|
|
5
|
+
* @param table - Table.
|
|
6
|
+
* @param getRowModel - Table getRowModel function.
|
|
7
|
+
* @returns row model.
|
|
8
|
+
*/
|
|
9
|
+
export function getRowModel(table, getRowModel) {
|
|
10
|
+
const rowModel = getRowModel();
|
|
11
|
+
rowModel.rows.forEach(({ id }, i) => {
|
|
12
|
+
rowModel.rowsById[id].getRowPosition = () => calculateRowPosition(table, i);
|
|
13
|
+
});
|
|
14
|
+
return rowModel;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns the position of the row in the table.
|
|
18
|
+
* @param rowId - Row ID.
|
|
19
|
+
* @param table - Table.
|
|
20
|
+
* @returns row position.
|
|
21
|
+
*/
|
|
22
|
+
export function getRowPosition(rowId, table) {
|
|
23
|
+
const { getRowModel } = table;
|
|
24
|
+
const { rowsById } = getRowModel();
|
|
25
|
+
return rowsById[rowId].getRowPosition();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Calculates the position of the row in the table.
|
|
29
|
+
* @param table - Table.
|
|
30
|
+
* @param index - Row index.
|
|
31
|
+
* @returns row position.
|
|
32
|
+
*/
|
|
33
|
+
function calculateRowPosition(table, index) {
|
|
34
|
+
const { getState } = table;
|
|
35
|
+
const { pagination: { pageIndex, pageSize }, } = getState();
|
|
36
|
+
return pageIndex * pageSize + (index + 1);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns the initial table state.
|
|
40
|
+
* @param initialState - Initial state.
|
|
41
|
+
* @returns initial state.
|
|
42
|
+
*/
|
|
43
|
+
export function initInitialState(initialState) {
|
|
44
|
+
return {
|
|
45
|
+
...initialState,
|
|
46
|
+
columnVisibility: {
|
|
47
|
+
[ACCESSOR_KEYS.ROW_POSITION]: false,
|
|
48
|
+
...initialState?.columnVisibility,
|
|
49
|
+
},
|
|
50
|
+
pagination: {
|
|
51
|
+
...DEFAULT_PAGINATION,
|
|
52
|
+
...initialState?.pagination,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { RowData } from "@tanstack/react-table";
|
|
2
|
+
import { RowPositionRow } from "./RowPosition/types";
|
|
2
3
|
import { RowPreviewInstance, RowPreviewOptions, RowPreviewRow, RowPreviewTableState } from "./RowPreview/entities";
|
|
3
4
|
export type CustomFeatureInitialTableState = Partial<RowPreviewTableState>;
|
|
4
5
|
export type CustomFeatureInstance<T extends RowData> = RowPreviewInstance<T>;
|
|
5
6
|
export type CustomFeatureOptions = RowPreviewOptions;
|
|
6
|
-
export type CustomFeatureRow = RowPreviewRow;
|
|
7
|
+
export type CustomFeatureRow = RowPositionRow & RowPreviewRow;
|
|
7
8
|
export type CustomFeatureTableState = RowPreviewTableState;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ColumnDef, CoreOptions, InitialTableState, RowData } from "@tanstack/react-table";
|
|
2
|
-
import { ListViewConfig } from "../../config/entities";
|
|
2
|
+
import { ListConfig, ListViewConfig } from "../../config/entities";
|
|
3
3
|
export interface TableProps<T extends RowData> {
|
|
4
4
|
columns: ColumnDef<T>[];
|
|
5
5
|
getRowId?: CoreOptions<T>["getRowId"];
|
|
@@ -7,6 +7,7 @@ export interface TableProps<T extends RowData> {
|
|
|
7
7
|
items: T[];
|
|
8
8
|
listView?: ListViewConfig;
|
|
9
9
|
loading?: boolean;
|
|
10
|
+
tableOptions?: ListConfig<T>["tableOptions"];
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
13
|
* This table can be Controlled or Uncontrolled based on the set of props passed to it.
|
|
@@ -18,7 +19,8 @@ export interface TableProps<T extends RowData> {
|
|
|
18
19
|
* @param tableProps.initialState - Initial table state.
|
|
19
20
|
* @param tableProps.items - Row data to display.
|
|
20
21
|
* @param tableProps.listView - List view configuration.
|
|
22
|
+
* @param tableProps.tableOptions - TanStack table options.
|
|
21
23
|
* @returns Configured table element for display.
|
|
22
24
|
*/
|
|
23
|
-
export declare const TableComponent: <T extends RowData>({ columns, getRowId, initialState, items, listView, }: TableProps<T>) => JSX.Element;
|
|
25
|
+
export declare const TableComponent: <T extends RowData>({ columns, getRowId, initialState, items, listView, tableOptions, }: TableProps<T>) => JSX.Element;
|
|
24
26
|
export declare const Table: typeof TableComponent;
|
|
@@ -18,6 +18,7 @@ import { Pagination as DXPagination } from "./components/Pagination/pagination";
|
|
|
18
18
|
import { TableBody } from "./components/TableBody/tableBody";
|
|
19
19
|
import { TableHead } from "./components/TableHead/tableHead";
|
|
20
20
|
import { TableToolbar } from "./components/TableToolbar/tableToolbar";
|
|
21
|
+
import { ROW_POSITION } from "./features/RowPosition/constants";
|
|
21
22
|
import { ROW_PREVIEW } from "./features/RowPreview/constants";
|
|
22
23
|
import { GridTable } from "./table.styles";
|
|
23
24
|
/**
|
|
@@ -30,9 +31,10 @@ import { GridTable } from "./table.styles";
|
|
|
30
31
|
* @param tableProps.initialState - Initial table state.
|
|
31
32
|
* @param tableProps.items - Row data to display.
|
|
32
33
|
* @param tableProps.listView - List view configuration.
|
|
34
|
+
* @param tableProps.tableOptions - TanStack table options.
|
|
33
35
|
* @returns Configured table element for display.
|
|
34
36
|
*/
|
|
35
|
-
export const TableComponent = ({ columns, getRowId, initialState, items, listView, }) => {
|
|
37
|
+
export const TableComponent = ({ columns, getRowId, initialState, items, listView, tableOptions, }) => {
|
|
36
38
|
const tabletDown = useBreakpointHelper(BREAKPOINT_FN_NAME.DOWN, TABLET);
|
|
37
39
|
const exploreMode = useExploreMode();
|
|
38
40
|
const { exploreDispatch, exploreState } = useExploreState();
|
|
@@ -84,8 +86,23 @@ export const TableComponent = ({ columns, getRowId, initialState, items, listVie
|
|
|
84
86
|
rowSelection,
|
|
85
87
|
sorting,
|
|
86
88
|
};
|
|
89
|
+
/**
|
|
90
|
+
* TODO: Refactor `ListConfig` to follow the API patterns of the TanStack Table library.
|
|
91
|
+
* TODO: Update `ColumnConfig` to follow the `ColumnDef` API of TanStack Table.
|
|
92
|
+
* - Standardize column definitions to leverage the full power of TanStack Table's feature set and improve compatibility.
|
|
93
|
+
* TODO: Deprecate the following properties:
|
|
94
|
+
* - `defaultSort` in `ListConfig`: Replace this with TanStack Table's `tableOptions.initialState.sorting` feature.
|
|
95
|
+
* - `columnVisible` in `ColumnConfig`: Replace this with TanStack Table's `tableOptions.initialState.columnVisibility` feature.
|
|
96
|
+
* TODO: Define `columnVisibility` and `sorting` directly within `ListConfig` via the `tableOptions.initialState` property.
|
|
97
|
+
* - This will simplify the configuration structure and centralize table state definitions, reducing redundancy and improving clarity.
|
|
98
|
+
* - It will also allow for direct configuration of other TanStack Table options such as `columnOrder` via `tableOptions.initialState.columnOrder`.
|
|
99
|
+
*
|
|
100
|
+
* Current Workaround:
|
|
101
|
+
* - The `initialState` property from `tableOptions` is destructured to separate it from other options. This allows the remaining properties in `tableOptions` to be passed directly to the TanStack Table configuration without breaking the current ListConfig `defaultSort` and `columnVisible` properties.
|
|
102
|
+
*/
|
|
103
|
+
const { initialState: _initialState, ...restTableOptions } = tableOptions ?? {};
|
|
87
104
|
const tableInstance = useReactTable({
|
|
88
|
-
_features: [ROW_PREVIEW],
|
|
105
|
+
_features: [ROW_POSITION, ROW_PREVIEW],
|
|
89
106
|
columns,
|
|
90
107
|
data: items,
|
|
91
108
|
enableColumnFilters: true, // client-side filtering.
|
|
@@ -104,7 +121,7 @@ export const TableComponent = ({ columns, getRowId, initialState, items, listVie
|
|
|
104
121
|
getPaginationRowModel: getPaginationRowModel(),
|
|
105
122
|
getRowId,
|
|
106
123
|
getSortedRowModel: clientFiltering ? getSortedRowModel() : undefined,
|
|
107
|
-
initialState,
|
|
124
|
+
initialState: { ...initialState, ..._initialState }, // `sorting` and `columnVisibility` are managed by the ExploreState.
|
|
108
125
|
manualPagination: true,
|
|
109
126
|
manualSorting: !clientFiltering,
|
|
110
127
|
onColumnVisibilityChange,
|
|
@@ -113,6 +130,7 @@ export const TableComponent = ({ columns, getRowId, initialState, items, listVie
|
|
|
113
130
|
onSortingChange,
|
|
114
131
|
pageCount,
|
|
115
132
|
state,
|
|
133
|
+
...restTableOptions,
|
|
116
134
|
});
|
|
117
135
|
const { getAllColumns, getRowModel, getState, getVisibleFlatColumns, nextPage: tableNextPage, previousPage: tablePreviousPage, } = tableInstance;
|
|
118
136
|
const allColumns = getAllColumns();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RowData } from "@tanstack/react-table";
|
|
2
2
|
import { BaseColumnConfig } from "./entities";
|
|
3
3
|
export declare const ACCESSOR_KEYS: {
|
|
4
|
+
ROW_POSITION: string;
|
|
4
5
|
SELECT: string;
|
|
5
6
|
};
|
|
6
7
|
export declare const COLUMN_CONFIGS: Record<string, BaseColumnConfig<RowData, unknown>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ColumnSort, CoreOptions, RowData } from "@tanstack/react-table";
|
|
2
|
-
import { ColumnConfig, ListViewConfig } from "../../config/entities";
|
|
2
|
+
import { ColumnConfig, ListConfig, ListViewConfig } from "../../config/entities";
|
|
3
3
|
export interface TableCreatorProps<T> {
|
|
4
4
|
columns: ColumnConfig<T>[];
|
|
5
5
|
defaultSort: ColumnSort | undefined;
|
|
@@ -7,5 +7,6 @@ export interface TableCreatorProps<T> {
|
|
|
7
7
|
items: T[];
|
|
8
8
|
listView?: ListViewConfig;
|
|
9
9
|
loading?: boolean;
|
|
10
|
+
tableOptions?: ListConfig<T>["tableOptions"];
|
|
10
11
|
}
|
|
11
|
-
export declare const TableCreator: <T extends RowData>({ columns, defaultSort, getRowId, items, listView, loading, }: TableCreatorProps<T>) => JSX.Element;
|
|
12
|
+
export declare const TableCreator: <T extends RowData>({ columns, defaultSort, getRowId, items, listView, loading, tableOptions, }: TableCreatorProps<T>) => JSX.Element;
|
|
@@ -2,6 +2,7 @@ import React, { useMemo } from "react";
|
|
|
2
2
|
import { PAPER_PANEL_STYLE } from "../common/Paper/paper";
|
|
3
3
|
import { ComponentCreator } from "../ComponentCreator/ComponentCreator";
|
|
4
4
|
import { Loading } from "../Loading/loading";
|
|
5
|
+
import { COLUMN_DEF } from "../Table/common/columnDef";
|
|
5
6
|
import { arrIncludesSome, getInitialState, sortingFn, } from "../Table/common/utils";
|
|
6
7
|
import { RowSelectionCell } from "../Table/components/TableCell/components/RowSelectionCell/rowSelectionCell";
|
|
7
8
|
import { HeadSelectionCell } from "../Table/components/TableHead/components/HeadSelectionCell/headSelectionCell";
|
|
@@ -18,7 +19,7 @@ const createHeaderSelectionCell = () => function CellCreator({ table }) {
|
|
|
18
19
|
const createRowSelectionCell = () => function CellCreator({ row }) {
|
|
19
20
|
return React.createElement(RowSelectionCell, { row: row });
|
|
20
21
|
};
|
|
21
|
-
export const TableCreator = ({ columns, defaultSort, getRowId, items, listView, loading, }) => {
|
|
22
|
+
export const TableCreator = ({ columns, defaultSort, getRowId, items, listView, loading, tableOptions, }) => {
|
|
22
23
|
const columnDefs = useMemo(() => columns.reduce((acc, columnConfig) => {
|
|
23
24
|
acc.push({
|
|
24
25
|
...buildBaseColumnDef(columnConfig),
|
|
@@ -28,6 +29,8 @@ export const TableCreator = ({ columns, defaultSort, getRowId, items, listView,
|
|
|
28
29
|
});
|
|
29
30
|
return acc;
|
|
30
31
|
}, [
|
|
32
|
+
/* Initialize column definitions with the "row position" column */
|
|
33
|
+
COLUMN_DEF.ROW_POSITION,
|
|
31
34
|
/* Initialize column definitions with the "select" column */
|
|
32
35
|
{
|
|
33
36
|
...buildBaseColumnDef(COLUMN_CONFIGS.SELECT),
|
|
@@ -38,5 +41,5 @@ export const TableCreator = ({ columns, defaultSort, getRowId, items, listView,
|
|
|
38
41
|
const initialState = getInitialState(columns, defaultSort);
|
|
39
42
|
return (React.createElement(TableCreatorContainer, null,
|
|
40
43
|
React.createElement(Loading, { appear: false, loading: loading || false, panelStyle: PAPER_PANEL_STYLE.FLUID }),
|
|
41
|
-
React.createElement(Table, { columns: columnDefs, getRowId: getRowId, initialState: initialState, items: items, listView: listView, loading: loading })));
|
|
44
|
+
React.createElement(Table, { columns: columnDefs, getRowId: getRowId, initialState: initialState, items: items, listView: listView, loading: loading, tableOptions: tableOptions })));
|
|
42
45
|
};
|
|
@@ -2,6 +2,7 @@ import ChevronRightRoundedIcon from "@mui/icons-material/ChevronRightRounded";
|
|
|
2
2
|
import { Link, Breadcrumbs as MBreadcrumbs, Typography } from "@mui/material";
|
|
3
3
|
import NLink from "next/link";
|
|
4
4
|
import React from "react";
|
|
5
|
+
import { LINK_PROPS } from "./constants";
|
|
5
6
|
export const Breadcrumbs = ({ breadcrumbs, className, Separator = React.createElement(ChevronRightRoundedIcon, { fontSize: "xxsmall" }), }) => {
|
|
6
|
-
return (React.createElement(React.Fragment, null, breadcrumbs.length > 0 ? (React.createElement(MBreadcrumbs, { className: className, separator: Separator }, breadcrumbs.map(({ path, text }, b) => path ? (React.createElement(Link, { component: NLink, key: b, href: path }, text)) : (React.createElement(Typography, { key: `${path}${b}`, maxWidth: 180, noWrap: true }, text))))) : null));
|
|
7
|
+
return (React.createElement(React.Fragment, null, breadcrumbs.length > 0 ? (React.createElement(MBreadcrumbs, { className: className, separator: Separator }, breadcrumbs.map(({ path, text }, b) => path ? (React.createElement(Link, { ...LINK_PROPS, component: NLink, key: b, href: path }, text)) : (React.createElement(Typography, { key: `${path}${b}`, maxWidth: 180, noWrap: true }, text))))) : null));
|
|
7
8
|
};
|