@addsign/moje-agenda-shared-lib 2.0.59 → 2.0.61

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.
@@ -21733,22 +21733,24 @@ function DataTableServer({
21733
21733
  const bottomScrollbarRef = useRef(null);
21734
21734
  const tableRef = useRef(null);
21735
21735
  const syncWidthRef = useRef(null);
21736
- const [itemsPerPageLocal, setItemsPerPageLocal] = useState();
21736
+ const [itemsPerPageLocal, setItemsPerPageLocal] = useState(10);
21737
21737
  const federationContext = useFederationContext();
21738
21738
  const [data, setData] = useState();
21739
21739
  const [isLoading, setIsLoading] = useState(false);
21740
21740
  const [isLocalStorageLoaded, setIsLocalStorageLoaded] = useState(false);
21741
21741
  const [tableKey, setTableKey] = useState(0);
21742
21742
  const [hasMounted, setHasMounted] = useState(false);
21743
- const [currentPage, setCurrentPage] = useState();
21743
+ const [currentPage, setCurrentPage] = useState(0);
21744
21744
  const [selectedItems, setSelectedItems] = useState([]);
21745
21745
  const [fulltextSearch, setFulltextSearch] = useState("");
21746
21746
  const [filterOptions, setFilterOptions] = useState({});
21747
21747
  const [columnFilters, setColumnFilters] = useState(
21748
21748
  {}
21749
21749
  );
21750
- const [showColFilters, setShowColFilters] = useState();
21750
+ const [showColFilters, setShowColFilters] = useState(false);
21751
21751
  const [sortConfig, setSortConfig] = useState(null);
21752
+ const prevDepsRef = useRef([]);
21753
+ const prevFilterDepsRef = useRef([]);
21752
21754
  const createDataPageable = (response, itemsPerPage) => {
21753
21755
  var _a2, _b2, _c, _d;
21754
21756
  const isPageable = !!((_a2 = response.data) == null ? void 0 : _a2.content);
@@ -21770,17 +21772,30 @@ function DataTableServer({
21770
21772
  return showColFilters ? { ...columnFilters, ...filters } : filters || {};
21771
21773
  }, [columnFilters, filters, showColFilters]);
21772
21774
  useEffect(() => {
21773
- setReloadData(true);
21775
+ const currentDeps = [
21776
+ url,
21777
+ showColFilters,
21778
+ columnFilters,
21779
+ itemsPerPageLocal,
21780
+ currentPage,
21781
+ sortConfig,
21782
+ filters,
21783
+ tableKey
21784
+ ];
21785
+ const hasChanged = currentDeps.some((dep, index) => {
21786
+ return JSON.stringify(dep) !== JSON.stringify(prevDepsRef.current[index]);
21787
+ });
21788
+ if (hasChanged) {
21789
+ setReloadData(true);
21790
+ }
21791
+ prevDepsRef.current = currentDeps;
21774
21792
  }, [
21775
21793
  url,
21776
21794
  showColFilters,
21777
- // id,
21778
21795
  columnFilters,
21779
21796
  itemsPerPageLocal,
21780
21797
  currentPage,
21781
21798
  sortConfig,
21782
- federationContext.apiClient,
21783
- federationContext.emitter,
21784
21799
  filters,
21785
21800
  tableKey
21786
21801
  ]);
@@ -21877,51 +21892,63 @@ function DataTableServer({
21877
21892
  }
21878
21893
  }, [id]);
21879
21894
  useEffect(() => {
21880
- const fetchFilterOptions = async (column) => {
21881
- if (column.filterOptions) {
21882
- return column.filterOptions;
21883
- } else if (column.filterSource) {
21884
- try {
21885
- const response = await federationContext.apiClient.get(
21886
- column.filterSource
21887
- );
21888
- const options = response.data.map((item) => {
21889
- var _a2, _b2;
21890
- return {
21891
- value: (_a2 = item[column.filterValueKey]) == null ? void 0 : _a2.toString(),
21892
- label: (_b2 = item[column.filterLabelKey]) == null ? void 0 : _b2.toString()
21893
- };
21894
- });
21895
- return options;
21896
- } catch (error) {
21897
- console.error("Error fetching filter options:", error);
21898
- return [];
21899
- }
21895
+ const currentFilterDeps = [columns, federationContext.apiClient];
21896
+ const hasFilterChanged = currentFilterDeps.some((dep, index) => {
21897
+ const prev = prevFilterDepsRef.current[index];
21898
+ if (index === 1) {
21899
+ return dep !== prev;
21900
21900
  } else {
21901
- return [];
21901
+ return JSON.stringify(dep) !== JSON.stringify(prev);
21902
21902
  }
21903
- };
21904
- const updateFilterOptions = async () => {
21905
- const newFilterOptions = {};
21906
- for (const column of columns) {
21907
- if ((column.filterType === "select" || column.filterType === "multi-select") && (column.filterSource || column.filterOptions) && column.filterValueKey && column.filterLabelKey && column.filterParam) {
21908
- const options = await fetchFilterOptions(column);
21909
- if (options && column.filterType === "select") {
21910
- const filteredOptions = options.filter(
21911
- (option) => option.value !== null && option.value !== void 0 && option.value !== ""
21903
+ });
21904
+ if (hasFilterChanged) {
21905
+ const fetchFilterOptions = async (column) => {
21906
+ if (column.filterOptions) {
21907
+ return column.filterOptions;
21908
+ } else if (column.filterSource) {
21909
+ try {
21910
+ const response = await federationContext.apiClient.get(
21911
+ column.filterSource
21912
21912
  );
21913
- newFilterOptions[column.filterParam] = [
21914
- { value: "__clear__", label: "Všechny" },
21915
- ...filteredOptions
21916
- ];
21917
- } else if (options && column.filterType === "multi-select") {
21918
- newFilterOptions[column.filterParam] = options;
21913
+ const options = response.data.map((item) => {
21914
+ var _a2, _b2;
21915
+ return {
21916
+ value: (_a2 = item[column.filterValueKey]) == null ? void 0 : _a2.toString(),
21917
+ label: (_b2 = item[column.filterLabelKey]) == null ? void 0 : _b2.toString()
21918
+ };
21919
+ });
21920
+ return options;
21921
+ } catch (error) {
21922
+ console.error("Error fetching filter options:", error);
21923
+ return [];
21919
21924
  }
21925
+ } else {
21926
+ return [];
21920
21927
  }
21921
- }
21922
- setFilterOptions(newFilterOptions);
21923
- };
21924
- updateFilterOptions();
21928
+ };
21929
+ const updateFilterOptions = async () => {
21930
+ const newFilterOptions = {};
21931
+ for (const column of columns) {
21932
+ if ((column.filterType === "select" || column.filterType === "multi-select") && (column.filterSource || column.filterOptions) && column.filterValueKey && column.filterLabelKey && column.filterParam) {
21933
+ const options = await fetchFilterOptions(column);
21934
+ if (options && column.filterType === "select") {
21935
+ const filteredOptions = options.filter(
21936
+ (option) => option.value !== null && option.value !== void 0 && option.value !== ""
21937
+ );
21938
+ newFilterOptions[column.filterParam] = [
21939
+ { value: "__clear__", label: "Všechny" },
21940
+ ...filteredOptions
21941
+ ];
21942
+ } else if (options && column.filterType === "multi-select") {
21943
+ newFilterOptions[column.filterParam] = options;
21944
+ }
21945
+ }
21946
+ }
21947
+ setFilterOptions(newFilterOptions);
21948
+ };
21949
+ updateFilterOptions();
21950
+ }
21951
+ prevFilterDepsRef.current = currentFilterDeps;
21925
21952
  }, [columns, federationContext.apiClient]);
21926
21953
  const hasSomeColFilters = useMemo(() => {
21927
21954
  return columns.some((column) => !!column.filterParam);
@@ -22297,13 +22324,7 @@ function DataTableServer({
22297
22324
  filters || {}
22298
22325
  ).includes(String(filterParam)),
22299
22326
  children: [
22300
- /* @__PURE__ */ jsx(
22301
- SelectTrigger,
22302
- {
22303
- className: "flex-1 w-full px-2 font-normal placeholder-muted-foreground",
22304
- children: /* @__PURE__ */ jsx(SelectValue, { placeholder: "Zadejte filtr" })
22305
- }
22306
- ),
22327
+ /* @__PURE__ */ jsx(SelectTrigger, { className: "flex-1 w-full px-2 font-normal placeholder-muted-foreground", children: /* @__PURE__ */ jsx(SelectValue, { placeholder: "Zadejte filtr" }) }),
22307
22328
  /* @__PURE__ */ jsx(SelectContent, { children: (_c = (_b2 = filterOptions[String(filterParam)]) == null ? void 0 : _b2.filter(
22308
22329
  (option) => option.value !== null && option.value !== void 0 && option.value !== ""
22309
22330
  )) == null ? void 0 : _c.map((option) => {