mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-22 20:54:49 +09:00
1 parent
099a3dbbd3
commit
280875068e
17 files changed
+792
-95
No files matched your search
@@ -0,0 +1,100 @@
|
||||
import React, { memo } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import clsx from 'clsx'
|
||||
import {
|
||||
makeStyles,
|
||||
Fade,
|
||||
Card,
|
||||
CardHeader,
|
||||
CardActionArea,
|
||||
CardContent,
|
||||
Typography
|
||||
} from '@material-ui/core'
|
||||
import ProvidersIcon from '@material-ui/icons/Public'
|
||||
|
||||
const useStyles = makeStyles(theme => ({
|
||||
root: {
|
||||
height: '100%',
|
||||
minHeight: 140
|
||||
},
|
||||
selected: {
|
||||
color: theme.palette.primary.contrastText,
|
||||
backgroundColor: theme.palette.primary.main,
|
||||
'& $badge': {
|
||||
color: theme.palette.primary.main,
|
||||
backgroundColor: theme.palette.common.white
|
||||
}
|
||||
},
|
||||
actionArea: {
|
||||
height: '100%',
|
||||
display: 'flex',
|
||||
flexDirection: 'column'
|
||||
},
|
||||
header: {
|
||||
overflowX: 'hidden',
|
||||
width: '100%'
|
||||
},
|
||||
content: {
|
||||
width: '100%',
|
||||
flexGrow: 1
|
||||
}
|
||||
}))
|
||||
|
||||
const LocationCard = memo(
|
||||
({ value, isSelected, handleClick }) => {
|
||||
const classes = useStyles()
|
||||
const { key, properties } = value
|
||||
|
||||
return (
|
||||
<Fade in unmountOnExit={false}>
|
||||
<Card
|
||||
className={clsx(classes.root, { [classes.selected]: isSelected })}
|
||||
>
|
||||
<CardActionArea
|
||||
className={classes.actionArea}
|
||||
onClick={handleClick}
|
||||
>
|
||||
<CardHeader
|
||||
avatar={<ProvidersIcon />}
|
||||
className={classes.header}
|
||||
title={key}
|
||||
titleTypographyProps={{
|
||||
variant: 'body2',
|
||||
noWrap: true,
|
||||
title: key
|
||||
}}
|
||||
/>
|
||||
{properties && <CardContent className={classes.content}>
|
||||
{Object.entries(properties)?.map(([pKey, pVal]) => (
|
||||
<Typography key={pKey} variant="body2">
|
||||
<b>{pKey}</b>{` - ${pVal}`}
|
||||
</Typography>
|
||||
))}
|
||||
</CardContent>}
|
||||
</CardActionArea>
|
||||
</Card>
|
||||
</Fade>
|
||||
)
|
||||
},
|
||||
(prev, next) => prev.isSelected === next.isSelected
|
||||
)
|
||||
|
||||
LocationCard.propTypes = {
|
||||
value: PropTypes.shape({
|
||||
key: PropTypes.string.isRequired,
|
||||
properties: PropTypes.object
|
||||
}),
|
||||
isSelected: PropTypes.bool,
|
||||
handleClick: PropTypes.func
|
||||
}
|
||||
|
||||
LocationCard.defaultProps = {
|
||||
value: {},
|
||||
isSelected: false,
|
||||
handleClick: undefined
|
||||
}
|
||||
|
||||
LocationCard.displayName = 'LocationCard'
|
||||
|
||||
export default LocationCard
|
||||
@@ -0,0 +1,112 @@
|
||||
import React, { memo } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import {
|
||||
makeStyles,
|
||||
Box,
|
||||
Fade,
|
||||
Button,
|
||||
Card,
|
||||
CardHeader,
|
||||
CardContent,
|
||||
CardActions,
|
||||
Chip
|
||||
} from '@material-ui/core'
|
||||
import FileIcon from '@material-ui/icons/Description'
|
||||
|
||||
import { Tr } from 'client/components/HOC'
|
||||
import { APPLICATION_STATES } from 'client/constants/states'
|
||||
|
||||
const useStyles = makeStyles(theme => ({
|
||||
root: {
|
||||
height: '100%',
|
||||
minHeight: 140,
|
||||
display: 'flex',
|
||||
flexDirection: 'column'
|
||||
},
|
||||
header: {
|
||||
overflowX: 'hidden',
|
||||
flexGrow: 1
|
||||
},
|
||||
subheader: {
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'initial',
|
||||
display: '-webkit-box',
|
||||
lineClamp: 2,
|
||||
boxOrient: 'vertical'
|
||||
},
|
||||
content: {
|
||||
display: 'flex',
|
||||
gap: theme.typography.pxToRem(12)
|
||||
}
|
||||
}))
|
||||
|
||||
const ProviderCard = memo(
|
||||
({ value, handleShow, handleRemove }) => {
|
||||
const classes = useStyles()
|
||||
const { ID, NAME, DESCRIPTION } = value
|
||||
|
||||
return (
|
||||
<Fade in unmountOnExit={false}>
|
||||
<Card className={classes.root}>
|
||||
<CardHeader
|
||||
avatar={<FileIcon />}
|
||||
className={classes.header}
|
||||
classes={{ content: classes.headerContent }}
|
||||
title={`${ID} - ${NAME}`}
|
||||
titleTypographyProps={{
|
||||
variant: 'body2',
|
||||
noWrap: true,
|
||||
title: NAME
|
||||
}}
|
||||
subheader={DESCRIPTION}
|
||||
subheaderTypographyProps={{
|
||||
variant: 'body2',
|
||||
noWrap: true,
|
||||
className: classes.subheader,
|
||||
title: DESCRIPTION
|
||||
}}
|
||||
/>
|
||||
<CardContent>
|
||||
<Box className={classes.content}>
|
||||
{'content'}
|
||||
</Box>
|
||||
</CardContent>
|
||||
<CardActions>
|
||||
{handleShow && (
|
||||
<Button variant="contained" size="small" onClick={handleShow} disableElevation>
|
||||
{Tr('Info')}
|
||||
</Button>
|
||||
)}
|
||||
{handleRemove && (
|
||||
<Button size="small" onClick={handleRemove} disableElevation>
|
||||
{Tr('Remove')}
|
||||
</Button>
|
||||
)}
|
||||
</CardActions>
|
||||
</Card>
|
||||
</Fade>
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
ProviderCard.propTypes = {
|
||||
value: PropTypes.shape({
|
||||
ID: PropTypes.string.isRequired,
|
||||
NAME: PropTypes.string.isRequired,
|
||||
DESCRIPTION: PropTypes.string
|
||||
}),
|
||||
handleShow: PropTypes.func,
|
||||
handleRemove: PropTypes.func
|
||||
}
|
||||
|
||||
ProviderCard.defaultProps = {
|
||||
value: {},
|
||||
handleShow: undefined,
|
||||
handleRemove: undefined
|
||||
}
|
||||
|
||||
ProviderCard.displayName = 'ProviderCard'
|
||||
|
||||
export default ProviderCard
|
||||
@@ -0,0 +1,67 @@
|
||||
import React, { memo } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import {
|
||||
makeStyles, Fade, Card, CardHeader, CardActionArea
|
||||
} from '@material-ui/core'
|
||||
import FileIcon from '@material-ui/icons/Description'
|
||||
|
||||
const useStyles = makeStyles(() => ({
|
||||
root: {
|
||||
height: '100%',
|
||||
minHeight: 140,
|
||||
display: 'flex',
|
||||
flexDirection: 'column'
|
||||
},
|
||||
actionArea: {
|
||||
height: '100%'
|
||||
},
|
||||
headerContent: {
|
||||
overflowX: 'hidden'
|
||||
}
|
||||
}))
|
||||
|
||||
const ProviderTemplateCard = memo(
|
||||
({ value, handleClick }) => {
|
||||
const classes = useStyles()
|
||||
const { name } = value
|
||||
|
||||
return (
|
||||
<Fade in unmountOnExit={false}>
|
||||
<Card className={classes.root}>
|
||||
<CardActionArea
|
||||
className={classes.actionArea}
|
||||
onClick={handleClick}
|
||||
>
|
||||
<CardHeader
|
||||
avatar={<FileIcon />}
|
||||
classes={{ content: classes.headerContent }}
|
||||
title={name}
|
||||
titleTypographyProps={{
|
||||
variant: 'body2',
|
||||
noWrap: true,
|
||||
title: name
|
||||
}}
|
||||
/>
|
||||
</CardActionArea>
|
||||
</Card>
|
||||
</Fade>
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
ProviderTemplateCard.propTypes = {
|
||||
value: PropTypes.shape({
|
||||
name: PropTypes.string.isRequired
|
||||
}),
|
||||
handleClick: PropTypes.func
|
||||
}
|
||||
|
||||
ProviderTemplateCard.defaultProps = {
|
||||
value: {},
|
||||
handleClick: undefined
|
||||
}
|
||||
|
||||
ProviderTemplateCard.displayName = 'ProviderTemplateCard'
|
||||
|
||||
export default ProviderTemplateCard
|
||||
@@ -6,6 +6,9 @@ import SelectCard from 'client/components/Cards/SelectCard'
|
||||
import ApplicationTemplateCard from 'client/components/Cards/ApplicationTemplateCard'
|
||||
import ApplicationCard from 'client/components/Cards/ApplicationCard'
|
||||
import PolicyCard from 'client/components/Cards/PolicyCard'
|
||||
import ProviderTemplateCard from 'client/components/Cards/ProviderTemplateCard'
|
||||
import ProviderCard from 'client/components/Cards/ProviderCard'
|
||||
import LocationCard from 'client/components/Cards/LocationCard'
|
||||
|
||||
export {
|
||||
ClusterCard,
|
||||
@@ -15,5 +18,8 @@ export {
|
||||
SelectCard,
|
||||
ApplicationTemplateCard,
|
||||
ApplicationCard,
|
||||
PolicyCard
|
||||
PolicyCard,
|
||||
ProviderTemplateCard,
|
||||
ProviderCard,
|
||||
LocationCard
|
||||
}
|
||||
@@ -1,65 +1,111 @@
|
||||
import React, { memo } from 'react'
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { styled, Button, MobileStepper } from '@material-ui/core'
|
||||
import { Button, MobileStepper, Typography, Box } from '@material-ui/core'
|
||||
import { KeyboardArrowLeft, KeyboardArrowRight } from '@material-ui/icons'
|
||||
import { makeStyles, fade } from '@material-ui/core/styles'
|
||||
|
||||
import { Tr } from 'client/components/HOC'
|
||||
|
||||
const StickyMobileStepper = styled(MobileStepper)({
|
||||
position: 'sticky',
|
||||
top: -15,
|
||||
backdropFilter: 'blur(5px)',
|
||||
background: '#fafafa9c',
|
||||
zIndex: 1
|
||||
})
|
||||
const useStyles = makeStyles(theme => ({
|
||||
root: {
|
||||
position: 'sticky',
|
||||
top: -15,
|
||||
backdropFilter: 'blur(5px)',
|
||||
background: fade(theme.palette.primary.main, 0.65),
|
||||
zIndex: theme.zIndex.mobileStepper,
|
||||
margin: theme.spacing(2, 0)
|
||||
},
|
||||
title: {
|
||||
padding: theme.spacing(1, 2),
|
||||
color: theme.palette.common.black
|
||||
},
|
||||
error: {
|
||||
padding: theme.spacing(1, 2)
|
||||
},
|
||||
button: { color: theme.palette.common.black },
|
||||
stepper: { background: 'transparent' }
|
||||
}))
|
||||
|
||||
const CustomMobileStepper = memo(
|
||||
({
|
||||
totalSteps,
|
||||
activeStep,
|
||||
lastStep,
|
||||
disabledBack,
|
||||
handleNext,
|
||||
handleBack
|
||||
}) => (
|
||||
<StickyMobileStepper
|
||||
variant="progress"
|
||||
position="static"
|
||||
steps={totalSteps}
|
||||
activeStep={activeStep}
|
||||
backButton={
|
||||
<Button size="small" onClick={handleBack} disabled={disabledBack}>
|
||||
<KeyboardArrowLeft /> {Tr('Back')}
|
||||
</Button>
|
||||
}
|
||||
nextButton={
|
||||
<Button size="small" onClick={handleNext}>
|
||||
{activeStep === lastStep ? Tr('Finish') : Tr('Next')}
|
||||
<KeyboardArrowRight />
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
),
|
||||
(prev, next) => prev.activeStep === next.activeStep
|
||||
)
|
||||
const CustomMobileStepper = ({
|
||||
steps,
|
||||
totalSteps,
|
||||
activeStep,
|
||||
lastStep,
|
||||
disabledBack,
|
||||
handleNext,
|
||||
handleBack,
|
||||
errors
|
||||
}) => {
|
||||
const classes = useStyles()
|
||||
const { id, label } = steps[activeStep]
|
||||
|
||||
return (
|
||||
<Box className={classes.root}>
|
||||
<Typography className={classes.title}>{label}</Typography>
|
||||
{Boolean(errors[id]) && (
|
||||
<Typography className={classes.error} variant="caption" color="error">
|
||||
{errors[id]?.message}
|
||||
</Typography>
|
||||
)}
|
||||
<MobileStepper
|
||||
className={classes.stepper}
|
||||
variant="progress"
|
||||
position="static"
|
||||
steps={totalSteps}
|
||||
activeStep={activeStep}
|
||||
backButton={
|
||||
<Button
|
||||
className={classes.button}
|
||||
size="small"
|
||||
onClick={handleBack}
|
||||
disabled={disabledBack}
|
||||
>
|
||||
<KeyboardArrowLeft /> {Tr('Back')}
|
||||
</Button>
|
||||
}
|
||||
nextButton={
|
||||
<Button className={classes.button} size="small" onClick={handleNext}>
|
||||
{activeStep === lastStep ? Tr('Finish') : Tr('Next')}
|
||||
<KeyboardArrowRight />
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
CustomMobileStepper.propTypes = {
|
||||
steps: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
id: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.number
|
||||
]).isRequired,
|
||||
label: PropTypes.string.isRequired
|
||||
})
|
||||
),
|
||||
totalSteps: PropTypes.number,
|
||||
activeStep: PropTypes.number,
|
||||
lastStep: PropTypes.number,
|
||||
disabledBack: PropTypes.bool,
|
||||
handleNext: PropTypes.func,
|
||||
handleBack: PropTypes.func
|
||||
handleBack: PropTypes.func,
|
||||
errors: PropTypes.shape({
|
||||
message: PropTypes.string
|
||||
})
|
||||
}
|
||||
|
||||
CustomMobileStepper.defaultProps = {
|
||||
steps: [],
|
||||
totalSteps: 0,
|
||||
activeStep: 0,
|
||||
lastStep: 0,
|
||||
disabledBack: false,
|
||||
handleNext: () => undefined,
|
||||
handleBack: () => undefined
|
||||
handleBack: () => undefined,
|
||||
errors: undefined
|
||||
}
|
||||
|
||||
CustomMobileStepper.displayName = 'MobileStepper'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { memo } from 'react'
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import {
|
||||
@@ -7,7 +7,8 @@ import {
|
||||
Stepper,
|
||||
Step,
|
||||
StepLabel,
|
||||
Box
|
||||
Box,
|
||||
Typography
|
||||
} from '@material-ui/core'
|
||||
|
||||
import { Tr } from 'client/components/HOC'
|
||||
@@ -20,33 +21,50 @@ const StickyStepper = styled(Stepper)({
|
||||
zIndex: 1
|
||||
})
|
||||
|
||||
const CustomStepper = memo(
|
||||
({ steps, activeStep, lastStep, disabledBack, handleNext, handleBack }) => (
|
||||
<>
|
||||
<StickyStepper activeStep={activeStep}>
|
||||
{steps?.map(({ label }) => (
|
||||
<Step key={label}>
|
||||
<StepLabel>{label}</StepLabel>
|
||||
</Step>
|
||||
))}
|
||||
</StickyStepper>
|
||||
<Box marginY={2}>
|
||||
<Button onClick={handleBack} disabled={disabledBack}>
|
||||
{Tr('Back')}
|
||||
</Button>
|
||||
<Button variant="contained" color="primary" onClick={handleNext}>
|
||||
{activeStep === lastStep ? Tr('Finish') : Tr('Next')}
|
||||
</Button>
|
||||
</Box>
|
||||
</>
|
||||
),
|
||||
(prev, next) => prev.activeStep === next.activeStep
|
||||
const CustomStepper = ({
|
||||
steps,
|
||||
activeStep,
|
||||
lastStep,
|
||||
disabledBack,
|
||||
handleNext,
|
||||
handleBack,
|
||||
errors
|
||||
}) => (
|
||||
<>
|
||||
<StickyStepper activeStep={activeStep}>
|
||||
{steps?.map(({ id, label }) => (
|
||||
<Step key={id}>
|
||||
<StepLabel
|
||||
{...(Boolean(errors[id]) && {
|
||||
error: true,
|
||||
optional: (
|
||||
<Typography variant="caption" color="error">
|
||||
{errors[id]?.message}
|
||||
</Typography>
|
||||
)
|
||||
})}
|
||||
>{label}</StepLabel>
|
||||
</Step>
|
||||
))}
|
||||
</StickyStepper>
|
||||
<Box marginY={2}>
|
||||
<Button onClick={handleBack} disabled={disabledBack}>
|
||||
{Tr('Back')}
|
||||
</Button>
|
||||
<Button variant="contained" color="primary" onClick={handleNext}>
|
||||
{activeStep === lastStep ? Tr('Finish') : Tr('Next')}
|
||||
</Button>
|
||||
</Box>
|
||||
</>
|
||||
)
|
||||
|
||||
CustomStepper.propTypes = {
|
||||
steps: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
||||
id: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.number
|
||||
]).isRequired,
|
||||
label: PropTypes.string.isRequired
|
||||
})
|
||||
),
|
||||
@@ -54,7 +72,10 @@ CustomStepper.propTypes = {
|
||||
lastStep: PropTypes.number.isRequired,
|
||||
disabledBack: PropTypes.bool.isRequired,
|
||||
handleNext: PropTypes.func,
|
||||
handleBack: PropTypes.func
|
||||
handleBack: PropTypes.func,
|
||||
errors: PropTypes.shape({
|
||||
message: PropTypes.string
|
||||
})
|
||||
}
|
||||
|
||||
CustomStepper.defaultProps = {
|
||||
@@ -63,7 +84,8 @@ CustomStepper.defaultProps = {
|
||||
lastStep: 0,
|
||||
disabledBack: false,
|
||||
handleNext: () => undefined,
|
||||
handleBack: () => undefined
|
||||
handleBack: () => undefined,
|
||||
errors: undefined
|
||||
}
|
||||
|
||||
CustomStepper.displayName = 'Stepper'
|
||||
|
||||
@@ -6,13 +6,12 @@ import { useMediaQuery } from '@material-ui/core'
|
||||
|
||||
import CustomMobileStepper from 'client/components/FormStepper/MobileStepper'
|
||||
import CustomStepper from 'client/components/FormStepper/Stepper'
|
||||
import ErrorHelper from 'client/components/FormControl/ErrorHelper'
|
||||
|
||||
const FIRST_STEP = 0
|
||||
|
||||
const FormStepper = ({ steps, schema, onSubmit }) => {
|
||||
const isMobile = useMediaQuery(theme => theme.breakpoints.only('xs'))
|
||||
const { watch, trigger, reset, errors } = useFormContext()
|
||||
const { watch, reset, errors, setError } = useFormContext()
|
||||
|
||||
const [formData, setFormData] = useState(() => watch())
|
||||
const [activeStep, setActiveStep] = useState(FIRST_STEP)
|
||||
@@ -26,22 +25,27 @@ const FormStepper = ({ steps, schema, onSubmit }) => {
|
||||
}, [formData])
|
||||
|
||||
const handleNext = () => {
|
||||
const { id, resolver } = steps[activeStep]
|
||||
const { id, resolver, optionsValidate } = steps[activeStep]
|
||||
const currentData = watch()[id]
|
||||
|
||||
resolver
|
||||
.validate(currentData)
|
||||
.then(() => {
|
||||
const validateData = { ...formData, [id]: currentData }
|
||||
const stepSchema = typeof resolver === 'function' ? resolver() : resolver
|
||||
|
||||
stepSchema
|
||||
.validate(currentData, optionsValidate)
|
||||
.then(() => {
|
||||
if (activeStep === lastStep) {
|
||||
onSubmit(schema.cast(validateData))
|
||||
onSubmit(schema().cast({ ...formData, [id]: currentData }))
|
||||
} else {
|
||||
setFormData(validateData)
|
||||
setFormData(prev => ({ ...prev, [id]: currentData }))
|
||||
setActiveStep(prevActiveStep => prevActiveStep + 1)
|
||||
}
|
||||
})
|
||||
.catch(() => trigger(id))
|
||||
.catch(({ inner, ...err }) => {
|
||||
setError(id, err)
|
||||
inner?.forEach(({ path, type, message }) =>
|
||||
setError(`${id}.${path}`, { type, message })
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
const handleBack = useCallback(() => {
|
||||
@@ -52,21 +56,22 @@ const FormStepper = ({ steps, schema, onSubmit }) => {
|
||||
|
||||
const { id, content: Content } = useMemo(() => steps[activeStep], [
|
||||
formData,
|
||||
activeStep,
|
||||
setFormData
|
||||
activeStep
|
||||
])
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* STEPPER */}
|
||||
{isMobile ? (
|
||||
{useMemo(() => isMobile ? (
|
||||
<CustomMobileStepper
|
||||
steps={steps}
|
||||
totalSteps={totalSteps}
|
||||
activeStep={activeStep}
|
||||
lastStep={lastStep}
|
||||
disabledBack={disabledBack}
|
||||
handleNext={handleNext}
|
||||
handleBack={handleBack}
|
||||
errors={errors}
|
||||
/>
|
||||
) : (
|
||||
<CustomStepper
|
||||
@@ -76,12 +81,10 @@ const FormStepper = ({ steps, schema, onSubmit }) => {
|
||||
disabledBack={disabledBack}
|
||||
handleNext={handleNext}
|
||||
handleBack={handleBack}
|
||||
errors={errors}
|
||||
/>
|
||||
)}
|
||||
), [isMobile, activeStep, errors[id]])}
|
||||
{/* FORM CONTENT */}
|
||||
{typeof errors[id]?.message === 'string' && (
|
||||
<ErrorHelper label={errors[id]?.message} />
|
||||
)}
|
||||
{Content && <Content data={formData[id]} setFormData={setFormData} />}
|
||||
</>
|
||||
)
|
||||
@@ -93,8 +96,17 @@ FormStepper.propTypes = {
|
||||
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
||||
label: PropTypes.string.isRequired,
|
||||
content: PropTypes.func.isRequired,
|
||||
resolver: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
||||
.isRequired
|
||||
resolver: PropTypes.oneOfType([
|
||||
PropTypes.func,
|
||||
PropTypes.object
|
||||
]).isRequired,
|
||||
optionsValidate: PropTypes.shape({
|
||||
strict: PropTypes.bool,
|
||||
abortEarly: PropTypes.bool,
|
||||
stripUnknown: PropTypes.bool,
|
||||
recursive: PropTypes.bool,
|
||||
context: PropTypes.object
|
||||
})
|
||||
})
|
||||
),
|
||||
schema: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).isRequired,
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import React, { useCallback, useEffect, useState } from 'react'
|
||||
|
||||
import { useFormContext } from 'react-hook-form'
|
||||
import useProvision from 'client/hooks/useProvision'
|
||||
import FormWithSchema from 'client/components/Forms/FormWithSchema'
|
||||
|
||||
import { STEP_ID as PROVIDER_ID } from 'client/containers/Providers/Form/Create/Steps/Provider'
|
||||
import { FORM_FIELDS, STEP_FORM_SCHEMA } from './schema'
|
||||
|
||||
export const STEP_ID = 'connection'
|
||||
|
||||
let ff = {}
|
||||
|
||||
const Connection = () => {
|
||||
return {
|
||||
id: STEP_ID,
|
||||
label: 'Connection configuration',
|
||||
resolver: () => STEP_FORM_SCHEMA(ff),
|
||||
optionsValidate: { abortEarly: false },
|
||||
content: useCallback(({ data, setFormData }) => {
|
||||
const [fields, setFields] = useState([])
|
||||
const { providersTemplates } = useProvision()
|
||||
const { watch } = useFormContext()
|
||||
|
||||
useEffect(() => {
|
||||
const { [PROVIDER_ID]: provider } = watch()
|
||||
const providerTemplate = providersTemplates
|
||||
.find(({ name }) => name === provider?.[0])
|
||||
|
||||
setFields(FORM_FIELDS(providerTemplate?.connection ?? {}))
|
||||
ff = providerTemplate?.connection ?? {}
|
||||
|
||||
return () => {
|
||||
const connection = watch(STEP_ID)
|
||||
setFormData(prev => ({ ...prev, [STEP_ID]: connection }))
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<FormWithSchema cy="form-provider" fields={fields} id={STEP_ID} />
|
||||
)
|
||||
}, [])
|
||||
}
|
||||
}
|
||||
|
||||
export default Connection
|
||||
@@ -0,0 +1,19 @@
|
||||
import * as yup from 'yup'
|
||||
import { INPUT_TYPES } from 'client/constants'
|
||||
import { getValidationFromFields } from 'client/utils'
|
||||
|
||||
export const FORM_FIELDS = connection =>
|
||||
Object.entries(connection)?.map(([name, label]) => ({
|
||||
name,
|
||||
label,
|
||||
type: INPUT_TYPES.TEXT,
|
||||
validation: yup
|
||||
.string()
|
||||
.trim()
|
||||
.required(`${label} field is required`)
|
||||
.default('')
|
||||
}))
|
||||
|
||||
export const STEP_FORM_SCHEMA = connection => yup.object(
|
||||
getValidationFromFields(FORM_FIELDS(connection))
|
||||
)
|
||||
@@ -0,0 +1,59 @@
|
||||
import React, { useCallback, useEffect, useState } from 'react'
|
||||
|
||||
import { useFormContext } from 'react-hook-form'
|
||||
|
||||
import useProvision from 'client/hooks/useProvision'
|
||||
import useListForm from 'client/hooks/useListForm'
|
||||
|
||||
import ListCards from 'client/components/List/ListCards'
|
||||
import { EmptyCard, LocationCard } from 'client/components/Cards'
|
||||
|
||||
import { STEP_ID as PROVIDER_ID } from 'client/containers/Providers/Form/Create/Steps/Provider'
|
||||
import { STEP_FORM_SCHEMA } from './schema'
|
||||
|
||||
export const STEP_ID = 'location'
|
||||
|
||||
const Locations = () => ({
|
||||
id: STEP_ID,
|
||||
label: 'Location',
|
||||
resolver: () => STEP_FORM_SCHEMA,
|
||||
content: useCallback(({ data, setFormData }) => {
|
||||
const [locationsList, setLocationsList] = useState([])
|
||||
const { providersTemplates } = useProvision()
|
||||
const { watch } = useFormContext()
|
||||
|
||||
const { handleSelect, handleUnselect } = useListForm({
|
||||
key: STEP_ID,
|
||||
setList: setFormData
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
const { [PROVIDER_ID]: selectedProvider } = watch()
|
||||
|
||||
const provider = providersTemplates
|
||||
.find(({ name }) => name === selectedProvider?.[0]) ?? {}
|
||||
|
||||
setLocationsList(
|
||||
Object.entries(provider?.locations)
|
||||
?.map(([key, properties]) => ({ key, properties })) ?? []
|
||||
)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<ListCards
|
||||
list={locationsList}
|
||||
EmptyComponent={<EmptyCard name={'locations'} />}
|
||||
CardComponent={LocationCard}
|
||||
cardsProps={({ value: { key } }) => {
|
||||
const isSelected = data?.some(selected => selected === key)
|
||||
const handleClick = () =>
|
||||
isSelected ? handleUnselect(key) : handleSelect(key)
|
||||
|
||||
return { isSelected, handleClick }
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}, [])
|
||||
})
|
||||
|
||||
export default Locations
|
||||
@@ -0,0 +1,8 @@
|
||||
import * as yup from 'yup'
|
||||
|
||||
export const STEP_FORM_SCHEMA = yup
|
||||
.array(yup.string().trim())
|
||||
.min(1, 'Select location')
|
||||
.max(1, 'Max. one location selected')
|
||||
.required('Location field is required')
|
||||
.default([])
|
||||
@@ -0,0 +1,67 @@
|
||||
import React, { useCallback, useEffect } from 'react'
|
||||
import { Redirect } from 'react-router-dom'
|
||||
|
||||
import { LinearProgress } from '@material-ui/core'
|
||||
import FileIcon from '@material-ui/icons/Description'
|
||||
|
||||
import useFetch from 'client/hooks/useFetch'
|
||||
import useProvision from 'client/hooks/useProvision'
|
||||
import useListForm from 'client/hooks/useListForm'
|
||||
|
||||
import ListCards from 'client/components/List/ListCards'
|
||||
import { EmptyCard, SelectCard } from 'client/components/Cards'
|
||||
import { PATH } from 'client/router/provision'
|
||||
|
||||
import { STEP_FORM_SCHEMA } from './schema'
|
||||
|
||||
export const STEP_ID = 'provider'
|
||||
|
||||
const Provider = () => ({
|
||||
id: STEP_ID,
|
||||
label: 'Provider Template',
|
||||
resolver: () => STEP_FORM_SCHEMA,
|
||||
content: useCallback(({ data, setFormData }) => {
|
||||
const { getProvidersTemplates } = useProvision()
|
||||
const { data: templates, fetchRequest, loading, error } = useFetch(
|
||||
getProvidersTemplates
|
||||
)
|
||||
|
||||
const { handleSelect, handleUnselect } = useListForm({
|
||||
key: STEP_ID,
|
||||
setList: setFormData
|
||||
})
|
||||
|
||||
useEffect(() => { fetchRequest() }, [])
|
||||
|
||||
const handleClick = (nameTemplate, isSelected) => {
|
||||
setFormData({ location: undefined, connection: undefined })
|
||||
isSelected ? handleUnselect(nameTemplate) : handleSelect(nameTemplate)
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <Redirect to={PATH.DASHBOARD} />
|
||||
}
|
||||
|
||||
return (!templates || loading) ? (
|
||||
<LinearProgress />
|
||||
) : (
|
||||
<ListCards
|
||||
list={templates}
|
||||
EmptyComponent={<EmptyCard name={'providers templates'} />}
|
||||
CardComponent={SelectCard}
|
||||
cardsProps={({ value: { name } }) => {
|
||||
const isSelected = data?.some(selected => selected === name)
|
||||
|
||||
return {
|
||||
icon: <FileIcon />,
|
||||
title: name,
|
||||
isSelected,
|
||||
handleClick: () => handleClick(name, isSelected)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}, [])
|
||||
})
|
||||
|
||||
export default Provider
|
||||
@@ -0,0 +1,8 @@
|
||||
import * as yup from 'yup'
|
||||
|
||||
export const STEP_FORM_SCHEMA = yup
|
||||
.array(yup.string().trim())
|
||||
.min(1, 'Select Provider template')
|
||||
.max(1, 'Max. one template selected')
|
||||
.required('Provider template field is required')
|
||||
.default([])
|
||||
@@ -0,0 +1,27 @@
|
||||
import * as yup from 'yup'
|
||||
|
||||
import Provider from './Provider'
|
||||
import Connection from './Connection'
|
||||
import Locations from './Locations'
|
||||
|
||||
const Steps = () => {
|
||||
const provider = Provider()
|
||||
const connection = Connection()
|
||||
const locations = Locations()
|
||||
|
||||
const steps = [provider, connection, locations]
|
||||
|
||||
const resolvers = () => yup
|
||||
.object({
|
||||
[provider.id]: provider.resolver(),
|
||||
[connection.id]: connection.resolver(),
|
||||
[locations.id]: locations.resolver()
|
||||
})
|
||||
// .from(provider.id, 'provider')
|
||||
|
||||
const defaultValues = resolvers().default()
|
||||
|
||||
return { steps, defaultValues, resolvers }
|
||||
}
|
||||
|
||||
export default Steps
|
||||
@@ -0,0 +1,40 @@
|
||||
import React from 'react'
|
||||
import { useHistory } from 'react-router'
|
||||
|
||||
import { useForm, FormProvider } from 'react-hook-form'
|
||||
import { yupResolver } from '@hookform/resolvers'
|
||||
|
||||
import useProvision from 'client/hooks/useProvision'
|
||||
import FormStepper from 'client/components/FormStepper'
|
||||
import Steps from 'client/containers/Providers/Form/Create/Steps'
|
||||
import { PATH } from 'client/router/provision'
|
||||
|
||||
function ProviderCreateForm () {
|
||||
const history = useHistory()
|
||||
const { createProvider } = useProvision()
|
||||
const { steps, defaultValues, resolvers } = Steps()
|
||||
|
||||
const methods = useForm({
|
||||
mode: 'onSubmit',
|
||||
defaultValues,
|
||||
resolver: yupResolver(resolvers())
|
||||
})
|
||||
|
||||
const onSubmit = formData => {
|
||||
console.log('formData', formData)
|
||||
createProvider({ data: formData })
|
||||
.then(() => history.push(PATH.PROVIDERS.LIST))
|
||||
}
|
||||
|
||||
return (
|
||||
<FormProvider {...methods}>
|
||||
<FormStepper steps={steps} schema={resolvers} onSubmit={onSubmit} />
|
||||
</FormProvider>
|
||||
)
|
||||
}
|
||||
|
||||
ProviderCreateForm.propTypes = {}
|
||||
|
||||
ProviderCreateForm.defaultProps = {}
|
||||
|
||||
export default ProviderCreateForm
|
||||
@@ -1,15 +1,60 @@
|
||||
import React from 'react'
|
||||
import React, { useEffect } from 'react'
|
||||
|
||||
import { Typography } from '@material-ui/core'
|
||||
import { useHistory } from 'react-router-dom'
|
||||
import { Box, LinearProgress } from '@material-ui/core'
|
||||
import { Alert } from '@material-ui/lab'
|
||||
|
||||
import { PATH } from 'client/router/provision'
|
||||
import useProvision from 'client/hooks/useProvision'
|
||||
import useFetch from 'client/hooks/useFetch'
|
||||
|
||||
// import DeployForm from 'client/containers/Applications/Form'
|
||||
import ListCards from 'client/components/List/ListCards'
|
||||
import { ProviderCard } from 'client/components/Cards'
|
||||
import { Tr } from 'client/components/HOC'
|
||||
|
||||
const Providers = () => {
|
||||
const history = useHistory()
|
||||
// const [showDialog, setShowDialog] = useState(false)
|
||||
const { providers, getProviders } = useProvision()
|
||||
const { fetchRequest, loading, error } = useFetch(getProviders)
|
||||
|
||||
useEffect(() => {
|
||||
fetchRequest()
|
||||
}, [])
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<Box pt={3} display="flex" justifyContent="center">
|
||||
<Alert severity="error" icon={false} variant="filled">
|
||||
{Tr('Cannot connect to OneProvision server')}
|
||||
</Alert>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return <LinearProgress />
|
||||
}
|
||||
|
||||
function Providers () {
|
||||
return (
|
||||
<Typography>Providers</Typography>
|
||||
<Box p={3}>
|
||||
<ListCards
|
||||
list={providers}
|
||||
handleCreate={() => history.push(PATH.PROVIDERS.CREATE)}
|
||||
CardComponent={ProviderCard}
|
||||
cardsProps={({ value: { ID } }) => ({
|
||||
handleEdit: () =>
|
||||
history.push(PATH.PROVIDERS.EDIT.replace(':id', ID)),
|
||||
// handleShow: () => setShowDialog(ID),
|
||||
handleRemove: undefined
|
||||
})}
|
||||
/>
|
||||
{/* {showDialog !== false && (
|
||||
<DeployForm id={showDialog} handleCancel={() => setShowDialog(false)} />
|
||||
)} */}
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
Providers.propTypes = {}
|
||||
|
||||
Providers.defaultProps = {}
|
||||
|
||||
export default Providers
|
||||
@@ -3,13 +3,14 @@ import {
|
||||
Public as ProvidersIcon,
|
||||
SettingsSystemDaydream as ProvisionsIcon
|
||||
} from '@material-ui/icons'
|
||||
import { matchPath } from 'react-router-dom'
|
||||
|
||||
import Login from 'client/containers/Login'
|
||||
import Dashboard from 'client/containers/Dashboard'
|
||||
import Settings from 'client/containers/Settings'
|
||||
|
||||
import Providers from 'client/containers/Providers'
|
||||
import ProvidersCreateForm from 'client/containers/Providers/Form/Create'
|
||||
|
||||
import Provisions from 'client/containers/Provisions'
|
||||
|
||||
export const PATH = {
|
||||
@@ -59,6 +60,18 @@ export const ENDPOINTS = [
|
||||
icon: ProvidersIcon,
|
||||
component: Providers
|
||||
},
|
||||
{
|
||||
label: 'Create Provider',
|
||||
path: PATH.PROVIDERS.CREATE,
|
||||
authenticated: true,
|
||||
component: ProvidersCreateForm
|
||||
},
|
||||
{
|
||||
label: 'Edit Provider template',
|
||||
path: PATH.PROVIDERS.EDIT,
|
||||
authenticated: true,
|
||||
component: ProvidersCreateForm
|
||||
},
|
||||
{
|
||||
label: 'Provisions',
|
||||
path: PATH.PROVISIONS.LIST,
|
||||
|
||||
Reference in new issue
Block a user