From 947be4f93c981f65d701c035687119b5e0bea61e Mon Sep 17 00:00:00 2001 From: Marina Fedyantceva Date: Wed, 20 Nov 2024 14:14:10 +0300 Subject: [PATCH 1/5] [SPT-738] added get status for model --- src/Redux/reducers/ServiceTrainingReducer.js | 15 +++++- .../ExistingModel/ModelDetails/index.js | 51 +++++++++++++------ .../ExistingModel/ModelDetails/styles.js | 6 ++- 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/Redux/reducers/ServiceTrainingReducer.js b/src/Redux/reducers/ServiceTrainingReducer.js index aec78934..26e39be8 100644 --- a/src/Redux/reducers/ServiceTrainingReducer.js +++ b/src/Redux/reducers/ServiceTrainingReducer.js @@ -1,5 +1,13 @@ import { serviceTrainingActions } from "../actionCreators"; +export const modelStatus = { + IN_PROGRESS: "IN_PROGRESS", + COMPLETED: "COMPLETED", + CREATED: "CREATED", + ERRORED: "ERRORED", + DELETED: "DELETED", +}; + const currentModellInitialState = { modelId: "", methodName: "", @@ -15,7 +23,7 @@ const currentModellInitialState = { const trainingModelInitialState = { currentModel: currentModellInitialState, - modelsList: [], + modelsList: undefined, }; const serviceTrainingReducer = (state = trainingModelInitialState, action) => { @@ -23,12 +31,15 @@ const serviceTrainingReducer = (state = trainingModelInitialState, action) => { case serviceTrainingActions.SET_MODEL_DETAILS: { return { ...state, currentModel: action.payload }; } - case serviceTrainingActions.CLEAN_MODEL_DETAILS: { + case serviceTrainingActions.RESET_MODEL_DETAILS: { return { ...state, currentModel: currentModellInitialState }; } case serviceTrainingActions.SET_MODELS_LIST: { return { ...state, modelsList: action.payload }; } + case serviceTrainingActions.RESET_MODEL_LIST: { + return { ...state, modelsList: trainingModelInitialState.modelsList }; + } default: { return state; } diff --git a/src/components/ServiceDetails/ExistingModel/ModelDetails/index.js b/src/components/ServiceDetails/ExistingModel/ModelDetails/index.js index eb43bba0..a1dea6a5 100644 --- a/src/components/ServiceDetails/ExistingModel/ModelDetails/index.js +++ b/src/components/ServiceDetails/ExistingModel/ModelDetails/index.js @@ -1,5 +1,5 @@ import React, { useState } from "react"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { withStyles } from "@mui/styles"; import { useStyles } from "./styles"; @@ -7,27 +7,25 @@ import { useStyles } from "./styles"; import Button from "@mui/material/Button"; // import EditIcon from "@mui/icons-material/Edit"; import DeleteIcon from "@mui/icons-material/Delete"; -import NearMeOutlinedIcon from "@mui/icons-material/NearMeOutlined"; import Box from "@mui/material/Box"; import Typography from "@mui/material/Typography"; import Modal from "@mui/material/Modal"; import StyledButton from "../../../common/StyledButton"; -import { setCurrentModelDetails, deleteModel } from "../../../../Redux/actionCreators/ServiceTrainingActions"; +import { + setCurrentModelDetails, + deleteModel, + getTrainingModelStatus, + setModelsList, +} from "../../../../Redux/actionCreators/ServiceTrainingActions"; import { useLocation, useNavigate, useParams } from "react-router-dom"; - -export const modelStatus = { - IN_PROGRESS: "IN_PROGRESS", - COMPLETED: "COMPLETED", - CREATED: "CREATED", - ERRORED: "ERRORED", - DELETED: "DELETED", -}; +import { modelStatus } from "../../../../Redux/reducers/ServiceTrainingReducer"; const ModelDetails = ({ classes, openEditModel, model, address }) => { const dispatch = useDispatch(); const navigate = useNavigate(); const location = useLocation(); + const { modelsList } = useSelector((state) => state.serviceTrainingReducer); const { orgId, serviceId } = useParams(); const [open, setOpen] = useState(false); @@ -51,6 +49,27 @@ const ModelDetails = ({ classes, openEditModel, model, address }) => { navigate(location.pathname.split("tab/")[0] + "tab/" + 0); //TODO }; + const handleGetModelStatus = async () => { + const getModelStatusParams = { + organizationId: orgId, + serviceId, + modelId: model.modelId, + name: model.serviceName, + method: model.methodName, + address, + }; + + const newModelStatus = await dispatch(getTrainingModelStatus(getModelStatusParams)); + const updatedModelList = modelsList.map((modelBeforeUpdating) => { + let modelForUpdating = modelBeforeUpdating; + if (modelForUpdating.modelId === model.modelId) { + modelForUpdating.status = newModelStatus; + } + return modelForUpdating; + }); + await dispatch(setModelsList(updatedModelList)); + }; + return ( <>
@@ -80,11 +99,11 @@ const ModelDetails = ({ classes, openEditModel, model, address }) => {
- -
+
+ + +
+
{/*