@evergis/react 3.1.81 → 3.1.83

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,7 +1,6 @@
1
1
  import { FC } from 'react';
2
- import { ConfigContainer, WidgetType } from '../../types';
2
+ import { WidgetType } from '../../types';
3
3
  export declare const Dashboard: FC<{
4
4
  type?: WidgetType;
5
- config?: ConfigContainer;
6
5
  noBorders?: boolean;
7
6
  }>;
@@ -24,3 +24,5 @@ export declare const DEFAULT_ZOOM = 10;
24
24
  export declare const NUMERIC_ATTRIBUTE_TYPES: AttributeType[];
25
25
  export declare const GEOMETRY_ATTRIBUTE = "geometry";
26
26
  export declare const DEFAULT_ID_ATTRIBUTE_NAME = "gid";
27
+ export declare const DEFAULT_DROPDOWN_WIDTH = 312;
28
+ export declare const DEFAULT_FILTER_PADDING = 12;
@@ -1,6 +1,5 @@
1
- import { ConfigContainer, ConfigContainerChild, WidgetType } from '../types';
1
+ import { ConfigContainerChild, WidgetType } from '../types';
2
2
  export declare const useWidgetConfig: (type?: WidgetType) => {
3
3
  config: any;
4
- editConfig: ConfigContainer;
5
4
  pages: ConfigContainerChild[];
6
5
  };
