karsten-design-system 1.2.82 → 1.2.83
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/dist/index.js +66 -46
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4668,32 +4668,6 @@ function parseDateRange(value) {
|
|
|
4668
4668
|
return [null, null];
|
|
4669
4669
|
}
|
|
4670
4670
|
}
|
|
4671
|
-
const useLocalStorage = (storageKey, key, defaultValue = {}) => {
|
|
4672
|
-
const getStoredValue = () => {
|
|
4673
|
-
if (!storageKey)
|
|
4674
|
-
return defaultValue;
|
|
4675
|
-
try {
|
|
4676
|
-
const stored = localStorage.getItem(`${storageKey}_${key}`);
|
|
4677
|
-
return stored ? JSON.parse(stored) : defaultValue;
|
|
4678
|
-
}
|
|
4679
|
-
catch {
|
|
4680
|
-
return defaultValue;
|
|
4681
|
-
}
|
|
4682
|
-
};
|
|
4683
|
-
const [storedValue, setStoredValue] = useState(getStoredValue);
|
|
4684
|
-
const setValue = (value) => {
|
|
4685
|
-
try {
|
|
4686
|
-
setStoredValue(value);
|
|
4687
|
-
if (storageKey) {
|
|
4688
|
-
localStorage.setItem(`${storageKey}_${key}`, JSON.stringify(value));
|
|
4689
|
-
}
|
|
4690
|
-
}
|
|
4691
|
-
catch (error) {
|
|
4692
|
-
console.error(`Erro ao salvar ${key} no localStorage:`, error);
|
|
4693
|
-
}
|
|
4694
|
-
};
|
|
4695
|
-
return [storedValue, setValue];
|
|
4696
|
-
};
|
|
4697
4671
|
const getFromLocalStorage = (localStorageKey, key) => {
|
|
4698
4672
|
try {
|
|
4699
4673
|
const stored = localStorage.getItem(`${localStorageKey}_${key}`);
|
|
@@ -4709,8 +4683,15 @@ function Table({ columns, data, totalRecords, actions = [], actionsHeaderClassNa
|
|
|
4709
4683
|
const [currentPage, setCurrentPage] = useState(1);
|
|
4710
4684
|
const [filters, setFilters] = useState(() => {
|
|
4711
4685
|
if (isPermanentFilterEnabled && localStorageKey) {
|
|
4686
|
+
const storedFilters = getFromLocalStorage(localStorageKey, 'permanentFilters');
|
|
4712
4687
|
const storedValues = getFromLocalStorage(localStorageKey, 'permanentFilterValues');
|
|
4713
|
-
|
|
4688
|
+
const initialFilters = {};
|
|
4689
|
+
Object.keys(storedFilters).forEach((dataIndex) => {
|
|
4690
|
+
if (storedFilters[dataIndex] && storedValues[dataIndex]) {
|
|
4691
|
+
initialFilters[dataIndex] = storedValues[dataIndex];
|
|
4692
|
+
}
|
|
4693
|
+
});
|
|
4694
|
+
return initialFilters;
|
|
4714
4695
|
}
|
|
4715
4696
|
return {};
|
|
4716
4697
|
});
|
|
@@ -4753,7 +4734,7 @@ function Table({ columns, data, totalRecords, actions = [], actionsHeaderClassNa
|
|
|
4753
4734
|
buttonApplyFilterMessage: 'Aplicar',
|
|
4754
4735
|
noResultsMessage: 'Não há dados disponíveis',
|
|
4755
4736
|
selectColumnsMessage: 'Selecionar colunas',
|
|
4756
|
-
permanentFilterMessage: 'Manter filtro ativo
|
|
4737
|
+
permanentFilterMessage: 'Manter filtro sempre ativo',
|
|
4757
4738
|
},
|
|
4758
4739
|
en: {
|
|
4759
4740
|
filterByMessage: 'Filter by',
|
|
@@ -4767,7 +4748,7 @@ function Table({ columns, data, totalRecords, actions = [], actionsHeaderClassNa
|
|
|
4767
4748
|
buttonApplyFilterMessage: 'Apply',
|
|
4768
4749
|
noResultsMessage: 'No data available',
|
|
4769
4750
|
selectColumnsMessage: 'Select columns',
|
|
4770
|
-
permanentFilterMessage: 'Keep filter active
|
|
4751
|
+
permanentFilterMessage: 'Keep filter always active',
|
|
4771
4752
|
},
|
|
4772
4753
|
es: {
|
|
4773
4754
|
filterByMessage: 'Filtrar por',
|
|
@@ -4781,7 +4762,7 @@ function Table({ columns, data, totalRecords, actions = [], actionsHeaderClassNa
|
|
|
4781
4762
|
buttonApplyFilterMessage: 'Aplicar',
|
|
4782
4763
|
noResultsMessage: 'No hay datos disponibles',
|
|
4783
4764
|
selectColumnsMessage: 'Seleccionar columnas',
|
|
4784
|
-
permanentFilterMessage: 'Mantener filtro activo
|
|
4765
|
+
permanentFilterMessage: 'Mantener filtro siempre activo',
|
|
4785
4766
|
},
|
|
4786
4767
|
};
|
|
4787
4768
|
return messages[systemLanguage || 'pt'];
|
|
@@ -4814,20 +4795,24 @@ function Table({ columns, data, totalRecords, actions = [], actionsHeaderClassNa
|
|
|
4814
4795
|
useEffect(() => {
|
|
4815
4796
|
setSortedData(data);
|
|
4816
4797
|
}, [data]);
|
|
4817
|
-
const [, setStoredFilters] = useLocalStorage(isPermanentFilterEnabled ? localStorageKey : undefined, 'permanentFilterValues', {});
|
|
4818
|
-
const [, setStoredPermanentFilters] = useLocalStorage(isPermanentFilterEnabled ? localStorageKey : undefined, 'permanentFilters', {});
|
|
4819
4798
|
useEffect(() => {
|
|
4820
4799
|
if (isPermanentFilterEnabled && localStorageKey) {
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4800
|
+
const permanentFiltersOnly = {};
|
|
4801
|
+
Object.keys(filters).forEach((dataIndex) => {
|
|
4802
|
+
if (localPermanentFilters[dataIndex] && filters[dataIndex]) {
|
|
4803
|
+
permanentFiltersOnly[dataIndex] = filters[dataIndex];
|
|
4804
|
+
}
|
|
4805
|
+
});
|
|
4806
|
+
try {
|
|
4807
|
+
localStorage.setItem(`${localStorageKey}_permanentFilterValues`, JSON.stringify(permanentFiltersOnly));
|
|
4808
|
+
}
|
|
4809
|
+
catch (error) {
|
|
4810
|
+
console.error('Erro ao salvar filtros permanentes:', error);
|
|
4811
|
+
}
|
|
4827
4812
|
}
|
|
4828
4813
|
}, [
|
|
4814
|
+
filters,
|
|
4829
4815
|
localPermanentFilters,
|
|
4830
|
-
setStoredPermanentFilters,
|
|
4831
4816
|
isPermanentFilterEnabled,
|
|
4832
4817
|
localStorageKey,
|
|
4833
4818
|
]);
|
|
@@ -4839,9 +4824,18 @@ function Table({ columns, data, totalRecords, actions = [], actionsHeaderClassNa
|
|
|
4839
4824
|
valuesToApply = getFromLocalStorage(localStorageKey, 'permanentFilterValues');
|
|
4840
4825
|
const updatedFilters = {};
|
|
4841
4826
|
const updatedStatus = {};
|
|
4827
|
+
const cleanedValues = {};
|
|
4828
|
+
Object.keys(valuesToApply).forEach((dataIndex) => {
|
|
4829
|
+
if (filtersToApply[dataIndex]) {
|
|
4830
|
+
cleanedValues[dataIndex] = valuesToApply[dataIndex];
|
|
4831
|
+
}
|
|
4832
|
+
});
|
|
4833
|
+
if (Object.keys(cleanedValues).length !== Object.keys(valuesToApply).length) {
|
|
4834
|
+
localStorage.setItem(`${localStorageKey}_permanentFilterValues`, JSON.stringify(cleanedValues));
|
|
4835
|
+
}
|
|
4842
4836
|
Object.keys(filtersToApply).forEach((dataIndex) => {
|
|
4843
|
-
if (filtersToApply[dataIndex] &&
|
|
4844
|
-
updatedFilters[dataIndex] =
|
|
4837
|
+
if (filtersToApply[dataIndex] && cleanedValues[dataIndex]) {
|
|
4838
|
+
updatedFilters[dataIndex] = cleanedValues[dataIndex];
|
|
4845
4839
|
updatedStatus[dataIndex] = 'applied';
|
|
4846
4840
|
}
|
|
4847
4841
|
});
|
|
@@ -4890,11 +4884,24 @@ function Table({ columns, data, totalRecords, actions = [], actionsHeaderClassNa
|
|
|
4890
4884
|
...prev,
|
|
4891
4885
|
[dataIndex]: filterValue ? 'applied' : 'default',
|
|
4892
4886
|
}));
|
|
4893
|
-
if (isPermanentFilterEnabled &&
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4887
|
+
if (isPermanentFilterEnabled && localStorageKey) {
|
|
4888
|
+
try {
|
|
4889
|
+
localStorage.setItem(`${localStorageKey}_permanentFilters`, JSON.stringify(localPermanentFilters));
|
|
4890
|
+
}
|
|
4891
|
+
catch (error) {
|
|
4892
|
+
console.error('Erro ao salvar filtros permanentes:', error);
|
|
4893
|
+
}
|
|
4894
|
+
if (!filterValue) {
|
|
4895
|
+
setLocalPermanentFilters((prev) => ({
|
|
4896
|
+
...prev,
|
|
4897
|
+
[dataIndex]: false,
|
|
4898
|
+
}));
|
|
4899
|
+
}
|
|
4900
|
+
if (filterValue && !localPermanentFilters[dataIndex]) {
|
|
4901
|
+
const storedValues = getFromLocalStorage(localStorageKey, 'permanentFilterValues');
|
|
4902
|
+
delete storedValues[dataIndex];
|
|
4903
|
+
localStorage.setItem(`${localStorageKey}_permanentFilterValues`, JSON.stringify(storedValues));
|
|
4904
|
+
}
|
|
4898
4905
|
}
|
|
4899
4906
|
};
|
|
4900
4907
|
const handleClearFilter = (column) => {
|
|
@@ -4913,6 +4920,19 @@ function Table({ columns, data, totalRecords, actions = [], actionsHeaderClassNa
|
|
|
4913
4920
|
...prev,
|
|
4914
4921
|
[dataIndex]: false,
|
|
4915
4922
|
}));
|
|
4923
|
+
if (localStorageKey) {
|
|
4924
|
+
try {
|
|
4925
|
+
const storedFilters = getFromLocalStorage(localStorageKey, 'permanentFilters');
|
|
4926
|
+
delete storedFilters[dataIndex];
|
|
4927
|
+
localStorage.setItem(`${localStorageKey}_permanentFilters`, JSON.stringify(storedFilters));
|
|
4928
|
+
const storedValues = getFromLocalStorage(localStorageKey, 'permanentFilterValues');
|
|
4929
|
+
delete storedValues[dataIndex];
|
|
4930
|
+
localStorage.setItem(`${localStorageKey}_permanentFilterValues`, JSON.stringify(storedValues));
|
|
4931
|
+
}
|
|
4932
|
+
catch (error) {
|
|
4933
|
+
console.error('Erro ao limpar filtros permanentes:', error);
|
|
4934
|
+
}
|
|
4935
|
+
}
|
|
4916
4936
|
}
|
|
4917
4937
|
if (onFilterChange) {
|
|
4918
4938
|
onFilterChange(newFilters);
|