Skip to content

Commit

Permalink
merge from 'main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ch3yne committed Jan 8, 2024
1 parent a4cac06 commit 981e21c
Showing 1 changed file with 45 additions and 17 deletions.
62 changes: 45 additions & 17 deletions web/app/metalakes/CreateCatalogDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ const CreateCatalogDialog = props => {
reset,
watch,
setValue,
getValues,
handleSubmit,
trigger,
formState: { errors }
} = useForm({
defaultValues,
mode: 'onChange',
mode: 'all',
resolver: yupResolver(schema)
})

Expand Down Expand Up @@ -146,43 +148,69 @@ const CreateCatalogDialog = props => {
setOpen(false)
}

const handleClickSubmit = e => {
e.preventDefault()

return handleSubmit(onSubmit(getValues()), onError)
}

const onSubmit = data => {
const { propItems, ...mainData } = data

const properties = innerProps.reduce((acc, item) => {
acc[item.key] = item.value
let nextProps = []

return acc
}, {})

const catalogData = {
...mainData,
properties
if (propItems[0]?.key === 'catalog-backend' && propItems[0]?.value === 'hive') {
nextProps = propItems.slice(0, 3)
} else {
nextProps = propItems
}

if (type === 'create') {
dispatch(createCatalog({ data: catalogData, metalake }))
}
trigger()

const validData = { propItems: nextProps, ...mainData }

schema
.validate(validData)
.then(() => {
const properties = innerProps.reduce((acc, item) => {
acc[item.key] = item.value

return acc
}, {})

const catalogData = {
...mainData,
properties
}

if (type === 'create') {
dispatch(createCatalog({ data: catalogData, metalake }))
}

handleClose()
handleClose()
})
.catch(err => {
console.error('valid error', err)
})
}

const onError = errors => {
console.error('fields error', errors)
}

useEffect(() => {
const providerItemIndex = providers.findIndex(i => i.value === providerSelect)

let defaultProps = []

const providerItemIndex = providers.findIndex(i => i.value === providerSelect)

if (providerItemIndex !== -1) {
defaultProps = providers[providerItemIndex].defaultProps

resetPropsFields(providers, providerItemIndex)
setInnerProps(defaultProps)
setValue('propItems', providers[providerItemIndex].defaultProps)
}
}, [providerSelect, setInnerProps])
}, [providerSelect, setInnerProps, setValue])

useEffect(() => {
if (open && JSON.stringify(data) !== '{}') {
Expand All @@ -205,7 +233,7 @@ const CreateCatalogDialog = props => {

return (
<Dialog fullWidth maxWidth='sm' scroll='body' TransitionComponent={Transition} open={open} onClose={handleClose}>
<form onSubmit={handleSubmit(onSubmit, onError)}>
<form onSubmit={e => handleClickSubmit(e)}>
<DialogContent
sx={{
position: 'relative',
Expand Down

0 comments on commit 981e21c

Please sign in to comment.