@@ -13,6 +13,8 @@ export declare const useWidgetContext: (type?: WidgetType) => {
13
13
  feature: import('../../..').SelectedFeature;
14
14
  closeFeatureCard: VoidFunction;
15
15
  containerIds: string[];
16
+ controls: Record<string, string>;
17
+ changeControls: (controls: Record<string, string>) => void;
16
18
  components: {
17
19
  LayerItem?: import('react').FC<import('../..').LayerItemProps>;
18
20
  ProjectCatalogMenu?: import('react').FC;
@@ -20,6 +22,7 @@ export declare const useWidgetContext: (type?: WidgetType) => {
20
22
  ProjectPagesMenu?: import('react').FC;
21
23
  };
22
24
  config: import('../types').ConfigContainer;
25
+ isEditing: boolean;
23
26
  isLoading: boolean;
24
27
  pageIndex: number;
25
28
  filters: import('../types').SelectedFilters;
@@ -48,6 +48,7 @@ export interface ConfigOptions {
48
48
  relatedResources?: ConfigRelatedResource[];
49
49
  statusColors?: Record<RemoteTaskStatus, string>;
50
50
  chartType?: "bar" | "line" | "pie" | "stack";
51
+ controlType?: "dropdown" | "checkbox";
51
52
  layerNames?: string[];
52
53
  layerName?: string;
53
54
  geometryType?: GeometryType | EditGeometryType;
@@ -127,6 +128,7 @@ export interface ConfigOptions {
127
128
  tabId?: string;
128
129
  column?: boolean;
129
130
  relatedDataSource?: string;
131
+ controlName?: string;
130
132
  filterName?: string;
131
133
  searchFilterName?: string;
132
134
  colorAttribute?: string;
@@ -12,6 +12,7 @@ export type DashboardContextProps = PropsWithChildren<{
12
12
  dataSources?: WidgetDataSource[];
13
13
  geometryFilter?: boolean;
14
14
  loading?: boolean;
15
+ editMode?: boolean;
15
16
  filters?: SelectedFilters;
16
17
  dashboardLayers?: DashboardState["layers"];
17
18
  setDashboardLayer?: (props: DashboardLayerPayload) => void;
@@ -10,7 +10,7 @@ export type FeatureCardContextSettings = PropsWithChildren<{
10
10
  pageIndex?: number;
11
11
  handBookReference?: LayerReferenceConfigurationDc;
12
12
  isRaster?: boolean;
13
- isEditing?: boolean;
13
+ editMode?: boolean;
14
14
  isFeatureEditable?: boolean;
15
15
  hasCopyRights?: boolean;
16
16
  editOnly?: boolean;
@@ -20,6 +20,8 @@ export type FeatureCardContextSettings = PropsWithChildren<{
20
20
  loading?: boolean;
21
21
  filters?: SelectedFilters;
22
22
  changeFilters?: (filters: SelectedFilters) => void;
23
+ controls?: Record<string, string>;
24
+ changeControls?: (controls: Record<string, string>) => void;
23
25
  expandContainer?: (id: string, expanded?: boolean) => void;
24
26
  setSelectedTabId?: (id: string) => void;
25
27
  setHandBookReference?: (reference: LayerReferenceConfigurationDc) => void;
package/dist/index.js CHANGED
@@ -3438,6 +3438,8 @@ const DEFAULT_ZOOM = 10;
3438
3438
  const NUMERIC_ATTRIBUTE_TYPES = [api.AttributeType.Double, api.AttributeType.Int32, api.AttributeType.Int64];
3439
3439
  const GEOMETRY_ATTRIBUTE = "geometry";
3440
3440
  const DEFAULT_ID_ATTRIBUTE_NAME = "gid";
3441
+ const DEFAULT_DROPDOWN_WIDTH = 312;
3442
+ const DEFAULT_FILTER_PADDING = 12;
3441
3443
 
3442
3444
  const StackBarContainer = styled(uilibGl.Flex) `
3443
3445
  flex-wrap: nowrap;
@@ -4003,8 +4005,8 @@ const ServerNotificationsProvider = ({ url, initialized, children }) => {
4003
4005
  };
4004
4006
 
4005
4007
  const useWidgetContext = (type = exports.WidgetType.Dashboard) => {
4006
- const { projectInfo, updateProject, layerInfos, geometryFilter, dashboardLayers, setDashboardLayer, components: dashboardComponents, config: dashboardConfig, containerIds, pageIndex: projectPageIndex, selectedTabId: projectSelectedTabId, setSelectedTabId: setProjectSelectedTabId, dataSources: projectDataSources, loading: projectLoading, filters: projectFilters, changeFilters: projectChangeFilters, expandContainer: projectExpandContainer, expandedContainers: projectExpandedContainers, nextPage: projectNextPage, prevPage: projectPrevPage, changePage: projectChangePage, } = React.useContext(DashboardContext) || {};
4007
- const { layerInfo, attributes, feature, closeFeatureCard, config: featureConfig, pageIndex: featurePageIndex, selectedTabId: featureSelectedTabId, setSelectedTabId: setFeatureSelectedTabId, dataSources: featureDataSources, loading: featureLoading, filters: featureFilters, changeFilters: featureChangeFilters, expandContainer: featureExpandContainer, expandedContainers: featureExpandedContainers, nextPage: featureNextPage, prevPage: featurePrevPage, changePage: featureChangePage, } = React.useContext(FeatureCardContext) || {};
4008
+ const { projectInfo, updateProject, layerInfos, geometryFilter, dashboardLayers, setDashboardLayer, components: dashboardComponents, config: dashboardConfig, containerIds, pageIndex: projectPageIndex, selectedTabId: projectSelectedTabId, setSelectedTabId: setProjectSelectedTabId, dataSources: projectDataSources, loading: projectLoading, editMode: projectEditMode, filters: projectFilters, changeFilters: projectChangeFilters, expandContainer: projectExpandContainer, expandedContainers: projectExpandedContainers, nextPage: projectNextPage, prevPage: projectPrevPage, changePage: projectChangePage, } = React.useContext(DashboardContext) || {};
4009
+ const { layerInfo, attributes, feature, controls, changeControls, closeFeatureCard, config: featureConfig, pageIndex: featurePageIndex, selectedTabId: featureSelectedTabId, setSelectedTabId: setFeatureSelectedTabId, dataSources: featureDataSources, loading: featureLoading, editMode: featureEditMode, filters: featureFilters, changeFilters: featureChangeFilters, expandContainer: featureExpandContainer, expandedContainers: featureExpandedContainers, nextPage: featureNextPage, prevPage: featurePrevPage, changePage: featureChangePage, } = React.useContext(FeatureCardContext) || {};
4008
4010
  return {
4009
4011
  projectInfo,
4010
4012
  layerInfos,
@@ -4017,8 +4019,11 @@ const useWidgetContext = (type = exports.WidgetType.Dashboard) => {
4017
4019
  feature,
4018
4020
  closeFeatureCard,
4019
4021
  containerIds,
4022
+ controls,
4023
+ changeControls,
4020
4024
  components: dashboardComponents,
4021
4025
  config: type === exports.WidgetType.Dashboard ? dashboardConfig : featureConfig,
4026
+ isEditing: type === exports.WidgetType.Dashboard ? projectEditMode : featureEditMode,
4022
4027
  isLoading: type === exports.WidgetType.Dashboard ? projectLoading : featureLoading,
4023
4028
  pageIndex: type === exports.WidgetType.Dashboard ? projectPageIndex || 1 : featurePageIndex || 1,
4024
4029
  filters: type === exports.WidgetType.Dashboard ? projectFilters : featureFilters,
@@ -6009,7 +6014,7 @@ const DEFAULT_BAR_CHART_MARGINS = {
6009
6014
 
6010
6015
  const FiltersContainerWrapper = styled(uilibGl.Flex) `
6011
6016
  flex-direction: column;
6012
- padding: ${({ $padding }) => $padding ?? "0.75rem"};
6017
+ padding: ${({ $padding }) => $padding ?? `${DEFAULT_FILTER_PADDING}px`};
6013
6018
  background-color: ${({ $bgColor, $fontColor, theme: { palette } }) => $bgColor || ($fontColor ? transparentizeColor($fontColor, 6) : palette.element)};
6014
6019
  border-radius: ${({ theme: { borderRadius } }) => borderRadius.medium};
6015
6020
 
@@ -7770,34 +7775,29 @@ const ElementChips = React.memo(({ type, elementConfig }) => {
7770
7775
 
7771
7776
  const ElementControl = ({ elementConfig }) => {
7772
7777
  const { t } = useGlobalContext();
7773
- const { dataSources, filters, changeFilters } = useWidgetContext(exports.WidgetType.FeatureCard);
7778
+ const { dataSources, controls, changeControls } = useWidgetContext(exports.WidgetType.FeatureCard);
7779
+ const [value, setValue] = React.useState();
7774
7780
  const { options, attributeName } = elementConfig || {};
7775
- const { filterName, relatedDataSource, label, placeholder = t("selectValue", { ns: "dashboard", defaultValue: "Выберите значение" }) } = options || {};
7776
- // Получаем данные из datasource
7781
+ const { relatedDataSource, controlName, label, width, placeholder = t("selectValue", { ns: "dashboard", defaultValue: "Выберите значение" }) } = options || {};
7777
7782
  const dataSource = React.useMemo(() => getDataSource(relatedDataSource, dataSources), [relatedDataSource, dataSources]);
7778
- // Формируем опции для dropdown из features datasource
7779
7783
  const items = React.useMemo(() => {
7780
7784
  if (!dataSource?.features?.length || !attributeName) {
7781
7785
  return [];
7782
7786
  }
7783
- return dataSource.features.map((feature, index) => ({
7784
- id: feature.id || index,
7785
- value: feature.attributes?.[attributeName] || "",
7786
- label: feature.attributes?.[attributeName] || "",
7787
+ return dataSource.features.map(({ attributes }) => ({
7788
+ value: attributes?.[attributeName] || "",
7789
+ text: attributes?.[attributeName] || "",
7787
7790
  }));
7788
- }, [dataSource, attributeName]);
7789
- // Получаем текущее выбранное значение
7790
- const selectedItem = React.useMemo(() => items.find(opt => opt.value === filters?.[filterName]?.value), [items, filters, filterName]);
7791
- const handleChange = React.useCallback((option) => {
7792
- if (changeFilters && filterName) {
7793
- changeFilters({
7794
- [filterName]: {
7795
- value: option?.value || null,
7796
- },
7791
+ }, [dataSource?.features, attributeName]);
7792
+ const handleChange = React.useCallback(([option]) => {
7793
+ setValue(option?.value);
7794
+ if (controlName && changeControls) {
7795
+ changeControls({
7796
+ [controlName]: option?.value,
7797
7797
  });
7798
7798
  }
7799
- }, [changeFilters, filterName]);
7800
- return (jsxRuntime.jsx(uilibGl.Dropdown, { label: label, options: items, value: selectedItem, onChange: handleChange, width: "100%", placeholder: placeholder }));
7799
+ }, [changeControls, controlName]);
7800
+ return (jsxRuntime.jsx(uilibGl.Dropdown, { zIndex: 1000, width: `${width ?? DEFAULT_DROPDOWN_WIDTH}px`, label: label, options: items, value: controls?.[controlName] ?? value, placeholder: placeholder, onChange: handleChange }));
7801
7801
  };
7802
7802
 
7803
7803
  const StyledIconFontSizeMixin = styled.css `
@@ -8718,7 +8718,7 @@ const DropdownFilter = ({ type, filter, elementConfig }) => {
8718
8718
  }, [changeFilters, filterName]);
8719
8719
  if (!configFilter)
8720
8720
  return null;
8721
- return (jsxRuntime.jsx(uilibGl.Dropdown, { zIndex: 100, width: `${width ?? 288}px`, value: value, placeholder: placeholder, options: filterOptions, onChange: onChange }));
8721
+ return (jsxRuntime.jsx(uilibGl.Dropdown, { zIndex: 100, width: `${width ?? (DEFAULT_DROPDOWN_WIDTH - DEFAULT_FILTER_PADDING * 2)}px`, value: value, placeholder: placeholder, options: filterOptions, onChange: onChange }));
8722
8722
  };
8723
8723
 
8724
8724
  const CheckboxFilter = ({ type, filter, elementConfig }) => {
@@ -9620,11 +9620,16 @@ const tooltipValueFromRelatedFeatures = (t, value, relatedAttributes, layerInfo)
9620
9620
  };
9621
9621
 
9622
9622
  const useWidgetConfig = (type = exports.WidgetType.Dashboard) => {
9623
- const { config: configProp, containerIds, projectInfo, layerInfo } = useWidgetContext(type);
9623
+ const { config: configProp, containerIds, projectInfo, layerInfo, isEditing } = useWidgetContext(type);
9624
9624
  const config = React.useMemo(() => {
9625
9625
  if (configProp) {
9626
9626
  return configProp;
9627
9627
  }
9628
+ if (isEditing) {
9629
+ return type === exports.WidgetType.Dashboard
9630
+ ? (projectInfo?.content?.editConfiguration || {})
9631
+ : (layerInfo?.configuration?.editConfiguration || {});
9632
+ }
9628
9633
  const currentConfig = type === exports.WidgetType.Dashboard
9629
9634
  ? (projectInfo?.content?.dashboardConfiguration || {})
9630
9635
  : (layerInfo?.configuration?.cardConfiguration || {});
@@ -9640,14 +9645,10 @@ const useWidgetConfig = (type = exports.WidgetType.Dashboard) => {
9640
9645
  return newConfig;
9641
9646
  }
9642
9647
  return currentConfig;
9643
- }, [configProp, containerIds, layerInfo?.configuration?.cardConfiguration, projectInfo?.content?.dashboardConfiguration, type]);
9644
- const editConfig = React.useMemo(() => type === exports.WidgetType.Dashboard
9645
- ? (projectInfo?.content?.editConfiguration || {})
9646
- : (layerInfo?.configuration?.editConfiguration || {}), []);
9648
+ }, [configProp, containerIds, layerInfo?.configuration?.cardConfiguration, projectInfo?.content?.dashboardConfiguration, type, isEditing]);
9647
9649
  const pages = React.useMemo(() => (getPagesFromConfig(config) || []), [config]);
9648
9650
  return {
9649
9651
  config,
9650
- editConfig,
9651
9652
  pages,
9652
9653
  };
9653
9654
  };
@@ -10384,20 +10385,17 @@ const Chart = React.memo(({ config, element, elementConfig, type, renderElement
10384
10385
  return (jsxRuntime.jsxs(Tooltip, { children: [jsxRuntime.jsx(ChartTooltipLabel, { children: labels[indexX] }), items
10385
10386
  .filter(({ value }) => !isEmptyValue(value))
10386
10387
  ?.map(({ layerName, attributeName, attributeUnits, dataSourceName, value, stroke }, index) => {
10387
- const layerInfo = !attributeUnits
10388
- ? layerInfos?.find(({ name }) => name === layerName)
10389
- : null;
10390
- const attribute = !attributeUnits
10391
- ? layerInfo?.layerDefinition.attributes[attributeName]
10392
- : null;
10393
- const dataSource = dataSourceName ? getDataSource(dataSourceName, dataSources) : null;
10394
- const dataSourceUnits = !dataSource || !attributeUnits
10395
- ? null
10396
- : dataSource.features?.[0]?.attributes?.[attributeUnits];
10397
- const legendValue = attribute
10398
- ? formatAttributeValue({ t, type: attribute.type, value, stringFormat: attribute.stringFormat })
10399
- : [value, dataSourceUnits].filter(Boolean).join(" ");
10400
- return (jsxRuntime.jsxs(ChartTooltipRow, { children: [jsxRuntime.jsx(ChartLegendColor$1, { "$color": stroke }), jsxRuntime.jsx(ChartLegendValue, { children: legendValue })] }, index));
10388
+ const layerInfo = layerInfos?.find(({ name }) => name === layerName);
10389
+ const attribute = layerInfo?.layerDefinition.attributes[attributeName];
10390
+ const dataSource = getDataSource(dataSourceName, dataSources);
10391
+ const units = attributeUnits
10392
+ ? dataSource?.features?.[0]?.attributes?.[attributeUnits]
10393
+ : attribute?.stringFormat?.unitsLabel;
10394
+ const formatValue = attribute
10395
+ ? formatAttributeValue({ t, type: attribute.type, value, stringFormat: attribute.stringFormat, noUnits: true })
10396
+ : value;
10397
+ const resultValue = [formatValue, units].filter(Boolean).join(" ");
10398
+ return (jsxRuntime.jsxs(ChartTooltipRow, { children: [jsxRuntime.jsx(ChartLegendColor$1, { "$color": stroke }), jsxRuntime.jsx(ChartLegendValue, { children: resultValue })] }, index));
10401
10399
  })] }));
10402
10400
  }, [labels, layerInfos, dataSources, dotSnapping]);
10403
10401
  const markers = React.useMemo(() => getChartMarkers(data[0]?.items, configMarkers, dataSources), [data, dataSources, configMarkers]);
@@ -10543,7 +10541,7 @@ const DashboardLoading = React.memo(() => {
10543
10541
  return (jsxRuntime.jsx(Container, { noBorders: true, children: jsxRuntime.jsx(ContainerWrapper, { "$noMargin": true, children: jsxRuntime.jsx(DashboardWrapper, { children: jsxRuntime.jsx(DashboardPlaceholderWrap, { children: jsxRuntime.jsxs(DashboardPlaceholder, { isLoading: true, children: [jsxRuntime.jsx(uilibGl.Icon, { kind: "dashboard_loading" }), jsxRuntime.jsx(uilibGl.Flex, { width: "8rem", children: jsxRuntime.jsx(uilibGl.LinearProgress, {}) })] }) }) }) }) }));
10544
10542
  });
10545
10543
 
10546
- const Dashboard = React.memo(({ type = exports.WidgetType.Dashboard, config, noBorders }) => {
10544
+ const Dashboard = React.memo(({ type = exports.WidgetType.Dashboard, noBorders }) => {
10547
10545
  const { dataSources, isLoading } = useWidgetContext(type);
10548
10546
  const { currentPage } = useWidgetPage(type);
10549
10547
  const isDiffPage = useDiffPage(type);
@@ -10551,7 +10549,7 @@ const Dashboard = React.memo(({ type = exports.WidgetType.Dashboard, config, noB
10551
10549
  if (dataSourceLoading || isDiffPage) {
10552
10550
  return (jsxRuntime.jsx(DashboardLoading, {}));
10553
10551
  }
10554
- return (jsxRuntime.jsx(PagesContainer, { type: type, config: config, noBorders: noBorders }));
10552
+ return (jsxRuntime.jsx(PagesContainer, { type: type, noBorders: noBorders }));
10555
10553
  });
10556
10554
 
10557
10555
  const CardCheckbox = styled(uilibGl.Checkbox) `
@@ -11165,8 +11163,10 @@ exports.DEFAULT_CHART_WIDTH = DEFAULT_CHART_WIDTH;
11165
11163
  exports.DEFAULT_CIRCLE_PAINT = DEFAULT_CIRCLE_PAINT;
11166
11164
  exports.DEFAULT_DASHBOARD_CONFIG = DEFAULT_DASHBOARD_CONFIG;
11167
11165
  exports.DEFAULT_DATA_SOURCE_LIMIT = DEFAULT_DATA_SOURCE_LIMIT;
11166
+ exports.DEFAULT_DROPDOWN_WIDTH = DEFAULT_DROPDOWN_WIDTH;
11168
11167
  exports.DEFAULT_FILL_EXTRUSION_PAINT = DEFAULT_FILL_EXTRUSION_PAINT;
11169
11168
  exports.DEFAULT_FILL_PAINT = DEFAULT_FILL_PAINT;
11169
+ exports.DEFAULT_FILTER_PADDING = DEFAULT_FILTER_PADDING;
11170
11170
  exports.DEFAULT_ID_ATTRIBUTE_NAME = DEFAULT_ID_ATTRIBUTE_NAME;
11171
11171
  exports.DEFAULT_LAT = DEFAULT_LAT;
11172
11172
  exports.DEFAULT_LINE_PAINT = DEFAULT_LINE_PAINT;