@evergis/react 4.0.7 → 4.0.8

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.
@@ -8,7 +8,7 @@ export declare const useDataSources: ({ type: widgetType, config, attributes, fi
8
8
  layerParams?: Record<string, string>;
9
9
  eqlParameters?: QueryLayerServiceConfigurationDc["eqlParameters"];
10
10
  }) => {
11
- getDataSourcePromises: ({ ds, query, parameters, layerName, limit, condition, url, resourceId, fileName, methodName }: ConfigDataSource, newFilters?: SelectedFilters, offset?: number) => Promise<EqlDataSource | PagedFeaturesListDc>;
11
+ getDataSourcePromises: ({ ds, query, parameters, layerName, limit, condition, url, resourceId, fileName, methodName, }: ConfigDataSource, newFilters?: SelectedFilters, offset?: number) => Promise<EqlDataSource | PagedFeaturesListDc>;
12
12
  getUpdatingDataSources: () => ConfigDataSource[];
13
13
  getUpdatedDataSources: (responses: DataSourcePromise[], currentDataSources: ConfigDataSource[], otherDataSources: FetchedDataSource[]) => any;
14
14
  zoomToLayersExtent: (layers: Array<{
package/dist/index.js CHANGED
@@ -3950,6 +3950,9 @@ const useFetchWithAuth = (url, transform, cleanup) => {
3950
3950
  })
3951
3951
  .then(res => (res.ok ? transformRef.current(res) : null))
3952
3952
  .then(setData)
3953
+ .catch(() => {
3954
+ setData(null);
3955
+ })
3953
3956
  .finally(() => {
3954
3957
  loadingRef.current = false;
3955
3958
  });
@@ -4402,13 +4405,13 @@ const applyQueryFilters = ({ parameters: configParameters, filters: configFilter
4402
4405
  if (configParameters[key].endsWith(".max")) {
4403
4406
  return {
4404
4407
  ...result,
4405
- [key]: selectedFilters?.[filterName]?.max ?? defaultValue,
4408
+ [key]: selectedFilters?.[filterName]?.max ?? (Array.isArray(defaultValue) ? defaultValue[1] : defaultValue),
4406
4409
  };
4407
4410
  }
4408
4411
  if (configParameters[key].endsWith(".min")) {
4409
4412
  return {
4410
4413
  ...result,
4411
- [key]: selectedFilters?.[filterName]?.min ?? defaultValue,
4414
+ [key]: selectedFilters?.[filterName]?.min ?? (Array.isArray(defaultValue) ? defaultValue[0] : defaultValue),
4412
4415
  };
4413
4416
  }
4414
4417
  if (configParameters[key].includes(".")) {
@@ -10705,12 +10708,13 @@ const useDashboardHeader = () => {
10705
10708
  };
10706
10709
  };
10707
10710
 
10711
+ /* eslint-disable max-lines */
10708
10712
  const useDataSources = ({ type: widgetType, config, attributes, filters, layerParams, eqlParameters, }) => {
10709
10713
  const { ewktGeometry, api } = useGlobalContext();
10710
10714
  const { dataSources } = useWidgetContext(widgetType);
10711
10715
  const { filters: configFilters, dataSources: configDataSources } = config || {};
10712
10716
  const prevFilters = React.useRef({});
10713
- const getDataSourcePromises = React.useCallback(async ({ ds, query, parameters, layerName, limit, condition, url, resourceId, fileName, methodName }, newFilters, offset = 0) => {
10717
+ const getDataSourcePromises = React.useCallback(async ({ ds, query, parameters, layerName, limit, condition, url, resourceId, fileName, methodName, }, newFilters, offset = 0) => {
10714
10718
  const selectedFilters = {
10715
10719
  ...(filters || {}),
10716
10720
  ...(newFilters || {}),
@@ -10725,7 +10729,7 @@ const useDataSources = ({ type: widgetType, config, attributes, filters, layerPa
10725
10729
  parameters,
10726
10730
  ...(fileName && { fileName }),
10727
10731
  ...(methodName && { methodName }),
10728
- }
10732
+ },
10729
10733
  });
10730
10734
  if (response.error) {
10731
10735
  throw new Error(response.error.message);
@@ -10740,19 +10744,27 @@ const useDataSources = ({ type: widgetType, config, attributes, filters, layerPa
10740
10744
  geometry: ewktGeometry,
10741
10745
  });
10742
10746
  if (url) {
10743
- const response = await fetch(url, {
10744
- method: "POST",
10745
- headers: {
10746
- Accept: "application/json",
10747
- "Content-Type": "application/json",
10748
- },
10749
- body: JSON.stringify(newParams),
10750
- });
10751
- const json = await response.json();
10752
- return {
10753
- items: json.result.items,
10754
- attributeDefinition: json.result.attributeDefinition,
10755
- };
10747
+ try {
10748
+ const response = await fetch(url, {
10749
+ method: "POST",
10750
+ headers: {
10751
+ Accept: "application/json",
10752
+ "Content-Type": "application/json",
10753
+ },
10754
+ body: JSON.stringify(newParams),
10755
+ });
10756
+ if (!response.ok) {
10757
+ throw new Error(`HTTP error: ${response.status}`);
10758
+ }
10759
+ const json = await response.json();
10760
+ return {
10761
+ items: json.result.items,
10762
+ attributeDefinition: json.result.attributeDefinition,
10763
+ };
10764
+ }
10765
+ catch (error) {
10766
+ throw error instanceof Error ? error : new Error(String(error));
10767
+ }
10756
10768
  }
10757
10769
  if (!layerName) {
10758
10770
  const getProps = {
@@ -10788,11 +10800,23 @@ const useDataSources = ({ type: widgetType, config, attributes, filters, layerPa
10788
10800
  ]
10789
10801
  : [condition, query].filter(Boolean),
10790
10802
  });
10791
- }, [filters, dataSources, configFilters, ewktGeometry, attributes, layerParams, eqlParameters]);
10803
+ }, [
10804
+ filters,
10805
+ dataSources,
10806
+ configFilters,
10807
+ ewktGeometry,
10808
+ api.layers,
10809
+ api.remoteTaskManager,
10810
+ api.eql,
10811
+ attributes,
10812
+ layerParams,
10813
+ eqlParameters,
10814
+ ]);
10792
10815
  const getUpdatingDataSources = React.useCallback(() => {
10793
10816
  const diffFilterNames = filters
10794
10817
  ? Object.keys(filters).filter(key => Array.isArray(filters[key].value)
10795
- ? filters[key].value.length !== prevFilters.current[key]?.value?.length ||
10818
+ ? filters[key].value.length !==
10819
+ prevFilters.current[key]?.value?.length ||
10796
10820
  filters[key].value.some((item, index) => item !== prevFilters.current[key]?.value?.[index])
10797
10821
  : filters[key].value !== prevFilters.current[key]?.value)
10798
10822
  : [];
@@ -10815,7 +10839,8 @@ const useDataSources = ({ type: widgetType, config, attributes, filters, layerPa
10815
10839
  newDataSources[index].layerName = currentDataSources[index].layerName;
10816
10840
  const items = response.status === "rejected"
10817
10841
  ? null
10818
- : response.value?.features || response.value?.items;
10842
+ : response.value?.features ||
10843
+ response.value?.items;
10819
10844
  newDataSources[index].features =
10820
10845
  response.status === "rejected"
10821
10846
  ? null
@@ -10827,13 +10852,18 @@ const useDataSources = ({ type: widgetType, config, attributes, filters, layerPa
10827
10852
  }))
10828
10853
  : items;
10829
10854
  newDataSources[index].attributeDefinition =
10830
- response.status === "rejected" || (!isQueryDataSource && !isPythonDataSource)
10855
+ response.status === "rejected" ||
10856
+ (!isQueryDataSource && !isPythonDataSource)
10831
10857
  ? null
10832
- : response.value?.attributeDefinition ||
10858
+ : response.value
10859
+ ?.attributeDefinition ||
10833
10860
  (isPythonDataSource && items?.[0]?.properties
10834
10861
  ? Object.fromEntries(Object.entries(items[0].properties).map(([key, val]) => [
10835
10862
  key,
10836
- { type: typeof val === "number" ? "Float" : "String", isDisplayed: true },
10863
+ {
10864
+ type: typeof val === "number" ? "Float" : "String",
10865
+ isDisplayed: true,
10866
+ },
10837
10867
  ]))
10838
10868
  : null);
10839
10869
  });
@@ -10859,7 +10889,7 @@ const useDataSources = ({ type: widgetType, config, attributes, filters, layerPa
10859
10889
  position: bbox.center,
10860
10890
  resolution: map.getAdjustedResolution(resolution),
10861
10891
  });*/
10862
- }, []);
10892
+ }, [api.layers]);
10863
10893
  return {
10864
10894
  getDataSourcePromises,
10865
10895
  getUpdatingDataSources,