@evergis/react 3.1.55 → 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';
@@ -6709,96 +6709,34 @@ const ExportPdfContainer = memo(({ type, elementConfig }) => {
6709
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" }) }) }));
6710
6710
  });
6711
6711
 
6712
- const UploaderContainer = styled(Container) `
6713
- ${UploaderItemArea} {
6714
- overflow: visible;
6715
- padding-top: 1rem;
6716
- padding-bottom: 1rem;
6717
- }
6718
-
6719
- ${UploaderTitleWrapper} {
6720
- top: 0;
6721
- padding-top: 0;
6722
- border: 0;
6723
- }
6724
- `;
6725
- const UploaderTitle = styled(Flex) `
6726
- flex-direction: column;
6727
- align-items: center;
6728
- width: 11rem;
6729
- margin: 0 auto;
6730
- text-align: center;
6731
- font-size: 0.625rem;
6732
- color: ${({ theme: { palette } }) => palette.textSecondary};
6733
-
6734
- span[kind] {
6735
- width: 1.5rem;
6736
- height: 1.5rem;
6737
- margin-bottom: 0.75rem;
6738
-
6739
- :after {
6740
- font-size: 1.5rem;
6741
- color: ${({ theme: { palette } }) => palette.textSecondary};
6742
- opacity: 0.12;
6743
- }
6744
- }
6745
- `;
6746
-
6747
- const DEFAULT_FILE_EXTENSIONS = ".txt,.csv,.py";
6748
6712
  const UploadContainer = memo(({ type, elementConfig, renderElement }) => {
6749
- const { t, api } = useGlobalContext();
6750
- const { changeFilters } = useWidgetContext(type);
6751
- const [files, setFiles] = useState([]);
6752
- const refInput = useRef();
6753
- const { id, style, options } = elementConfig || {};
6754
- const { icon, title, filterName, fileExtensions = DEFAULT_FILE_EXTENSIONS, parentResourceId, multiSelect } = options || {};
6755
- const onUpload = useCallback(async (input) => {
6756
- const files = Array.isArray(input) ? input : [input];
6757
- const response = await Promise.all(files.map(file => {
6758
- return api.file.upload(file, true, parentResourceId, file.name);
6759
- }));
6760
- const uploadedFiles = response.map(item => ({
6761
- name: item.name,
6762
- id: item.resourceId,
6763
- done: true,
6764
- }));
6765
- setFiles(currentFiles => ([...uploadedFiles, ...currentFiles]));
6766
- }, [parentResourceId]);
6767
- const onDelete = useCallback(async (id) => {
6768
- const index = files.findIndex(file => file.id === id);
6769
- if (index === -1)
6770
- return;
6771
- const resourceId = files[index].id;
6772
- await api.file.deleteResource(resourceId);
6773
- setFiles(currentFiles => currentFiles.filter(({ id }) => id !== resourceId));
6774
- }, [files]);
6775
- const renderTitle = useMemo(() => {
6776
- if (files.length)
6777
- return null;
6778
- return (jsxs(UploaderTitle, { children: [jsx(Icon, { kind: icon || "upload" }), jsx("div", { children: title ?? t("uploadTitle", {
6779
- ns: "dashboard",
6780
- defaultValue: "Перетащите файл сюда или нажмите, чтобы выбрать",
6781
- }) })] }));
6782
- }, [icon, t, title, files.length]);
6783
- useEffect(() => {
6784
- if (!filterName)
6785
- return;
6786
- changeFilters({ [filterName]: { value: files.map(({ id }) => id) } });
6787
- }, [files]);
6788
- 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 })] }));
6789
6718
  });
6790
6719
 
6791
- const TaskContainer = memo(({ elementConfig }) => {
6792
- const { t } = useGlobalContext();
6793
- 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();
6794
6725
  const { options } = elementConfig || {};
6795
- const { title, relatedResources } = options || {};
6726
+ const { title, relatedResources, center, icon } = options || {};
6796
6727
  const onClick = useCallback(async () => {
6797
6728
  await Promise.all(relatedResources.map(({ resourceId, parameters, script }) => {
6798
- 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 });
6799
6737
  }));
6800
- }, [relatedResources, runTask]);
6801
- 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: "Запуск" })] }) }));
6802
6740
  });
6803
6741
 
6804
6742
  const containerComponents = {
@@ -8182,6 +8120,86 @@ const getDefaultConfig = ({ title, defaultTitle, items, baseMapName, position, r
8182
8120
  return dashboardConfiguration;
8183
8121
  };
8184
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
+
8185
8203
  const elementComponents = {
8186
8204
  image: ElementImage,
8187
8205
  slideshow: ElementSlideshow,
@@ -8195,6 +8213,7 @@ const elementComponents = {
8195
8213
  chart: ElementChart,
8196
8214
  legend: ElementLegend,
8197
8215
  markdown: ElementMarkdown,
8216
+ uploader: ElementUploader,
8198
8217
  };
8199
8218
 
8200
8219
  const getElementValue = ({ getDefaultContainer, ...props }) => {