playbook_ui 13.20.0.pre.alpha.PBNTR225advancedtablefeedback2375 → 13.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx +19 -21
- data/app/pb_kits/playbook/pb_advanced_table/Components/SortIconButton.tsx +3 -6
- data/app/pb_kits/playbook/pb_advanced_table/Components/SubRowHeaderRow.tsx +8 -12
- data/app/pb_kits/playbook/pb_advanced_table/Components/TableHeaderCell.tsx +9 -14
- data/app/pb_kits/playbook/pb_advanced_table/Components/ToggleIconButton.tsx +5 -9
- data/app/pb_kits/playbook/pb_advanced_table/SubKits/TableBody.tsx +10 -14
- data/app/pb_kits/playbook/pb_advanced_table/SubKits/TableHeader.tsx +8 -12
- data/app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx +2 -3
- data/app/pb_kits/playbook/pb_advanced_table/Utilities/types.ts +2 -0
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.scss +9 -2
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.tsx +78 -82
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.test.jsx +54 -54
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_collapsible_trail.jsx +7 -7
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_default.jsx +7 -7
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_expanded_control.jsx +7 -7
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_inline_row_loading.jsx +7 -7
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_inline_row_loading.md +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_loading.jsx +7 -7
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sort.jsx +7 -7
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sort_control.jsx +7 -7
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_subrow_headers.jsx +7 -7
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_options.jsx +7 -7
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_props.jsx +7 -7
- data/app/pb_kits/playbook/pb_advanced_table/docs/_mock_data.js +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_mock_data_inline_loading.js +1 -1
- data/app/pb_kits/playbook/pb_nav/_subtle_mixin.scss +0 -4
- data/app/pb_kits/playbook/pb_table/docs/example.yml +0 -3
- data/app/pb_kits/playbook/pb_table/styles/_striped.scss +2 -2
- data/app/pb_kits/playbook/pb_table/styles/_structure.scss +2 -4
- data/app/pb_kits/playbook/pb_table/table_header.html.erb +39 -49
- data/app/pb_kits/playbook/pb_table/table_header.rb +1 -8
- data/app/pb_kits/playbook/pb_table/table_row.html.erb +7 -17
- data/app/pb_kits/playbook/pb_table/table_row.rb +1 -8
- data/app/pb_kits/playbook/pb_text_input/_text_input.tsx +5 -9
- data/app/pb_kits/playbook/pb_text_input/docs/_text_input_add_on.jsx +0 -20
- data/app/pb_kits/playbook/pb_user/docs/_user_props_table.md +1 -2
- data/app/pb_kits/playbook/pb_user/docs/example.yml +0 -1
- data/dist/playbook-rails.js +1 -1
- data/lib/playbook/version.rb +2 -2
- metadata +7 -19
- data/app/pb_kits/playbook/pb_advanced_table/scss_partials/_chrome_styles.scss +0 -13
- data/app/pb_kits/playbook/pb_table/docs/_table_with_subcomponents.html.erb +0 -34
- data/app/pb_kits/playbook/pb_table/docs/_table_with_subcomponents.md +0 -7
- data/app/pb_kits/playbook/pb_table/docs/_table_with_subcomponents_as_divs.html.erb +0 -34
- data/app/pb_kits/playbook/pb_table/docs/_table_with_subcomponents_as_divs.md +0 -3
- data/app/pb_kits/playbook/pb_table/table_body.html.erb +0 -17
- data/app/pb_kits/playbook/pb_table/table_body.rb +0 -15
- data/app/pb_kits/playbook/pb_table/table_cell.html.erb +0 -17
- data/app/pb_kits/playbook/pb_table/table_cell.rb +0 -17
- data/app/pb_kits/playbook/pb_table/table_head.html.erb +0 -17
- data/app/pb_kits/playbook/pb_table/table_head.rb +0 -15
- data/app/pb_kits/playbook/pb_user/docs/_user_presence_indicator_swift.md +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89bd4e938528cafc5784b31a33e8164edd9b132e4f63f2ebbf2ba1160b07738f
|
4
|
+
data.tar.gz: b87c8966e25b1b0b6fc2a01b84ae7164436a4f2be860f49c7414f667d1c5d40f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7991e682deaf82d106bb0e2a29bb029a6299eba736a0c3e85de50366efa998db4f30026c9fcfc3cf4f7c2ac95f2fddaa38a90add59379d7c7b0890e070e8850a
|
7
|
+
data.tar.gz: 6f649c427896f5010b9721ffd3a0e0c9f282f6eb6c65c666cdbd2487aab6132175a7660b7e48bc89cbe1133736ac4a79d9911f053bb481193096f6032220e6c9
|
@@ -1,21 +1,19 @@
|
|
1
|
-
import React, { useContext } from "react"
|
2
|
-
import { Getter, Row } from "@tanstack/react-table"
|
1
|
+
import React, { useContext } from "react";
|
3
2
|
|
4
|
-
import
|
3
|
+
import Flex from "../../pb_flex/_flex";
|
4
|
+
import FlexItem from "../../pb_flex/_flex_item";
|
5
|
+
import Icon from "../../pb_icon/_icon";
|
6
|
+
import { GlobalProps } from "../../utilities/globalProps";
|
5
7
|
|
6
|
-
import {
|
7
|
-
|
8
|
-
import
|
9
|
-
import FlexItem from "../../pb_flex/_flex_item"
|
10
|
-
import Icon from "../../pb_icon/_icon"
|
11
|
-
|
12
|
-
import AdvancedTableContext from "../Context/AdvancedTableContext"
|
8
|
+
import { Getter, Row } from "@tanstack/react-table";
|
9
|
+
import { DataType } from "../Utilities/types";
|
10
|
+
import AdvancedTableContext from "../Context/AdvancedTableContext";
|
13
11
|
|
14
12
|
interface CustomCellProps {
|
15
|
-
getValue?: Getter<string
|
16
|
-
onRowToggleClick?: (arg: Row<
|
17
|
-
row: Row<
|
18
|
-
value?: string
|
13
|
+
getValue?: Getter<string>;
|
14
|
+
onRowToggleClick?: (arg: Row<DataType>) => void;
|
15
|
+
row: Row<DataType>;
|
16
|
+
value?: string;
|
19
17
|
}
|
20
18
|
|
21
19
|
export const CustomCell = ({
|
@@ -24,12 +22,12 @@ export const CustomCell = ({
|
|
24
22
|
row,
|
25
23
|
value,
|
26
24
|
}: CustomCellProps & GlobalProps) => {
|
27
|
-
const { setExpanded, expanded, inlineRowLoading } = useContext(AdvancedTableContext)
|
25
|
+
const { setExpanded, expanded, inlineRowLoading } = useContext(AdvancedTableContext);
|
28
26
|
|
29
|
-
const handleOnExpand = (row: Row<
|
30
|
-
onRowToggleClick && onRowToggleClick(row)
|
31
|
-
setExpanded({ ...expanded, [row.id]: !row.getIsExpanded() })
|
32
|
-
}
|
27
|
+
const handleOnExpand = (row: Row<DataType>) => {
|
28
|
+
onRowToggleClick && onRowToggleClick(row);
|
29
|
+
setExpanded({ ...expanded, [row.id]: !row.getIsExpanded() });
|
30
|
+
};
|
33
31
|
const RowHasChildren = row.original.children ? true : false
|
34
32
|
const renderButton = inlineRowLoading ? RowHasChildren : row.getCanExpand()
|
35
33
|
|
@@ -61,5 +59,5 @@ export const CustomCell = ({
|
|
61
59
|
</FlexItem>
|
62
60
|
</Flex>
|
63
61
|
</div>
|
64
|
-
)
|
65
|
-
}
|
62
|
+
);
|
63
|
+
};
|
@@ -1,14 +1,11 @@
|
|
1
1
|
import React from "react"
|
2
|
-
import { Header } from "@tanstack/react-table"
|
3
|
-
|
4
|
-
import { GenericObject } from "../../types"
|
5
|
-
|
6
2
|
import Icon from "../../pb_icon/_icon"
|
7
|
-
|
3
|
+
import { Header } from "@tanstack/react-table"
|
4
|
+
import { DataType } from "../Utilities/types"
|
8
5
|
import { displayIcon } from "../Utilities/IconHelpers"
|
9
6
|
|
10
7
|
type SortIconButtonProps = {
|
11
|
-
header: Header<
|
8
|
+
header: Header<DataType, unknown>
|
12
9
|
sortIcon?: string | string[]
|
13
10
|
}
|
14
11
|
export const SortIconButton = ({ header, sortIcon }: SortIconButtonProps) => {
|
@@ -1,27 +1,23 @@
|
|
1
1
|
import React, { useContext } from "react"
|
2
|
-
import { Row, Table } from "@tanstack/react-table"
|
3
|
-
|
4
|
-
import { GenericObject } from "../../types"
|
5
|
-
|
6
|
-
import { GlobalProps } from "../../utilities/globalProps"
|
7
|
-
|
8
2
|
import Flex from "../../pb_flex/_flex"
|
9
3
|
import Caption from "../../pb_caption/_caption"
|
4
|
+
import { Row, Table } from "@tanstack/react-table"
|
10
5
|
|
6
|
+
import AdvancedTableContext from "../Context/AdvancedTableContext";
|
11
7
|
import { ToggleIconButton } from "./ToggleIconButton"
|
12
8
|
import { renderCollapsibleTrail } from "./CollapsibleTrail"
|
13
9
|
|
14
10
|
import { isChrome } from "../Utilities/BrowserCheck"
|
15
|
-
|
16
|
-
import
|
11
|
+
import { DataType } from "../Utilities/types"
|
12
|
+
import { GlobalProps } from "../../utilities/globalProps"
|
17
13
|
|
18
14
|
interface SubRowHeaderRowProps {
|
19
15
|
collapsibleTrail?: boolean
|
20
16
|
enableToggleExpansion?: "all" | "header" | "none"
|
21
|
-
onClick: (row: Row<
|
22
|
-
row: Row<
|
17
|
+
onClick: (row: Row<DataType>) => void
|
18
|
+
row: Row<DataType>
|
23
19
|
subRowHeaders?: string[]
|
24
|
-
table: Table<
|
20
|
+
table: Table<DataType>
|
25
21
|
}
|
26
22
|
|
27
23
|
export const SubRowHeaderRow = ({
|
@@ -32,7 +28,7 @@ export const SubRowHeaderRow = ({
|
|
32
28
|
subRowHeaders,
|
33
29
|
table,
|
34
30
|
}: SubRowHeaderRowProps & GlobalProps) => {
|
35
|
-
const { inlineRowLoading } = useContext(AdvancedTableContext)
|
31
|
+
const { inlineRowLoading } = useContext(AdvancedTableContext);
|
36
32
|
|
37
33
|
const numberOfColumns = table.getAllFlatColumns().length
|
38
34
|
const rowHasChildren = row.original.children ? true : false
|
@@ -1,25 +1,20 @@
|
|
1
1
|
import React, { useContext } from "react"
|
2
|
-
import classnames from "classnames"
|
3
|
-
import { flexRender, Header } from "@tanstack/react-table"
|
4
|
-
|
5
|
-
import { GenericObject } from "../../types"
|
6
|
-
|
7
|
-
import { GlobalProps } from "../../utilities/globalProps"
|
8
|
-
|
2
|
+
import classnames from "classnames";
|
9
3
|
import Flex from "../../pb_flex/_flex"
|
4
|
+
import { flexRender, Header } from "@tanstack/react-table"
|
10
5
|
|
11
6
|
import { SortIconButton } from "./SortIconButton"
|
12
7
|
import { ToggleIconButton } from "./ToggleIconButton"
|
13
|
-
|
14
8
|
import { isChrome } from "../Utilities/BrowserCheck"
|
15
|
-
|
9
|
+
import { DataType } from "../Utilities/types"
|
16
10
|
import AdvancedTableContext from "../Context/AdvancedTableContext"
|
11
|
+
import { GlobalProps } from "../../utilities/globalProps"
|
17
12
|
|
18
13
|
type TableHeaderCellProps = {
|
19
14
|
enableSorting?: boolean
|
20
15
|
enableToggleExpansion?: "all" | "header" | "none"
|
21
16
|
handleExpandOrCollapse?: () => void
|
22
|
-
header?: Header<
|
17
|
+
header?: Header<DataType, unknown>
|
23
18
|
headerChildren?: React.ReactNode | React.ReactNode[]
|
24
19
|
loading?: boolean
|
25
20
|
sortIcon?: string | string[]
|
@@ -50,24 +45,24 @@ export const TableHeaderCell = ({
|
|
50
45
|
const cellClassName = classnames("table-header-cells",
|
51
46
|
`${isChrome() ? "chrome-styles" : ""}`,
|
52
47
|
`${enableSorting ? "table-header-cells-active" : ""}`
|
53
|
-
)
|
48
|
+
);
|
54
49
|
|
55
50
|
const cellId = `${loading ?
|
56
51
|
`loading-${header.id}`
|
57
52
|
: `${header.id}`
|
58
|
-
}
|
53
|
+
}`;
|
59
54
|
|
60
55
|
const isToggleExpansionEnabledLoading =
|
61
56
|
header.index === 0 &&
|
62
57
|
loading &&
|
63
58
|
(enableToggleExpansion === "all" || "header") &&
|
64
|
-
enableToggleExpansion !== "none"
|
59
|
+
enableToggleExpansion !== "none";
|
65
60
|
|
66
61
|
const isToggleExpansionEnabled =
|
67
62
|
header.index === 0 &&
|
68
63
|
!loading &&
|
69
64
|
(enableToggleExpansion === "all" || "header") &&
|
70
|
-
enableToggleExpansion !== "none"
|
65
|
+
enableToggleExpansion !== "none";
|
71
66
|
|
72
67
|
return (
|
73
68
|
<th
|
@@ -1,17 +1,13 @@
|
|
1
1
|
import React, { useContext } from "react"
|
2
|
-
import { Row } from "@tanstack/react-table"
|
3
|
-
|
4
|
-
import { GenericObject } from "../../types"
|
5
|
-
|
6
2
|
import Icon from "../../pb_icon/_icon"
|
7
|
-
|
8
|
-
import { displayIcon } from "../Utilities/IconHelpers"
|
9
|
-
|
3
|
+
import { Row } from "@tanstack/react-table"
|
10
4
|
import AdvancedTableContext from "../Context/AdvancedTableContext"
|
5
|
+
import { DataType } from "../Utilities/types"
|
6
|
+
import { displayIcon } from "../Utilities/IconHelpers"
|
11
7
|
|
12
8
|
interface ToggleIconButtonProps {
|
13
|
-
onClick: (row: Row<
|
14
|
-
row?: Row<
|
9
|
+
onClick: (row: Row<DataType>) => void
|
10
|
+
row?: Row<DataType>
|
15
11
|
}
|
16
12
|
|
17
13
|
export const ToggleIconButton = ({ row, onClick }: ToggleIconButtonProps) => {
|
@@ -1,25 +1,21 @@
|
|
1
1
|
import React, { useContext } from "react"
|
2
|
-
import classnames from "classnames"
|
3
|
-
import {
|
4
|
-
|
5
|
-
import { GenericObject } from "../../types"
|
6
|
-
|
7
|
-
import { buildCss } from "../../utilities/props"
|
8
|
-
import { globalProps } from "../../utilities/globalProps"
|
9
|
-
import { isChrome } from "../Utilities/BrowserCheck"
|
10
|
-
|
2
|
+
import classnames from "classnames";
|
3
|
+
import { buildCss } from "../../utilities/props";
|
4
|
+
import { globalProps } from "../../utilities/globalProps";
|
11
5
|
import LoadingInline from "../../pb_loading_inline/_loading_inline"
|
6
|
+
import { flexRender, Row } from "@tanstack/react-table"
|
12
7
|
|
13
8
|
import { SubRowHeaderRow } from "../Components/SubRowHeaderRow"
|
14
9
|
import { LoadingCell } from "../Components/LoadingCell"
|
15
10
|
import { renderCollapsibleTrail } from "../Components/CollapsibleTrail"
|
16
|
-
|
17
11
|
import AdvancedTableContext from "../Context/AdvancedTableContext"
|
12
|
+
import { isChrome } from "../Utilities/BrowserCheck"
|
13
|
+
import { DataType } from "../Utilities/types"
|
18
14
|
|
19
15
|
type TableBodyProps = {
|
20
|
-
className?: string
|
16
|
+
className?: string;
|
21
17
|
collapsibleTrail?: boolean
|
22
|
-
id?: string
|
18
|
+
id?: string;
|
23
19
|
subRowHeaders?: string[]
|
24
20
|
}
|
25
21
|
|
@@ -44,14 +40,14 @@ export const TableBody = ({
|
|
44
40
|
buildCss("pb_advanced_table_body"),
|
45
41
|
globalProps(props),
|
46
42
|
className
|
47
|
-
)
|
43
|
+
);
|
48
44
|
|
49
45
|
return (
|
50
46
|
<>
|
51
47
|
<tbody className={classes}
|
52
48
|
id={id}
|
53
49
|
>
|
54
|
-
{table.getRowModel().rows.map((row: Row<
|
50
|
+
{table.getRowModel().rows.map((row: Row<DataType>) => {
|
55
51
|
const isExpandable = row.getIsExpanded()
|
56
52
|
const isFirstChildofSubrow = row.depth > 0 && row.index === 0
|
57
53
|
const rowHasNoChildren = row.original.children && !row.original.children.length ? true : false
|
@@ -1,21 +1,17 @@
|
|
1
1
|
import React, { useContext } from "react"
|
2
|
-
import classnames from "classnames"
|
2
|
+
import classnames from "classnames";
|
3
|
+
import { buildCss } from "../../utilities/props";
|
4
|
+
import { globalProps } from "../../utilities/globalProps";
|
3
5
|
import { HeaderGroup } from "@tanstack/react-table"
|
4
|
-
|
5
|
-
import { GenericObject } from "../../types"
|
6
|
-
|
7
|
-
import { buildCss } from "../../utilities/props"
|
8
|
-
import { globalProps } from "../../utilities/globalProps"
|
9
|
-
|
10
|
-
import { TableHeaderCell } from "../Components/TableHeaderCell"
|
11
|
-
|
12
6
|
import AdvancedTableContext from "../Context/AdvancedTableContext"
|
7
|
+
import { TableHeaderCell } from "../Components/TableHeaderCell"
|
8
|
+
import { DataType } from "../Utilities/types"
|
13
9
|
|
14
10
|
type TableHeaderProps = {
|
15
11
|
children?: React.ReactNode | React.ReactNode[]
|
16
12
|
className?: string
|
17
13
|
enableSorting?: boolean
|
18
|
-
id?: string
|
14
|
+
id?: string;
|
19
15
|
sortIcon?: string | string[]
|
20
16
|
}
|
21
17
|
|
@@ -38,7 +34,7 @@ export const TableHeader = ({
|
|
38
34
|
buildCss("pb_advanced_table_header"),
|
39
35
|
globalProps(props),
|
40
36
|
className
|
41
|
-
)
|
37
|
+
);
|
42
38
|
|
43
39
|
|
44
40
|
return (
|
@@ -47,7 +43,7 @@ export const TableHeader = ({
|
|
47
43
|
id={id}
|
48
44
|
>
|
49
45
|
{/* Get the header groups (only one in this example) */}
|
50
|
-
{table.getHeaderGroups().map((headerGroup: HeaderGroup<
|
46
|
+
{table.getHeaderGroups().map((headerGroup: HeaderGroup<DataType>) => (
|
51
47
|
<tr key={`${headerGroup.id}-headerGroup`}>
|
52
48
|
{headerGroup.headers.map(header => (
|
53
49
|
<TableHeaderCell
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import { RowModel } from "@tanstack/react-table"
|
2
|
-
import { ExpandedStateObject } from "./types"
|
3
|
-
import { GenericObject } from "../../types"
|
2
|
+
import { DataType, ExpandedStateObject } from "./types"
|
4
3
|
|
5
4
|
const filterExpandableRows = (expandedState: Record<string, boolean>) => {
|
6
5
|
for (const expandedRow in expandedState) {
|
@@ -12,7 +11,7 @@ const filterExpandableRows = (expandedState: Record<string, boolean>) => {
|
|
12
11
|
}
|
13
12
|
|
14
13
|
export const updateExpandAndCollapseState = (
|
15
|
-
tableRows: RowModel<
|
14
|
+
tableRows: RowModel<DataType>,
|
16
15
|
expanded: Record<string, boolean>,
|
17
16
|
targetParent: string
|
18
17
|
) => {
|
@@ -4,7 +4,6 @@
|
|
4
4
|
@import "../tokens/spacing";
|
5
5
|
@import "./scss_partials/loading";
|
6
6
|
@import "./scss_partials/pseudo_states";
|
7
|
-
@import "./scss_partials/chrome_styles";
|
8
7
|
|
9
8
|
.pb_advanced_table {
|
10
9
|
$border-color: 1px solid $border_light !important;
|
@@ -87,5 +86,13 @@
|
|
87
86
|
box-shadow: 1px 0px 0px 0px #e4e8f0 !important;
|
88
87
|
}
|
89
88
|
|
90
|
-
|
89
|
+
.chrome-styles:first-child {
|
90
|
+
border-right: $border-color;
|
91
|
+
}
|
92
|
+
|
93
|
+
.table-card {
|
94
|
+
.chrome-styles:first-child {
|
95
|
+
border-right: $transparent !important;
|
96
|
+
}
|
97
|
+
}
|
91
98
|
}
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import React, { useState, useEffect, useCallback } from "react"
|
2
|
-
import classnames from "classnames"
|
3
|
-
|
4
|
-
import {
|
5
|
-
|
1
|
+
import React, { useState, useEffect, useCallback } from "react";
|
2
|
+
import classnames from "classnames";
|
3
|
+
import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from "../utilities/props";
|
4
|
+
import { globalProps, GlobalProps } from "../utilities/globalProps";
|
5
|
+
import Table from "../pb_table/_table";
|
6
6
|
import {
|
7
7
|
createColumnHelper,
|
8
8
|
getCoreRowModel,
|
@@ -11,42 +11,38 @@ import {
|
|
11
11
|
Row,
|
12
12
|
useReactTable,
|
13
13
|
Getter,
|
14
|
-
} from "@tanstack/react-table"
|
15
|
-
|
16
|
-
import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from "../utilities/props"
|
17
|
-
import { globalProps, GlobalProps } from "../utilities/globalProps"
|
14
|
+
} from "@tanstack/react-table";
|
18
15
|
|
19
|
-
import
|
16
|
+
import { updateExpandAndCollapseState } from "./Utilities/ExpansionControlHelpers";
|
20
17
|
|
21
|
-
import
|
18
|
+
import { CustomCell } from "./Components/CustomCell";
|
19
|
+
import AdvancedTableContext from "./Context/AdvancedTableContext";
|
20
|
+
import { TableHeader } from "./SubKits/TableHeader";
|
21
|
+
import { TableBody } from "./SubKits/TableBody";
|
22
22
|
|
23
|
-
import {
|
24
|
-
|
25
|
-
import { CustomCell } from "./Components/CustomCell"
|
26
|
-
import { TableHeader } from "./SubKits/TableHeader"
|
27
|
-
import { TableBody } from "./SubKits/TableBody"
|
23
|
+
import { DataType } from "./Utilities/types";
|
28
24
|
|
29
25
|
type AdvancedTableProps = {
|
30
|
-
aria?: { [key: string]: string }
|
31
|
-
children?: React.ReactNode | React.ReactNode[]
|
32
|
-
className?: string
|
33
|
-
columnDefinitions:
|
34
|
-
data?: { [key: string]: string }
|
35
|
-
enableToggleExpansion?: "all" | "header" | "none"
|
36
|
-
expandedControl?:
|
26
|
+
aria?: { [key: string]: string };
|
27
|
+
children?: React.ReactNode | React.ReactNode[];
|
28
|
+
className?: string;
|
29
|
+
columnDefinitions: DataType[];
|
30
|
+
data?: { [key: string]: string };
|
31
|
+
enableToggleExpansion?: "all" | "header" | "none";
|
32
|
+
expandedControl?: DataType;
|
37
33
|
htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
|
38
|
-
id?: string
|
39
|
-
initialLoadingRowsCount?: number
|
40
|
-
inlineRowLoading?: boolean
|
41
|
-
loading?: boolean | string
|
42
|
-
onRowToggleClick?: (arg: Row<
|
43
|
-
onToggleExpansionClick?: (arg: Row<
|
44
|
-
sortControl?:
|
45
|
-
tableData:
|
46
|
-
tableOptions?:
|
47
|
-
tableProps?:
|
48
|
-
toggleExpansionIcon?: string | string[]
|
49
|
-
} & GlobalProps
|
34
|
+
id?: string;
|
35
|
+
initialLoadingRowsCount?: number;
|
36
|
+
inlineRowLoading?: boolean;
|
37
|
+
loading?: boolean | string;
|
38
|
+
onRowToggleClick?: (arg: Row<DataType>) => void;
|
39
|
+
onToggleExpansionClick?: (arg: Row<DataType>) => void;
|
40
|
+
sortControl?: DataType;
|
41
|
+
tableData: DataType[];
|
42
|
+
tableOptions?: DataType;
|
43
|
+
tableProps?: DataType;
|
44
|
+
toggleExpansionIcon?: string | string[];
|
45
|
+
} & GlobalProps;
|
50
46
|
|
51
47
|
const AdvancedTable = (props: AdvancedTableProps) => {
|
52
48
|
const {
|
@@ -69,22 +65,22 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
69
65
|
tableOptions,
|
70
66
|
tableProps,
|
71
67
|
toggleExpansionIcon = "arrows-from-line",
|
72
|
-
} = props
|
68
|
+
} = props;
|
73
69
|
|
74
70
|
const [loadingStateRowCount, setLoadingStateRowCount] = useState(
|
75
71
|
initialLoadingRowsCount
|
76
|
-
)
|
72
|
+
);
|
77
73
|
|
78
74
|
// Create a local state for expanded and setExpanded if expandedControl not used
|
79
|
-
const [localExpanded, setLocalExpanded] = useState({})
|
75
|
+
const [localExpanded, setLocalExpanded] = useState({});
|
80
76
|
|
81
77
|
// Determine whether to use the prop or the local state
|
82
|
-
const expanded = expandedControl ? expandedControl.value : localExpanded
|
78
|
+
const expanded = expandedControl ? expandedControl.value : localExpanded;
|
83
79
|
const setExpanded = expandedControl
|
84
80
|
? expandedControl.onChange
|
85
|
-
: setLocalExpanded
|
81
|
+
: setLocalExpanded;
|
86
82
|
|
87
|
-
const columnHelper = createColumnHelper()
|
83
|
+
const columnHelper = createColumnHelper();
|
88
84
|
|
89
85
|
//Create cells for first columns
|
90
86
|
const createCellFunction = (cellAccessors: string[]) => {
|
@@ -92,10 +88,10 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
92
88
|
row,
|
93
89
|
getValue,
|
94
90
|
}: {
|
95
|
-
row: Row<
|
96
|
-
getValue: Getter<string
|
91
|
+
row: Row<DataType>;
|
92
|
+
getValue: Getter<string>;
|
97
93
|
}) => {
|
98
|
-
const rowData = row.original
|
94
|
+
const rowData = row.original;
|
99
95
|
|
100
96
|
switch (row.depth) {
|
101
97
|
case 0: {
|
@@ -105,12 +101,12 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
105
101
|
onRowToggleClick={onRowToggleClick}
|
106
102
|
row={row}
|
107
103
|
/>
|
108
|
-
)
|
104
|
+
);
|
109
105
|
}
|
110
106
|
default: {
|
111
107
|
// Handle other depths based on cellAccessors
|
112
|
-
const depthAccessor = cellAccessors[row.depth - 1] // Adjust index for depth
|
113
|
-
const accessorValue = rowData[depthAccessor]
|
108
|
+
const depthAccessor = cellAccessors[row.depth - 1]; // Adjust index for depth
|
109
|
+
const accessorValue = rowData[depthAccessor];
|
114
110
|
return accessorValue ? (
|
115
111
|
<CustomCell
|
116
112
|
onRowToggleClick={onRowToggleClick}
|
@@ -119,13 +115,13 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
119
115
|
/>
|
120
116
|
) : (
|
121
117
|
"N/A"
|
122
|
-
)
|
118
|
+
);
|
123
119
|
}
|
124
120
|
}
|
125
|
-
}
|
121
|
+
};
|
126
122
|
|
127
|
-
return columnCells
|
128
|
-
}
|
123
|
+
return columnCells;
|
124
|
+
};
|
129
125
|
|
130
126
|
//Create column array in format needed by Tanstack
|
131
127
|
const columns =
|
@@ -136,12 +132,12 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
136
132
|
...columnHelper.accessor(column.accessor, {
|
137
133
|
header: column.label,
|
138
134
|
}),
|
139
|
-
}
|
135
|
+
};
|
140
136
|
if (column.cellAccessors) {
|
141
|
-
columnStructure.cell = createCellFunction(column.cellAccessors)
|
137
|
+
columnStructure.cell = createCellFunction(column.cellAccessors);
|
142
138
|
}
|
143
|
-
return columnStructure
|
144
|
-
})
|
139
|
+
return columnStructure;
|
140
|
+
});
|
145
141
|
|
146
142
|
//Syntax for sorting Array if we want to manage state ourselves
|
147
143
|
const sorting = [
|
@@ -152,22 +148,22 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
152
148
|
? !sortControl.value.desc
|
153
149
|
: false,
|
154
150
|
},
|
155
|
-
]
|
151
|
+
];
|
156
152
|
|
157
153
|
const expandAndSortState = () => {
|
158
154
|
if (sortControl) {
|
159
|
-
return { state: { expanded, sorting } }
|
155
|
+
return { state: { expanded, sorting } };
|
160
156
|
} else {
|
161
|
-
return { state: { expanded } }
|
157
|
+
return { state: { expanded } };
|
162
158
|
}
|
163
|
-
}
|
159
|
+
};
|
164
160
|
|
165
161
|
//initialize table
|
166
162
|
const table = useReactTable({
|
167
163
|
data: loading ? Array(loadingStateRowCount).fill({}) : tableData,
|
168
164
|
columns,
|
169
165
|
onExpandedChange: setExpanded,
|
170
|
-
getSubRows: (row:
|
166
|
+
getSubRows: (row: DataType) => row.children,
|
171
167
|
getCoreRowModel: getCoreRowModel(),
|
172
168
|
getExpandedRowModel: getExpandedRowModel(),
|
173
169
|
getSortedRowModel: getSortedRowModel(),
|
@@ -175,42 +171,42 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
175
171
|
sortDescFirst: true,
|
176
172
|
...expandAndSortState(),
|
177
173
|
...tableOptions,
|
178
|
-
})
|
174
|
+
});
|
179
175
|
|
180
|
-
const tableRows = table.getRowModel()
|
176
|
+
const tableRows = table.getRowModel();
|
181
177
|
|
182
178
|
// Set table row count for loading state
|
183
179
|
const updateLoadingStateRowCount = useCallback(() => {
|
184
|
-
const rowsCount = table.getRowModel().rows.length
|
180
|
+
const rowsCount = table.getRowModel().rows.length;
|
185
181
|
if (rowsCount !== loadingStateRowCount && rowsCount !== 0) {
|
186
|
-
setLoadingStateRowCount(rowsCount)
|
182
|
+
setLoadingStateRowCount(rowsCount);
|
187
183
|
}
|
188
|
-
}, [tableData, loadingStateRowCount])
|
184
|
+
}, [tableData, loadingStateRowCount]);
|
189
185
|
|
190
186
|
useEffect(() => {
|
191
187
|
if (!loading) {
|
192
|
-
updateLoadingStateRowCount()
|
188
|
+
updateLoadingStateRowCount();
|
193
189
|
}
|
194
|
-
}, [loading, updateLoadingStateRowCount])
|
190
|
+
}, [loading, updateLoadingStateRowCount]);
|
195
191
|
|
196
|
-
const handleExpandOrCollapse = (row: Row<
|
197
|
-
onToggleExpansionClick && onToggleExpansionClick(row)
|
192
|
+
const handleExpandOrCollapse = (row: Row<DataType>) => {
|
193
|
+
onToggleExpansionClick && onToggleExpansionClick(row);
|
198
194
|
|
199
|
-
const expandedState = expanded
|
200
|
-
const targetParent = row?.parentId
|
195
|
+
const expandedState = expanded;
|
196
|
+
const targetParent = row?.parentId;
|
201
197
|
return setExpanded(
|
202
198
|
updateExpandAndCollapseState(tableRows, expandedState, targetParent)
|
203
|
-
)
|
204
|
-
}
|
199
|
+
);
|
200
|
+
};
|
205
201
|
|
206
|
-
const ariaProps = buildAriaProps(aria)
|
207
|
-
const dataProps = buildDataProps(data)
|
208
|
-
const htmlProps = buildHtmlProps(htmlOptions)
|
202
|
+
const ariaProps = buildAriaProps(aria);
|
203
|
+
const dataProps = buildDataProps(data);
|
204
|
+
const htmlProps = buildHtmlProps(htmlOptions);
|
209
205
|
const classes = classnames(
|
210
206
|
buildCss("pb_advanced_table"),
|
211
207
|
globalProps(props),
|
212
208
|
className
|
213
|
-
)
|
209
|
+
);
|
214
210
|
|
215
211
|
return (
|
216
212
|
<div {...ariaProps}
|
@@ -251,10 +247,10 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
251
247
|
</Table>
|
252
248
|
</AdvancedTableContext.Provider>
|
253
249
|
</div>
|
254
|
-
)
|
255
|
-
}
|
250
|
+
);
|
251
|
+
};
|
256
252
|
|
257
|
-
AdvancedTable.Header = TableHeader
|
258
|
-
AdvancedTable.Body = TableBody
|
253
|
+
AdvancedTable.Header = TableHeader;
|
254
|
+
AdvancedTable.Body = TableBody;
|
259
255
|
|
260
|
-
export default AdvancedTable
|
256
|
+
export default AdvancedTable;
|