@evergis/react 3.1.57 → 3.1.58

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.
@@ -1,5 +1,6 @@
1
- import { ConfigContainerChild, ContainerProps } from '../../types';
1
+ import { ConfigContainerChild, ContainerProps, WidgetType } from '../../types';
2
2
  export type ContainerChildrenProps = {
3
+ type: WidgetType;
3
4
  items: ConfigContainerChild[];
4
5
  elementConfig?: ConfigContainerChild;
5
6
  isColumn?: boolean;
@@ -9,6 +9,7 @@ export * from './useWidgetFilters';
9
9
  export * from './useGetConfigLayer';
10
10
  export * from './useGlobalContext';
11
11
  export * from './useHeaderRender';
12
+ export * from './useHideIfEmptyDataSource';
12
13
  export * from './useProjectDashboardInit';
13
14
  export * from './useRelatedDataSourceAttributes';
14
15
  export * from './useRenderElement';
@@ -0,0 +1,2 @@
1
+ import { WidgetType } from '../types';
2
+ export declare const useHideIfEmptyDataSource: (type?: WidgetType) => (dataSourceName: string) => boolean;
@@ -118,6 +118,7 @@ export interface ConfigOptions {
118
118
  bigIcon?: boolean;
119
119
  onlyIcon?: boolean;
120
120
  hideEmpty?: boolean;
121
+ hideIfEmptyDataSource?: string;
121
122
  innerValue?: boolean;
122
123
  groupTooltip?: boolean;
123
124
  tabId?: string;
package/dist/index.js CHANGED
@@ -5417,7 +5417,7 @@ const ContainersGroupContainer = React.memo(({ elementConfig, type, renderElemen
5417
5417
  const { column, expandable, expanded } = options || {};
5418
5418
  const isColumn = column === undefined || column;
5419
5419
  const isVisible = isVisibleContainer(id, expandable, expanded, expandedContainers);
5420
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(ExpandableTitle, { elementConfig: elementConfig, type: type, renderElement: renderElement }), isVisible && (jsxRuntime.jsx(Container, { id: id, isColumn: isColumn, children: jsxRuntime.jsx(ContainerChildren, { items: children, elementConfig: elementConfig, isColumn: isColumn, isMain: id?.startsWith(CONFIG_PAGE_ID), renderElement: renderElement }) }))] }));
5420
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(ExpandableTitle, { elementConfig: elementConfig, type: type, renderElement: renderElement }), isVisible && (jsxRuntime.jsx(Container, { id: id, isColumn: isColumn, children: jsxRuntime.jsx(ContainerChildren, { type: type, items: children, elementConfig: elementConfig, isColumn: isColumn, isMain: id?.startsWith(CONFIG_PAGE_ID), renderElement: renderElement }) }))] }));
5421
5421
  });
5422
5422
 
5423
5423
  const ChartLegendContainer = styled(uilibGl.Flex) `
@@ -6122,7 +6122,7 @@ const PagesContainer = React.memo(({ type = exports.WidgetType.Dashboard, noBord
6122
6122
  setSelectedTabId,
6123
6123
  type,
6124
6124
  ]);
6125
- return (jsxRuntime.jsx(Container, { id: getRootElementId(type), style: { width }, isMain: true, isColumn: isColumn, noBorders: noBorders, children: jsxRuntime.jsx(ContainerChildren, { items: filteredChildren, isMain: true, renderElement: renderElement }) }));
6125
+ 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 }) }));
6126
6126
  });
6127
6127
 
6128
6128
  const ImageContainerBg$1 = styled.div `
@@ -8257,7 +8257,7 @@ const getElementValue = ({ getDefaultContainer, ...props }) => {
8257
8257
  return attribute?.name ? layerInfo.layerDefinition.attributes[attribute.name]?.description || null : null;
8258
8258
  }
8259
8259
  const ElementComponent = type ? elementComponents[type] : null;
8260
- return ElementComponent ? jsxRuntime.jsx(ElementComponent, { ...props }) : getDefaultContainer();
8260
+ return ElementComponent ? jsxRuntime.jsx(ElementComponent, { ...props }) : getDefaultContainer?.();
8261
8261
  };
