rez-table-listing-mui 0.0.23 → 0.0.25

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.
@@ -17,13 +17,13 @@ interface DragAlongCellProps<T> {
17
17
 
18
18
  function DragAlongCell<T>({
19
19
  cell,
20
- featureOptions,
20
+ // featureOptions,
21
21
  tableStates,
22
22
  }: DragAlongCellProps<T>) {
23
23
  const { isDragging, setNodeRef, transform } = useSortable({
24
24
  id: cell.column.id,
25
25
  });
26
- const { enableWordBreakAll } = featureOptions;
26
+ // const { enableWordBreakAll } = featureOptions;
27
27
  const { wrapColumns } = tableStates;
28
28
 
29
29
  const isPinned = cell.column.getIsPinned();
@@ -34,7 +34,7 @@ function DragAlongCell<T>({
34
34
  transition: "width transform 0.2s ease-in-out",
35
35
  width: cell.column.getSize(),
36
36
  ...getColumnPinningStylesBody(cell.column),
37
- ...(wrapColumns[cell.column.id] && {
37
+ ...((wrapColumns.all_wrap || wrapColumns[cell.column.id]) && {
38
38
  wordBreak: "break-all",
39
39
  // whiteSpace: "normal",
40
40
  }),
@@ -64,7 +64,7 @@ function TableBody<T>({
64
64
  style: {
65
65
  ...getColumnPinningStylesBody(cell.column),
66
66
  width: cell.column.getSize(),
67
- ...(wrapColumns[cell.column.id] && {
67
+ ...((wrapColumns.all_wrap || wrapColumns[cell.column.id]) && {
68
68
  wordBreak: "break-all",
69
69
  // whiteSpace: "normal",
70
70
  }),
@@ -98,9 +98,10 @@ function TableBody<T>({
98
98
  <React.Fragment key={row.id}>
99
99
  {renderedRow}
100
100
  <tr>
101
- <td colSpan={table.getAllLeafColumns().length}>
101
+ {/* <td colSpan={table.getAllLeafColumns().length}>//commented out to remove extra line on opening of nested row
102
102
  {NestedComponent && <NestedComponent {...{ row }} />}
103
- </td>
103
+ </td> */}
104
+ {NestedComponent && <NestedComponent {...{ row }} />}
104
105
  </tr>
105
106
  </React.Fragment>
106
107
  );
@@ -39,6 +39,7 @@ function TableHeadPopover<T>({
39
39
  setWrapColumns((prev: Record<string, boolean>) => ({
40
40
  ...prev,
41
41
  [columnId]: !prev[columnId],
42
+ all_wrap: false,
42
43
  }));
43
44
  };
44
45
 
@@ -84,7 +85,7 @@ function TableHeadPopover<T>({
84
85
  <ListItemButton>
85
86
  <ListItemText primary="Wrap Cell" />
86
87
  <Switch
87
- checked={wrapColumns[column.id]}
88
+ checked={wrapColumns.all_wrap || wrapColumns[column.id]}
88
89
  onChange={() => toggleWrapForColumn(column.id)}
89
90
  />
90
91
  </ListItemButton>
@@ -1,73 +1,31 @@
1
- import { useEffect, useMemo, useState } from "react";
2
1
  import "./index.scss";
3
2
  import { formatClassName } from "../../libs/utils/common";
4
- import {
5
- Popover,
6
- Box,
7
- Typography,
8
- List,
9
- ListItemButton,
10
- ListItemText,
11
- CircularProgress,
12
- } from "@mui/material";
13
- import { useCraftTable } from "../../libs/hooks/useCraftTable";
3
+ import { CircularProgress } from "@mui/material";
4
+ import { CraftTableOptionsProps } from "../../types/table-options";
14
5
 
15
- interface TabStat {
16
- tab_value: string;
17
- tab_value_count: number | string;
6
+ interface TabDataProps {
7
+ tab_value: string | null;
8
+ tab_value_count: string | number;
18
9
  }
19
10
 
20
- interface TableTabsProps<T> {
21
- data: T[];
22
- state: string;
23
- statusKey: string;
24
- onClick: (state: string) => void;
25
- tabStats?: TabStat[];
11
+ interface TableTabsProps {
26
12
  loading?: boolean;
13
+ tabsData: TabDataProps[] | undefined;
14
+ activeTab?: string;
15
+ tableStates: CraftTableOptionsProps;
16
+ onClick: (state: string) => void;
27
17
  }
28
18
 
29
- export function TableTabs<T>({
30
- data = [],
31
- state = "ALL",
32
- statusKey,
19
+ export function TableTabs({
20
+ loading = false,
21
+ tabsData = [],
22
+ activeTab = "ALL",
33
23
  onClick,
34
- tabStats,
35
- loading,
36
- }: TableTabsProps<T>) {
37
- const [activeTab, setActiveTab] = useState<string>(state || "ALL");
38
- const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
39
- const [selectedColumn, setSelectedColumn] = useState<string | null>(null);
40
- const { pagination, setPagination, ...tableOptions } = useCraftTable();
41
- useEffect(() => {
42
- if (tabStats?.length && activeTab === "ALL") {
43
- onClick("ALL");
44
- }
45
- }, [tabStats, activeTab, onClick]);
46
-
47
- const columns = useMemo(() => {
48
- if (!data.length) return [];
49
- return Object.entries(data[0] as Record<string, any>)
50
- .filter(([, value]) => typeof value !== "object" && !Array.isArray(value))
51
- .map(([key]) => ({
52
- accessorKey: key,
53
- header: key
54
- .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
55
- .replace(/^./, (str) => str.toUpperCase()),
56
- }));
57
- }, [data]);
58
-
59
- const tabsData = useMemo(() => {
60
- if (!tabStats || !tabStats.length) return [];
61
- return tabStats.map(({ tab_value, tab_value_count }) => ({
62
- label: tab_value,
63
- count: tab_value_count,
64
- }));
65
- }, [tabStats]);
66
-
67
- const handleColumnSelect = (columnKey: string) => {
68
- setSelectedColumn(columnKey);
69
- setActiveTab("ALL");
70
- setAnchorEl(null);
24
+ tableStates,
25
+ }: TableTabsProps) {
26
+ const handleTabClick = (tab: string) => {
27
+ onClick && onClick(tab);
28
+ tableStates.setPagination((prev) => ({ ...prev, pageIndex: 0 }));
71
29
  };
72
30
 
73
31
  return (
@@ -78,51 +36,27 @@ export function TableTabs<T>({
78
36
  </div>
79
37
  ) : (
80
38
  <ul className="tabs">
81
- {tabStats && tabStats.length > 0 && (
82
- <>
39
+ {tabsData?.length > 0 &&
40
+ tabsData.map(({ tab_value, tab_value_count }) => (
83
41
  <li
42
+ key={tab_value}
84
43
  className={formatClassName(
85
- `tab ${activeTab === "ALL" ? "active" : ""}`
44
+ `tab ${activeTab === tab_value ? "active" : ""}`
86
45
  )}
87
- onClick={() => {
88
- setActiveTab("ALL");
89
- setPagination((prev) => ({ ...prev, pageIndex: 0 }));
90
- onClick("ALL");
91
- }}
46
+ onClick={() => handleTabClick(tab_value || "ALL")}
92
47
  >
93
- <span className="tab__label">ALL</span>
94
- <span className="count">
95
- {tabsData.find((tab) => tab.label === "ALL")?.count ?? 0}
48
+ <span className="tab__label">
49
+ {typeof tab_value === "string"
50
+ ? tab_value.toUpperCase()
51
+ : "UNKNOWN"}
96
52
  </span>
53
+ <span className="count">{tab_value_count}</span>
97
54
  </li>
98
- {tabsData
99
- .filter(({ label }) => label !== "ALL")
100
- .map(({ label, count }) => (
101
- <li
102
- key={label}
103
- className={formatClassName(
104
- `tab ${activeTab === label ? "active" : ""}`
105
- )}
106
- onClick={() => {
107
- setActiveTab(label);
108
- setPagination((prev) => ({ ...prev, pageIndex: 0 }));
109
- onClick(label);
110
- }}
111
- >
112
- <span className="tab__label">
113
- {typeof label === "string"
114
- ? label.toUpperCase()
115
- : "UNKNOWN"}
116
- </span>
117
- <span className="count">{count}</span>
118
- </li>
119
- ))}
120
- </>
121
- )}
55
+ ))}
122
56
  </ul>
123
57
  )}
124
58
 
125
- <Popover
59
+ {/* <Popover
126
60
  open={Boolean(anchorEl)}
127
61
  anchorEl={anchorEl}
128
62
  onClose={() => setAnchorEl(null)}
@@ -143,7 +77,7 @@ export function TableTabs<T>({
143
77
  ))}
144
78
  </List>
145
79
  </Box>
146
- </Popover>
80
+ </Popover> */}
147
81
  </div>
148
82
  );
149
83
  }
@@ -62,7 +62,7 @@
62
62
  }
63
63
 
64
64
  .change-layout {
65
- margin-top: 1rem;
65
+ margin-top: 0.99rem;
66
66
  cursor: pointer;
67
67
  }
68
68
 
@@ -1,7 +1,6 @@
1
1
  import React, { useState, useRef, useEffect } from "react";
2
2
  import {
3
3
  ChangeLayoutIcon,
4
- SearchIcon,
5
4
  SortingIcon,
6
5
  CustomizationIcon,
7
6
  HideColumnIcon,
@@ -28,7 +27,7 @@ interface TopbarProps<T> {
28
27
  topbarOptions?: TopbarOptionsProps;
29
28
  columnOrder?: string[];
30
29
  setColumnOrder?: React.Dispatch<React.SetStateAction<string[]>>;
31
- tableStates?: CraftTableOptionsProps;
30
+ tableStates: CraftTableOptionsProps;
32
31
  searchValue?: string;
33
32
  onSearchChange?: (val: string) => void;
34
33
  }
@@ -40,10 +39,8 @@ function Topbar<T>({
40
39
  setIsCompactTable,
41
40
  paginationComponent,
42
41
  topbarOptions,
43
- searchValue,
44
- onSearchChange,
42
+ tableStates,
45
43
  }: TopbarProps<T>) {
46
- const [wrapCell, setWrapCell] = useState(false);
47
44
  const [isFullscreen, setIsFullscreen] = useState(false);
48
45
  const [sortAnchorEl, setSortAnchorEl] = useState<HTMLElement | null>(null);
49
46
  const [groupBy, setGroupBy] = useState<string>("None");
@@ -76,6 +73,8 @@ function Topbar<T>({
76
73
  showSearch,
77
74
  showFilter,
78
75
  showCustomizationToggle,
76
+ searchValue,
77
+ onSearchChange,
79
78
  } = topbarOptions ?? {};
80
79
 
81
80
  const { container: fullscreenContainer } = useFullscreenPopoverContainer();
@@ -112,13 +111,6 @@ function Topbar<T>({
112
111
  {rightSideComponent}
113
112
  {paginationComponent}
114
113
 
115
- {/* {showSearch && (
116
- <div className="search ts--button" title="Search">
117
- <SearchIcon />
118
-
119
- </div>
120
- )} */}
121
-
122
114
  {showSearch && (
123
115
  <TableSearch
124
116
  value={searchValue ?? ""}
@@ -206,8 +198,6 @@ function Topbar<T>({
206
198
  {viewMoreToggle && (
207
199
  <div className="view-more ts--button" title="View More">
208
200
  <ViewMore
209
- wrapCell={wrapCell}
210
- onWrapCellToggle={() => setWrapCell((prev) => !prev)}
211
201
  compactMode={isCompactTable}
212
202
  onCompactToggle={(value: string) =>
213
203
  setIsCompactTable(value === "Compact")
@@ -219,6 +209,7 @@ function Topbar<T>({
219
209
  }}
220
210
  groupBy={groupBy}
221
211
  onGroupByChange={(value: string) => setGroupBy(value)}
212
+ tableStates={tableStates}
222
213
  />
223
214
  </div>
224
215
  )}
@@ -10,28 +10,26 @@ import {
10
10
  } from "@mui/material";
11
11
  import { CloseIcon, ViewMoreIcon } from "../../assets/svg";
12
12
  import { useFullscreenPopoverContainer } from "../../libs/hooks/useFullScreen";
13
+ import { CraftTableOptionsProps } from "../../types/table-options";
13
14
 
14
15
  interface ViewMorePopoverProps {
15
- wrapCell: boolean;
16
- onWrapCellToggle: () => void;
17
16
  compactMode: boolean;
18
17
  onCompactToggle: (value: string) => void;
19
18
  isFullscreen: boolean;
20
19
  onFullscreenToggle: () => void;
21
20
  groupBy: string;
22
21
  onGroupByChange: (value: string) => void;
23
- // tableStates: CraftTableOptionsProps;
22
+ tableStates: CraftTableOptionsProps;
24
23
  }
25
24
 
26
25
  const ViewMore = ({
27
- wrapCell,
28
- onWrapCellToggle,
29
26
  compactMode,
30
27
  onCompactToggle,
31
28
  isFullscreen,
32
29
  onFullscreenToggle,
33
30
  groupBy,
34
31
  onGroupByChange,
32
+ tableStates,
35
33
  }: ViewMorePopoverProps) => {
36
34
  const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
37
35
 
@@ -46,16 +44,13 @@ const ViewMore = ({
46
44
  setAnchorEl(null);
47
45
  };
48
46
 
49
- // const { wrapColumns, globalWrapColumns, setGlobalWrapColumns } = tableStates;
47
+ const { wrapColumns, setWrapColumns } = tableStates;
50
48
 
51
- // const toggleGlobalWrap = (value: boolean | null) => {
52
- // setGlobalWrapColumns(value); // true = wrap all, false = un-wrap all, null = use wrapState
53
- // };
54
-
55
- // const isWrapped =
56
- // globalWrapColumns !== null
57
- // ? globalWrapColumns
58
- // : !!wrapColumns[cell.column.id];
49
+ const onWrapCellToggle = () => {
50
+ setWrapColumns((prev: Record<string, boolean>) => ({
51
+ all_wrap: !prev["all_wrap"],
52
+ }));
53
+ };
59
54
 
60
55
  return (
61
56
  <>
@@ -112,7 +107,10 @@ const ViewMore = ({
112
107
  <Typography fontSize="14px" fontWeight={400} color="#000000DE">
113
108
  Wrap Cell
114
109
  </Typography>
115
- <MUISwitch checked={wrapCell} onChange={onWrapCellToggle} />
110
+ <MUISwitch
111
+ checked={wrapColumns?.all_wrap || false}
112
+ onChange={onWrapCellToggle}
113
+ />
116
114
  </Box>
117
115
 
118
116
  {/* List View */}
@@ -135,6 +133,15 @@ const ViewMore = ({
135
133
  color: "#000",
136
134
  fontSize: "13px",
137
135
  }}
136
+ MenuProps={{
137
+ container: fullscreenContainer,
138
+ disablePortal: false,
139
+ PaperProps: {
140
+ style: {
141
+ zIndex: 1500,
142
+ },
143
+ },
144
+ }}
138
145
  >
139
146
  <MenuItem value="Comfy">Comfy</MenuItem>
140
147
  <MenuItem value="Compact">Compact</MenuItem>
@@ -142,7 +149,7 @@ const ViewMore = ({
142
149
  </Box>
143
150
 
144
151
  {/* Group By */}
145
- <Box
152
+ {/* <Box
146
153
  display="flex"
147
154
  justifyContent="space-between"
148
155
  alignItems="center"
@@ -161,12 +168,21 @@ const ViewMore = ({
161
168
  color: "#000",
162
169
  fontSize: "13px",
163
170
  }}
171
+ MenuProps={{
172
+ container: fullscreenContainer,
173
+ disablePortal: false,
174
+ PaperProps: {
175
+ style: {
176
+ zIndex: 1500,
177
+ },
178
+ },
179
+ }}
164
180
  >
165
181
  <MenuItem value="None">None</MenuItem>
166
182
  <MenuItem value="Status">Status</MenuItem>
167
183
  <MenuItem value="Owner">Owner</MenuItem>
168
184
  </Select>
169
- </Box>
185
+ </Box> */}
170
186
 
171
187
  {/* Fullscreen */}
172
188
  <Box display="flex" justifyContent="space-between" alignItems="center">
@@ -15,7 +15,9 @@ export function useCraftTable(paginationPageSize: number = 25) {
15
15
  const [sorting, setSorting] = useState<SortingState>([]);
16
16
  const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
17
17
  const [expanded, setExpanded] = useState<ExpandedState>({});
18
- const [wrapColumns, setWrapColumns] = useState<Record<string, boolean>>({});
18
+ const [wrapColumns, setWrapColumns] = useState<Record<string, boolean>>({
19
+ all_wrap: true,
20
+ });
19
21
  const [globalWrapColumns, setGlobalWrapColumns] = useState<boolean | null>(
20
22
  null
21
23
  );
@@ -26,11 +26,12 @@ export const useDefaultColumns = () => {
26
26
  // ),
27
27
  cell: ({ row, getValue }) => {
28
28
  return (
29
- <div style={{ paddingLeft: `${row.depth * 2}rem` }}>
29
+ <div
30
+ style={{ paddingLeft: `${row.depth * 2}rem`, display: "flex" }}
31
+ >
30
32
  {row.getCanExpand() ? (
31
33
  <button
32
34
  style={{
33
- // marginRight: "0.8rem",
34
35
  cursor: "pointer",
35
36
  background: "none",
36
37
  border: "none",
@@ -48,7 +49,7 @@ export const useDefaultColumns = () => {
48
49
  ) : (
49
50
  <span style={{ marginRight: "0.8rem" }}></span>
50
51
  )}
51
- {getValue<boolean>()}
52
+ <span style={{ marginTop: "0.2rem" }}>{getValue<boolean>()}</span>
52
53
  </div>
53
54
  );
54
55
  },
@@ -37,6 +37,9 @@ export interface TopbarOptionsProps {
37
37
  showSearch?: boolean;
38
38
  showFilter?: boolean;
39
39
  showCustomizationToggle?: boolean;
40
+ tableStates: CraftTableOptionsProps;
41
+ searchValue?: string;
42
+ onSearchChange?: (val: string) => void;
40
43
  }
41
44
 
42
45
  export interface CustomRenderContext<T> {
@@ -75,8 +78,6 @@ export interface CraftTableProps<T> {
75
78
  customRenderFn?: CustomRenderFnMap<T>;
76
79
  shouldHideColumn?: (accessorKey?: string) => boolean;
77
80
  styleOptions?: CraftTableStyleProps;
78
- searchValue?: string;
79
- onSearchChange?: (val: string) => void;
80
81
  }
81
82
  export interface CraftTableComponentProps<T> {
82
83
  table: Table<T>;