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