8262
8262
 
8263
8263
  const getLayerAttributes = (layerDefinition) => {
@@ -9965,6 +9965,15 @@ const useGetConfigLayer = () => {
9965
9965
  return React.useCallback((layerName) => currentPage?.layers?.find(({ name }) => name === layerName), [currentPage?.layers]);
9966
9966
  };
9967
9967
 
9968
+ const useHideIfEmptyDataSource = (type = exports.WidgetType.Dashboard) => {
9969
+ const { dataSources } = useWidgetContext(type);
9970
+ return React.useCallback((dataSourceName) => {
9971
+ if (!dataSourceName)
9972
+ return false;
9973
+ return !getDataSource(dataSourceName, dataSources)?.features?.length;
9974
+ }, [dataSources]);
9975
+ };
9976
+
9968
9977
  const useProjectDashboardInit = () => {
9969
9978
  const { projectInfo, updateProject } = useWidgetContext();
9970
9979
  return React.useCallback(() => {
@@ -10272,7 +10281,8 @@ const ChartLegend = ({ data, chartElement, fontSize, type, twoColumns, loading }
10272
10281
  return (jsxRuntime.jsxs(uilibGl.Flex, { flexDirection: "column", opacity: loading ? FILTERED_VALUE_OPACITY / 100 : 1, children: [jsxRuntime.jsx(ChartLegendContainer, { twoColumns: twoColumns, children: sliceItems(data)?.map(({ name, color }, index) => (jsxRuntime.jsxs(ChartLegendItem, { hasAnyFilter: hasAnyFilter, isFiltered: isFiltered(name), onClick: axes?.[0]?.filterName ? () => onFilter(name) : undefined, children: [jsxRuntime.jsx(ChartLegendColor, { color: color }), jsxRuntime.jsx(ChartLegendName, { "$fontSize": fontSize, "$fontColor": fontColor, children: name })] }, index))) }), showMoreBtn && (jsxRuntime.jsx(uilibGl.LegendToggler, { onClick: onShowMore, toggled: showMore, children: t("other", { ns: "dashboard", defaultValue: "Другое" }) }))] }));
10273
10282
  };
10274
10283
 
10275
- const ContainerChildren = React.memo(({ items, isColumn, isMain, renderElement }) => {
10284
+ const ContainerChildren = React.memo(({ type, items, isColumn, isMain, renderElement }) => {
10285
+ const checkIfEmptyDataSource = useHideIfEmptyDataSource(type);
10276
10286
  return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: items
10277
10287
  ?.filter(item => !["title", "icon", "titleIcon"].includes(item.id))
10278
10288
  ?.map((item, index) => {
@@ -10281,6 +10291,8 @@ const ContainerChildren = React.memo(({ items, isColumn, isMain, renderElement }
10281
10291
  index,
10282
10292
  wrap: isColumn || isMain,
10283
10293
  });
10294
+ if (checkIfEmptyDataSource(item.options?.hideIfEmptyDataSource))
10295
+ return null;
10284
10296
  return isMain ? (jsxRuntime.jsx(ContainerWrapper, { "data-id": item.id, "data-templatename": item.templateName, "$noMargin": item.options?.noMargin, children: jsxRuntime.jsx(DashboardWrapper, { children: render }) }, index)) : (jsxRuntime.jsx(React.Fragment, { children: render }, index));
10285
10297
  }) }));
10286
10298
  });
@@ -11021,6 +11033,7 @@ exports.useExportPdf = useExportPdf;
11021
11033
  exports.useGetConfigLayer = useGetConfigLayer;
11022
11034
  exports.useGlobalContext = useGlobalContext;
11023
11035
  exports.useHeaderRender = useHeaderRender;
11036
+ exports.useHideIfEmptyDataSource = useHideIfEmptyDataSource;
11024
11037
  exports.useLayerParams = useLayerParams;
11025
11038
  exports.useMapContext = useMapContext;
11026
11039
  exports.useMapDraw = useMapDraw;