ar-design 0.2.25 → 0.2.27

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.
@@ -7,6 +7,7 @@ import Pagination from "../../navigation/pagination";
7
7
  import React, { forwardRef, memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
8
8
  import Input from "../../form/input";
9
9
  import Popover from "../../feedback/popover";
10
+ import Utils from "../../../libs/infrastructure/shared/Utils";
10
11
  const Table = forwardRef(({ children, title, description, data, columns, actions, selections, previousSelections, searchedParams, pagination, config = { isSearchable: false }, }, ref) => {
11
12
  // refs
12
13
  const _tableWrapper = useRef(null);
@@ -109,8 +110,18 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
109
110
  }, 750);
110
111
  }
111
112
  else {
112
- setSearchedText((prev) => ({ ...prev, [event.target.name]: event.target.value }));
113
+ setSearchedText((prev) => {
114
+ const _state = { ...prev };
115
+ if (event.target.value === "") {
116
+ delete _state[event.target.name]; // Key'i siliyoruz
117
+ }
118
+ else {
119
+ _state[event.target.name] = event.target.value; // Yeni değeri ekliyoruz
120
+ }
121
+ return _state;
122
+ });
113
123
  }
124
+ setCurrentPage(1);
114
125
  };
115
126
  const handleCheckboxChange = useCallback(async (event) => {
116
127
  event.stopPropagation();
@@ -127,8 +138,8 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
127
138
  }, []);
128
139
  // Derinlemesine arama yapmak için özyinelemeli bir fonksiyon tanımlayalım.
129
140
  const deepSearch = (item, searchedText) => {
130
- if (!searchedText)
131
- return false;
141
+ if (!searchedText || Object.keys(searchedText).length === 0)
142
+ return true;
132
143
  // Eğer değer bir sayı veya string ise, aranan metinle eşleşip eşleşmediğini kontrol ediyoruz.
133
144
  return Object.entries(searchedText).every(([key, value]) => {
134
145
  const _itemValue = item[key];
@@ -162,7 +173,6 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
162
173
  if (searchedText) {
163
174
  _data = _data.filter((item) => deepSearch(item, searchedText));
164
175
  setTotalRecords(_data.length);
165
- setCurrentPage(1);
166
176
  }
167
177
  else {
168
178
  setTotalRecords(data.length);
@@ -198,7 +208,7 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
198
208
  setSearchedParams(checkboxSelectedParams);
199
209
  }
200
210
  else {
201
- setSearchedText(checkboxSelectedParams);
211
+ setSearchedText((prev) => ({ ...prev, ...checkboxSelectedParams }));
202
212
  }
203
213
  setCurrentPage(1);
204
214
  pagination && pagination.onChange(1);
@@ -215,6 +225,9 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
215
225
  setSelectAll(_checkboxItems.current.every((item) => item?.checked === true));
216
226
  }
217
227
  }, [selectionItems, currentPage]);
228
+ useEffect(() => {
229
+ console.log("Table component re-rendered!", actions);
230
+ });
218
231
  return (React.createElement("div", { ref: _tableWrapper, className: _tableClassName.map((c) => c).join(" ") },
219
232
  (title || description || actions || React.Children.count(children) > 0) && (React.createElement("div", { className: "header" },
220
233
  React.createElement("div", { className: "title" },
@@ -345,6 +358,9 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
345
358
  } })))));
346
359
  });
347
360
  export default memo(Table, (prevProps, nextProps) => {
348
- return (JSON.stringify(prevProps.data) === JSON.stringify(nextProps.data) &&
349
- JSON.stringify(prevProps.columns) === JSON.stringify(nextProps.columns));
361
+ const data = Utils.DeepEqual(prevProps.data, nextProps.data);
362
+ const columns = Utils.DeepEqual(prevProps.columns, nextProps.columns);
363
+ const actions = Utils.DeepEqual(prevProps.actions, nextProps.actions);
364
+ const previousSelections = Utils.DeepEqual(prevProps.previousSelections, nextProps.previousSelections);
365
+ return data && columns && actions && previousSelections;
350
366
  });
@@ -6,6 +6,7 @@ declare class Utils {
6
6
  GetOSShortCutIcons: () => "⌘" | "ctrl" | "";
7
7
  StringFormat: (value: string, ...args: any[]) => string;
8
8
  IsNullOrEmpty: (value: unknown) => boolean;
9
+ DeepEqual: (obj1: any, obj2: any) => boolean;
9
10
  }
10
11
  declare const _default: Utils;
11
12
  export default _default;
@@ -66,5 +66,17 @@ class Utils {
66
66
  return true;
67
67
  return false;
68
68
  };
69
+ DeepEqual = (obj1, obj2) => {
70
+ if (Object.is(obj1, obj2))
71
+ return true; // Aynı referanssa true döndür
72
+ if (typeof obj1 !== "object" || typeof obj2 !== "object" || obj1 === null || obj2 === null) {
73
+ return false; // Eğer biri obje değilse ve eşit değilse false
74
+ }
75
+ const keys1 = Object.keys(obj1);
76
+ const keys2 = Object.keys(obj2);
77
+ if (keys1.length !== keys2.length)
78
+ return false; // Farklı uzunlukta anahtar varsa false
79
+ return keys1.every((key) => this.DeepEqual(obj1[key], obj2[key])); // Rekürsif karşılaştırma
80
+ };
69
81
  }
70
82
  export default new Utils();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.2.25",
3
+ "version": "0.2.27",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",