playbook_ui 13.17.0.pre.alpha.nodealphaupgrade2157 → 13.18.0.pre.alpha.PBNTR191AdvancedTableFinalFixes2159

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d229baf16d600479c55f9fc35e8b93b5978cba2506b23e883860ea2094294809
4
- data.tar.gz: 0d23fa917195b34c496c19a7f7f741e4ffce3807706019805469d92ba728c015
3
+ metadata.gz: ed6b5c8bc5abff794a42552366bce14785ce52a52f77e4897a96c59279b6bab0
4
+ data.tar.gz: 0b1feee9f1e0abafb95db62e695a1c4df57a95f82e0acdf0e079a9febf22f52c
5
5
  SHA512:
6
- metadata.gz: 2d3610e3ec299cc4bc396ebe9d11169d3da50624aec176a2656bb846f426410027213461715d2cfd83f55f8e53b478c4f734e2115fe9265a4203046d6318358d
7
- data.tar.gz: f91b7cfefcb02e1078a1ff1f607bb71b55a10460ec8b9707f0e740783aeb0e36d6c54b84538cfa4857ef8daa044f1045d7d2aded18e2e51877acc2542d1a815c
6
+ metadata.gz: 73a5a055067a0942784bb05576cf3cfc1002be59a2a06a061ea130da7f2eb561d86f61db61704874231d209ad32ead88ae47775058d43e2a7aba2bf4f73942ac
7
+ data.tar.gz: 2bff7638226878a69f3c8b7d3eed25c0a794be24894f82164983b8829d46c9cf874ec880f18e396052b615cc58d824420058fff6a698d23848b43bec7e674481
@@ -23,20 +23,22 @@ export const CustomCell = ({
23
23
  value,
24
24
  }: CustomCellProps & GlobalProps) => {
25
25
  const { setExpanded, expanded } = useContext(AdvancedTableContext);
26
- const RowWithoutChildren = row.originalSubRows === undefined;
27
26
 
28
27
  const handleOnExpand = (row: Row<DataType>) => {
29
28
  onRowToggleClick && onRowToggleClick(row);
30
29
  setExpanded({ ...expanded, [row.id]: !row.getIsExpanded() });
31
30
  };
32
31
 
32
+ const RowHasChildren = row.original.children ? true : false
33
+
34
+
33
35
  return (
34
36
  <div style={{ paddingLeft: `${row.depth * 1.25}em` }}>
35
37
  <Flex alignItems="center"
36
38
  columnGap="xs"
37
39
  orientation="row"
38
40
  >
39
- {!RowWithoutChildren ? (
41
+ {RowHasChildren ? (
40
42
  <button
41
43
  className="gray-icon expand-toggle-icon"
42
44
  onClick={() => handleOnExpand(row)}
@@ -53,7 +55,7 @@ export const CustomCell = ({
53
55
  )}
54
56
  </button>
55
57
  ) : null}
56
- <FlexItem paddingLeft={!RowWithoutChildren ? "none" : "xs"}>
58
+ <FlexItem paddingLeft={RowHasChildren? "none" : "xs"}>
57
59
  {row.depth === 0 ? getValue() : value}
58
60
  </FlexItem>
59
61
  </Flex>
@@ -12,7 +12,7 @@ import { GlobalProps } from "../../utilities/globalProps"
12
12
 
13
13
  interface SubRowHeaderRowProps {
14
14
  collapsibleTrail?: boolean
15
- enableToggleExpansion?: "all" | "header"
15
+ enableToggleExpansion?: "all" | "header" | "none"
16
16
  onClick: (row: Row<DataType>) => void
17
17
  row: Row<DataType>
18
18
  subRowHeaders?: string[]
@@ -28,6 +28,7 @@ export const SubRowHeaderRow = ({
28
28
  table,
29
29
  }: SubRowHeaderRowProps & GlobalProps) => {
30
30
  const numberOfColumns = table.getAllFlatColumns().length
31
+ const canExpand = row.depth < subRowHeaders.length
31
32
 
32
33
  return (
33
34
  <tr className="custom-row bg-silver">
@@ -42,13 +43,13 @@ export const SubRowHeaderRow = ({
42
43
  <Flex align="center"
43
44
  columnGap="xs"
44
45
  >
45
- {enableToggleExpansion === "all" && row.getCanExpand() ? (
46
+ {enableToggleExpansion === "all" && canExpand ? (
46
47
  <ToggleIconButton onClick={onClick}
47
48
  row={row}
48
49
  />
49
50
  ) : null}
50
51
  <Caption
51
- marginLeft={row.getCanExpand() ? "none" : "xs"}
52
+ marginLeft={canExpand ? "none" : "xs"}
52
53
  text={subRowHeaders[row.depth - 1]}
53
54
  />
54
55
  </Flex>
@@ -12,11 +12,10 @@ import { GlobalProps } from "../../utilities/globalProps"
12
12
 
13
13
  type TableHeaderCellProps = {
14
14
  enableSorting?: boolean
15
- enableToggleExpansion?: "all" | "header"
15
+ enableToggleExpansion?: "all" | "header" | "none"
16
16
  handleExpandOrCollapse?: () => void
17
17
  header?: Header<DataType, unknown>
18
18
  headerChildren?: React.ReactNode | React.ReactNode[]
19
- headerId?: string
20
19
  loading?: boolean
21
20
  sortIcon?: string | string[]
22
21
  } & GlobalProps
@@ -27,7 +26,6 @@ export const TableHeaderCell = ({
27
26
  handleExpandOrCollapse,
28
27
  header,
29
28
  headerChildren,
30
- headerId,
31
29
  loading,
32
30
  sortIcon,
33
31
  }: TableHeaderCellProps) => {
@@ -50,10 +48,22 @@ const cellClassName = classnames("table-header-cells",
50
48
  );
51
49
 
52
50
  const cellId = `${loading ?
53
- `loading-${header.id}${headerId ? `-${headerId}` : ""}`
54
- : `${header.id}${headerId ? `-${headerId}` : ""}`
51
+ `loading-${header.id}`
52
+ : `${header.id}`
55
53
  }`;
56
54
 
55
+ const isToggleExpansionEnabledLoading =
56
+ header.index === 0 &&
57
+ loading &&
58
+ (enableToggleExpansion === "all" || "header") &&
59
+ enableToggleExpansion !== "none";
60
+
61
+ const isToggleExpansionEnabled =
62
+ header.index === 0 &&
63
+ !loading &&
64
+ (enableToggleExpansion === "all" || "header") &&
65
+ enableToggleExpansion !== "none";
66
+
57
67
  return (
58
68
  <th
59
69
  align="right"
@@ -73,15 +83,11 @@ const cellId = `${loading ?
73
83
  alignItems="center"
74
84
  justify={header.index === 0 && enableSorting ? "between" : header.index === 0 && !enableSorting ? "start" : "end"}
75
85
  >
76
- {header.index === 0 &&
77
- !loading &&
78
- (enableToggleExpansion === "all" || "header") && (
86
+ {isToggleExpansionEnabled && (
79
87
  <ToggleIconButton onClick={handleExpandOrCollapse} />
80
88
  )}
81
89
 
82
- {header.index === 0 &&
83
- loading &&
84
- (enableToggleExpansion === "all" || "header") && (
90
+ {isToggleExpansionEnabledLoading &&(
85
91
  <div className="loading-toggle-icon header-toggle-icon" />
86
92
  )}
87
93
 
@@ -1,4 +1,7 @@
1
1
  import React, { useContext } from "react"
2
+ import classnames from "classnames";
3
+ import { buildCss } from "../../utilities/props";
4
+ import { globalProps } from "../../utilities/globalProps";
2
5
  import LoadingInline from "../../pb_loading_inline/_loading_inline"
3
6
  import { flexRender, Row } from "@tanstack/react-table"
4
7
 
@@ -10,28 +13,45 @@ import { isChrome } from "../Utilities/BrowserCheck"
10
13
  import { DataType } from "../Utilities/types"
11
14
 
12
15
  type TableBodyProps = {
16
+ className?: string;
13
17
  collapsibleTrail?: boolean
18
+ id?: string;
14
19
  subRowHeaders?: string[]
15
20
  }
16
21
 
17
22
  export const TableBody = ({
23
+ className,
18
24
  collapsibleTrail = true,
25
+ id,
19
26
  subRowHeaders,
27
+ ...props
20
28
  }: TableBodyProps) => {
29
+
21
30
  const {
31
+ columnDefinitions,
22
32
  enableToggleExpansion,
23
33
  handleExpandOrCollapse,
24
34
  loading,
25
35
  table,
26
36
  } = useContext(AdvancedTableContext)
37
+
38
+ const classes = classnames(
39
+ buildCss("pb_advanced_table_body"),
40
+ globalProps(props),
41
+ className
42
+ );
43
+
27
44
  return (
28
45
  <>
29
- <tbody>
46
+ <tbody className={classes}
47
+ id={id}
48
+ >
30
49
  {table.getRowModel().rows.map((row: Row<DataType>) => {
31
50
  const isExpandable = row.getIsExpanded()
32
51
  const isFirstChildofSubrow = row.depth > 0 && row.index === 0
33
- const rowHasNoChildren = !row.original.children?.length
52
+ const rowHasNoChildren = row.original.children && !row.original.children.length ? true : false
34
53
  const numberOfColumns = table.getAllFlatColumns().length
54
+ const isDataLoading = isExpandable && rowHasNoChildren && (row.depth < columnDefinitions[0].cellAccessors?.length)
35
55
 
36
56
  return (
37
57
  <React.Fragment key={`${row.index}-${row.id}-${row.depth}-row`}>
@@ -79,9 +99,11 @@ export const TableBody = ({
79
99
  </tr>
80
100
 
81
101
  {/* Display LoadingInline if Row Data is querying and there are no children already */}
82
- {isExpandable && rowHasNoChildren && row.depth === 0 ? (
102
+ {isDataLoading ? (
83
103
  <tr key={`${row.id}-row`}>
84
- <td colSpan={numberOfColumns}>
104
+ <td colSpan={numberOfColumns}
105
+ style={{ paddingLeft: `${row.depth === 0 ? 0.5 : (row.depth * 2)}em` }}
106
+ >
85
107
  <LoadingInline />
86
108
  </td>
87
109
  </tr>
@@ -1,4 +1,7 @@
1
1
  import React, { useContext } from "react"
2
+ import classnames from "classnames";
3
+ import { buildCss } from "../../utilities/props";
4
+ import { globalProps } from "../../utilities/globalProps";
2
5
  import { HeaderGroup } from "@tanstack/react-table"
3
6
  import AdvancedTableContext from "../Context/AdvancedTableContext"
4
7
  import { TableHeaderCell } from "../Components/TableHeaderCell"
@@ -6,16 +9,19 @@ import { DataType } from "../Utilities/types"
6
9
 
7
10
  type TableHeaderProps = {
8
11
  children?: React.ReactNode | React.ReactNode[]
12
+ className?: string
9
13
  enableSorting?: boolean
10
- headerId?: string
14
+ id?: string;
11
15
  sortIcon?: string | string[]
12
16
  }
13
17
 
14
18
  export const TableHeader = ({
15
19
  children,
20
+ className,
16
21
  enableSorting = false,
17
- headerId,
22
+ id,
18
23
  sortIcon = ["arrow-up-short-wide", "arrow-down-short-wide"],
24
+ ...props
19
25
  }: TableHeaderProps) => {
20
26
  const {
21
27
  enableToggleExpansion,
@@ -24,9 +30,18 @@ export const TableHeader = ({
24
30
  table,
25
31
  } = useContext(AdvancedTableContext)
26
32
 
33
+ const classes = classnames(
34
+ buildCss("pb_advanced_table_header"),
35
+ globalProps(props),
36
+ className
37
+ );
38
+
39
+
27
40
  return (
28
41
  <>
29
- <thead>
42
+ <thead className={classes}
43
+ id={id}
44
+ >
30
45
  {/* Get the header groups (only one in this example) */}
31
46
  {table.getHeaderGroups().map((headerGroup: HeaderGroup<DataType>) => (
32
47
  <tr key={`${headerGroup.id}-headerGroup`}>
@@ -37,7 +52,6 @@ export const TableHeader = ({
37
52
  handleExpandOrCollapse={handleExpandOrCollapse}
38
53
  header={header}
39
54
  headerChildren={children}
40
- headerId={headerId}
41
55
  key={`${header.id}-header`}
42
56
  loading={loading}
43
57
  sortIcon={sortIcon}
@@ -24,10 +24,9 @@ export const updateExpandAndCollapseState = (
24
24
  // Update isExpansionConsistent variable
25
25
  for (const row of rows) {
26
26
  if (
27
- row.getCanExpand() &&
28
- (targetParent === undefined
27
+ targetParent === undefined
29
28
  ? row.depth === 0
30
- : targetParent === row.parentId)
29
+ : targetParent === row.parentId
31
30
  ) {
32
31
  areRowsExpanded.add(row.getIsExpanded())
33
32
  if (areRowsExpanded.size > 1) {
@@ -48,7 +47,7 @@ export const updateExpandAndCollapseState = (
48
47
  })
49
48
  } else {
50
49
  for (const row of rows) {
51
- if (row.getCanExpand() && targetParent === row.parentId) {
50
+ if (targetParent === row.parentId) {
52
51
  updateExpandedRows[row.id] = !isExpansionConsistent
53
52
  ? true
54
53
  : !row.getIsExpanded()
@@ -1,6 +1,6 @@
1
1
  import React, { useState, useEffect, useCallback } from "react";
2
2
  import classnames from "classnames";
3
- import { buildAriaProps, buildCss, buildDataProps } from "../utilities/props";
3
+ import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from "../utilities/props";
4
4
  import { globalProps, GlobalProps } from "../utilities/globalProps";
5
5
  import Table from "../pb_table/_table";
6
6
  import {
@@ -28,8 +28,9 @@ type AdvancedTableProps = {
28
28
  className?: string;
29
29
  columnDefinitions: DataType[];
30
30
  data?: { [key: string]: string };
31
- enableToggleExpansion?: "all" | "header";
31
+ enableToggleExpansion?: "all" | "header" | "none";
32
32
  expandedControl?: DataType;
33
+ htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
33
34
  id?: string;
34
35
  initialLoadingRowsCount?: number;
35
36
  loading?: boolean | string;
@@ -51,6 +52,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
51
52
  data = {},
52
53
  enableToggleExpansion = "header",
53
54
  expandedControl,
55
+ htmlOptions = {},
54
56
  id,
55
57
  initialLoadingRowsCount = 10,
56
58
  loading,
@@ -104,7 +106,9 @@ const AdvancedTable = (props: AdvancedTableProps) => {
104
106
  const depthAccessor = cellAccessors[row.depth - 1]; // Adjust index for depth
105
107
  const accessorValue = rowData[depthAccessor];
106
108
  return accessorValue ? (
107
- <CustomCell row={row}
109
+ <CustomCell
110
+ onRowToggleClick={onRowToggleClick}
111
+ row={row}
108
112
  value={accessorValue}
109
113
  />
110
114
  ) : (
@@ -195,6 +199,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
195
199
 
196
200
  const ariaProps = buildAriaProps(aria);
197
201
  const dataProps = buildDataProps(data);
202
+ const htmlProps = buildHtmlProps(htmlOptions);
198
203
  const classes = classnames(
199
204
  buildCss("pb_advanced_table"),
200
205
  globalProps(props),
@@ -204,19 +209,21 @@ const AdvancedTable = (props: AdvancedTableProps) => {
204
209
  return (
205
210
  <div {...ariaProps}
206
211
  {...dataProps}
212
+ {...htmlProps}
207
213
  className={classes}
208
214
  id={id}
209
215
  >
210
216
  <AdvancedTableContext.Provider
211
217
  value={{
212
- table,
218
+ columnDefinitions,
219
+ enableToggleExpansion,
220
+ expanded,
213
221
  handleExpandOrCollapse,
214
222
  loading,
215
- enableToggleExpansion,
216
- toggleExpansionIcon,
217
223
  setExpanded,
218
- expanded,
219
224
  sortControl,
225
+ table,
226
+ toggleExpansionIcon,
220
227
  }}
221
228
  >
222
229
  <Table
@@ -343,3 +343,39 @@ test("sort button exists and sorts column data", () => {
343
343
  const row2 = kit.getElementsByTagName('tr')[2]
344
344
  expect(row2.id).toBe("0-0-0-row")
345
345
  });
346
+
347
+ test("Generates Table.Header default + custom classname", () => {
348
+ render(
349
+ <AdvancedTable
350
+ columnDefinitions={columnDefinitions}
351
+ data={{ testid: testId }}
352
+ tableData={MOCK_DATA}
353
+ >
354
+ <AdvancedTable.Header className="custom-header" />
355
+ <AdvancedTable.Body />
356
+
357
+ </AdvancedTable>
358
+ );
359
+
360
+ const kit = screen.getByTestId(testId);
361
+ const tableHeader = kit.querySelector('thead')
362
+ expect(tableHeader).toHaveClass('pb_advanced_table_header custom-header')
363
+ });
364
+
365
+ test("Generates Table.Body default + custom classname", () => {
366
+ render(
367
+ <AdvancedTable
368
+ columnDefinitions={columnDefinitions}
369
+ data={{ testid: testId }}
370
+ tableData={MOCK_DATA}
371
+ >
372
+ <AdvancedTable.Header />
373
+ <AdvancedTable.Body className="custom-body-classname"/>
374
+
375
+ </AdvancedTable>
376
+ );
377
+
378
+ const kit = screen.getByTestId(testId);
379
+ const tableHeader = kit.querySelector('tbody')
380
+ expect(tableHeader).toHaveClass('pb_advanced_table_body custom-body-classname')
381
+ });
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Playbook
4
- PREVIOUS_VERSION = "13.17.0"
5
- VERSION = "13.17.0.pre.alpha.nodealphaupgrade2157"
4
+ PREVIOUS_VERSION = "13.18.0"
5
+ VERSION = "13.18.0.pre.alpha.PBNTR191AdvancedTableFinalFixes2159"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playbook_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.17.0.pre.alpha.nodealphaupgrade2157
4
+ version: 13.18.0.pre.alpha.PBNTR191AdvancedTableFinalFixes2159
5
5
  platform: ruby
6
6
  authors:
7
7
  - Power UX
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-02-16 00:00:00.000000000 Z
12
+ date: 2024-02-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack