@evergis/react 3.1.56 → 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;
@@ -1,3 +1,8 @@
1
- export declare const LayersContainerWrapper: import('styled-components').StyledComponent<any, any, {
1
+ export declare const LayersContainerWrapper: import('styled-components').StyledComponent<"div", any, import('@evergis/uilib-gl').FlexProps & {
2
+ isTitle?: boolean;
3
+ isColumn?: boolean;
4
+ isMain?: boolean;
5
+ noBorders?: boolean;
6
+ } & {
2
7
  isPresentationMode?: boolean;
3
- }, string | number | symbol>;
8
+ }, never>;
@@ -1 +1,6 @@
1
- export declare const UploaderContainer: import('styled-components').StyledComponent<any, any, object, string | number | symbol>;
1
+ export declare const UploaderContainer: import('styled-components').StyledComponent<"div", any, import('@evergis/uilib-gl').FlexProps & {
2
+ isTitle?: boolean;
3
+ isColumn?: boolean;
4
+ isMain?: boolean;
5
+ noBorders?: boolean;
6
+ }, never>;
@@ -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;
@@ -1,5 +1,17 @@
1
- export declare const Container: any;
2
- export declare const ContainerWrapper: any;
1
+ import { CSSProperties } from 'react';
2
+ export declare const ElementValueWrapper: import('styled-components').StyledComponent<"div", any, {
3
+ noMargin?: boolean;
4
+ }, never>;
5
+ export declare const Container: import('styled-components').StyledComponent<"div", any, import('@evergis/uilib-gl').FlexProps & {
6
+ isTitle?: boolean;
7
+ isColumn?: boolean;
8
+ isMain?: boolean;
9
+ noBorders?: boolean;
10
+ }, never>;
11
+ export declare const ContainerWrapper: import('styled-components').StyledComponent<"div", any, import('@evergis/uilib-gl').FlexProps & {
12
+ $zIndex?: CSSProperties["zIndex"];
13
+ $noMargin?: boolean;
14
+ }, never>;
3
15
  export declare const DashboardChip: import('styled-components').StyledComponent<any, any, any, any>;
4
16
  export declare const DashboardPlaceholderWrap: import('styled-components').StyledComponent<"div", any, import('@evergis/uilib-gl').FlexProps, never>;
5
17
  export declare const DashboardPlaceholder: import('styled-components').StyledComponent<"div", any, import('@evergis/uilib-gl').FlexProps & {
@@ -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
@@ -4507,75 +4507,6 @@ const DashboardChip$1 = styled(uilibGl.Chip) `
4507
4507
  ${({ $fontColor, $isDefault }) => !!$fontColor && !$isDefault && CustomChipColorMixin}
4508
4508
  `;
4509
4509
 
4510
- const getAttributeByName = (attributeName, attributes) => {
4511
- return Array.isArray(attributeName)
4512
- ? null
4513
- : attributeName
4514
- ? attributes?.find(({ name }) => name === attributeName)
4515
- : null;
4516
- };
4517
-
4518
- const formatElementValue = ({ t, value, elementConfig, attributes, wrap, }) => {
4519
- const { id, type, defaultValue, options, style, attributeName, templateName } = elementConfig || {};
4520
- const attribute = attributeName ? getAttributeByName(attributeName, attributes) : null;
4521
- const { fontColor, fontSize, noUnits, tagView, bgColor, withDivider, radius } = options || {};
4522
- const valueOrDefault = value || defaultValue;
4523
- const resultValue = type === "attributeValue" && attribute?.type && attribute?.stringFormat
4524
- ? formatAttributeValue({
4525
- t,
4526
- type: attribute.type,
4527
- value: valueOrDefault,
4528
- stringFormat: attribute.stringFormat,
4529
- noUnits,
4530
- })
4531
- : valueOrDefault;
4532
- if (!wrap)
4533
- return resultValue;
4534
- return (jsxRuntime.jsxs(React.Fragment, { children: [tagView ? (jsxRuntime.jsx(DashboardChip$1, { text: resultValue, "$bgColor": bgColor, "$fontColor": fontColor, "$fontSize": fontSize, "$radius": radius, style: style })) : resultValue, withDivider && jsxRuntime.jsx(uilibGl.Divider, {})] }, id));
4535
- };
4536
-
4537
- const getAttributeValue = (element, attributes) => {
4538
- const attribute = getAttributeByName(element?.attributeName, attributes);
4539
- const { maxLength, separator, expandable, lineBreak } = element.options || {};
4540
- let value = "";
4541
- if (attribute?.type === api.AttributeType.Boolean && typeof attribute.value === "boolean") {
4542
- return jsxRuntime.jsx(DashboardCheckbox, { title: attribute.alias || attribute.name, checked: attribute.value });
4543
- }
4544
- if (Array.isArray(element?.attributeName)) {
4545
- const concatAttributes = element.attributeName.map((attributeName) => attributes?.find(({ name }) => name === attributeName)?.value || "");
4546
- value = concatAttributes.join(separator || ", ");
4547
- }
4548
- else {
4549
- value = attribute?.value?.toString() || "";
4550
- }
4551
- return maxLength && maxLength < value.length ? (jsxRuntime.jsx(TextTrim, { maxLength: maxLength, expandable: expandable, lineBreak: lineBreak, children: value })) : (value);
4552
- };
4553
-
4554
- const getChartAxes = (chartElement) => chartElement?.options?.relatedDataSources?.filter(({ chartAxis }) => chartAxis === "y");
4555
-
4556
- const getChartFilterName = (relatedDataSources) => {
4557
- const relatedAttributes = relatedDataSources || [];
4558
- const axes = relatedAttributes.filter(({ chartAxis }) => chartAxis === "y");
4559
- return axes?.[0]?.filterName;
4560
- };
4561
-
4562
- function getValueIndex(items, attributes) {
4563
- return items?.findIndex(({ name }) => name.toString() === attributes.value?.toString());
4564
- }
4565
- const getChartMarkers = (items, markers, dataSources) => {
4566
- if (typeof markers === "string") {
4567
- const dataSource = getDataSource(markers, dataSources);
4568
- return dataSource?.features?.map(({ attributes }) => ({
4569
- ...attributes,
4570
- value: getValueIndex(items, attributes),
4571
- })) || [];
4572
- }
4573
- return (markers?.map(marker => ({
4574
- ...marker,
4575
- value: getValueIndex(items, marker),
4576
- })) || []);
4577
- };
4578
-
4579
4510
  const LayerGroupContainer = styled(uilibGl.Flex) `
4580
4511
  display: flex;
4581
4512
  justify-content: center;
@@ -5104,21 +5035,34 @@ const LayerListContainer = styled(uilibGl.Flex) `
5104
5035
  box-sizing: border-box;
5105
5036
  `;
5106
5037
 
5038
+ const ElementValueWrapper = styled.div `
5039
+ transition: background-color ${uilibGl.transition.toggle};
5040
+
5041
+ ${({ noMargin }) => styled.css `
5042
+ &&&& {
5043
+ margin-bottom: 0;
5044
+ }
5045
+ `};
5046
+ `;
5107
5047
  const Container = styled(uilibGl.Flex) `
5108
5048
  flex-direction: column;
5109
5049
  width: 100%;
5110
-
5050
+
5111
5051
  ${({ isColumn }) => isColumn
5112
5052
  ? styled.css `
5113
- > * {
5114
- width: 100%;
5053
+ > * {
5054
+ width: 100%;
5055
+
5056
+ :not(:last-child) {
5057
+ margin-bottom: 1.5rem;
5115
5058
  }
5116
- `
5059
+ }
5060
+ `
5117
5061
  : styled.css `
5118
- flex-direction: row;
5119
- justify-content: space-between;
5120
- align-items: center;
5121
- `}
5062
+ flex-direction: row;
5063
+ justify-content: space-between;
5064
+ align-items: center;
5065
+ `}
5122
5066
 
5123
5067
  ${({ isTitle }) => isTitle &&
5124
5068
  styled.css `
@@ -5147,10 +5091,6 @@ const ContainerWrapper = styled(uilibGl.Flex) `
5147
5091
  color: ${({ theme: { palette } }) => palette.textPrimary};
5148
5092
  z-index: ${({ $zIndex }) => $zIndex ?? 1};
5149
5093
  transition: background-color ${uilibGl.transition.toggle};
5150
-
5151
- ${Container} > :not(:last-child) {
5152
- margin-bottom: 1.5rem;
5153
- }
5154
5094
 
5155
5095
  ${({ $noMargin }) => $noMargin && styled.css `
5156
5096
  &&&& {
@@ -5192,6 +5132,7 @@ const DashboardPlaceholder = styled(uilibGl.Flex) `
5192
5132
  styled.css `
5193
5133
  width: 6.25rem;
5194
5134
  `}
5135
+
5195
5136
  &&& > * {
5196
5137
  margin-bottom: 0;
5197
5138
  }
@@ -5401,13 +5342,82 @@ const FeatureControls = styled(uilibGl.Flex) `
5401
5342
  }
5402
5343
  `;
5403
5344
 
5345
+ const getAttributeByName = (attributeName, attributes) => {
5346
+ return Array.isArray(attributeName)
5347
+ ? null
5348
+ : attributeName
5349
+ ? attributes?.find(({ name }) => name === attributeName)
5350
+ : null;
5351
+ };
5352
+
5353
+ const formatElementValue = ({ t, value, elementConfig, attributes, wrap, }) => {
5354
+ const { id, type, defaultValue, options, style, attributeName, templateName } = elementConfig || {};
5355
+ const attribute = attributeName ? getAttributeByName(attributeName, attributes) : null;
5356
+ const { fontColor, fontSize, noUnits, tagView, bgColor, withDivider, radius, noMargin } = options || {};
5357
+ const valueOrDefault = value || defaultValue;
5358
+ const resultValue = type === "attributeValue" && attribute?.type && attribute?.stringFormat
5359
+ ? formatAttributeValue({
5360
+ t,
5361
+ type: attribute.type,
5362
+ value: valueOrDefault,
5363
+ stringFormat: attribute.stringFormat,
5364
+ noUnits,
5365
+ })
5366
+ : valueOrDefault;
5367
+ if (!wrap)
5368
+ return resultValue;
5369
+ return (jsxRuntime.jsxs(React.Fragment, { children: [tagView ? (jsxRuntime.jsx(DashboardChip$1, { "data-id": id, "data-templatename": templateName, style: style, text: resultValue, "$bgColor": bgColor, "$fontColor": fontColor, "$fontSize": fontSize, "$radius": radius })) : (jsxRuntime.jsx(ElementValueWrapper, { "data-id": id, "data-templatename": templateName, style: style, noMargin: noMargin, children: resultValue })), withDivider && jsxRuntime.jsx(uilibGl.Divider, {})] }, id));
5370
+ };
5371
+
5372
+ const getAttributeValue = (element, attributes) => {
5373
+ const attribute = getAttributeByName(element?.attributeName, attributes);
5374
+ const { maxLength, separator, expandable, lineBreak } = element.options || {};
5375
+ let value = "";
5376
+ if (attribute?.type === api.AttributeType.Boolean && typeof attribute.value === "boolean") {
5377
+ return jsxRuntime.jsx(DashboardCheckbox, { title: attribute.alias || attribute.name, checked: attribute.value });
5378
+ }
5379
+ if (Array.isArray(element?.attributeName)) {
5380
+ const concatAttributes = element.attributeName.map((attributeName) => attributes?.find(({ name }) => name === attributeName)?.value || "");
5381
+ value = concatAttributes.join(separator || ", ");
5382
+ }
5383
+ else {
5384
+ value = attribute?.value?.toString() || "";
5385
+ }
5386
+ return maxLength && maxLength < value.length ? (jsxRuntime.jsx(TextTrim, { maxLength: maxLength, expandable: expandable, lineBreak: lineBreak, children: value })) : (value);
5387
+ };
5388
+
5389
+ const getChartAxes = (chartElement) => chartElement?.options?.relatedDataSources?.filter(({ chartAxis }) => chartAxis === "y");
5390
+
5391
+ const getChartFilterName = (relatedDataSources) => {
5392
+ const relatedAttributes = relatedDataSources || [];
5393
+ const axes = relatedAttributes.filter(({ chartAxis }) => chartAxis === "y");
5394
+ return axes?.[0]?.filterName;
5395
+ };
5396
+
5397
+ function getValueIndex(items, attributes) {
5398
+ return items?.findIndex(({ name }) => name.toString() === attributes.value?.toString());
5399
+ }
5400
+ const getChartMarkers = (items, markers, dataSources) => {
5401
+ if (typeof markers === "string") {
5402
+ const dataSource = getDataSource(markers, dataSources);
5403
+ return dataSource?.features?.map(({ attributes }) => ({
5404
+ ...attributes,
5405
+ value: getValueIndex(items, attributes),
5406
+ })) || [];
5407
+ }
5408
+ return (markers?.map(marker => ({
5409
+ ...marker,
5410
+ value: getValueIndex(items, marker),
5411
+ })) || []);
5412
+ };
5413
+
5404
5414
  const ContainersGroupContainer = React.memo(({ elementConfig, type, renderElement }) => {
5405
5415
  const { expandedContainers } = useWidgetContext(type);
5406
- const { id, children, options, style } = elementConfig || {};
5416
+ const { id, children, options } = elementConfig || {};
5407
5417
  const { column, expandable, expanded } = options || {};
5408
5418
  const isColumn = column === undefined || column;
5409
5419
  const isVisible = isVisibleContainer(id, expandable, expanded, expandedContainers);
5410
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(ExpandableTitle, { elementConfig: elementConfig, type: type, renderElement: renderElement }), isVisible && (jsxRuntime.jsx(Container, { id: id, isColumn: isColumn, style: style, 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 }) }))] }));
5411
5421
  });
