@evergis/react 3.1.54 → 3.1.56

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.
package/dist/react.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
2
- import { IconButton, Flex, transition, Chip, Divider, Icon, Description, FlexSpan, IconToggle, Popup, Menu, DraggableTree, shadows, LegendToggler, Tooltip as Tooltip$1, DropdownField, MultiSelectContainer, IconButtonButton, FlatButton, DraggableTreeContainer, UploaderItemArea, UploaderTitleWrapper, Uploader, WaitingButton, LinearProgress, H2, ThemeProvider, defaultTheme, Preview, Blank, Popover, Expander, darkTheme, NumberRangeSlider, useAsyncAutocomplete, AutoComplete, Dropdown, Checkbox, CircularProgress, RangeNumberInput, dateFormat } from '@evergis/uilib-gl';
2
+ import { IconButton, Flex, transition, Chip, Divider, Icon, Description, FlexSpan, IconToggle, Popup, Menu, DraggableTree, shadows, LegendToggler, Tooltip as Tooltip$1, DropdownField, MultiSelectContainer, IconButtonButton, FlatButton, DraggableTreeContainer, WaitingButton, LinearProgress, H2, ThemeProvider, defaultTheme, Preview, Blank, Popover, Expander, darkTheme, UploaderItemArea, UploaderTitleWrapper, Uploader, NumberRangeSlider, useAsyncAutocomplete, AutoComplete, Dropdown, Checkbox, CircularProgress, RangeNumberInput, dateFormat } from '@evergis/uilib-gl';
3
3
  import { createContext, memo, useRef, useState, useEffect, useCallback, useContext, useMemo, Fragment } from 'react';
4
4
  import styled, { createGlobalStyle, css, useTheme } from 'styled-components';
5
5
  import { lineChartClassNames, BarChart as BarChart$1, barChartClassNames, LineChart, PieChart } from '@evergis/charts';
@@ -5118,13 +5118,6 @@ const Container = styled(Flex) `
5118
5118
  align-items: center;
5119
5119
  `}
5120
5120
 
