@evergis/react 3.1.109 → 3.1.110

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
+ };
@@ -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;
package/dist/index.js CHANGED
@@ -6072,62 +6072,40 @@ 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" }) })] })] }));
6075
+ const BASE_STYLE = {
6076
+ marginBottom: "1rem",
6077
+ };
6078
+ const OneColumnContainer = React.memo(({ config, elementConfig, type, renderElement }) => {
6079
+ const { getAttributesToRender, renderContainer } = useMultipleAttributesRender(config, elementConfig, type, renderElement);
6080
+ const attributesToRender = getAttributesToRender();
6081
+ if (!attributesToRender.length) {
6082
+ const { id, options, style } = elementConfig || {};
6083
+ const { innerTemplateStyle, hideEmpty } = options || {};
6084
+ const value = renderElement({ id: "value" });
6085
+ const hasUnits = elementConfig?.children?.some(({ id }) => id === "units");
6086
+ if (!value && hideEmpty)
6087
+ return null;
6088
+ return (jsxRuntime.jsxs(Container, { id: id, isColumn: true, style: { ...BASE_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" }) })] })] }));
6089
+ }
6090
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: attributesToRender.map(attribute => {
6091
+ const containerData = renderContainer(attribute);
6092
+ if (!containerData)
6093
+ return null;
6094
+ const { render, hasUnits, id, style } = containerData;
6095
+ return (jsxRuntime.jsxs(Container, { id: id, isColumn: true, style: { ...BASE_STYLE, ...(elementConfig?.options?.innerTemplateStyle || style) }, children: [jsxRuntime.jsxs(ContainerAlias, { hasBottomMargin: true, children: [render({ id: "alias" }), render({ id: "tooltip" })] }), jsxRuntime.jsxs(ContainerValue, { children: [render({ id: "value" }), hasUnits && jsxRuntime.jsx(ContainerUnits, { children: render({ id: "units" }) })] })] }, attribute));
6096
+ }) }));
6083
6097
  });
6084
6098
 
6085
6099
  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) => {
6089
- const { id, options, style, children } = elementConfig || {};
6090
- const { hideEmpty, innerTemplateStyle } = options || {};
6091
- const hasUnits = children?.some(({ id }) => id === "units");
6092
- const iconIndex = children?.findIndex(({ id }) => id === "icon");
6093
- const icon = children?.[iconIndex];
6094
- const hasIcon = !!icon;
6095
- const elementChildren = elementConfig?.children?.map(child => ({
6096
- type: "attributeValue",
6097
- ...child,
6098
- attributeName: attribute,
6099
- options: { noUnits: hasUnits, ...child.options },
6100
- }));
6101
- const attr = attribute
6102
- ? layerInfo?.layerAttributes?.find(({ attributeName }) => attributeName === attribute)
6103
- : null;
6104
- if (hasIcon) {
6105
- elementChildren[iconIndex] = {
6106
- ...elementChildren[iconIndex],
6107
- type: attr?.icon?.type?.toLowerCase(),
6108
- value: attr?.icon?.resourceId || attr?.icon?.url || attr?.icon?.iconName,
6109
- attributeName: null,
6110
- };
6111
- }
6112
- const render = attribute
6113
- ? getRenderElement({
6114
- config,
6115
- elementConfig: {
6116
- ...elementConfig,
6117
- children: elementChildren,
6118
- },
6119
- selectedTabId,
6120
- attributes,
6121
- layerInfo,
6122
- type,
6123
- })
6124
- : renderElement;
6125
- const value = render({ id: "value" });
6126
- if (!value && hideEmpty)
6127
- return null;
6128
- 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]);
6130
- return renderAttributes?.length ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderAttributes.map(attribute => renderContainer(attribute)) })) : (renderContainer());
6100
+ const { getAttributesToRender, renderContainer } = useMultipleAttributesRender(config, elementConfig, type, renderElement);
6101
+ const attributesToRender = getAttributesToRender();
6102
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: attributesToRender.map(attribute => {
6103
+ const containerData = renderContainer(attribute);
6104
+ if (!containerData)
6105
+ return null;
6106
+ const { render, hasUnits, id, style, hasIcon } = containerData;
6107
+ return (jsxRuntime.jsxs(TwoColumnContainerWrapper, { id: id, style: 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: [render({ id: "value" }), hasUnits && jsxRuntime.jsx(ContainerUnits, { children: render({ id: "units" }) })] })] }, attribute));
6108
+ }) }));
6131
6109
  });
6132
6110
 
