@evergis/react 4.0.62 → 4.0.63
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/componentTypes.d.ts +1 -1
- package/dist/components/Dashboard/containers/TaskContainer/useTaskNotifications.d.ts +9 -0
- package/dist/components/Dashboard/hooks/useGlobalContext.d.ts +7 -0
- package/dist/components/Dashboard/types.d.ts +1 -0
- package/dist/contexts/GlobalContext/types.d.ts +8 -0
- package/dist/hooks/task/usePythonTask.d.ts +1 -0
- package/dist/index.js +89 -4
- package/dist/index.js.map +1 -1
- package/dist/react.esm.js +89 -4
- package/dist/react.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/react.esm.js
CHANGED
|
@@ -4215,7 +4215,7 @@ const useAttachmentItems = ({ type, elementConfig, valueOverride, }) => {
|
|
|
4215
4215
|
};
|
|
4216
4216
|
|
|
4217
4217
|
const useGlobalContext = () => {
|
|
4218
|
-
const { t, language, themeName, api, ewktGeometry } = useContext(GlobalContext) || {};
|
|
4218
|
+
const { t, language, themeName, api, ewktGeometry, notification } = useContext(GlobalContext) || {};
|
|
4219
4219
|
const translate = useCallback((value, options) => {
|
|
4220
4220
|
if (t)
|
|
4221
4221
|
return t(value, options);
|
|
@@ -4227,7 +4227,8 @@ const useGlobalContext = () => {
|
|
|
4227
4227
|
themeName,
|
|
4228
4228
|
api,
|
|
4229
4229
|
ewktGeometry,
|
|
4230
|
-
|
|
4230
|
+
notification,
|
|
4231
|
+
}), [language, translate, api, ewktGeometry, themeName, notification]);
|
|
4231
4232
|
};
|
|
4232
4233
|
|
|
4233
4234
|
const GRID_TILE_SIZE = "4.5rem";
|
|
@@ -5620,6 +5621,7 @@ const usePythonTask = () => {
|
|
|
5620
5621
|
const { preparePythonSandbox } = usePythonSandbox();
|
|
5621
5622
|
const [status, setStatus] = useState(RemoteTaskStatus.Unknown);
|
|
5622
5623
|
const [log, setLog] = useState(null);
|
|
5624
|
+
const [lastMessage, setLastMessage] = useState(null);
|
|
5623
5625
|
const [error, setError] = useState(null);
|
|
5624
5626
|
const [loading, setLoading] = useState(false);
|
|
5625
5627
|
const [executionTime, setExecutionTime] = useState(null);
|
|
@@ -5641,6 +5643,7 @@ const usePythonTask = () => {
|
|
|
5641
5643
|
reset();
|
|
5642
5644
|
setStatus(RemoteTaskStatus.Process);
|
|
5643
5645
|
setLog(null);
|
|
5646
|
+
setLastMessage(null);
|
|
5644
5647
|
setLoading(true);
|
|
5645
5648
|
const start = Date.now();
|
|
5646
5649
|
let prototypeId = await api.remoteTaskManager.createTaskPrototype({
|
|
@@ -5681,6 +5684,8 @@ const usePythonTask = () => {
|
|
|
5681
5684
|
const isFinished = [RemoteTaskStatus.Completed, RemoteTaskStatus.Error].includes(data.status);
|
|
5682
5685
|
setStatus(data.status);
|
|
5683
5686
|
setLog([logRef.current, data.log].filter(Boolean).join("\n"));
|
|
5687
|
+
if (data.log)
|
|
5688
|
+
setLastMessage(data.log);
|
|
5684
5689
|
setExecutionTime(Date.now() - start);
|
|
5685
5690
|
setLoading(false);
|
|
5686
5691
|
setTaskId(isFinished ? null : newTaskId);
|
|
@@ -5733,6 +5738,7 @@ const usePythonTask = () => {
|
|
|
5733
5738
|
stopTask,
|
|
5734
5739
|
openLog,
|
|
5735
5740
|
log,
|
|
5741
|
+
lastMessage,
|
|
5736
5742
|
error,
|
|
5737
5743
|
status,
|
|
5738
5744
|
loading,
|
|
@@ -7706,14 +7712,93 @@ const buildFiltersFromResponse = (responseFilters, result) => {
|
|
|
7706
7712
|
return Object.keys(filters).length ? filters : null;
|
|
7707
7713
|
};
|
|
7708
7714
|
|
|
7715
|
+
const RUN_ID_RADIX = 36;
|
|
7716
|
+
const RUN_ID_LENGTH = 8;
|
|
7717
|
+
const generateRunId = () => `task-${Date.now()}-${Math.random().toString(RUN_ID_RADIX).slice(2, RUN_ID_LENGTH)}`;
|
|
7718
|
+
const useTaskNotifications = ({ enabled, status, lastMessage, openLog, }) => {
|
|
7719
|
+
const { t, notification } = useGlobalContext();
|
|
7720
|
+
const runIdRef = useRef(null);
|
|
7721
|
+
const prevStatusRef = useRef(RemoteTaskStatus.Unknown);
|
|
7722
|
+
useEffect(() => {
|
|
7723
|
+
if (!enabled) {
|
|
7724
|
+
if (runIdRef.current) {
|
|
7725
|
+
notification?.close(runIdRef.current);
|
|
7726
|
+
runIdRef.current = null;
|
|
7727
|
+
}
|
|
7728
|
+
prevStatusRef.current = status;
|
|
7729
|
+
return;
|
|
7730
|
+
}
|
|
7731
|
+
if (status === RemoteTaskStatus.Unknown) {
|
|
7732
|
+
prevStatusRef.current = status;
|
|
7733
|
+
return;
|
|
7734
|
+
}
|
|
7735
|
+
const isFreshRun = status === RemoteTaskStatus.Process && prevStatusRef.current !== RemoteTaskStatus.Process;
|
|
7736
|
+
if (isFreshRun) {
|
|
7737
|
+
runIdRef.current = generateRunId();
|
|
7738
|
+
}
|
|
7739
|
+
if (!runIdRef.current) {
|
|
7740
|
+
runIdRef.current = generateRunId();
|
|
7741
|
+
}
|
|
7742
|
+
const id = runIdRef.current;
|
|
7743
|
+
const description = lastMessage || t("taskStarted", { ns: "dashboard", defaultValue: "Запуск задачи…" });
|
|
7744
|
+
const button = t("details", { ns: "dashboard", defaultValue: "Подробнее" });
|
|
7745
|
+
const base = {
|
|
7746
|
+
id,
|
|
7747
|
+
title: "",
|
|
7748
|
+
description,
|
|
7749
|
+
duration: Number.MAX_SAFE_INTEGER,
|
|
7750
|
+
button,
|
|
7751
|
+
buttonIcon: "info",
|
|
7752
|
+
buttonColor: "primary",
|
|
7753
|
+
onButtonClick: openLog,
|
|
7754
|
+
};
|
|
7755
|
+
if (status === RemoteTaskStatus.Process) {
|
|
7756
|
+
const item = {
|
|
7757
|
+
...base,
|
|
7758
|
+
title: t("taskInProgress", { ns: "dashboard", defaultValue: "Выполняется" }),
|
|
7759
|
+
progress: true,
|
|
7760
|
+
};
|
|
7761
|
+
if (isFreshRun) {
|
|
7762
|
+
notification?.add(item);
|
|
7763
|
+
}
|
|
7764
|
+
else {
|
|
7765
|
+
notification?.update(item);
|
|
7766
|
+
}
|
|
7767
|
+
}
|
|
7768
|
+
else if (status === RemoteTaskStatus.Completed) {
|
|
7769
|
+
notification?.update({
|
|
7770
|
+
...base,
|
|
7771
|
+
title: t("taskCompleted", { ns: "dashboard", defaultValue: "Выполнено" }),
|
|
7772
|
+
success: true,
|
|
7773
|
+
progress: false,
|
|
7774
|
+
});
|
|
7775
|
+
}
|
|
7776
|
+
else if (status === RemoteTaskStatus.Error) {
|
|
7777
|
+
notification?.update({
|
|
7778
|
+
...base,
|
|
7779
|
+
title: t("taskError", { ns: "dashboard", defaultValue: "Ошибка" }),
|
|
7780
|
+
error: true,
|
|
7781
|
+
progress: false,
|
|
7782
|
+
});
|
|
7783
|
+
}
|
|
7784
|
+
prevStatusRef.current = status;
|
|
7785
|
+
}, [enabled, status, lastMessage, openLog, t, notification]);
|
|
7786
|
+
};
|
|
7787
|
+
|
|
7709
7788
|
const TaskContainer = memo(({ type, elementConfig, renderElement }) => {
|
|
7710
7789
|
const { t, ewktGeometry } = useGlobalContext();
|
|
7711
7790
|
const { dataSources, filters: selectedFilters, attributes, layerInfo, changeFilters, } = useWidgetContext(type);
|
|
7712
7791
|
const { dataSources: projectDataSources } = useWidgetContext(WidgetType.Dashboard);
|
|
7713
7792
|
const { currentPage } = useWidgetPage(type);
|
|
7714
|
-
const { taskId, runTask, stopTask, status, openLog, loading, isLogDialogOpen, closeLog, log, result, } = usePythonTask();
|
|
7793
|
+
const { taskId, runTask, stopTask, status, openLog, loading, isLogDialogOpen, closeLog, log, lastMessage, result, } = usePythonTask();
|
|
7715
7794
|
const { options } = elementConfig || {};
|
|
7716
|
-
const { title, relatedResources, center, icon, statusColors, responseFilters } = options || {};
|
|
7795
|
+
const { title, relatedResources, center, icon, statusColors, responseFilters, useNotifications, } = options || {};
|
|
7796
|
+
useTaskNotifications({
|
|
7797
|
+
enabled: !!useNotifications,
|
|
7798
|
+
status,
|
|
7799
|
+
lastMessage,
|
|
7800
|
+
openLog,
|
|
7801
|
+
});
|
|
7717
7802
|
useEffect(() => {
|
|
7718
7803
|
const filtersToApply = buildFiltersFromResponse(responseFilters, result);
|
|
7719
7804
|
if (filtersToApply)
|