@evergis/react 3.1.65 → 3.1.66
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/styled.d.ts +5 -0
- package/dist/components/Dashboard/types.d.ts +3 -2
- package/dist/hooks/task/usePythonTask.d.ts +3 -0
- package/dist/index.js +22 -5
- package/dist/index.js.map +1 -1
- package/dist/react.esm.js +22 -5
- package/dist/react.esm.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RemoteTaskStatus } from '@evergis/api';
|
|
2
|
+
export declare const StatusWaitingButton: import('styled-components').StyledComponent<import('react').FC<import('@evergis/uilib-gl').IWaitingButton>, any, {
|
|
3
|
+
status?: RemoteTaskStatus;
|
|
4
|
+
statusColors?: Record<RemoteTaskStatus, string>;
|
|
5
|
+
}, never>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { CSSProperties, FC, ReactNode } from 'react';
|
|
2
2
|
import { Projection } from 'mapbox-gl';
|
|
3
|
-
import {
|
|
3
|
+
import { i18n } from 'i18next';
|
|
4
|
+
import { AttributeDefinitionDc, AttributeFormatDefinitionDc, AttributeType, EqlRequestDc, FeatureDc, GeometryType, PagedFeaturesListDc, PositionDc, RemoteTaskStatus, StringSubType } from '@evergis/api';
|
|
4
5
|
import { PieChartData, BarChartMarker } from '@evergis/charts';
|
|
5
6
|
import { IOption } from '@evergis/uilib-gl';
|
|
6
7
|
import { FeatureAttributeValue, EditGeometryType, LayerInfo, ThemeName } from '../../types';
|
|
7
8
|
import { InnerContainerProps } from './containers/DataSourceInnerContainer/types';
|
|
8
|
-
import { i18n } from 'i18next';
|
|
9
9
|
export interface DashboardsProps {
|
|
10
10
|
zIndex?: CSSProperties["zIndex"];
|
|
11
11
|
}
|
|
@@ -46,6 +46,7 @@ export interface ConfigOptions {
|
|
|
46
46
|
relatedDataSources?: ConfigRelatedDataSource[];
|
|
47
47
|
relatedAttributes?: ConfigRelatedAttribute[];
|
|
48
48
|
relatedResources?: ConfigRelatedResource[];
|
|
49
|
+
statusColors?: Record<RemoteTaskStatus, string>;
|
|
49
50
|
chartType?: "bar" | "line" | "pie" | "stack";
|
|
50
51
|
layerNames?: string[];
|
|
51
52
|
layerName?: string;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { RemoteTaskStatus } from '@evergis/api';
|
|
1
2
|
export declare const usePythonTask: () => {
|
|
3
|
+
taskId: string;
|
|
2
4
|
runTask: ({ resourceId, parameters, script, fileName, methodName, }: {
|
|
3
5
|
resourceId: string;
|
|
4
6
|
parameters: Record<string, unknown>;
|
|
@@ -9,6 +11,7 @@ export declare const usePythonTask: () => {
|
|
|
9
11
|
stopTask: () => Promise<void>;
|
|
10
12
|
result: string;
|
|
11
13
|
error: Error;
|
|
14
|
+
status: RemoteTaskStatus;
|
|
12
15
|
loading: boolean;
|
|
13
16
|
executionTime: number;
|
|
14
17
|
};
|
package/dist/index.js
CHANGED
|
@@ -4827,6 +4827,7 @@ const SERVER_NOTIFICATION_EVENT = {
|
|
|
4827
4827
|
const usePythonTask = () => {
|
|
4828
4828
|
const { api: api$1, t } = useGlobalContext();
|
|
4829
4829
|
const { addSubscription, connection, unsubscribeById } = useServerNotificationsContext();
|
|
4830
|
+
const [status, setStatus] = React.useState(api.RemoteTaskStatus.Unknown);
|
|
4830
4831
|
const [result, setResult] = React.useState(null);
|
|
4831
4832
|
const [error, setError] = React.useState(null);
|
|
4832
4833
|
const [loading, setLoading] = React.useState(false);
|
|
@@ -4834,15 +4835,18 @@ const usePythonTask = () => {
|
|
|
4834
4835
|
const [taskId, setTaskId] = React.useState(null);
|
|
4835
4836
|
const [subscriptionId, setSubscriptionId] = React.useState(null);
|
|
4836
4837
|
const reset = React.useCallback(() => {
|
|
4838
|
+
setStatus(api.RemoteTaskStatus.Unknown);
|
|
4837
4839
|
setResult(null);
|
|
4838
4840
|
setError(null);
|
|
4839
|
-
setLoading(
|
|
4841
|
+
setLoading(false);
|
|
4840
4842
|
setExecutionTime(null);
|
|
4841
4843
|
setTaskId(null);
|
|
4842
4844
|
setSubscriptionId(null);
|
|
4843
4845
|
}, []);
|
|
4844
4846
|
const runTask = React.useCallback(async ({ resourceId, parameters, script, fileName, methodName, }) => {
|
|
4845
4847
|
reset();
|
|
4848
|
+
setStatus(api.RemoteTaskStatus.Process);
|
|
4849
|
+
setLoading(true);
|
|
4846
4850
|
const start = Date.now();
|
|
4847
4851
|
let prototypeId = await api$1.remoteTaskManager.createTaskPrototype({
|
|
4848
4852
|
enabled: true,
|
|
@@ -4865,6 +4869,7 @@ const usePythonTask = () => {
|
|
|
4865
4869
|
prototypeId = prototypeId.replace(/["']+/g, "");
|
|
4866
4870
|
const { id: newTaskId, success } = await api$1.remoteTaskManager.startTask1(prototypeId);
|
|
4867
4871
|
if (!success) {
|
|
4872
|
+
setStatus(api.RemoteTaskStatus.Error);
|
|
4868
4873
|
setResult(t("taskRunFail", { ns: "devMode", defaultValue: "Не удалось запустить задачу" }));
|
|
4869
4874
|
setExecutionTime(Date.now() - start);
|
|
4870
4875
|
setLoading(false);
|
|
@@ -4877,6 +4882,7 @@ const usePythonTask = () => {
|
|
|
4877
4882
|
setSubscriptionId(newSubscriptionId);
|
|
4878
4883
|
const onNotification = ({ data }) => {
|
|
4879
4884
|
if (data?.taskId === newTaskId) {
|
|
4885
|
+
setStatus(data.status);
|
|
4880
4886
|
setResult(`${data ? `${data}\n` : ""}${data.log || ""}`);
|
|
4881
4887
|
setError(null);
|
|
4882
4888
|
setExecutionTime(Date.now() - start);
|
|
@@ -4900,7 +4906,7 @@ const usePythonTask = () => {
|
|
|
4900
4906
|
reset();
|
|
4901
4907
|
unsubscribeById(subscriptionId);
|
|
4902
4908
|
}, [api$1, reset, unsubscribeById, taskId, subscriptionId]);
|
|
4903
|
-
return { runTask, stopTask, result, error, loading, executionTime };
|
|
4909
|
+
return { taskId, runTask, stopTask, result, error, status, loading, executionTime };
|
|
4904
4910
|
};
|
|
4905
4911
|
|
|
4906
4912
|
const useAppHeight = () => {
|
|
@@ -6732,13 +6738,24 @@ const UploadContainer = React.memo(({ type, elementConfig, renderElement }) => {
|
|
|
6732
6738
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(ExpandableTitle, { elementConfig: elementConfig, type: type, renderElement: renderElement }), isVisible && renderElement({ id: "uploader", wrap: false })] }));
|
|
6733
6739
|
});
|
|
6734
6740
|
|
|
6741
|
+
const StatusWaitingButton = styled(uilibGl.WaitingButton) `
|
|
6742
|
+
${({ status = api.RemoteTaskStatus.Unknown, statusColors }) => !!statusColors?.[status] && styled.css `
|
|
6743
|
+
transition: background-color ${uilibGl.transition.toggle};
|
|
6744
|
+
background-color: ${statusColors[status]};
|
|
6745
|
+
|
|
6746
|
+
:hover {
|
|
6747
|
+
background-color: ${statusColors[status]};
|
|
6748
|
+
}
|
|
6749
|
+
`}
|
|
6750
|
+
`;
|
|
6751
|
+
|
|
6735
6752
|
const TaskContainer = React.memo(({ type, elementConfig }) => {
|
|
6736
6753
|
const { t, ewktGeometry } = useGlobalContext();
|
|
6737
6754
|
const { dataSources, filters: selectedFilters } = useWidgetContext(type);
|
|
6738
6755
|
const { currentPage } = useWidgetPage(type);
|
|
6739
|
-
const { runTask, loading } = usePythonTask();
|
|
6756
|
+
const { taskId, runTask, stopTask, status, loading } = usePythonTask();
|
|
6740
6757
|
const { options } = elementConfig || {};
|
|
6741
|
-
const { title, relatedResources, center, icon } = options || {};
|
|
6758
|
+
const { title, relatedResources, center, icon, statusColors } = options || {};
|
|
6742
6759
|
const onClick = React.useCallback(async () => {
|
|
6743
6760
|
await Promise.all(relatedResources.map(({ resourceId, parameters, script, fileName, methodName }) => {
|
|
6744
6761
|
const newParams = applyQueryFilters({
|
|
@@ -6751,7 +6768,7 @@ const TaskContainer = React.memo(({ type, elementConfig }) => {
|
|
|
6751
6768
|
return runTask({ resourceId, parameters: newParams, script, fileName, methodName });
|
|
6752
6769
|
}));
|
|
6753
6770
|
}, [currentPage.filters, dataSources, ewktGeometry, relatedResources, runTask, selectedFilters]);
|
|
6754
|
-
return (jsxRuntime.
|
|
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 }))] }));
|
|
6755
6772
|
});
|
|
6756
6773
|
|
|
6757
6774
|
const containerComponents = {
|