5121
- ${({ isMain, isColumn }) => (isMain || isColumn) &&
5122
- css `
5123
- > :not(:last-child) {
5124
- margin-bottom: 1.5rem;
5125
- }
5126
- `}
5127
-
5128
5121
  ${({ isTitle }) => isTitle &&
5129
5122
  css `
5130
5123
  &&&& {
@@ -5145,6 +5138,7 @@ const ContainerWrapper = styled(Flex) `
5145
5138
  width: 100%;
5146
5139
  background: ${({ theme: { palette } }) => palette.backgroundAlpha};
5147
5140
  box-shadow: rgb(0 0 0 / 15%) 0 0.1875rem 0.625rem;
5141
+ margin-bottom: 2rem;
5148
5142
  padding: 1.5rem;
5149
5143
  border-radius: 0.5rem;
5150
5144
  backdrop-filter: blur(20px);
@@ -5155,6 +5149,12 @@ const ContainerWrapper = styled(Flex) `
5155
5149
  ${Container} > :not(:last-child) {
5156
5150
  margin-bottom: 1.5rem;
5157
5151
  }
5152
+
5153
+ ${({ $noMargin }) => $noMargin && css `
5154
+ &&&& {
5155
+ margin-bottom: 0;
5156
+ }
5157
+ `}
5158
5158
  `;
5159
5159
  const DashboardChip = styled(Chip) `
5160
5160
  margin: 0 0.25rem 0.25rem 0;
@@ -5219,12 +5219,6 @@ const DashboardWrapper = styled(Flex) `
5219
5219
  width: calc(100% - 3rem);
5220
5220
  height: calc(100% - ${LEFT_PANEL_HEADER_HEIGHT});
5221
5221
 
5222
- > ${ContainerWrapper} {
5223
- > * {
5224
- margin-bottom: 2rem;
5225
- }
5226
- }
5227
-
5228
5222
  ${({ hasImage, isPresentationMode }) => hasImage &&
5229
5223
  !isPresentationMode &&
5230
5224
  css `
@@ -6715,96 +6709,34 @@ const ExportPdfContainer = memo(({ type, elementConfig }) => {
6715
6709
  return (jsx(Container, { id: id, style: style, children: jsx(IconButton, { kind: icon || "download", primary: true, disabled: loading, onClick: onExport, children: title ?? t("downloadPdf", { ns: "dashboard", defaultValue: "Скачать PDF" }) }) }));
6716
6710
  });
6717
6711
 
6718
- const UploaderContainer = styled(Container) `
6719
- ${UploaderItemArea} {
6720
- overflow: visible;
6721
- padding-top: 1rem;
6722
- padding-bottom: 1rem;
6723
- }
6724
-
6725
- ${UploaderTitleWrapper} {
6726
- top: 0;
6727
- padding-top: 0;
6728
- border: 0;
6729
- }
6730
- `;
6731
- const UploaderTitle = styled(Flex) `
6732
- flex-direction: column;
6733
- align-items: center;
6734
- width: 11rem;
6735
- margin: 0 auto;
6736
- text-align: center;
6737
- font-size: 0.625rem;
6738
- color: ${({ theme: { palette } }) => palette.textSecondary};
6739
-
6740
- span[kind] {
6741
- width: 1.5rem;
6742
- height: 1.5rem;
6743
- margin-bottom: 0.75rem;
6744
-
6745
- :after {
6746
- font-size: 1.5rem;
6747
- color: ${({ theme: { palette } }) => palette.textSecondary};
6748
- opacity: 0.12;
6749
- }
6750
- }
6751
- `;
6752
-
6753
- const DEFAULT_FILE_EXTENSIONS = ".txt,.csv,.py";
6754
6712
  const UploadContainer = memo(({ type, elementConfig, renderElement }) => {
6755
- const { t, api } = useGlobalContext();
6756
- const { changeFilters } = useWidgetContext(type);
6757
- const [files, setFiles] = useState([]);
6758
- const refInput = useRef();
6759
- const { id, style, options } = elementConfig || {};
6760
- const { icon, title, filterName, fileExtensions = DEFAULT_FILE_EXTENSIONS, parentResourceId, multiSelect } = options || {};
6761
- const onUpload = useCallback(async (input) => {
6762
- const files = Array.isArray(input) ? input : [input];
6763
- const response = await Promise.all(files.map(file => {
6764
- return api.file.upload(file, true, parentResourceId, file.name);
6765
- }));
6766
- const uploadedFiles = response.map(item => ({
6767
- name: item.name,
6768
- id: item.resourceId,
6769
- done: true,
6770
- }));
6771
- setFiles(currentFiles => ([...uploadedFiles, ...currentFiles]));
6772
- }, [parentResourceId]);
6773
- const onDelete = useCallback(async (id) => {
6774
- const index = files.findIndex(file => file.id === id);
6775
- if (index === -1)
6776
- return;
6777
- const resourceId = files[index].id;
6778
- await api.file.deleteResource(resourceId);
6779
- setFiles(currentFiles => currentFiles.filter(({ id }) => id !== resourceId));
6780
- }, [files]);
6781
- const renderTitle = useMemo(() => {
6782
- if (files.length)
6783
- return null;
6784
- return (jsxs(UploaderTitle, { children: [jsx(Icon, { kind: icon || "upload" }), jsx("div", { children: title ?? t("uploadTitle", {
6785
- ns: "dashboard",
6786
- defaultValue: "Перетащите файл сюда или нажмите, чтобы выбрать",
6787
- }) })] }));
6788
- }, [icon, t, title, files.length]);
6789
- useEffect(() => {
6790
- if (!filterName)
6791
- return;
6792
- changeFilters({ [filterName]: { value: files.map(({ id }) => id) } });
6793
- }, [files]);
6794
- return (jsxs(Fragment$1, { children: [jsx(ExpandableTitle, { elementConfig: elementConfig, type: type, renderElement: renderElement }), jsx(UploaderContainer, { id: id, style: style, children: jsx(Uploader, { title: renderTitle, accept: fileExtensions, fileItems: files, currentRef: refInput, isMultiple: multiSelect, onUpload: onUpload, onDelete: onDelete }) })] }));
6713
+ const { expandedContainers } = useWidgetContext(type);
6714
+ const { id, options } = elementConfig || {};
6715
+ const { expandable, expanded } = options || {};
6716
+ const isVisible = isVisibleContainer(id, expandable, expanded, expandedContainers);
6717
+ return (jsxs(Fragment$1, { children: [jsx(ExpandableTitle, { elementConfig: elementConfig, type: type, renderElement: renderElement }), isVisible && renderElement({ id: "uploader", wrap: false })] }));
6795
6718
  });
6796
6719
 
6797
- const TaskContainer = memo(({ elementConfig }) => {
6798
- const { t } = useGlobalContext();
6799
- const { runTask, error, result, executionTime, loading } = usePythonTask();
6720
+ const TaskContainer = memo(({ type, elementConfig }) => {
6721
+ const { t, ewktGeometry } = useGlobalContext();
6722
+ const { dataSources, filters: selectedFilters } = useWidgetContext(type);
6723
+ const { currentPage } = useWidgetPage(type);
6724
+ const { runTask, loading } = usePythonTask();
6800
6725
  const { options } = elementConfig || {};
6801
- const { title, relatedResources } = options || {};
6726
+ const { title, relatedResources, center, icon } = options || {};
6802
6727
  const onClick = useCallback(async () => {
6803
6728
  await Promise.all(relatedResources.map(({ resourceId, parameters, script }) => {
6804
- return runTask({ resourceId, parameters, script });
6729
+ const newParams = applyQueryFilters({
6730
+ parameters,
6731
+ dataSources,
6732
+ selectedFilters,
6733
+ filters: currentPage.filters,
6734
+ geometry: ewktGeometry,
6735
+ });
6736
+ return runTask({ resourceId, parameters: newParams, script });
6805
6737
  }));
6806
- }, [relatedResources, runTask]);
6807
- return (jsx(WaitingButton, { primary: true, isWaiting: loading, disabled: !relatedResources?.length, onClick: onClick, children: title || t("run", { ns: "dashboard", defaultValue: "Запуск" }) }));
6738
+ }, [currentPage.filters, dataSources, ewktGeometry, relatedResources, runTask, selectedFilters]);
6739
+ return (jsx(Flex, { justifyContent: center ? "center" : "flex-start", children: jsxs(WaitingButton, { primary: true, isWaiting: loading, disabled: !relatedResources?.length, onClick: onClick, children: [icon && jsx(FlexSpan, { marginRight: "0.5rem", children: jsx(Icon, { kind: icon }) }), title || t("run", { ns: "dashboard", defaultValue: "Запуск" })] }) }));
6808
6740
  });
6809
6741
 
6810
6742
  const containerComponents = {
@@ -8188,6 +8120,86 @@ const getDefaultConfig = ({ title, defaultTitle, items, baseMapName, position, r
8188
8120
  return dashboardConfiguration;
8189
8121
  };
8190
8122
 
8123
+ const UploaderContainer = styled(Container) `
8124
+ ${UploaderItemArea} {
8125
+ overflow: visible;
8126
+ padding-top: 1rem;
8127
+ padding-bottom: 1rem;
8128
+ }
8129
+
8130
+ ${UploaderTitleWrapper} {
8131
+ top: 0;
8132
+ padding-top: 0;
8133
+ border: 0;
8134
+ }
8135
+ `;
8136
+
8137
+ const UploaderTitle = styled(Flex) `
8138
+ flex-direction: column;
8139
+ align-items: center;
8140
+ width: 11rem;
8141
+ margin: 0 auto;
8142
+ text-align: center;
8143
+ font-size: 0.625rem;
8144
+ color: ${({ theme: { palette } }) => palette.textSecondary};
8145
+
8146
+ span[kind] {
8147
+ width: 1.5rem;
8148
+ height: 1.5rem;
8149
+ margin-bottom: 0.75rem;
8150
+
8151
+ :after {
8152
+ font-size: 1.5rem;
8153
+ color: ${({ theme: { palette } }) => palette.textSecondary};
8154
+ opacity: 0.12;
8155
+ }
8156
+ }
8157
+ `;
8158
+
8159
+ const DEFAULT_FILE_EXTENSIONS = ".txt,.csv,.py";
8160
+ const ElementUploader = memo(({ elementConfig, type }) => {
8161
+ const { t, api } = useGlobalContext();
8162
+ const { changeFilters } = useWidgetContext(type);
8163
+ const [files, setFiles] = useState([]);
8164
+ const refInput = useRef();
8165
+ const { id, style, options } = elementConfig || {};
8166
+ const { fileExtensions = DEFAULT_FILE_EXTENSIONS, multiSelect, parentResourceId, icon, title, filterName } = options || {};
8167
+ const onUpload = useCallback(async (input) => {
8168
+ const files = Array.isArray(input) ? input : [input];
8169
+ const response = await Promise.all(files.map(file => {
8170
+ return api.file.upload(file, true, parentResourceId || "", file.name);
8171
+ }));
8172
+ const uploadedFiles = response.map(item => ({
8173
+ name: item.name,
8174
+ id: item.resourceId,
8175
+ done: true,
8176
+ }));
8177
+ setFiles(currentFiles => ([...uploadedFiles, ...currentFiles]));
8178
+ }, [parentResourceId]);
8179
+ const onDelete = useCallback(async (id) => {
8180
+ const index = files.findIndex(file => file.id === id);
8181
+ if (index === -1)
8182
+ return;
8183
+ const resourceId = files[index].id;
8184
+ await api.file.deleteResource(resourceId);
8185
+ setFiles(currentFiles => currentFiles.filter(({ id }) => id !== resourceId));
8186
+ }, [files]);
8187
+ const renderTitle = useMemo(() => {
8188
+ if (files.length)
8189
+ return null;
8190
+ return (jsxs(UploaderTitle, { children: [jsx(Icon, { kind: icon || "upload" }), jsx("div", { children: title ?? t("uploadTitle", {
8191
+ ns: "dashboard",
8192
+ defaultValue: "Перетащите файл сюда или нажмите, чтобы выбрать",
8193
+ }) })] }));
8194
+ }, [icon, t, title, files.length]);
8195
+ useEffect(() => {
8196
+ if (!filterName)
8197
+ return;
8198
+ changeFilters({ [filterName]: { value: files.map(({ id }) => id) } });
8199
+ }, [files]);
8200
+ return (jsx(UploaderContainer, { id: id, style: style, children: jsx("div", { children: jsx(Uploader, { currentRef: refInput, title: renderTitle, accept: fileExtensions, width: "100%", fileItems: files, isMultiple: multiSelect, onUpload: onUpload, onDelete: onDelete }) }) }));
8201
+ });
8202
+
8191
8203
  const elementComponents = {
8192
8204
  image: ElementImage,
8193
8205
  slideshow: ElementSlideshow,
@@ -8201,6 +8213,7 @@ const elementComponents = {
8201
8213
  chart: ElementChart,
8202
8214
  legend: ElementLegend,
8203
8215
  markdown: ElementMarkdown,
8216
+ uploader: ElementUploader,
8204
8217
  };
8205
8218
 
8206
8219
  const getElementValue = ({ getDefaultContainer, ...props }) => {
@@ -10256,12 +10269,12 @@ const ContainerChildren = memo(({ items, isColumn, isMain, renderElement }) => {
10256
10269
  index,
10257
10270
  wrap: isColumn || isMain,
10258
10271
  });
10259
- return isMain ? (jsx(ContainerWrapper, { id: item.id, "data-templatename": item.templateName, children: jsx(DashboardWrapper, { children: render }) }, index)) : (jsx(Fragment, { children: render }, index));
10272
+ return isMain ? (jsx(ContainerWrapper, { "data-id": item.id, "data-templatename": item.templateName, "$noMargin": item.options?.noMargin, children: jsx(DashboardWrapper, { children: render }) }, index)) : (jsx(Fragment, { children: render }, index));
10260
10273
  }) }));
10261
10274
  });
10262
10275
 
10263
10276
  const DashboardLoading = memo(() => {
10264
- return (jsx(Container, { noBorders: true, children: jsx(ContainerWrapper, { children: jsx(DashboardWrapper, { children: jsx(DashboardPlaceholderWrap, { children: jsxs(DashboardPlaceholder, { isLoading: true, children: [jsx(Icon, { kind: "dashboard_loading" }), jsx(Flex, { width: "8rem", children: jsx(LinearProgress, {}) })] }) }) }) }) }));
10277
+ return (jsx(Container, { noBorders: true, children: jsx(ContainerWrapper, { "$noMargin": true, children: jsx(DashboardWrapper, { children: jsx(DashboardPlaceholderWrap, { children: jsxs(DashboardPlaceholder, { isLoading: true, children: [jsx(Icon, { kind: "dashboard_loading" }), jsx(Flex, { width: "8rem", children: jsx(LinearProgress, {}) })] }) }) }) }) }));
10265
10278
  });
10266
10279
 
10267
10280
  const Dashboard = memo(({ type = WidgetType.Dashboard, config, noBorders }) => {