@ssplib/react-components 0.0.279 → 0.0.280

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.
@@ -74,7 +74,7 @@ function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
74
74
  const theme = (0, material_1.useTheme)();
75
75
  const isSmall = (0, material_1.useMediaQuery)(theme.breakpoints.only('xs'));
76
76
  const startData = (0, react_1.useRef)(data);
77
- const orderAsc = (0, react_1.useRef)(false);
77
+ const orderAsc = (0, react_1.useRef)((localStorage.getItem(`order-${id}`) === 'true') || false);
78
78
  const lg = (0, material_1.useMediaQuery)(theme.breakpoints.up(2000));
79
79
  localTableName = `tableFilter_${id}`;
80
80
  localTableNameCache = `tableFilterCache_${id}`;
@@ -116,8 +116,31 @@ function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
116
116
  startData.current = [];
117
117
  }
118
118
  else {
119
- setData(value);
120
- startData.current = JSON.parse(JSON.stringify(value));
119
+ let newValue = value;
120
+ // começando a ordenação padrão
121
+ if (localStorage.getItem(`order-data-${id}`)) {
122
+ try {
123
+ const orderData = JSON.parse(localStorage.getItem(`order-data-${id}`));
124
+ newValue = (0, utils_1.ordenarDados)({
125
+ order: orderData,
126
+ list: value,
127
+ orderAsc: orderAsc.current,
128
+ });
129
+ }
130
+ catch (err) {
131
+ console.log(err);
132
+ }
133
+ }
134
+ else if (orderBy.length > 0) {
135
+ // se não tiver salvo uma ordenação, ordena pelo primeiro da lista
136
+ newValue = (0, utils_1.ordenarDados)({
137
+ order: orderBy[0],
138
+ list: value,
139
+ orderAsc: orderAsc.current,
140
+ });
141
+ }
142
+ setData(newValue);
143
+ startData.current = JSON.parse(JSON.stringify(newValue));
121
144
  }
122
145
  }
123
146
  setIsLoading(false);
@@ -139,7 +162,7 @@ function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
139
162
  (0, react_1.useEffect)(() => {
140
163
  if (isLoading || error || !getData(data))
141
164
  return;
142
- const value = getData(data);
165
+ let value = getData(data);
143
166
  setList(value);
144
167
  setListClone(value);
145
168
  setPagCount((0, utils_1.getCount)(value, itemsCount));
@@ -313,13 +336,15 @@ function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
313
336
  });
314
337
  };
315
338
  const handleOrdenarDados = (x) => {
339
+ /** Inverter a ordem de ordenação no segundo clique */
340
+ orderAsc.current = !orderAsc.current;
316
341
  const dadosOrdenados = (0, utils_1.ordenarDados)({
317
342
  order: x,
318
343
  list,
319
344
  orderAsc: orderAsc.current,
320
345
  });
321
- /** Inverter a ordem de ordenação no segundo clique */
322
- orderAsc.current = !orderAsc.current;
346
+ localStorage.setItem(`order-${id}`, orderAsc.current.toString());
347
+ localStorage.setItem(`order-data-${id}`, JSON.stringify(x));
323
348
  setList(dadosOrdenados);
324
349
  };
325
350
  if (error)
@@ -353,7 +378,7 @@ function Table({ mediaQueryLG, columns, fetchFunc, emptyMsg = {
353
378
  react_1.default.createElement(material_1.Stack, { direction: 'row', borderRadius: 5, padding: 0 },
354
379
  react_1.default.createElement("span", null, "Filtrar"))),
355
380
  react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1 },
356
- react_1.default.createElement(CustomMenu_1.default, { data: orderBy.map((x) => ({
381
+ orderBy.length > 0 && react_1.default.createElement(CustomMenu_1.default, { data: orderBy.map((x) => ({
357
382
  name: x.label,
358
383
  onClick: () => handleOrdenarDados(x),
359
384
  })), btProps: {
@@ -124,7 +124,7 @@ export interface TableProps {
124
124
  /** Usa autenticação via Keycloak */
125
125
  useKC?: boolean;
126
126
  /** Dados iniciais da tabela */
127
- initialData: Array<{
127
+ initialData?: Array<{
128
128
  [key: string]: any;
129
129
  }> | null;
130
130
  /** Flag de carregamento dos dados da tabela */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssplib/react-components",
3
- "version": "0.0.279",
3
+ "version": "0.0.280",
4
4
  "description": "SSP React Components",
5
5
  "main": "index.js",
6
6
  "author": "Pedro Henrique <sr.hudrick@gmail.com>",
@@ -36,9 +36,15 @@
36
36
  "type": "git",
37
37
  "url": "git+https://github.com/SSPDF/ssp-components.git"
38
38
  },
39
- "keywords": ["front", "react", "components", "ssp", "df"],
39
+ "keywords": [
40
+ "front",
41
+ "react",
42
+ "components",
43
+ "ssp",
44
+ "df"
45
+ ],
40
46
  "bugs": {
41
47
  "url": "https://github.com/SSPDF/ssp-components/issues"
42
48
  },
43
49
  "homepage": "https://github.com/SSPDF/ssp-components#readme"
44
- }
50
+ }