@evergis/react 3.1.109 → 3.1.111

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.
@@ -16,5 +16,6 @@ export * from './useRenderElement';
16
16
  export * from './useShownOtherItems';
17
17
  export * from './useUpdateDataSource';
18
18
  export * from './useWidgetConfig';
19
+ export * from './useMultipleAttributesRender';
19
20
  export * from './useWidgetContext';
20
21
  export * from './useWidgetPage';
@@ -0,0 +1,13 @@
1
+ import { ContainerProps } from '../types';
2
+ export declare const useMultipleAttributesRender: (config: ContainerProps["config"], elementConfig: ContainerProps["elementConfig"], type: ContainerProps["type"], renderElement: ContainerProps["renderElement"]) => {
3
+ getAttributesToRender: () => string[];
4
+ renderContainer: (attribute?: string) => {
5
+ render: import('../types').RenderElementFunction;
6
+ value: import('react').ReactNode;
7
+ hasUnits: boolean;
8
+ id: string;
9
+ style: import('react').CSSProperties;
10
+ hasIcon: boolean;
11
+ attr: import('@evergis/api').AttributeConfigurationDc;
12
+ };
13
+ };
@@ -0,0 +1,10 @@
1
+ import { ConfigContainerChild, RenderElementFunction, WidgetType } from '../types';
2
+ export declare const useRenderContainerItem: (type: WidgetType, renderElement: RenderElementFunction) => (elementConfig: ConfigContainerChild, attribute: string) => {
3
+ id: string;
4
+ value: import('react').ReactNode;
5
+ hideEmpty: boolean;
6
+ style: import('react').CSSProperties;
7
+ hasIcon: boolean;
8
+ hasUnits: boolean;
9
+ render: RenderElementFunction;
10
+ };
@@ -100,6 +100,7 @@ export interface ConfigOptions {
100
100
  markers?: BarChartMarker[] | string;
101
101
  drawMinMax?: boolean;
102
102
  attributes?: string[];
103
+ attributesExclude?: string[];
103
104
  colors?: string[];
104
105
  defaultColor?: string;
105
106
  primaryColor?: string;
@@ -2,4 +2,5 @@ import { FC } from 'react';
2
2
  import { LayerInfo } from '../../types';
3
3
  export declare const LayerIcon: FC<{
4
4
  layerInfo: LayerInfo;
5
+ error?: boolean;
5
6
  }>;
package/dist/index.js CHANGED
@@ -6072,20 +6072,9 @@ const TwoColumnContainerWrapper = styled(uilibGl.Flex) `
6072
6072
  }
6073
6073
  `;
6074
6074
 
6075
- const OneColumnContainer = React.memo(({ elementConfig, renderElement }) => {
6076
- const { id, options, style } = elementConfig || {};
6077
- const { innerTemplateStyle, hideEmpty } = options || {};
6078
- const value = renderElement({ id: "value" });
6079
- const hasUnits = elementConfig?.children?.some(({ id }) => id === "units");
6080
- if (!value && hideEmpty)
6081
- return null;
6082
- return (jsxRuntime.jsxs(Container, { id: id, isColumn: true, style: innerTemplateStyle || style, children: [jsxRuntime.jsxs(ContainerAlias, { hasBottomMargin: true, children: [renderElement({ id: "alias" }), renderElement({ id: "tooltip" })] }), jsxRuntime.jsxs(ContainerValue, { children: [value, hasUnits && jsxRuntime.jsx(ContainerUnits, { children: renderElement({ id: "units" }) })] })] }));
6083
- });
6084
-
6085
- const TwoColumnContainer = React.memo(({ config, elementConfig, type, renderElement }) => {
6086
- const { selectedTabId, layerInfo, attributes } = useWidgetContext(type);
6087
- const { attributes: renderAttributes } = elementConfig?.options || {};
6088
- const renderContainer = React.useCallback((attribute) => {
6075
+ const useRenderContainerItem = (type, renderElement) => {
6076
+ const { config, layerInfo, selectedTabId, attributes } = useWidgetContext(type);
6077
+ return React.useCallback((elementConfig, attribute) => {
6089
6078
  const { id, options, style, children } = elementConfig || {};
6090
6079
  const { hideEmpty, innerTemplateStyle } = options || {};
6091
6080
  const hasUnits = children?.some(({ id }) => id === "units");
@@ -6123,10 +6112,44 @@ const TwoColumnContainer = React.memo(({ config, elementConfig, type, renderElem
6123
6112
  })
6124
6113
  : renderElement;
6125
6114
  const value = render({ id: "value" });
6115
+ return {
6116
+ id,
6117
+ value,
6118
+ hideEmpty,
6119
+ style: innerTemplateStyle || style,
6120
+ hasIcon,
6121
+ hasUnits,
6122
+ render,
6123
+ };
6124
+ }, []);
6125
+ };
6126
+
6127
+ const BASE_STYLE = {
6128
+ marginBottom: "1rem",
6129
+ };
6130
+ const OneColumnContainer = React.memo(({ type, elementConfig, renderElement }) => {
6131
+ const getRenderContainerItem = useRenderContainerItem(type, renderElement);
6132
+ const { options } = elementConfig || {};
6133
+ const { attributes: renderAttributes, innerTemplateStyle } = options || {};
6134
+ const renderContainer = React.useCallback((attribute) => {
6135
+ const { id, value, hideEmpty, style, hasUnits, render } = getRenderContainerItem(elementConfig, attribute);
6136
+ if (!value && hideEmpty)
6137
+ return null;
6138
+ return (jsxRuntime.jsxs(Container, { id: id, isColumn: true, style: { ...BASE_STYLE, ...(innerTemplateStyle || style) }, children: [jsxRuntime.jsxs(ContainerAlias, { hasBottomMargin: true, children: [render({ id: "alias" }), render({ id: "tooltip" })] }), jsxRuntime.jsxs(ContainerValue, { children: [value, hasUnits && jsxRuntime.jsx(ContainerUnits, { children: render({ id: "units" }) })] })] }));
6139
+ }, [getRenderContainerItem, elementConfig, innerTemplateStyle]);
6140
+ return renderAttributes?.length ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderAttributes.map(attribute => renderContainer(attribute)) })) : (renderContainer());
6141
+ });
6142
+
6143
+ const TwoColumnContainer = React.memo(({ elementConfig, type, renderElement }) => {
6144
+ const getRenderContainerItem = useRenderContainerItem(type, renderElement);
6145
+ const { options } = elementConfig || {};
6146
+ const { attributes: renderAttributes, innerTemplateStyle } = options || {};
6147
+ const renderContainer = React.useCallback((attribute) => {
6148
+ const { id, value, hideEmpty, style, hasIcon, hasUnits, render } = getRenderContainerItem(elementConfig, attribute);
6126
6149
  if (!value && hideEmpty)
6127
6150
  return null;
6128
6151
  return (jsxRuntime.jsxs(TwoColumnContainerWrapper, { id: id, style: innerTemplateStyle || style, children: [jsxRuntime.jsxs(ContainerAlias, { children: [hasIcon && jsxRuntime.jsx(ContainerAliasIcon, { children: render({ id: "icon" }) }), render({ id: "alias" }), render({ id: "tooltip" })] }), jsxRuntime.jsxs(ContainerValue, { big: true, children: [value, hasUnits && jsxRuntime.jsx(ContainerUnits, { children: render({ id: "units" }) })] })] }, attribute));
6129
- }, [attributes, config, getRenderElement, layerInfo, renderElement, selectedTabId, type, elementConfig]);
6152
+ }, [getRenderContainerItem, elementConfig]);
6130
6153
  return renderAttributes?.length ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderAttributes.map(attribute => renderContainer(attribute)) })) : (renderContainer());