5412
5422
 
5413
5423
  const ChartLegendContainer = styled(uilibGl.Flex) `
@@ -6112,7 +6122,7 @@ const PagesContainer = React.memo(({ type = exports.WidgetType.Dashboard, noBord
6112
6122
  setSelectedTabId,
6113
6123
  type,
6114
6124
  ]);
6115
- 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 }) }));
6116
6126
  });
6117
6127
 
6118
6128
  const ImageContainerBg$1 = styled.div `
@@ -8247,7 +8257,7 @@ const getElementValue = ({ getDefaultContainer, ...props }) => {
8247
8257
  return attribute?.name ? layerInfo.layerDefinition.attributes[attribute.name]?.description || null : null;
8248
8258
  }
8249
8259
  const ElementComponent = type ? elementComponents[type] : null;
8250
- return ElementComponent ? jsxRuntime.jsx(ElementComponent, { ...props }) : getDefaultContainer();
8260
+ return ElementComponent ? jsxRuntime.jsx(ElementComponent, { ...props }) : getDefaultContainer?.();
8251
8261
  };
8252
8262
 
8253
8263
  const getLayerAttributes = (layerDefinition) => {
@@ -9955,6 +9965,15 @@ const useGetConfigLayer = () => {
9955
9965
  return React.useCallback((layerName) => currentPage?.layers?.find(({ name }) => name === layerName), [currentPage?.layers]);
9956
9966
  };
9957
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
+
9958
9977
  const useProjectDashboardInit = () => {
9959
9978
  const { projectInfo, updateProject } = useWidgetContext();
9960
9979
  return React.useCallback(() => {
@@ -10262,7 +10281,8 @@ const ChartLegend = ({ data, chartElement, fontSize, type, twoColumns, loading }
10262
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: "Другое" }) }))] }));
10263
10282
  };
10264
10283
 
10265
- const ContainerChildren = React.memo(({ items, isColumn, isMain, renderElement }) => {
10284
+ const ContainerChildren = React.memo(({ type, items, isColumn, isMain, renderElement }) => {
10285
+ const checkIfEmptyDataSource = useHideIfEmptyDataSource(type);
10266
10286
  return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: items
10267
10287
  ?.filter(item => !["title", "icon", "titleIcon"].includes(item.id))
10268
10288
  ?.map((item, index) => {
@@ -10271,6 +10291,8 @@ const ContainerChildren = React.memo(({ items, isColumn, isMain, renderElement }
10271
10291
  index,
10272
10292
  wrap: isColumn || isMain,
10273
10293
  });
10294
+ if (checkIfEmptyDataSource(item.options?.hideIfEmptyDataSource))
10295
+ return null;
10274
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));
10275
10297
  }) }));
10276
10298
  });
@@ -10827,6 +10849,7 @@ exports.ElementMarkdown = ElementMarkdown;
10827
10849
  exports.ElementSlideshow = ElementSlideshow;
10828
10850
  exports.ElementSvg = ElementSvg;
10829
10851
  exports.ElementTooltip = ElementTooltip;
10852
+ exports.ElementValueWrapper = ElementValueWrapper;
10830
10853
  exports.ExpandableTitle = ExpandableTitle;
10831
10854
  exports.FEATURE_CARD_DEFAULT_COLORS = FEATURE_CARD_DEFAULT_COLORS;
10832
10855
  exports.FEATURE_CARD_OTHER_COLOR = FEATURE_CARD_OTHER_COLOR;
@@ -11010,6 +11033,7 @@ exports.useExportPdf = useExportPdf;
11010
11033
  exports.useGetConfigLayer = useGetConfigLayer;
11011
11034
  exports.useGlobalContext = useGlobalContext;
11012
11035
  exports.useHeaderRender = useHeaderRender;
11036
+ exports.useHideIfEmptyDataSource = useHideIfEmptyDataSource;
11013
11037
  exports.useLayerParams = useLayerParams;
11014
11038
  exports.useMapContext = useMapContext;
11015
11039
  exports.useMapDraw = useMapDraw;