@evergis/react 3.1.66 → 3.1.67
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/components/Dashboard/containers/TaskContainer/components/LogDialog/constants.d.ts +4 -0
- package/dist/components/Dashboard/containers/TaskContainer/components/LogDialog/index.d.ts +3 -0
- package/dist/components/Dashboard/containers/TaskContainer/components/LogDialog/styled.d.ts +4 -0
- package/dist/components/Dashboard/containers/TaskContainer/components/LogDialog/types.d.ts +8 -0
- package/dist/hooks/task/usePythonTask.d.ts +3 -0
- package/dist/index.js +87 -5
- package/dist/index.js.map +1 -1
- package/dist/react.esm.js +88 -6
- package/dist/react.esm.js.map +1 -1
- package/package.json +2 -2
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, Icon, Description, FlexSpan, IconToggle, Popup, Menu, DraggableTree, shadows, Divider, 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';
|
|
2
|
+
import { IconButton, Flex, transition, Chip, Icon, Description, FlexSpan, IconToggle, Popup, Menu, DraggableTree, shadows, Divider, LegendToggler, Tooltip as Tooltip$1, DropdownField, MultiSelectContainer, IconButtonButton, FlatButton, DraggableTreeContainer, Dialog, DialogTitle, DialogContent, 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';
|
|
@@ -4832,9 +4832,10 @@ const usePythonTask = () => {
|
|
|
4832
4832
|
const [executionTime, setExecutionTime] = useState(null);
|
|
4833
4833
|
const [taskId, setTaskId] = useState(null);
|
|
4834
4834
|
const [subscriptionId, setSubscriptionId] = useState(null);
|
|
4835
|
+
const [isLogDialogOpen, setIsLogDialogOpen] = useState(false);
|
|
4836
|
+
const resultRef = useRef(null);
|
|
4835
4837
|
const reset = useCallback(() => {
|
|
4836
4838
|
setStatus(RemoteTaskStatus.Unknown);
|
|
4837
|
-
setResult(null);
|
|
4838
4839
|
setError(null);
|
|
4839
4840
|
setLoading(false);
|
|
4840
4841
|
setExecutionTime(null);
|
|
@@ -4844,6 +4845,7 @@ const usePythonTask = () => {
|
|
|
4844
4845
|
const runTask = useCallback(async ({ resourceId, parameters, script, fileName, methodName, }) => {
|
|
4845
4846
|
reset();
|
|
4846
4847
|
setStatus(RemoteTaskStatus.Process);
|
|
4848
|
+
setResult(null);
|
|
4847
4849
|
setLoading(true);
|
|
4848
4850
|
const start = Date.now();
|
|
4849
4851
|
let prototypeId = await api.remoteTaskManager.createTaskPrototype({
|
|
@@ -4881,7 +4883,7 @@ const usePythonTask = () => {
|
|
|
4881
4883
|
const onNotification = ({ data }) => {
|
|
4882
4884
|
if (data?.taskId === newTaskId) {
|
|
4883
4885
|
setStatus(data.status);
|
|
4884
|
-
setResult(
|
|
4886
|
+
setResult([data.log, resultRef.current].filter(Boolean).join("\n\n"));
|
|
4885
4887
|
setError(null);
|
|
4886
4888
|
setExecutionTime(Date.now() - start);
|
|
4887
4889
|
setLoading(false);
|
|
@@ -4904,7 +4906,28 @@ const usePythonTask = () => {
|
|
|
4904
4906
|
reset();
|
|
4905
4907
|
unsubscribeById(subscriptionId);
|
|
4906
4908
|
}, [api, reset, unsubscribeById, taskId, subscriptionId]);
|
|
4907
|
-
|
|
4909
|
+
const openLog = useCallback(() => {
|
|
4910
|
+
setIsLogDialogOpen(true);
|
|
4911
|
+
}, []);
|
|
4912
|
+
const closeLog = useCallback(() => {
|
|
4913
|
+
setIsLogDialogOpen(false);
|
|
4914
|
+
}, []);
|
|
4915
|
+
useEffect(() => {
|
|
4916
|
+
resultRef.current = result;
|
|
4917
|
+
}, [result]);
|
|
4918
|
+
return {
|
|
4919
|
+
taskId,
|
|
4920
|
+
runTask,
|
|
4921
|
+
stopTask,
|
|
4922
|
+
openLog,
|
|
4923
|
+
result,
|
|
4924
|
+
error,
|
|
4925
|
+
status,
|
|
4926
|
+
loading,
|
|
4927
|
+
executionTime,
|
|
4928
|
+
isLogDialogOpen,
|
|
4929
|
+
closeLog,
|
|
4930
|
+
};
|
|
4908
4931
|
};
|
|
4909
4932
|
|
|
4910
4933
|
const useAppHeight = () => {
|
|
@@ -6736,6 +6759,65 @@ const UploadContainer = memo(({ type, elementConfig, renderElement }) => {
|
|
|
6736
6759
|
return (jsxs(Fragment$1, { children: [jsx(ExpandableTitle, { elementConfig: elementConfig, type: type, renderElement: renderElement }), isVisible && renderElement({ id: "uploader", wrap: false })] }));
|
|
6737
6760
|
});
|
|
6738
6761
|
|
|
6762
|
+
const StatusBadge = styled(Flex) `
|
|
6763
|
+
margin-bottom: 1rem;
|
|
6764
|
+
padding: 0.5rem 1rem;
|
|
6765
|
+
background-color: ${({ $statusColor }) => $statusColor};
|
|
6766
|
+
color: ${({ theme }) => theme.palette.iconContrast};
|
|
6767
|
+
border-radius: 0.25rem;
|
|
6768
|
+
`;
|
|
6769
|
+
const LogContainer = styled.div `
|
|
6770
|
+
flex: 1;
|
|
6771
|
+
padding: 1rem;
|
|
6772
|
+
background-color: ${({ theme }) => theme.palette.element};
|
|
6773
|
+
color: ${({ theme }) => theme.palette.textPrimary};
|
|
6774
|
+
font-family: monospace;
|
|
6775
|
+
font-size: 0.875rem;
|
|
6776
|
+
overflow: auto;
|
|
6777
|
+
white-space: pre-wrap;
|
|
6778
|
+
word-break: break-word;
|
|
6779
|
+
border-radius: 0.25rem;
|
|
6780
|
+
max-height: 31.25rem;
|
|
6781
|
+
`;
|
|
6782
|
+
|
|
6783
|
+
const STATUS_TRANSLATION_KEYS = {
|
|
6784
|
+
[RemoteTaskStatus.Process]: "task.status.process",
|
|
6785
|
+
[RemoteTaskStatus.Completed]: "task.status.completed",
|
|
6786
|
+
[RemoteTaskStatus.Error]: "task.status.error",
|
|
6787
|
+
[RemoteTaskStatus.Unknown]: "task.status.unknown",
|
|
6788
|
+
};
|
|
6789
|
+
const STATUS_DEFAULT_VALUES = {
|
|
6790
|
+
[RemoteTaskStatus.Process]: "Выполняется...",
|
|
6791
|
+
[RemoteTaskStatus.Completed]: "Завершено",
|
|
6792
|
+
[RemoteTaskStatus.Error]: "Ошибка",
|
|
6793
|
+
[RemoteTaskStatus.Unknown]: "Неизвестно",
|
|
6794
|
+
};
|
|
6795
|
+
const STATUS_COLORS = {
|
|
6796
|
+
[RemoteTaskStatus.Process]: "#2196f3",
|
|
6797
|
+
[RemoteTaskStatus.Completed]: "#4caf50",
|
|
6798
|
+
[RemoteTaskStatus.Error]: "#f44336",
|
|
6799
|
+
[RemoteTaskStatus.Unknown]: "#757575",
|
|
6800
|
+
};
|
|
6801
|
+
|
|
6802
|
+
const LogDialog = ({ isOpen, onClose, logs, status, statusColors }) => {
|
|
6803
|
+
const { t } = useGlobalContext();
|
|
6804
|
+
const contentRef = useRef(null);
|
|
6805
|
+
useEffect(() => {
|
|
6806
|
+
if (contentRef.current) {
|
|
6807
|
+
contentRef.current.scrollTop = 0;
|
|
6808
|
+
}
|
|
6809
|
+
}, [logs]);
|
|
6810
|
+
const getStatusText = useCallback((status) => {
|
|
6811
|
+
const translationKey = STATUS_TRANSLATION_KEYS[status] || STATUS_TRANSLATION_KEYS[RemoteTaskStatus.Unknown];
|
|
6812
|
+
const defaultValue = STATUS_DEFAULT_VALUES[status] || STATUS_DEFAULT_VALUES[RemoteTaskStatus.Unknown];
|
|
6813
|
+
return t(translationKey, { ns: "dashboard", defaultValue });
|
|
6814
|
+
}, [t]);
|
|
6815
|
+
const getStatusColor = useCallback((status) => {
|
|
6816
|
+
return statusColors?.[status] || STATUS_COLORS[status] || STATUS_COLORS[RemoteTaskStatus.Unknown];
|
|
6817
|
+
}, [statusColors]);
|
|
6818
|
+
return (jsxs(Dialog, { isOpen: isOpen, onCloseRequest: onClose, modal: true, maxWidth: "800px", minWidth: "600px", minHeight: "400px", children: [jsx(DialogTitle, { children: jsxs(Flex, { justifyContent: "space-between", alignItems: "center", children: [jsx("span", { children: t("task.logs.title", { ns: "dashboard", defaultValue: "Логи выполнения задачи" }) }), jsx(IconButton, { kind: "close", onClick: onClose })] }) }), jsx(DialogContent, { children: jsxs(Flex, { flexDirection: "column", height: "100%", marginBottom: "2rem", children: [jsxs(StatusBadge, { "$statusColor": getStatusColor(status), children: [t("task.status.label", { ns: "dashboard", defaultValue: "Статус" }), ": ", getStatusText(status)] }), jsx(LogContainer, { ref: contentRef, children: logs || t("task.logs.empty", { ns: "dashboard", defaultValue: "Логи отсутствуют" }) })] }) })] }));
|
|
6819
|
+
};
|
|
6820
|
+
|
|
6739
6821
|
const StatusWaitingButton = styled(WaitingButton) `
|
|
6740
6822
|
${({ status = RemoteTaskStatus.Unknown, statusColors }) => !!statusColors?.[status] && css `
|
|
6741
6823
|
transition: background-color ${transition.toggle};
|
|
@@ -6751,7 +6833,7 @@ const TaskContainer = memo(({ type, elementConfig }) => {
|
|
|
6751
6833
|
const { t, ewktGeometry } = useGlobalContext();
|
|
6752
6834
|
const { dataSources, filters: selectedFilters } = useWidgetContext(type);
|
|
6753
6835
|
const { currentPage } = useWidgetPage(type);
|
|
6754
|
-
const { taskId, runTask, stopTask, status, loading } = usePythonTask();
|
|
6836
|
+
const { taskId, runTask, stopTask, status, openLog, loading, isLogDialogOpen, closeLog, result } = usePythonTask();
|
|
6755
6837
|
const { options } = elementConfig || {};
|
|
6756
6838
|
const { title, relatedResources, center, icon, statusColors } = options || {};
|
|
6757
6839
|
const onClick = useCallback(async () => {
|
|
@@ -6766,7 +6848,7 @@ const TaskContainer = memo(({ type, elementConfig }) => {
|
|
|
6766
6848
|
return runTask({ resourceId, parameters: newParams, script, fileName, methodName });
|
|
6767
6849
|
}));
|
|
6768
6850
|
}, [currentPage.filters, dataSources, ewktGeometry, relatedResources, runTask, selectedFilters]);
|
|
6769
|
-
return (jsxs(Flex, { justifyContent: center ? "center" : "flex-start", children: [jsxs(StatusWaitingButton, { primary: true, status: status, statusColors: statusColors, 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: "Запуск" })] }), !!taskId && (jsx(IconButton, { kind: "stop", onClick: stopTask }))] }));
|
|
6851
|
+
return (jsx(Fragment$1, { children: jsxs(Flex, { justifyContent: center ? "center" : "flex-start", children: [jsxs(StatusWaitingButton, { primary: true, status: status, statusColors: statusColors, 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: "Запуск" })] }), !!taskId && (jsx(IconButton, { kind: "stop", onClick: stopTask })), !!result && (jsxs(Fragment$1, { children: [jsx(IconButton, { kind: "info", onClick: openLog }), jsx(LogDialog, { isOpen: isLogDialogOpen, onClose: closeLog, logs: result, status: status, statusColors: statusColors })] }))] }) }));
|
|
6770
6852
|
});
|
|
6771
6853
|
|
|
6772
6854
|
const containerComponents = {
|