Skip to content

Commit ead8601

Browse files
committed
Refactoring after review
1 parent e8a5661 commit ead8601

5 files changed

Lines changed: 30 additions & 22 deletions

File tree

frontend/src/pages/Fleets/Add/index.tsx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import React, { useState } from 'react';
22
import { useForm } from 'react-hook-form';
33
import { useTranslation } from 'react-i18next';
4-
import { useNavigate } from 'react-router-dom';
4+
import { useNavigate, useParams } from 'react-router-dom';
55
import { isNil } from 'lodash';
66
import * as yup from 'yup';
77
import { WizardProps } from '@cloudscape-design/components';
88

9-
import { Container, FormSelect, KeyValuePairs, SpaceBetween, Wizard } from 'components';
9+
import { Container, FormInput, InfoLink, KeyValuePairs, SpaceBetween, Wizard } from 'components';
1010

11-
import { useBreadcrumbs, useConfirmationDialog, useNotifications } from 'hooks';
12-
import { useProjectFilter } from 'hooks/useProjectFilter';
11+
import { useBreadcrumbs, useConfirmationDialog, useHelpPanel, useNotifications } from 'hooks';
1312
import { ROUTES } from 'routes';
1413
import { useApplyFleetMutation } from 'services/fleet';
1514

15+
import { DEFAULT_FLEET_INFO } from 'pages/Project/constants';
1616
import { useYupValidationResolver } from 'pages/Project/hooks/useYupValidationResolver';
1717

