@evergis/react 4.0.31 → 4.0.32

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,4 +1,5 @@
1
1
  export declare const SERVER_NOTIFICATION_EVENT: {
2
2
  ReceiveFeaturesUpdate: string;
3
3
  PythonProgressNotification: string;
4
+ PythonSandboxStats: string;
4
5
  };
@@ -1,3 +1,4 @@
1
1
  export * from './constants';
2
2
  export * from './usePythonTask';
3
+ export * from './usePythonSandbox';
3
4
  export * from './types';
@@ -1,7 +1,7 @@
1
1
  import { RemoteTaskStatus } from '@evergis/api';
2
2
  export interface PythonTaskProgressSubscription {
3
3
  tag: "python_task_progress_event";
4
- taskId: string;
4
+ resourceId: string;
5
5
  }
6
6
  export interface PythonTaskProgressNotification {
7
7
  data: {
@@ -14,3 +14,7 @@ export interface PythonTaskProgressNotification {
14
14
  tag: string;
15
15
  createdAt: string;
16
16
  }
17
+ export interface PythonSandbox {
18
+ path: string;
19
+ sandboxId: string;
20
+ }
@@ -0,0 +1,7 @@
1
+ import { PythonSandbox } from './types';
2
+ export declare const usePythonSandbox: () => {
3
+ preparePythonSandbox: ({ resourceId, isNotebook }: {
4
+ resourceId: string;
5
+ isNotebook?: boolean;
6
+ }) => Promise<PythonSandbox>;
7
+ };
package/dist/index.js CHANGED
@@ -5392,11 +5392,23 @@ const useServerNotificationsContext = () => {
5392
5392
  const SERVER_NOTIFICATION_EVENT = {
5393
5393
  ReceiveFeaturesUpdate: "ReceiveFeaturesUpdateNotification",
5394
5394
  PythonProgressNotification: "ReceivePythonProgressNotification",
5395
+ PythonSandboxStats: "ReceivePythonSandboxStatsNotification",
5396
+ };
5397
+
5398
+ const usePythonSandbox = () => {
5399
+ const { api } = useGlobalContext();
5400
+ const preparePythonSandbox = React.useCallback(({ resourceId, isNotebook = false }) => api.remoteTaskManager.post({
5401
+ workerType: "pythonService",
5402
+ methodType: "pythonrunner/prepare",
5403
+ data: { resourceId, isNotebook },
5404
+ }), [api.remoteTaskManager]);
5405
+ return { preparePythonSandbox };
5395
5406
  };
5396
5407
 
5397
5408
  const usePythonTask = () => {
5398
5409
  const { api: api$1, t } = useGlobalContext();
5399
5410
  const { addSubscription, connection, unsubscribeById } = useServerNotificationsContext();
5411
+ const { preparePythonSandbox } = usePythonSandbox();
5400
5412
  const [status, setStatus] = React.useState(api.RemoteTaskStatus.Unknown);
5401
5413
  const [log, setLog] = React.useState(null);
5402
5414
  const [error, setError] = React.useState(null);
@@ -5441,6 +5453,7 @@ const usePythonTask = () => {
5441
5453
  ],
5442
5454
  });
5443
5455
  prototypeId = prototypeId.replace(/["']+/g, "");
5456
+ await preparePythonSandbox({ resourceId });
5444
5457
  const { id: newTaskId, success } = await api$1.remoteTaskManager.startTask1(prototypeId);
5445
5458
  if (!success) {
5446
5459
  setStatus(api.RemoteTaskStatus.Error);
@@ -5450,34 +5463,31 @@ const usePythonTask = () => {
5450
5463
  }
5451
5464
  const newSubscriptionId = await addSubscription({
5452
5465
  tag: "python_task_progress_event",
5453
- taskId: newTaskId,
5466
+ resourceId,
5454
5467
  });
5455
5468
  setTaskId(newTaskId);
5456
5469
  setSubscriptionId(newSubscriptionId);
5457
5470
  const onNotification = async ({ data }) => {
5458
5471
  if (data?.taskId === newTaskId) {
5472
+ const isFinished = [api.RemoteTaskStatus.Completed, api.RemoteTaskStatus.Error].includes(data.status);
5459
5473
  setStatus(data.status);
5460
5474
  setLog([logRef.current, data.log].filter(Boolean).join("\n"));
5461
5475
  setExecutionTime(Date.now() - start);
5462
5476
  setLoading(false);
5463
- setTaskId([api.RemoteTaskStatus.Completed, api.RemoteTaskStatus.Error].includes(data.status)
5464
- ? null
5465
- : newTaskId);
5466
- setSubscriptionId([api.RemoteTaskStatus.Completed, api.RemoteTaskStatus.Error].includes(data.status)
5467
- ? null
5468
- : newSubscriptionId);
5469
- if ([api.RemoteTaskStatus.Completed, api.RemoteTaskStatus.Error].includes(data.status)) {
5477
+ setTaskId(isFinished ? null : newTaskId);
5478
+ setSubscriptionId(isFinished ? null : newSubscriptionId);
5479
+ if (isFinished) {
5470
5480
  unsubscribeById(newSubscriptionId);
5471
5481
  connection.off(SERVER_NOTIFICATION_EVENT.PythonProgressNotification, onNotification);
5472
5482
  }
5473
5483
  if (data.status === api.RemoteTaskStatus.Completed) {
5474
5484
  const subTasks = await api$1.remoteTaskManager.get(newTaskId);
5475
- setResult(subTasks?.[0]?.results ?? null);
5485
+ setResult(subTasks?.[0]?.results?.response ?? null);
5476
5486
  }
5477
5487
  }
5478
5488
  };
5479
5489
  connection.on(SERVER_NOTIFICATION_EVENT.PythonProgressNotification, onNotification);
5480
- }, [reset, api$1.remoteTaskManager, addSubscription, connection, t, unsubscribeById]);
5490
+ }, [reset, api$1, preparePythonSandbox, addSubscription, connection, t, unsubscribeById]);
5481
5491
  const stopTask = React.useCallback(async () => {
5482
5492
  await api$1.remoteTaskManager.stop(taskId);
5483
5493
  reset();
@@ -12587,6 +12597,7 @@ exports.useMapContext = useMapContext;
12587
12597
  exports.useMapDraw = useMapDraw;
12588
12598
  exports.useMapImages = useMapImages;
12589
12599
  exports.useProjectDashboardInit = useProjectDashboardInit;
12600
+ exports.usePythonSandbox = usePythonSandbox;
12590
12601
  exports.usePythonTask = usePythonTask;
12591
12602
  exports.useRedrawLayer = useRedrawLayer;
12592
12603
  exports.useRelatedDataSourceAttributes = useRelatedDataSourceAttributes;