rez-table-listing-mui 1.0.28 → 1.0.30

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.
@@ -15,7 +15,7 @@ import {
15
15
  } from "../../../../types/filter";
16
16
  import { Controller, useForm } from "react-hook-form";
17
17
  import FormTextfield from "./components/Textfield";
18
- import React, { useEffect, useMemo } from "react";
18
+ import React, { useEffect, useMemo, useCallback } from "react";
19
19
  import FormSelect from "./components/Select";
20
20
  import FormDatePicker from "./components/Date";
21
21
  import FormDropdown from "./components/Dropdown";
@@ -23,6 +23,7 @@ import FormMultiSelect from "./components/Multi-Select";
23
23
  import { CraftTableOptionsProps } from "../../../../types/table-options";
24
24
  import FilterCriteria from "./components/Filter-criteria";
25
25
  import CustomSearch from "../search";
26
+ import { customDebounce } from "../../../../libs/utils/debounce";
26
27
 
27
28
  interface FormValues {
28
29
  filterName: string;
@@ -106,9 +107,18 @@ const FilterForm = ({
106
107
 
107
108
  // Reset form when filters change
108
109
  useEffect(() => {
109
- reset(defaultValues);
110
+ if (!isDirty) reset(defaultValues);
110
111
  }, [selectedFilters, filterName]);
111
112
 
113
+ // Create a debounced version of the filter update function
114
+ const debouncedUpdateFilters = useCallback(
115
+ customDebounce((updatedFilters: UpdatedFilterStateProps[]) => {
116
+ setSelectedFilters(updatedFilters);
117
+ setFilters(updatedFilters);
118
+ }, 1000), // 1000ms delay
119
+ [setSelectedFilters, setFilters]
120
+ );
121
+
112
122
  // Effect to update filters when form values change
113
123
  useEffect(() => {
114
124
  if (isDirty) {
@@ -128,10 +138,10 @@ const FilterForm = ({
128
138
  return filter;
129
139
  });
130
140
 
131
- setSelectedFilters(updatedFilters);
132
- setFilters(updatedFilters);
141
+ // Use the debounced update function instead of direct updates
142
+ debouncedUpdateFilters(updatedFilters);
133
143
  }
134
- }, [formValues]);
144
+ }, [formValues, isDirty, selectedFilters, debouncedUpdateFilters]);
135
145
 
136
146
  // Cleanup effect
137
147
  useEffect(() => {
@@ -428,7 +438,7 @@ const FilterForm = ({
428
438
  },
429
439
  }}
430
440
  // onClick={() => setSaveFilterModalOpen(true)}
431
- // disabled={editMode && !isDirty}
441
+ disabled={editMode && !isDirty}
432
442
  onClick={() => {
433
443
  setSavedFilterModalOpen && setSavedFilterModalOpen(true);
434
444
  }}
@@ -6,6 +6,7 @@ interface SearchInputProps {
6
6
  value: string;
7
7
  onChange: (value: string) => void;
8
8
  placeholder?: string;
9
+ className?: string;
9
10
  }
10
11
 
11
12
  const CustomSearch = ({
@@ -28,10 +29,14 @@ const CustomSearch = ({
28
29
  value={search}
29
30
  onChange={handleChange}
30
31
  placeholder={placeholder}
32
+ className={"search-input"}
31
33
  InputProps={{
32
34
  startAdornment: (
33
35
  <InputAdornment position="start">
34
- <SearchIcon sx={{ color: "#888888", fontSize: "20px" }} />
36
+ <SearchIcon
37
+ sx={{ color: "#888888", fontSize: "20px" }}
38
+ className="search-icon-svg"
39
+ />
35
40
  </InputAdornment>
36
41
  ),
37
42
  }}
@@ -241,14 +241,18 @@ const FilterDrawer = ({
241
241
  },
242
242
  {
243
243
  label: "Delete",
244
+
244
245
  onClick: () => {
245
246
  onDeleteFilter && onDeleteFilter();
246
-
247
247
  setDeleteFilterModalOpen(false);
248
248
  setEditMode && setEditMode(false);
249
249
  },
250
250
  variant: "contained",
251
- sx: { color: "white", backgroundColor: "#f63d68" },
251
+ sx: {
252
+ color: "white",
253
+ backgroundColor: "#f63d68",
254
+ "&:hover": { backgroundColor: "#f63d68" },
255
+ },
252
256
  },
253
257
  ]}
254
258
  maxWidth="xs"
@@ -33,6 +33,7 @@ function TableWrapper<T>({
33
33
  customRenderFn = {},
34
34
  // styleOptions,
35
35
  shouldHideColumn,
36
+ emptyListComponent,
36
37
  }: CraftTableProps<T>) {
37
38
  if (!Array.isArray(data)) {
38
39
  throw new Error("data must be an array of objects.");
@@ -274,6 +275,8 @@ function TableWrapper<T>({
274
275
  {loaderText && <p>{loaderText}</p>}
275
276
  </div>
276
277
  )
278
+ ) : !isLoading && data.length === 0 && emptyListComponent ? (
279
+ emptyListComponent
277
280
  ) : (
278
281
  <div
279
282
  // {...tableWrapperProps}
@@ -0,0 +1,15 @@
1
+ export const customDebounce = <T extends (...args: any[]) => any>(
2
+ func: T,
3
+ delay: number
4
+ ) => {
5
+ let timerId: NodeJS.Timeout;
6
+
7
+ return function (this: any, ...args: Parameters<T>) {
8
+ const context = this;
9
+
10
+ clearTimeout(timerId);
11
+ timerId = setTimeout(() => {
12
+ func.apply(context, args);
13
+ }, delay);
14
+ };
15
+ };
@@ -78,6 +78,7 @@ export interface CraftTableProps<T> {
78
78
  customRenderFn?: CustomRenderFnMap<T>;
79
79
  shouldHideColumn?: (accessorKey?: string) => boolean;
80
80
  styleOptions?: CraftTableStyleProps;
81
+ emptyListComponent?: React.ReactNode;
81
82
  }
82
83
  export interface CraftTableComponentProps<T> {
83
84
  table: Table<T>;