diff --git a/README.md b/README.md index c83a30f..bed6197 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@
{runDetails.result}+ Model ID: {runDetails.model_id}
{runDetails.result}+ > + )} + {modelType !== 'optimization' && ( <> -
Name | diff --git a/src/components/RunModelModal/RunModelModal.jsx b/src/components/RunModelModal/RunModelModal.jsx index 36dbc53..0e57d25 100644 --- a/src/components/RunModelModal/RunModelModal.jsx +++ b/src/components/RunModelModal/RunModelModal.jsx @@ -1,6 +1,6 @@ // src/components/RunModelModal/RunModelModal.jsx -import React, { useState, useEffect, useCallback, useMemo } from 'react'; -import { Modal, Button, Form } from 'react-bootstrap'; +import React, { useState, useEffect, useCallback } from 'react'; +import { Modal, Button, Form, Alert } from 'react-bootstrap'; import axios from 'axios'; import { API_ENDPOINTS } from '../../config/config'; @@ -12,6 +12,7 @@ const RunModelModal = ({ show, handleClose, refreshModelRuns }) => { const [inputValues, setInputValues] = useState({}); const [file, setFile] = useState(null); const [fileError, setFileError] = useState(''); + const [formError, setFormError] = useState(''); const token = localStorage.getItem('token'); @@ -22,7 +23,12 @@ const RunModelModal = ({ show, handleClose, refreshModelRuns }) => { }); setModels(response.data); } catch (error) { - console.error('Error fetching models:', error); + const errorMessage = error.response?.data?.error; + setFormError( + Array.isArray(errorMessage) + ? errorMessage.map(err => err.msg).join(', ') + : errorMessage || 'Failed to load models. Please try again.' + ); } }, [token]); @@ -40,7 +46,12 @@ const RunModelModal = ({ show, handleClose, refreshModelRuns }) => { setFeatures(features); setModelType(type); } catch (error) { - console.error('Error fetching model details:', error); + const errorMessage = error.response?.data?.error; + setFormError( + Array.isArray(errorMessage) + ? errorMessage.map(err => err.msg).join(', ') + : errorMessage || 'Failed to load model details. Please try again.' + ); } } }, [selectedModel, token]); @@ -54,6 +65,7 @@ const RunModelModal = ({ show, handleClose, refreshModelRuns }) => { setInputValues({}); setFile(null); setFileError(''); + setFormError(''); }; const handleInputChange = (feature, event) => { @@ -105,7 +117,7 @@ const RunModelModal = ({ show, handleClose, refreshModelRuns }) => { model_id: selectedModel, input_features: features.map(feature => ({ name: feature.name, - value: inputValues[feature.name] == '0' ? 0 : (inputValues[feature.name] || '') + value: inputValues[feature.name] === '0' || inputValues[feature.name] === '0.0' ? 0 : (inputValues[feature.name] || '') })) }; headers['Content-Type'] = 'application/json'; @@ -125,10 +137,25 @@ const RunModelModal = ({ show, handleClose, refreshModelRuns }) => { handleClose(); refreshModelRuns(); } catch (error) { - console.error('Error running model:', error); + const errorMessage = error.response?.data?.error; + setFormError( + Array.isArray(errorMessage) + ? errorMessage.map(err => err.msg).join(', ') + : errorMessage || 'Failed to run the model. Please try again.' + ); } }; + useEffect(() => { + if (show) { + const params = new URLSearchParams(window.location.search); + const modelId = params.get('model_id'); + if (modelId && models.length > 0) { + setSelectedModel(modelId); + } + } + }, [show, models]); + return (
---|
handleSort('name')}>Name | -handleSort('type')}>Type | -handleSort('engine')}>Engine | -handleSort('created_at')}>Created At | +handleSort('name')}> + Name {getSortArrow('name')} + | +handleSort('type')}> + Type {getSortArrow('type')} + | +handleSort('engine')}> + Engine {getSortArrow('engine')} + | +handleSort('language')}> + Language {getSortArrow('language')} + | +handleSort('serialization')}> + Serialization {getSortArrow('serialization')} + | +handleSort('created_at')}> + Created On {getSortArrow('created_at')} + | {model.name} | {model.type} | {model.engine} | +{model.language} | +{model.serialization} | {new Date(model.created_at).toLocaleString()} | ))} -
---|
handleSort('model_name')}>Model Name | -handleSort('updatedAt')}>Updated At | -handleSort('duration')}>Duration (s) | -handleSort('state')}>State | +handleSort('model_name')}> + Model Name {getSortArrow('model_name')} + | +handleSort('model_type')}> + Type {getSortArrow('model_type')} + | +handleSort('model_engine')}> + Engine {getSortArrow('model_engine')} + | +handleSort('updatedAt')}> + Last Updated On {getSortArrow('updatedAt')} + | +handleSort('duration')}> + Duration {getSortArrow('duration')} + | +handleSort('state')}> + State {getSortArrow('state')} + |
---|---|---|---|---|---|---|---|---|---|
{run.model_name} | +{run.model_type} | +{run.model_engine} | {new Date(run.updatedAt).toLocaleString()} | -{Math.round((new Date(run.updatedAt) - new Date(run.createdAt)) / 1000)} | +{formatDuration(run.createdAt, run.updatedAt)} | {getStateIcon(run.state)} |