ar-design 0.1.76 → 0.1.78

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.
@@ -1,28 +1,32 @@
1
1
  import { TableColumnType } from "../../../libs/types";
2
2
  import { IChildren } from "../../../libs/types/IGlobalProps";
3
+ export type SearchedParam = {
4
+ [key: string]: string;
5
+ };
3
6
  interface IProps<T> extends IChildren {
4
7
  title?: string;
5
8
  description?: string;
6
9
  data: T[];
7
10
  columns: TableColumnType<T>[];
8
11
  actions?: {
9
- add?: {
12
+ create?: {
10
13
  tooltip: string;
11
- click: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
14
+ onClick: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
12
15
  };
13
16
  import?: {
14
17
  tooltip: string;
15
- click: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
18
+ onClick: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
16
19
  };
17
20
  };
18
21
  selections?: (selectionItems: T[]) => void;
22
+ searchedParams?: (params: SearchedParam | undefined, query: string) => void;
19
23
  pagination?: {
20
24
  totalRecords: number;
21
25
  perPage: number;
22
26
  onChange: (currentPage: number) => void;
23
27
  };
24
28
  config?: {
25
- isServer?: boolean;
29
+ isServerSide?: boolean;
26
30
  isSearchable?: boolean;
27
31
  scroll?: {
28
32
  maxHeight: number;
@@ -2,7 +2,7 @@ import React from "react";
2
2
  import IProps from "./IProps";
3
3
  import "../../../assets/css/components/data-display/table/styles.css";
4
4
  declare const Table: {
5
- <T extends object>({ children, title, description, data, columns, actions, selections, pagination, config, }: IProps<T>): React.JSX.Element;
5
+ <T extends object>({ children, title, description, data, columns, actions, selections, searchedParams, pagination, config, }: IProps<T>): React.JSX.Element;
6
6
  Action: React.FC<{
7
7
  children: React.ReactElement | React.ReactElement[];
8
8
  }>;
@@ -6,19 +6,21 @@ import Actions from "./Actions";
6
6
  import Pagination from "../../navigation/pagination";
7
7
  import Button from "../../form/button";
8
8
  import { ARIcon } from "../../icons";
9
- const Table = function ({ children, title, description, data, columns, actions, selections, pagination, config = { isSearchable: true }, }) {
9
+ const Table = function ({ children, title, description, data, columns, actions, selections, searchedParams, pagination, config = { isSearchable: true }, }) {
10
10
  // refs
11
11
  let _dataLength = useRef(0);
12
12
  const _tableWrapper = useRef(null);
13
13
  const _tableContent = useRef(null);
14
14
  const _table = useRef(null);
15
15
  const _checkboxItems = useRef([]);
16
+ const _searchTimeOut = useRef(null);
16
17
  // className
17
18
  const _tableClassName = ["ar-table", "scroll"];
18
19
  // states
19
20
  const [selectAll, setSelectAll] = useState(false);
20
21
  const [selectionItems, setSelectionItems] = useState([]);
21
- const [searchedText, setSearchedText] = useState([]);
22
+ const [searchedTexts, setSearchedTexts] = useState([]);
23
+ const [_searchedParams, setSearchedParams] = useState(undefined);
22
24
  const [currentPage, setCurrentPage] = useState(1);
23
25
  if (config && Object.keys(config.scroll || {}).length > 0) {
24
26
  if (_tableContent.current && config.scroll) {
@@ -105,7 +107,7 @@ const Table = function ({ children, title, description, data, columns, actions,
105
107
  }
106
108
  // Eğer değer bir nesne veya dizi ise, içindeki her bir değeri yine deepSearch fonksiyonuyla kontrol ediyoruz.
107
109
  if (typeof value === "object") {
108
- return Object.values(value).some((innerValue) => deepSearch(key, innerValue, searchedText));
110
+ return Object.values(value).some((innerValue) => deepSearch(key, innerValue, searchedTexts));
109
111
  }
110
112
  // Diğer türlerdeki değerleri atla.
111
113
  return false;
@@ -113,19 +115,18 @@ const Table = function ({ children, title, description, data, columns, actions,
113
115
  const getData = useCallback(() => {
114
116
  let _data = [...data];
115
117
  _dataLength.current = data.length;
116
- if (pagination) {
118
+ if (pagination && !config.isServerSide) {
117
119
  const indexOfLastRow = currentPage * pagination.perPage;
118
120
  const indexOfFirstRow = indexOfLastRow - pagination.perPage;
119
- if (!config?.isServer)
120
- _data = data.slice(indexOfFirstRow, indexOfLastRow);
121
+ _data = data.slice(indexOfFirstRow, indexOfLastRow);
121
122
  }
122
- return Object.keys(searchedText).length > 0
123
+ return Object.keys(searchedTexts).length > 0
123
124
  ? _data.filter((item) => {
124
125
  // `some` kullanarak herhangi bir girişin arama koşulunu karşılayıp karşılamadığını kontrol ediyoruz.
125
- return Object.entries(item).some(([_key, _value]) => deepSearch(_key, _value, searchedText));
126
+ return Object.entries(item).some(([_key, _value]) => deepSearch(_key, _value, searchedTexts));
126
127
  })
127
128
  : _data;
128
- }, [data, searchedText, currentPage]);
129
+ }, [data, searchedTexts, currentPage]);
129
130
  // useEffects
130
131
  useEffect(() => {
131
132
  handleOnScroll();
@@ -136,6 +137,19 @@ const Table = function ({ children, title, description, data, columns, actions,
136
137
  selections(selectionItems);
137
138
  }, [selectionItems]);
138
139
  useEffect(() => {
140
+ if (config?.isServerSide && searchedParams) {
141
+ // const query = Object.entries(_searchedParams ?? {})
142
+ // .map(([key, value]) => {
143
+ // return `${key}=${value}`;
144
+ // })
145
+ // .join("&");
146
+ const query = new URLSearchParams(_searchedParams).toString();
147
+ searchedParams(_searchedParams, query);
148
+ }
149
+ }, [_searchedParams]);
150
+ useEffect(() => {
151
+ if (!selections)
152
+ return;
139
153
  let allChecked = false;
140
154
  if (_checkboxItems.current.length > 0) {
141
155
  allChecked = _checkboxItems.current.every((item) => item?.checked === true);
@@ -150,8 +164,8 @@ const Table = function ({ children, title, description, data, columns, actions,
150
164
  React.createElement("div", { className: "actions" },
151
165
  React.Children.count(children) > 0 && React.createElement("div", null, React.Children.map(children, (child) => child)),
152
166
  actions && (React.createElement(React.Fragment, null,
153
- actions.add && (React.createElement(Button, { variant: "outlined", status: "dark", icon: { element: React.createElement(ARIcon, { icon: "Add", size: 16 }) }, tooltip: { text: actions.add.tooltip, direction: "top" }, onClick: actions.add.click })),
154
- actions.import && (React.createElement(Button, { variant: "outlined", status: "dark", icon: { element: React.createElement(ARIcon, { icon: "Import", size: 16 }) }, tooltip: { text: actions.import.tooltip, direction: "top" }, onClick: actions.import.click })))))),
167
+ actions.create && (React.createElement(Button, { variant: "outlined", status: "dark", icon: { element: React.createElement(ARIcon, { icon: "Add", size: 16 }) }, tooltip: { text: actions.create.tooltip, direction: "top" }, onClick: actions.create.onClick })),
168
+ actions.import && (React.createElement(Button, { variant: "outlined", status: "dark", icon: { element: React.createElement(ARIcon, { icon: "Import", size: 16 }) }, tooltip: { text: actions.import.tooltip, direction: "top" }, onClick: actions.import.onClick })))))),
155
169
  React.createElement("div", { ref: _tableContent, className: "content", onScroll: handleOnScroll },
156
170
  React.createElement("table", { ref: _table },
157
171
  React.createElement("thead", null,
@@ -201,18 +215,31 @@ const Table = function ({ children, title, description, data, columns, actions,
201
215
  }), ...(c.config?.sticky && {
202
216
  "data-sticky-position": c.config.sticky,
203
217
  }) },
204
- React.createElement("input", { className: "search-input", onChange: (event) => setSearchedText((prev) => {
205
- const updated = prev.some((item) => item.key === c.key);
206
- if (updated) {
207
- if (event.target.value.toLowerCase() === "") {
208
- return prev.filter((item) => item.key !== c.key);
209
- }
210
- return prev.map((item) => item.key === c.key ? { ...item, value: event.target.value.toLowerCase() } : item);
218
+ React.createElement("input", { name: String(c.key), className: "search-input", onChange: (event) => {
219
+ if (config.isServerSide) {
220
+ if (_searchTimeOut.current)
221
+ clearTimeout(_searchTimeOut.current);
222
+ _searchTimeOut.current = setTimeout(() => {
223
+ setSearchedParams((prev) => ({ ...prev, [event.target.name]: event.target.value }));
224
+ pagination && pagination.onChange(1);
225
+ }, 750);
211
226
  }
212
227
  else {
213
- return [...prev, { key: c.key, value: event.target.value.toLowerCase() }];
228
+ // Bileşen bazlı arama işlemi.
229
+ setSearchedTexts((prev) => {
230
+ const updated = prev.some((item) => item.key === c.key);
231
+ if (updated) {
232
+ if (event.target.value.toLowerCase() === "") {
233
+ return prev.filter((item) => item.key !== c.key);
234
+ }
235
+ return prev.map((item) => item.key === c.key ? { ...item, value: event.target.value.toLowerCase() } : item);
236
+ }
237
+ else {
238
+ return [...prev, { key: c.key, value: event.target.value.toLowerCase() }];
239
+ }
240
+ });
214
241
  }
215
- }) })));
242
+ } })));
216
243
  })))),
217
244
  React.createElement("tbody", null, getData().length > 0 ? (getData().map((item, index) => (React.createElement("tr", { key: `row-${index}` },
218
245
  selections && (React.createElement("td", { key: `selection-${index}`, className: "sticky-left", "data-sticky-position": "left" },
@@ -268,9 +295,7 @@ const Table = function ({ children, title, description, data, columns, actions,
268
295
  pagination?.perPage ?? getData().length,
269
296
  " agreement")),
270
297
  pagination && pagination.totalRecords > pagination.perPage && (React.createElement(Pagination, { totalRecords: pagination.totalRecords, perPage: pagination.perPage, onChange: (currentPage) => {
271
- setCurrentPage(currentPage);
272
- // Table tarafında yapılan sayfalamayı dışarı aktarmak için kullanılan callback.
273
- pagination.onChange(currentPage);
298
+ !config.isServerSide ? setCurrentPage(currentPage) : pagination.onChange(currentPage);
274
299
  } })))));
275
300
  };
276
301
  Table.Action = Actions;
@@ -93,6 +93,7 @@ export const useValidation = function (data, params, step) {
93
93
  }
94
94
  };
95
95
  const paramsShape = (param, value) => {
96
+ const vLenght = value ? value.length : 0;
96
97
  const getKey = (subkey) => {
97
98
  if (!subkey)
98
99
  return param.key;
@@ -103,10 +104,10 @@ export const useValidation = function (data, params, step) {
103
104
  if (s.type === "required" && Utils.IsNullOrEmpty(value)) {
104
105
  setError(key, s.message, param.step);
105
106
  }
106
- if (s.type === "minimum" && value.length < s.value) {
107
+ if (s.type === "minimum" && vLenght < s.value) {
107
108
  setError(key, Utils.StringFormat(s.message, s.value), param.step);
108
109
  }
109
- if (s.type === "maximum" && value.length > s.value) {
110
+ if (s.type === "maximum" && vLenght > s.value) {
110
111
  setError(key, Utils.StringFormat(s.message, s.value), param.step);
111
112
  }
112
113
  if (s.type === "email" && value && !/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(value)) {
@@ -11,6 +11,9 @@ class Api {
11
11
  this._url = `${this._host}/${this._core ? this._core + "/" : ""}`;
12
12
  }
13
13
  async Get(values) {
14
+ if (values.input && values.input.toString().includes("?")) {
15
+ values.input = values.input.toString().replace(/\/(?=\?)/, "");
16
+ }
14
17
  const response = await this.CustomFetch(`${this._url}${values.input}`, {
15
18
  method: "GET",
16
19
  headers: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.1.76",
3
+ "version": "0.1.78",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",