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