rez-table-listing-mui 1.3.7 → 1.3.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez-table-listing-mui",
3
- "version": "1.3.7",
3
+ "version": "1.3.8",
4
4
  "type": "module",
5
5
  "description": "A rez table listing component built on TanStack Table",
6
6
  "main": "dist/index.js",
@@ -1,8 +1,9 @@
1
1
  import { Box, Button, styled, Paper } from "@mui/material";
2
- import { useRef } from "react";
2
+ import { useMemo, useRef } from "react";
3
3
  import { AddIcon } from "../../../../../../assets/svg";
4
4
  import {
5
5
  FilterColumnsDataProps,
6
+ FilterComponentOptions,
6
7
  FilterDataMainFilterEntityWiseCriteriaProps,
7
8
  } from "../../../../../types/filter";
8
9
  import { CraftTableOptionsProps } from "../../../../../types/table-options";
@@ -16,15 +17,15 @@ const FilterCriteria = ({
16
17
  columnsData,
17
18
  tableStates,
18
19
  onChangeFunction,
20
+ filterComponentOptions,
19
21
  }: {
20
22
  columnsData: FilterColumnsDataProps;
21
23
  tableStates: CraftTableOptionsProps;
22
- searchTerm: string;
23
- setSearchTerm: React.Dispatch<React.SetStateAction<string>>;
24
24
  onChangeFunction: ({
25
25
  updatedFilters,
26
26
  filterMaster,
27
27
  }: onFilterChangeFunctionProps) => void;
28
+ filterComponentOptions?: FilterComponentOptions;
28
29
  }) => {
29
30
  const FilterButton = styled(Button)(({ theme }) => ({
30
31
  borderRadius: 20,
@@ -100,12 +101,20 @@ const FilterCriteria = ({
100
101
  setShowFilterOption((prev) => !prev);
101
102
  };
102
103
 
104
+ // Disable button if only one filter is allowed
105
+ const isSingleFilter =
106
+ filterComponentOptions?.tabOptions?.isSingleFilter || false;
107
+ const disableButton = useMemo(() => {
108
+ return isSingleFilter && filters?.length > 0;
109
+ }, [filters?.length, isSingleFilter]);
110
+
103
111
  return (
104
112
  <Box>
105
113
  <FilterButton
106
114
  fullWidth
107
115
  startIcon={<AddIcon />}
108
116
  onClick={toggleFilterOptions}
117
+ disabled={disableButton}
109
118
  sx={{
110
119
  bgcolor: "#eae4fe",
111
120
  borderRadius: "6px",
@@ -42,8 +42,6 @@ const FilterForm = ({
42
42
  dropdownData,
43
43
  searchTerm = "",
44
44
  setSearchTerm,
45
- criteriaSearchTerm = "",
46
- setCriteriaSearchTerm,
47
45
  handleRemoveFilter,
48
46
  editMode = false,
49
47
  tableStates,
@@ -56,8 +54,6 @@ const FilterForm = ({
56
54
  dropdownData: FilterDropdownDataProps;
57
55
  searchTerm?: string;
58
56
  setSearchTerm: React.Dispatch<React.SetStateAction<string>>;
59
- criteriaSearchTerm?: string;
60
- setCriteriaSearchTerm: React.Dispatch<React.SetStateAction<string>>;
61
57
  handleRemoveFilter: (filter_attribute: string) => void;
62
58
  editMode?: boolean;
63
59
  tableStates: CraftTableOptionsProps;
@@ -76,6 +72,8 @@ const FilterForm = ({
76
72
  filterComponentOptions?.tabOptions?.mainFilter?.showSaveButton;
77
73
  const showClearAllButton =
78
74
  filterComponentOptions?.tabOptions?.mainFilter?.showClearAllButton;
75
+ const customButtons =
76
+ filterComponentOptions?.tabOptions?.mainFilter?.customButtons;
79
77
 
80
78
  const filterName = filterMaster?.saved_filters?.selectedName || "";
81
79
 
@@ -283,9 +281,8 @@ const FilterForm = ({
283
281
  <FilterCriteria
284
282
  columnsData={columnsData}
285
283
  tableStates={tableStates}
286
- searchTerm={criteriaSearchTerm}
287
- setSearchTerm={setCriteriaSearchTerm}
288
284
  onChangeFunction={onChangeFunction}
285
+ filterComponentOptions={filterComponentOptions}
289
286
  />
290
287
 
291
288
  {!editMode && (
@@ -497,6 +494,19 @@ const FilterForm = ({
497
494
  Save Filter
498
495
  </Button>
499
496
  )}
497
+
498
+ {/* Custom buttons from props */}
499
+ {customButtons?.map((btn, idx) => (
500
+ <Button
501
+ key={idx}
502
+ fullWidth
503
+ variant={btn?.variant ?? "outlined"}
504
+ sx={btn?.sx}
505
+ {...btn}
506
+ >
507
+ {btn?.label}
508
+ </Button>
509
+ ))}
500
510
  </Box>
501
511
  )}
502
512
  </form>
@@ -16,7 +16,6 @@ const MainFilter = ({
16
16
  filterComponentOptions,
17
17
  }: FilterFormComponentProps) => {
18
18
  const [searchTerm, setSearchTerm] = useState<string>("");
19
- const [criteriaSearchTerm, setCriteriaSearchTerm] = useState<string>("");
20
19
 
21
20
  const { setFilters, setFilterMaster, filterMaster } = tableStates;
22
21
 
@@ -60,8 +59,6 @@ const MainFilter = ({
60
59
  columnsData={columnsData}
61
60
  searchTerm={searchTerm}
62
61
  setSearchTerm={setSearchTerm}
63
- criteriaSearchTerm={criteriaSearchTerm}
64
- setCriteriaSearchTerm={setCriteriaSearchTerm}
65
62
  handleRemoveFilter={handleRemoveFilter}
66
63
  tableStates={tableStates}
67
64
  setSavedFilterModalOpen={setSavedFilterModalOpen}
@@ -1,3 +1,4 @@
1
+ import { ButtonProps } from "@mui/material";
1
2
  import { onFilterChangeFunctionProps } from "./common";
2
3
  import { CraftTableOptionsProps } from "./table-options";
3
4
 
@@ -65,6 +66,12 @@ export interface FilterDropdownDataProps {
65
66
  export interface FilterComponentOptionsMainFilterOptions {
66
67
  showSaveButton?: boolean;
67
68
  showClearAllButton?: boolean;
69
+ customButtons?: Array<
70
+ {
71
+ label: string;
72
+ onClick: () => void;
73
+ } & Partial<ButtonProps>
74
+ >;
68
75
  }
69
76
 
70
77
  // Button config type
@@ -88,28 +95,29 @@ type RecordFilterComponentProps = {
88
95
  delete: ModalConfig;
89
96
  };
90
97
 
98
+ interface FilterComponentTabOptions {
99
+ mainFilter?: FilterComponentOptionsMainFilterOptions;
100
+ isSingleFilter?: boolean;
101
+ }
102
+
91
103
  export type FilterComponentOptions =
92
104
  | {
105
+ showTabs?: true; // when true → additional fields allowed
93
106
  showMainHeader?: boolean;
94
107
  mainHeaderTitle?: string;
95
- showTabs?: true; // when true → additional fields allowed
96
108
  showMainFilter?: boolean;
97
109
  showSavedFilter?: boolean;
98
110
  showAttributesFilter?: boolean;
99
111
  isRuleEngine?: boolean;
100
- tabOptions?: {
101
- mainFilter?: FilterComponentOptionsMainFilterOptions;
102
- };
112
+ tabOptions?: FilterComponentTabOptions;
103
113
  recordFilterComponentProps?: RecordFilterComponentProps;
104
114
  }
105
115
  | {
116
+ showTabs?: false; // explicitly false or omitted
106
117
  showMainHeader?: boolean;
107
118
  mainHeaderTitle?: string;
108
- showTabs?: false; // explicitly false or omitted
109
119
  isRuleEngine?: boolean;
110
- tabOptions?: {
111
- mainFilter?: FilterComponentOptionsMainFilterOptions;
112
- };
120
+ tabOptions?: FilterComponentTabOptions;
113
121
  recordFilterComponentProps?: RecordFilterComponentProps;
114
122
  };
115
123