Skip to content

Commit cdfbdc8

Browse files
Merge branch 'main' into adjust-dependabot
2 parents ecd003b + 830783a commit cdfbdc8

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

src/pages/services/create-edit/index.tsx

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable dot-notation */
2-
import { Box, Button, Divider, Grid } from '@mui/material'
2+
import { Box, Divider, Grid } from '@mui/material'
33
import { LandingHeader } from 'components/LandingHeader'
44
import PaperLayout from 'layouts/Paper'
55
import React, { useEffect, useMemo, useState } from 'react'
@@ -27,11 +27,12 @@ import { MenuItem } from 'components/List'
2727
import { Typography } from 'components/Typography'
2828
import KeyValue from 'components/forms/KeyValue'
2929
import ControlledCheckbox from 'components/forms/ControlledCheckbox'
30-
import { isEmpty } from 'lodash'
30+
import { cloneDeep, isEmpty, isEqual } from 'lodash'
3131
import LinkedNumberField from 'components/forms/LinkedNumberField'
3232
import AdvancedSettings from 'components/AdvancedSettings'
3333
import font from 'theme/font'
3434
import { Autocomplete } from 'components/forms/Autocomplete'
35+
import { LoadingButton } from '@mui/lab'
3536
import { useStyles } from './create-edit.styles'
3637
import { serviceApiResponseSchema } from './create-edit.validator'
3738

@@ -143,6 +144,8 @@ export default function ({
143144
if (path.includes('/')) setValue(`spec.paths.${index}`, path.replace(/^\/+/, ''))
144145
})
145146
}
147+
148+
if (teamId !== 'admin' && !serviceName) setValue('spec.namespace', `team-${teamId}`)
146149
}, [data, setValue])
147150

148151
useEffect(() => {
@@ -181,17 +184,20 @@ export default function ({
181184
}
182185
}
183186
const onSubmit = (submitData: CreateAplServiceApiResponse) => {
184-
if (!isEmpty(submitData.spec?.paths)) {
185-
submitData.spec?.paths.forEach((path, index) => {
186-
submitData.spec.paths[index] = `/${path}`
187+
const body = cloneDeep(submitData)
188+
if (!isEmpty(body.spec?.paths)) {
189+
body.spec?.paths.forEach((path, index) => {
190+
body.spec.paths[index] = `/${path}`
187191
})
188192
}
189-
if (submitData.spec?.cname?.tlsSecretName === '') submitData.spec.cname.tlsSecretName = undefined
190-
if (submitData.spec?.ingressClassName === '') submitData.spec.ingressClassName = undefined
191-
if (isPreInstalled) submitData.spec.ingressClassName = 'platform'
192-
// eslint-disable-next-line object-shorthand
193-
if (serviceName) update({ teamId, serviceName: serviceName, body: submitData })
194-
else create({ teamId, body: submitData })
193+
if (body.spec?.cname?.tlsSecretName === '') {
194+
body.spec.cname.tlsSecretName = undefined
195+
body.spec.useCname = false
196+
} else if (body.spec?.cname?.tlsSecretName) body.spec.useCname = true
197+
198+
if (body.spec?.ingressClassName === '') body.spec.ingressClassName = undefined
199+
if (serviceName) update({ teamId, serviceName, body })
200+
else create({ teamId, body })
195201
}
196202
const mutating = isLoadingCreate || isLoadingUpdate || isLoadingDelete
197203
if (!mutating && (isSuccessCreate || isSuccessUpdate || isSuccessDelete))
@@ -202,7 +208,7 @@ export default function ({
202208
const error = isError || isErrorK8sServices || isErrorTeamSecrets || isErrorSettingsInfo
203209

204210
if (loading || fetching) return <PaperLayout loading title={t('TITLE_SERVICE')} />
205-
if (teamId !== 'admin') setValue('spec.namespace', `team-${teamId}`)
211+
206212
return (
207213
<Grid className={classes.root}>
208214
<PaperLayout loading={loading || error} title={t('TITLE_SERVICE')}>
@@ -454,17 +460,20 @@ export default function ({
454460
resourceType='service'
455461
data-cy='button-delete-service'
456462
sx={{ marginRight: '10px', textTransform: 'capitalize', ml: 2 }}
463+
loading={isLoadingDelete}
464+
disabled={isLoadingDelete || isLoadingCreate || isLoadingUpdate}
457465
/>
458466
)}
459-
<Button
460-
disabled={isEmpty(service)}
467+
<LoadingButton
461468
type='submit'
462469
variant='contained'
463470
color='primary'
464471
sx={{ textTransform: 'none' }}
472+
loading={isLoadingCreate || isLoadingUpdate}
473+
disabled={isLoadingCreate || isLoadingUpdate || isLoadingDelete || isEqual(watch(), data)}
465474
>
466475
{serviceName ? 'Save Changes' : 'Create Service'}
467-
</Button>
476+
</LoadingButton>
468477
</Box>
469478
</form>
470479
</FormProvider>

0 commit comments

Comments
 (0)