6131
6154
  });
6132
6155
 
@@ -7681,9 +7704,9 @@ var img$1 = "data:image/svg+xml,%3csvg width='32' height='32' viewBox='0 0 32 32
7681
7704
 
7682
7705
  var img = "data:image/svg+xml,%3csvg width='32' height='32' viewBox='0 0 32 32' fill='none' xmlns='http://www.w3.org/2000/svg'%3e %3crect width='32' height='32' fill='transparent'/%3e %3crect x='8' y='8' width='16' height='16' rx='2' fill='url(%23paint0_linear_6459_10399)'/%3e %3cdefs%3e %3clinearGradient id='paint0_linear_6459_10399' x1='8' y1='8' x2='24' y2='24' gradientUnits='userSpaceOnUse'%3e %3cstop stop-color='%230084D6'/%3e %3cstop offset='0.489583' stop-color='%230084D6'/%3e %3cstop offset='0.489683' stop-color='%2305A9FF'/%3e %3cstop offset='0.921875' stop-color='%2305A9FF'/%3e %3c/linearGradient%3e %3c/defs%3e%3c/svg%3e";
7683
7706
 
7684
- const LayerIcon = ({ layerInfo }) => {
7707
+ const LayerIcon = ({ layerInfo, error }) => {
7685
7708
  const renderSymbol = React.useMemo(() => {
7686
- if (!layerInfo.geometryType) {
7709
+ if (!layerInfo.geometryType || error) {
7687
7710
  return (jsxRuntime.jsx(AlertIconContainer, { children: jsxRuntime.jsx(uilibGl.Icon, { kind: "warning" }) }));
7688
7711
  }
7689
7712
  switch (layerInfo.geometryType) {
@@ -10763,6 +10786,75 @@ const useUpdateDataSource = ({ dataSource, config, filters, attributes, layerPar
10763
10786
  }, [dataSource, getDataSourcePromises, getUpdatedDataSources, dataSources]);
10764
10787
  };
10765
10788
 
10789
+ const useMultipleAttributesRender = (config, elementConfig, type, renderElement) => {
10790
+ const { selectedTabId, layerInfo, attributes } = useWidgetContext(type);
10791
+ const { attributes: renderAttributes, attributesExclude } = elementConfig?.options || {};
10792
+ const getAttributesToRender = React.useCallback(() => {
10793
+ if (renderAttributes) {
10794
+ return renderAttributes;
10795
+ }
10796
+ if (attributesExclude) {
10797
+ const allAttributes = attributes?.map(attr => attr.name) || [];
10798
+ return allAttributes.filter(attr => !attributesExclude.includes(attr));
10799
+ }
10800
+ return null;
10801
+ }, [renderAttributes, attributesExclude, attributes]);
10802
+ const renderContainer = React.useCallback((attribute) => {
10803
+ const { id, options, style, children } = elementConfig || {};
10804
+ const { hideEmpty, innerTemplateStyle } = options || {};
10805
+ const hasUnits = children?.some(({ id }) => id === "units");
10806
+ const iconIndex = children?.findIndex(({ id }) => id === "icon");
10807
+ const icon = children?.[iconIndex];
10808
+ const hasIcon = !!icon;
10809
+ const elementChildren = elementConfig?.children?.map(child => ({
10810
+ type: "attributeValue",
10811
+ ...child,
10812
+ attributeName: attribute,
10813
+ options: { noUnits: hasUnits, ...child.options },
10814
+ }));
10815
+ const attr = attribute
10816
+ ? layerInfo?.layerAttributes?.find(({ attributeName }) => attributeName === attribute)
10817
+ : null;
10818
+ if (hasIcon) {
10819
+ elementChildren[iconIndex] = {
10820
+ ...elementChildren[iconIndex],
10821
+ type: attr?.icon?.type?.toLowerCase(),
10822
+ value: attr?.icon?.resourceId || attr?.icon?.url || attr?.icon?.iconName,
10823
+ attributeName: null,
10824
+ };
10825
+ }
10826
+ const render = attribute
10827
+ ? getRenderElement({
10828
+ config,
10829
+ elementConfig: {
10830
+ ...elementConfig,
10831
+ children: elementChildren,
10832
+ },
10833
+ selectedTabId,
10834
+ attributes,
10835
+ layerInfo,
10836
+ type,
10837
+ })
10838
+ : renderElement;
10839
+ const value = render({ id: "value" });
10840
+ if (!value && hideEmpty)
10841
+ return null;
10842
+ return {
10843
+ render,
10844
+ value,
10845
+ hasUnits,
10846
+ id,
10847
+ style: innerTemplateStyle || style,
10848
+ hasIcon,
10849
+ attr,
10850
+ };
10851
+ }, [attributes, config, getRenderElement, layerInfo, renderElement, selectedTabId, type, elementConfig]);
10852
+ return {
10853
+ getAttributesToRender,
10854
+ renderContainer,
10855
+ };
10856
+ };
10857
+
10766
10858
  const StackBar = ({ data, filterName, type, alias, options, renderElement, renderTooltip }) => {
10767
10859
  const { height, showTotal, cornerRadius, groupTooltip } = options || {};
10768
10860
  const { t } = useGlobalContext();
@@ -11898,6 +11990,7 @@ exports.useLayerParams = useLayerParams;
11898
11990
  exports.useMapContext = useMapContext;
11899
11991
  exports.useMapDraw = useMapDraw;
11900
11992
  exports.useMapImages = useMapImages;
11993
+ exports.useMultipleAttributesRender = useMultipleAttributesRender;
11901
11994
  exports.useProjectDashboardInit = useProjectDashboardInit;
11902
11995
  exports.usePythonTask = usePythonTask;
11903
11996
  exports.useRedrawLayer = useRedrawLayer;