@evergis/react 3.1.110 → 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.
@@ -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
+ };
@@ -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,40 +6072,85 @@ const TwoColumnContainerWrapper = styled(uilibGl.Flex) `
6072
6072
  }
6073
6073
  `;
6074
6074
 
6075
+ const useRenderContainerItem = (type, renderElement) => {
6076
+ const { config, layerInfo, selectedTabId, attributes } = useWidgetContext(type);
6077
+ return React.useCallback((elementConfig, attribute) => {
6078
+ const { id, options, style, children } = elementConfig || {};
6079
+ const { hideEmpty, innerTemplateStyle } = options || {};
6080
+ const hasUnits = children?.some(({ id }) => id === "units");
6081
+ const iconIndex = children?.findIndex(({ id }) => id === "icon");
6082
+ const icon = children?.[iconIndex];
6083
+ const hasIcon = !!icon;
6084
+ const elementChildren = elementConfig?.children?.map(child => ({
6085
+ type: "attributeValue",
6086
+ ...child,
6087
+ attributeName: attribute,
6088
+ options: { noUnits: hasUnits, ...child.options },
6089
+ }));
6090
+ const attr = attribute
6091
+ ? layerInfo?.layerAttributes?.find(({ attributeName }) => attributeName === attribute)
6092
+ : null;
6093
+ if (hasIcon) {
6094
+ elementChildren[iconIndex] = {
6095
+ ...elementChildren[iconIndex],
6096
+ type: attr?.icon?.type?.toLowerCase(),
6097
+ value: attr?.icon?.resourceId || attr?.icon?.url || attr?.icon?.iconName,
6098
+ attributeName: null,
6099
+ };
6100
+ }
6101
+ const render = attribute
6102
+ ? getRenderElement({
6103
+ config,
6104
+ elementConfig: {
6105
+ ...elementConfig,
6106
+ children: elementChildren,
6107
+ },
6108
+ selectedTabId,
6109
+ attributes,
6110
+ layerInfo,
6111
+ type,
6112
+ })
6113
+ : renderElement;
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
+
6075
6127
  const BASE_STYLE = {
6076
6128
  marginBottom: "1rem",
6077
6129
  };
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");
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);
6086
6136
  if (!value && hideEmpty)
6087
6137
  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
- }) }));
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());
6097
6141
  });
6098
6142
 
6099
- const TwoColumnContainer = React.memo(({ config, elementConfig, type, renderElement }) => {
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
- }) }));
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);
6149
+ if (!value && hideEmpty)
6150
+ return null;
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));
6152
+ }, [getRenderContainerItem, elementConfig]);
6153
+ return renderAttributes?.length ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderAttributes.map(attribute => renderContainer(attribute)) })) : (renderContainer());
6109
6154
  });
6110
6155
 
6111
6156
  const InnerContainerWrapper = styled.div `
@@ -6612,7 +6657,6 @@ const PagesContainer = React.memo(({ type = exports.WidgetType.Dashboard, noBord
6612
6657
  setSelectedTabId,
6613
6658
  type,
6614
6659
  ]);
6615
- console.info("PagesContainer", config, filteredChildren);
6616
6660
  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 }) }));
6617
6661
  });
6618
6662
 
@@ -7660,9 +7704,9 @@ var img$1 = "data:image/svg+xml,%3csvg width='32' height='32' viewBox='0 0 32 32
7660
7704
 
7661
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";
7662
7706
 
7663
- const LayerIcon = ({ layerInfo }) => {
7707
+ const LayerIcon = ({ layerInfo, error }) => {
7664
7708
  const renderSymbol = React.useMemo(() => {
7665
- if (!layerInfo.geometryType) {
7709
+ if (!layerInfo.geometryType || error) {
7666
7710
  return (jsxRuntime.jsx(AlertIconContainer, { children: jsxRuntime.jsx(uilibGl.Icon, { kind: "warning" }) }));
7667
7711
  }
7668
7712
  switch (layerInfo.geometryType) {
@@ -10746,14 +10790,14 @@ const useMultipleAttributesRender = (config, elementConfig, type, renderElement)
10746
10790
  const { selectedTabId, layerInfo, attributes } = useWidgetContext(type);
10747
10791
  const { attributes: renderAttributes, attributesExclude } = elementConfig?.options || {};
10748
10792
  const getAttributesToRender = React.useCallback(() => {
10749
- if (renderAttributes && renderAttributes.length > 0) {
10793
+ if (renderAttributes) {
10750
10794
  return renderAttributes;
10751
10795
  }
10752
- const allAttributes = attributes?.map(attr => attr.name) || [];
10753
- if (attributesExclude && attributesExclude.length > 0) {
10796
+ if (attributesExclude) {
10797
+ const allAttributes = attributes?.map(attr => attr.name) || [];
10754
10798
  return allAttributes.filter(attr => !attributesExclude.includes(attr));
10755
10799
  }
10756
- return allAttributes;
10800
+ return null;
10757
10801
  }, [renderAttributes, attributesExclude, attributes]);
10758
10802
  const renderContainer = React.useCallback((attribute) => {
10759
10803
  const { id, options, style, children } = elementConfig || {};