1818
import { getMaxInstancesValidator, getMinInstancesValidator, idleDurationValidator } from './FleetFormFields/constants';
@@ -38,18 +38,21 @@ const fleetValidationSchema = yup.object({
3838
export const FleetAdd: React.FC = () => {
3939
const { t } = useTranslation();
4040
const navigate = useNavigate();
41+
const params = useParams();
42+
const paramProjectName = params.projectName ?? '';
43+
const [openHelpPanel] = useHelpPanel();
4144
const [pushNotification] = useNotifications();
4245
const [openConfirmationDialog] = useConfirmationDialog();
4346
const [applyFleet, { isLoading: isApplyingFleet }] = useApplyFleetMutation();
4447
const [activeStepIndex, setActiveStepIndex] = useState(0);
4548
const resolver = useYupValidationResolver(fleetValidationSchema);
46-
const { projectOptions } = useProjectFilter({ localStorePrefix: 'add-fleet-page' });
4749

4850
const loading = isApplyingFleet;
4951

5052
const formMethods = useForm<IFleetWizardForm>({
5153
resolver,
5254
defaultValues: {
55+
project_name: paramProjectName,
5356
min_instances: 0,
5457
idle_duration: '5m',
5558
},
@@ -80,14 +83,21 @@ export const FleetAdd: React.FC = () => {
8083
};
8184

8285
useBreadcrumbs([
86+
{
87+
text: t('navigation.project_other'),
88+
href: ROUTES.PROJECT.LIST,
89+
},
90+
{
91+
text: paramProjectName,
92+
href: ROUTES.PROJECT.DETAILS.FORMAT(paramProjectName),
93+
},
8394
{
8495
text: t('navigation.fleets'),
8596
href: ROUTES.FLEETS.LIST,
8697
},
87-
8898
{
8999
text: t('common.create_wit_text', { text: t('navigation.fleet') }),
90-
href: ROUTES.FLEETS.ADD,
100+
href: ROUTES.FLEETS.ADD.FORMAT(paramProjectName),
91101
},
92102
]);
93103

@@ -214,19 +224,20 @@ export const FleetAdd: React.FC = () => {
214224
content: (
215225
<Container>
216226
<SpaceBetween direction="vertical" size="l">
217-
<FormSelect
227+
<FormInput
218228
label={t('projects.edit.project_name')}
219229
control={control}
220230
name="project_name"
221-
options={projectOptions}
231+
readOnly
222232
disabled={loading}
223233
/>
224234
</SpaceBetween>
225235
</Container>
226236
),
227237
},
228238
{
229-
title: 'Fleets',
239+
title: 'Settings',
240+
info: <InfoLink onFollow={() => openHelpPanel(DEFAULT_FLEET_INFO)} />,
230241
content: (
231242
<Container>
232243
<SpaceBetween direction="vertical" size="l">

frontend/src/pages/Fleets/List/index.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import { useTranslation } from 'react-i18next';
3-
import { useNavigate } from 'react-router-dom';
43

54
import { Button, Header, Loader, PropertyFilter, SpaceBetween, Table, Toggle } from 'components';
65

@@ -19,7 +18,6 @@ import styles from './styles.module.scss';
1918

2019
export const FleetList: React.FC = () => {
2120
const { t } = useTranslation();
22-
const navigate = useNavigate();
2321

2422
useBreadcrumbs([
2523
{
@@ -68,10 +66,6 @@ export const FleetList: React.FC = () => {
6866

6967
const isDisabledDeleteButton = !selectedItems?.length || isDeleting;
7068

71-
const addFleetHandler = () => {
72-
navigate(ROUTES.FLEETS.ADD);
73-
};
74-
7569
const deleteClickHandle = () => {
7670
if (!selectedItems?.length) return;
7771

@@ -107,8 +101,6 @@ export const FleetList: React.FC = () => {
107101
{t('common.delete')}
108102
</Button>
109103

110-
<Button onClick={addFleetHandler}>{t('common.create')}</Button>
111-
112104
<Button
113105
iconName="refresh"
114106
disabled={isLoading}

frontend/src/pages/Project/components/NoFleetProjectAlert/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React from 'react';
22
import { useTranslation } from 'react-i18next';
3+
import { useNavigate } from 'react-router-dom';
34
import cn from 'classnames';
45

56
import type { ButtonProps } from 'components';
67
import { Alert, AlertProps, Button } from 'components';
78

89
import { useLocalStorageState } from 'hooks/useLocalStorageState';
9-
import { goToUrl } from 'libs';
10+
import { ROUTES } from 'routes';
1011

1112
import styles from './styles.module.scss';
1213

@@ -19,11 +20,12 @@ type NoFleetProjectAlertProps = {
1920

2021
export const NoFleetProjectAlert: React.FC<NoFleetProjectAlertProps> = ({ projectName, show, className, dismissible }) => {
2122
const { t } = useTranslation();
23+
const navigate = useNavigate();
2224
const [dontShowAgain, setDontShowAgain] = useLocalStorageState(`noFleetProjectAlert-${projectName}`, false);
2325

2426
const onCreateAFleet: ButtonProps['onClick'] = (event) => {
2527
event.preventDefault();
26-
goToUrl('https://dstack.ai/docs/quickstart/#create-a-fleet', true);
28+
navigate(ROUTES.FLEETS.ADD.FORMAT(projectName));
2729
};
2830

2931
const onDismiss: AlertProps['onDismiss'] = () => setDontShowAgain(true);

frontend/src/router.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export const router = createBrowserRouter([
203203
element: <FleetList />,
204204
},
205205
{
206-
path: ROUTES.FLEETS.ADD,
206+
path: ROUTES.FLEETS.ADD.TEMPLATE,
207207
element: <FleetAdd />,
208208
},
209209
{

frontend/src/routes.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ export const ROUTES = {
137137

138138
FLEETS: {
139139
LIST: '/fleets',
140-
ADD: '/fleets/add',
140+
ADD: {
141+
TEMPLATE: `/projects/:projectName/fleets/add`,
142+
FORMAT: (projectName: string) => buildRoute(ROUTES.FLEETS.ADD.TEMPLATE, { projectName }),
143+
},
141144
DETAILS: {
142145
TEMPLATE: `/projects/:projectName/fleets/:fleetId`,
143146
FORMAT: (projectName: string, fleetId: string) =>

0 commit comments

Comments
 (0)