Skip to content

Commit edf4096

Browse files
committed
[UI] Run Wizard. Added docker, python and repos fields
1 parent 3458b14 commit edf4096

4 files changed

Lines changed: 27 additions & 15 deletions

File tree

frontend/src/locale/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,14 +481,14 @@
481481
"docker": "Docker",
482482
"docker_image": "Docker image",
483483
"docker_image_description": "The Docker image",
484-
"docker_image_placeholder": "Optional",
484+
"docker_image_placeholder": "Required",
485485
"python": "Python",
486486
"python_description": "Version of python",
487487
"python_placeholder": "Optional",
488488
"repo": "Repo",
489489
"repo_url": "URL",
490490
"repo_url_description": "Repository URL",
491-
"repo_url_placeholder": "Optional",
491+
"repo_url_placeholder": "Required",
492492
"repo_local_path": "Repo local path",
493493
"repo_local_path_description": "Repo local path name",
494494
"repo_local_path_placeholder": "Optional",

frontend/src/pages/Runs/CreateDevEnvironment/hooks/useGenerateYaml.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ export const useGenerateYaml = ({ formValues }: UseGenerateYamlArgs) => {
1515
return '';
1616
}
1717

18-
const { name, ide, image, python, offer, repo_url, repo_local_path } = formValues;
18+
const { name, ide, image, python, offer, docker, repo_url, repo_local_path } = formValues;
1919

2020
return jsYaml.dump({
2121
type: 'dev-environment',
2222
...(name ? { name } : {}),
2323
ide,
24-
...(image ? { docker: true, image } : {}),
24+
...(docker ? { docker } : {}),
25+
...(image ? { image } : {}),
2526
...(python ? { python } : {}),
2627

2728
resources: {

frontend/src/pages/Runs/CreateDevEnvironment/index.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { ROUTES } from 'routes';
1616
import { useApplyRunMutation } from 'services/run';
1717

1818
import { OfferList } from 'pages/Offers/List';
19-
import { convertMiBToGB, renderRange, round } from 'pages/Offers/List/helpers';
2019

2120
import { getRunSpecFromYaml } from './helpers/getRunSpecFromYaml';
2221
import { useGenerateYaml } from './hooks/useGenerateYaml';
@@ -27,6 +26,7 @@ import styles from './styles.module.scss';
2726

2827
const requiredFieldError = 'This is required field';
2928
const namesFieldError = 'Only latin characters, dashes, and digits';
29+
const urlFormatError = 'Only URLs';
3030

3131
const ideOptions = [
3232
{
@@ -49,6 +49,16 @@ const envValidationSchema = yup.object({
4949
name: yup.string().matches(/^[a-z][a-z0-9-]{1,40}$/, namesFieldError),
5050
ide: yup.string().required(requiredFieldError),
5151
config_yaml: yup.string().required(requiredFieldError),
52+
53+
image: yup.string().when('docker', {
54+
is: true,
55+
then: yup.string().required(requiredFieldError),
56+
}),
57+
58+
repo_url: yup.string().when('repo_enabled', {
59+
is: true,
60+
then: yup.string().url(urlFormatError).required(requiredFieldError),
61+
}),
5262
});
5363

5464
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -94,8 +104,6 @@ export const CreateDevEnvironment: React.FC = () => {
94104
const navigate = useNavigate();
95105
const [pushNotification] = useNotifications();
96106
const [activeStepIndex, setActiveStepIndex] = useState(0);
97-
const [isEnabledRepo, setIsEnabledRepo] = useState(false);
98-
const [activeTab, setActiveTab] = useState(DockerPythonTabs.DOCKER);
99107
const [selectedOffers, setSelectedOffers] = useState<IGpu[]>([]);
100108
const [selectedProject, setSelectedProject] = useState<IProject['project_name'] | null>(
101109
() => searchParams.get('project_name') ?? null,
@@ -121,6 +129,8 @@ export const CreateDevEnvironment: React.FC = () => {
121129
resolver,
122130
defaultValues: {
123131
ide: 'cursor',
132+
docker: true,
133+
repo_enabled: false,
124134
},
125135
});
126136
const { handleSubmit, control, trigger, setValue, watch, formState, getValues } = formMethods;
@@ -134,24 +144,22 @@ export const CreateDevEnvironment: React.FC = () => {
134144
return await trigger(['offer']);
135145
};
136146

137-
const validateName = async () => {
138-
return await trigger(['name', 'ide']);
147+
const validateSecondStep = async () => {
148+
return await trigger(['name', 'ide', 'docker', 'image', 'python', 'repo_enabled', 'repo_url', 'repo_local_path']);
139149
};
140150

141151
const validateConfig = async () => {
142152
return await trigger(['config_yaml']);
143153
};
144154

145-
const emptyValidator = async () => Promise.resolve(true);
146-
147155
const onNavigate = ({
148156
requestedStepIndex,
149157
reason,
150158
}: {
151159
requestedStepIndex: number;
152160
reason: WizardProps.NavigationReason;
153161
}) => {
154-
const stepValidators = [validateOffer, validateName, validateConfig, emptyValidator];
162+
const stepValidators = [validateOffer, validateSecondStep, validateConfig];
155163

156164
if (reason === 'next') {
157165
stepValidators[activeStepIndex]?.().then((isValid) => {
@@ -171,7 +179,7 @@ export const CreateDevEnvironment: React.FC = () => {
171179
};
172180

173181
const toggleRepo: ToggleProps['onChange'] = ({ detail }) => {
174-
setIsEnabledRepo(detail.checked);
182+
setValue('repo_enabled', detail.checked);
175183

176184
if (!detail.checked) {
177185
setValue('repo_url', '');
@@ -187,6 +195,8 @@ export const CreateDevEnvironment: React.FC = () => {
187195
if (detail.activeTabId === DockerPythonTabs.PYTHON) {
188196
setValue('image', '');
189197
}
198+
199+
setValue('docker', detail.activeTabId === DockerPythonTabs.DOCKER);
190200
};
191201

192202
const onChangeOffer: CardsProps<IGpu>['onSelectionChange'] = ({ detail }) => {
@@ -360,11 +370,11 @@ export const CreateDevEnvironment: React.FC = () => {
360370
]}
361371
/>
362372

363-
<Toggle checked={isEnabledRepo} onChange={toggleRepo}>
373+
<Toggle checked={!!formValues.repo_enabled} onChange={toggleRepo}>
364374
{t('runs.dev_env.wizard.repo')}
365375
</Toggle>
366376

367-
{isEnabledRepo && (
377+
{formValues.repo_enabled && (
368378
<>
369379
<FormInput
370380
label={t('runs.dev_env.wizard.repo_url')}

frontend/src/pages/Runs/CreateDevEnvironment/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface IRunEnvironmentFormValues {
66
docker: boolean;
77
image?: string;
88
python?: string;
9+
repo_enabled?: boolean;
910
repo_url?: string;
1011
repo_local_path?: string;
1112
}

0 commit comments

Comments
 (0)