Unverified Commit 0ad73ef0 authored by Lijiaoa's avatar Lijiaoa Committed by GitHub
Browse files

[fix issue#4015] webui prompts error message if user set maxExperimentDuration...

[fix issue#4015] webui prompts error message if user set maxExperimentDuration < execDuration (#4164)
parent 8875fa77
...@@ -2,6 +2,7 @@ import React, { useState, useCallback, useContext } from 'react'; ...@@ -2,6 +2,7 @@ import React, { useState, useCallback, useContext } from 'react';
import axios from 'axios'; import axios from 'axios';
import { Dropdown } from '@fluentui/react'; import { Dropdown } from '@fluentui/react';
import { EXPERIMENT } from '../../../static/datamodel'; import { EXPERIMENT } from '../../../static/datamodel';
import { toSeconds } from '../../../static/experimentConfig';
import { AppContext } from '../../../App'; import { AppContext } from '../../../App';
import { EditExpeParamContext } from './context'; import { EditExpeParamContext } from './context';
import { durationUnit } from '../overviewConst'; import { durationUnit } from '../overviewConst';
...@@ -63,20 +64,32 @@ export const EditExperimentParam = (): any => { ...@@ -63,20 +64,32 @@ export const EditExperimentParam = (): any => {
} }
} }
function promptErrorMessage(mess: string, type: string, value: string): void {
showMessageInfo(mess, type);
setEditValInput(value);
}
async function confirmEdit(): Promise<void> { async function confirmEdit(): Promise<void> {
const isMaxDuration = title === 'Max duration'; const isMaxDuration = title === 'Max duration';
const newProfile = Object.assign({}, EXPERIMENT.profile); const newProfile = Object.assign({}, EXPERIMENT.profile);
let beforeParam = ''; let beforeParam = '';
if (isMaxDuration) { if (isMaxDuration) {
if (!editInputVal.match(/^\d+(?=\.{0,1}\d+$|$)/)) { if (!editInputVal.match(/^\d+(?=\.{0,1}\d+$|$)/)) {
showMessageInfo('Please enter a number!', 'error'); promptErrorMessage('Please enter a number!', 'error', defaultVal);
setEditValInput(defaultVal); return;
}
if (toSeconds(`${editInputVal}${unit}`) < EXPERIMENT.profile.execDuration) {
// maxDuration should > current run time(execDuration)
promptErrorMessage(
'Please input a valid value. (Current duration is more than the number you input.)',
'error',
defaultVal
);
return; return;
} }
} else { } else {
if (!editInputVal.match(/^[1-9]\d*$/)) { if (!editInputVal.match(/^[1-9]\d*$/)) {
showMessageInfo('Please enter a positive integer!', 'error'); promptErrorMessage('Please enter a positive integer!', 'error', defaultVal);
setEditValInput(defaultVal);
return; return;
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment