@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
package/dist/react.esm.js
CHANGED
|
@@ -4825,6 +4825,7 @@ const SERVER_NOTIFICATION_EVENT = {
|
|
|
4825
4825
|
const usePythonTask = () => {
|
|
4826
4826
|
const { api, t } = useGlobalContext();
|
|
4827
4827
|
const { addSubscription, connection, unsubscribeById } = useServerNotificationsContext();
|
|
4828
|
+
const [status, setStatus] = useState(RemoteTaskStatus.Unknown);
|
|
4828
4829
|
const [result, setResult] = useState(null);
|
|
4829
4830
|
const [error, setError] = useState(null);
|
|
4830
4831
|
const [loading, setLoading] = useState(false);
|
|
@@ -4832,15 +4833,18 @@ const usePythonTask = () => {
|
|
|
4832
4833
|
const [taskId, setTaskId] = useState(null);
|
|
4833
4834
|
const [subscriptionId, setSubscriptionId] = useState(null);
|
|
4834
4835
|
const reset = useCallback(() => {
|
|
4836
|
+
setStatus(RemoteTaskStatus.Unknown);
|
|
4835
4837
|
setResult(null);
|
|
4836
4838
|
setError(null);
|
|
4837
|
-
setLoading(
|
|
4839
|
+
setLoading(false);
|
|
4838
4840
|
setExecutionTime(null);
|
|
4839
4841
|
setTaskId(null);
|
|
4840
4842
|
setSubscriptionId(null);
|
|
4841
4843
|
}, []);
|
|
4842
4844
|
const runTask = useCallback(async ({ resourceId, parameters, script, fileName, methodName, }) => {
|
|
4843
4845
|
reset();
|
|
4846
|
+
setStatus(RemoteTaskStatus.Process);
|
|
4847
|
+
setLoading(true);
|
|
4844
4848
|
const start = Date.now();
|
|
4845
4849
|
let prototypeId = await api.remoteTaskManager.createTaskPrototype({
|
|
4846
4850
|
enabled: true,
|
|
@@ -4863,6 +4867,7 @@ const usePythonTask = () => {
|
|
|
4863
4867
|
prototypeId = prototypeId.replace(/["']+/g, "");
|
|
4864
4868
|
const { id: newTaskId, success } = await api.remoteTaskManager.startTask1(prototypeId);
|
|
4865
4869
|
if (!success) {
|
|
4870
|
+
setStatus(RemoteTaskStatus.Error);
|
|
4866
4871
|
setResult(t("taskRunFail", { ns: "devMode", defaultValue: "Не удалось запустить задачу" }));
|
|
4867
4872
|
setExecutionTime(Date.now() - start);
|
|
4868
4873
|
setLoading(false);
|
|
@@ -4875,6 +4880,7 @@ const usePythonTask = () => {
|
|
|
4875
4880
|
setSubscriptionId(newSubscriptionId);
|
|
4876
4881
|
const onNotification = ({ data }) => {
|
|
4877
4882
|
if (data?.taskId === newTaskId) {
|
|
4883
|
+
setStatus(data.status);
|
|
4878
4884
|
setResult(`${data ? `${data}\n` : ""}${data.log || ""}`);
|
|
4879
4885
|
setError(null);
|
|
4880
4886
|
setExecutionTime(Date.now() - start);
|
|
@@ -4898,7 +4904,7 @@ const usePythonTask = () => {
|
|
|
4898
4904
|
reset();
|
|
4899
4905
|
unsubscribeById(subscriptionId);
|
|
4900
4906
|
}, [api, reset, unsubscribeById, taskId, subscriptionId]);
|
|
4901
|
-
return { runTask, stopTask, result, error, loading, executionTime };
|
|
4907
|
+
return { taskId, runTask, stopTask, result, error, status, loading, executionTime };
|
|
4902
4908
|
};
|
|
4903
4909
|
|
|
4904
4910
|
const useAppHeight = () => {
|
|
@@ -6730,13 +6736,24 @@ const UploadContainer = memo(({ type, elementConfig, renderElement }) => {
|
|
|
6730
6736
|
return (jsxs(Fragment$1, { children: [jsx(ExpandableTitle, { elementConfig: elementConfig, type: type, renderElement: renderElement }), isVisible && renderElement({ id: "uploader", wrap: false })] }));
|
|
6731
6737
|
});
|
|
6732
6738
|
|
|
6739
|
+
const StatusWaitingButton = styled(WaitingButton) `
|
|
6740
|
+
${({ status = RemoteTaskStatus.Unknown, statusColors }) => !!statusColors?.[status] && css `
|
|
6741
|
+
transition: background-color ${transition.toggle};
|
|
6742
|
+
background-color: ${statusColors[status]};
|
|
6743
|
+
|
|
6744
|
+
:hover {
|
|
6745
|
+
background-color: ${statusColors[status]};
|
|
6746
|
+
}
|
|
6747
|
+
`}
|
|
6748
|
+
`;
|
|
6749
|
+
|
|
6733
6750
|
const TaskContainer = memo(({ type, elementConfig }) => {
|
|
6734
6751
|
const { t, ewktGeometry } = useGlobalContext();
|
|
6735
6752
|
const { dataSources, filters: selectedFilters } = useWidgetContext(type);
|
|
6736
6753
|
const { currentPage } = useWidgetPage(type);
|
|
6737
|
-
const { runTask, loading } = usePythonTask();
|
|
6754
|
+
const { taskId, runTask, stopTask, status, loading } = usePythonTask();
|
|
6738
6755
|
const { options } = elementConfig || {};
|
|
6739
|
-
const { title, relatedResources, center, icon } = options || {};
|
|
6756
|
+
const { title, relatedResources, center, icon, statusColors } = options || {};
|
|
6740
6757
|
const onClick = useCallback(async () => {
|
|
6741
6758
|
await Promise.all(relatedResources.map(({ resourceId, parameters, script, fileName, methodName }) => {
|
|
6742
6759
|
const newParams = applyQueryFilters({
|
|
@@ -6749,7 +6766,7 @@ const TaskContainer = memo(({ type, elementConfig }) => {
|
|
|
6749
6766
|
return runTask({ resourceId, parameters: newParams, script, fileName, methodName });
|
|
6750
6767
|
}));
|
|
6751
6768
|
}, [currentPage.filters, dataSources, ewktGeometry, relatedResources, runTask, selectedFilters]);
|
|
6752
|
-
return (
|
|
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 }))] }));
|
|
6753
6770
|
});
|
|
6754
6771
|
|
|
6755
6772
|
const containerComponents = {
|