6133
6111
  const InnerContainerWrapper = styled.div `
@@ -6634,6 +6612,7 @@ const PagesContainer = React.memo(({ type = exports.WidgetType.Dashboard, noBord
6634
6612
  setSelectedTabId,
6635
6613
  type,
6636
6614
  ]);
6615
+ console.info("PagesContainer", config, filteredChildren);
6637
6616
  return (jsxRuntime.jsx(Container, { id: getRootElementId(type), style: { width }, isMain: true, isColumn: isColumn, noBorders: noBorders, children: jsxRuntime.jsx(ContainerChildren, { type: type, items: filteredChildren, isMain: true, renderElement: renderElement }) }));
6638
6617
  });
6639
6618
 
@@ -10763,6 +10742,75 @@ const useUpdateDataSource = ({ dataSource, config, filters, attributes, layerPar
10763
10742
  }, [dataSource, getDataSourcePromises, getUpdatedDataSources, dataSources]);
10764
10743
  };
10765
10744
 
10745
+ const useMultipleAttributesRender = (config, elementConfig, type, renderElement) => {
10746
+ const { selectedTabId, layerInfo, attributes } = useWidgetContext(type);
10747
+ const { attributes: renderAttributes, attributesExclude } = elementConfig?.options || {};
10748
+ const getAttributesToRender = React.useCallback(() => {
10749
+ if (renderAttributes && renderAttributes.length > 0) {
10750
+ return renderAttributes;
10751
+ }
10752
+ const allAttributes = attributes?.map(attr => attr.name) || [];
10753
+ if (attributesExclude && attributesExclude.length > 0) {
10754
+ return allAttributes.filter(attr => !attributesExclude.includes(attr));
10755
+ }
10756
+ return allAttributes;
10757
+ }, [renderAttributes, attributesExclude, attributes]);
10758
+ const renderContainer = React.useCallback((attribute) => {
10759
+ const { id, options, style, children } = elementConfig || {};
10760
+ const { hideEmpty, innerTemplateStyle } = options || {};
10761
+ const hasUnits = children?.some(({ id }) => id === "units");
10762
+ const iconIndex = children?.findIndex(({ id }) => id === "icon");
10763
+ const icon = children?.[iconIndex];
10764
+ const hasIcon = !!icon;
10765
+ const elementChildren = elementConfig?.children?.map(child => ({
10766
+ type: "attributeValue",
10767
+ ...child,
10768
+ attributeName: attribute,
10769
+ options: { noUnits: hasUnits, ...child.options },
10770
+ }));
10771
+ const attr = attribute
10772
+ ? layerInfo?.layerAttributes?.find(({ attributeName }) => attributeName === attribute)
10773
+ : null;
10774
+ if (hasIcon) {
10775
+ elementChildren[iconIndex] = {
10776
+ ...elementChildren[iconIndex],
10777
+ type: attr?.icon?.type?.toLowerCase(),
10778
+ value: attr?.icon?.resourceId || attr?.icon?.url || attr?.icon?.iconName,
10779
+ attributeName: null,
10780
+ };
10781
+ }
10782
+ const render = attribute
10783
+ ? getRenderElement({
10784
+ config,
10785
+ elementConfig: {
10786
+ ...elementConfig,
10787
+ children: elementChildren,
10788
+ },
10789
+ selectedTabId,
10790
+ attributes,
10791
+ layerInfo,
10792
+ type,
10793
+ })
10794
+ : renderElement;
10795
+ const value = render({ id: "value" });
10796
+ if (!value && hideEmpty)
10797
+ return null;
10798
+ return {
10799
+ render,
10800
+ value,
10801
+ hasUnits,
10802
+ id,
10803
+ style: innerTemplateStyle || style,
10804
+ hasIcon,
10805
+ attr,
10806
+ };
10807
+ }, [attributes, config, getRenderElement, layerInfo, renderElement, selectedTabId, type, elementConfig]);
10808
+ return {
10809
+ getAttributesToRender,
10810
+ renderContainer,
10811
+ };
10812
+ };
10813
+
10766
10814
  const StackBar = ({ data, filterName, type, alias, options, renderElement, renderTooltip }) => {
10767
10815
  const { height, showTotal, cornerRadius, groupTooltip } = options || {};
10768
10816
  const { t } = useGlobalContext();
@@ -11898,6 +11946,7 @@ exports.useLayerParams = useLayerParams;
11898
11946
  exports.useMapContext = useMapContext;
11899
11947
  exports.useMapDraw = useMapDraw;
11900
11948
  exports.useMapImages = useMapImages;
11949
+ exports.useMultipleAttributesRender = useMultipleAttributesRender;
11901
11950
  exports.useProjectDashboardInit = useProjectDashboardInit;
11902
11951
  exports.usePythonTask = usePythonTask;
11903
11952
  exports.useRedrawLayer = useRedrawLayer;