mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-21 12:22:38 +09:00
1 parent
770664e947
commit
cd73f8eb38
17 files changed
+294
-173
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { Box } from '@material-ui/core'
|
||||
import { Alert } from '@material-ui/lab'
|
||||
|
||||
const AlertError = ({ children, ...props }) => (
|
||||
<Box pt={3} display="flex" justifyContent="center" {...props}>
|
||||
<Alert severity="error" icon={false} variant="filled">
|
||||
{children}
|
||||
</Alert>
|
||||
</Box>
|
||||
)
|
||||
|
||||
AlertError.propTypes = {
|
||||
children: PropTypes.oneOfType([PropTypes.string, PropTypes.node])
|
||||
}
|
||||
|
||||
AlertError.defaultProps = {
|
||||
children: 'Error!'
|
||||
}
|
||||
|
||||
export default AlertError
|
||||
@@ -3,12 +3,10 @@ import PropTypes from 'prop-types'
|
||||
|
||||
import {
|
||||
makeStyles,
|
||||
Box,
|
||||
Fade,
|
||||
Button,
|
||||
Card,
|
||||
CardHeader,
|
||||
CardContent,
|
||||
CardActions
|
||||
} from '@material-ui/core'
|
||||
import FileIcon from '@material-ui/icons/Description'
|
||||
@@ -26,14 +24,6 @@ const useStyles = makeStyles(theme => ({
|
||||
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)
|
||||
@@ -43,7 +33,7 @@ const useStyles = makeStyles(theme => ({
|
||||
const ProviderCard = memo(
|
||||
({ value, handleShow, handleRemove }) => {
|
||||
const classes = useStyles()
|
||||
const { ID, NAME, DESCRIPTION } = value
|
||||
const { ID, NAME } = value
|
||||
|
||||
return (
|
||||
<Fade in unmountOnExit={false}>
|
||||
@@ -58,19 +48,7 @@ const ProviderCard = memo(
|
||||
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>
|
||||
@@ -92,8 +70,7 @@ const ProviderCard = memo(
|
||||
ProviderCard.propTypes = {
|
||||
value: PropTypes.shape({
|
||||
ID: PropTypes.string.isRequired,
|
||||
NAME: PropTypes.string.isRequired,
|
||||
DESCRIPTION: PropTypes.string
|
||||
NAME: PropTypes.string.isRequired
|
||||
}),
|
||||
handleShow: PropTypes.func,
|
||||
handleRemove: PropTypes.func
|
||||
|
||||
@@ -1,41 +1,56 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { makeStyles, CircularProgress, Button } from '@material-ui/core'
|
||||
import { makeStyles, CircularProgress, Button, Fab } from '@material-ui/core'
|
||||
|
||||
import { Submit } from 'client/constants/translates'
|
||||
import { Tr } from 'client/components/HOC'
|
||||
|
||||
const useStyles = makeStyles(() => ({
|
||||
button: {
|
||||
transition: 'disabled 0.5s ease'
|
||||
root: {
|
||||
transition: 'disabled 0.5s ease',
|
||||
boxShadow: 'none'
|
||||
}
|
||||
}))
|
||||
|
||||
const SubmitButton = ({ isSubmitting, label, ...rest }) => {
|
||||
const ButtonComponent = ({ fab, children, ...props }) => fab ? (
|
||||
<Fab color="primary" size="small" {...props}>{children}</Fab>
|
||||
) : (
|
||||
<Button color="primary" type="submit" variant="contained" {...props}>
|
||||
{children}
|
||||
</Button>
|
||||
)
|
||||
|
||||
ButtonComponent.propTypes = {
|
||||
fab: PropTypes.bool,
|
||||
children: PropTypes.any
|
||||
}
|
||||
|
||||
const SubmitButton = ({ isSubmitting, label, fab, ...props }) => {
|
||||
const classes = useStyles()
|
||||
|
||||
return (
|
||||
<Button
|
||||
<ButtonComponent
|
||||
color="primary"
|
||||
className={classes.root}
|
||||
disabled={isSubmitting}
|
||||
type="submit"
|
||||
variant="contained"
|
||||
className={classes.button}
|
||||
{...rest}
|
||||
fab={fab}
|
||||
{...props}
|
||||
>
|
||||
{isSubmitting && <CircularProgress size={24} />}
|
||||
{!isSubmitting && (label ?? Tr(Submit))}
|
||||
</Button>
|
||||
</ButtonComponent>
|
||||
)
|
||||
}
|
||||
|
||||
SubmitButton.propTypes = {
|
||||
fab: PropTypes.bool,
|
||||
isSubmitting: PropTypes.bool,
|
||||
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node])
|
||||
}
|
||||
|
||||
SubmitButton.defaultProps = {
|
||||
fab: false,
|
||||
isSubmitting: false,
|
||||
label: undefined
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ const ListCards = memo(({
|
||||
|
||||
return (
|
||||
<Grid container spacing={3}>
|
||||
{/* CREATE CARD COMPONENT */}
|
||||
{handleCreate && (
|
||||
<Grid item {...breakpoints}>
|
||||
{ButtonCreateComponent ? (
|
||||
@@ -56,6 +57,8 @@ const ListCards = memo(({
|
||||
)}
|
||||
</Grid>
|
||||
)}
|
||||
|
||||
{/* LIST */}
|
||||
{list.length > 0 ? (
|
||||
list?.map((value, index) => (
|
||||
<Grid key={`card-${index}`} item {...breakpoints}>
|
||||
|
||||
@@ -25,7 +25,12 @@ module.exports = {
|
||||
CannotConnectOneFlow: 'Cannot connect to OneFlow server',
|
||||
NotFound: 'Not found',
|
||||
|
||||
/* sections */
|
||||
Dashboard: 'Dashboard',
|
||||
Settings: 'Settings',
|
||||
Providers: 'Providers',
|
||||
Provisions: 'Provisions',
|
||||
|
||||
Language: 'Language',
|
||||
Response: 'Response',
|
||||
Settings: 'Settings'
|
||||
Response: 'Response'
|
||||
}
|
||||
+1
-2
@@ -135,6 +135,5 @@ export const NETWORK_FORM_SCHEMA = yup.object(
|
||||
)
|
||||
|
||||
export const STEP_FORM_SCHEMA = yup
|
||||
.array()
|
||||
.of(NETWORK_FORM_SCHEMA)
|
||||
.array(NETWORK_FORM_SCHEMA)
|
||||
.default([])
|
||||
-1
@@ -3,7 +3,6 @@ import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
import { INPUT_TYPES } from 'client/constants'
|
||||
import { getValidationFromFields } from 'client/utils/helpers'
|
||||
import { parseFloat } from 'window-or-global'
|
||||
|
||||
export const ID = {
|
||||
name: 'id',
|
||||
|
||||
@@ -18,6 +18,8 @@ import React from 'react'
|
||||
import { Box, Typography } from '@material-ui/core'
|
||||
|
||||
import dashboardStyles from 'client/containers/Dashboard/styles'
|
||||
import { Tr } from 'client/components/HOC/Translate'
|
||||
import { Dashboard as Title } from 'client/constants/translates'
|
||||
|
||||
function Dashboard () {
|
||||
const classes = dashboardStyles()
|
||||
@@ -29,7 +31,7 @@ function Dashboard () {
|
||||
className={classes.title}
|
||||
data-cy="dashboard-title"
|
||||
>
|
||||
Dashboard
|
||||
{Tr(Title)}
|
||||
</Typography>
|
||||
</Box>
|
||||
)
|
||||
|
||||
@@ -37,7 +37,6 @@ export default makeStyles(theme =>
|
||||
},
|
||||
wrapperForm: {
|
||||
padding: theme.spacing(),
|
||||
flexGrow: 1,
|
||||
display: 'flex',
|
||||
overflow: 'hidden'
|
||||
},
|
||||
|
||||
+22
-29
@@ -9,38 +9,31 @@ import { FORM_FIELDS, STEP_FORM_SCHEMA } from './schema'
|
||||
|
||||
export const STEP_ID = 'connection'
|
||||
|
||||
let ff = {}
|
||||
let connection = {}
|
||||
|
||||
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()
|
||||
const Connection = () => ({
|
||||
id: STEP_ID,
|
||||
label: 'Connection configuration',
|
||||
resolver: () => STEP_FORM_SCHEMA(connection),
|
||||
optionsValidate: { abortEarly: false },
|
||||
content: useCallback(() => {
|
||||
const [fields, setFields] = useState([])
|
||||
const { providersTemplates } = useProvision()
|
||||
const { watch } = useFormContext()
|
||||
|
||||
useEffect(() => {
|
||||
const { [PROVIDER_ID]: provider } = watch()
|
||||
const providerTemplate = providersTemplates
|
||||
.find(({ name }) => name === provider?.[0])
|
||||
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} />
|
||||
)
|
||||
connection = providerTemplate?.connection ?? {}
|
||||
setFields(FORM_FIELDS(connection))
|
||||
}, [])
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<FormWithSchema cy="form-provider" fields={fields} id={STEP_ID} />
|
||||
)
|
||||
}, [])
|
||||
})
|
||||
|
||||
export default Connection
|
||||
@@ -11,6 +11,8 @@ import ListCards from 'client/components/List/ListCards'
|
||||
import { EmptyCard, SelectCard } from 'client/components/Cards'
|
||||
import { PATH } from 'client/router/provision'
|
||||
|
||||
import { STEP_ID as CONNECTION_ID } from 'client/containers/Providers/Form/Create/Steps/Connection'
|
||||
import { STEP_ID as LOCATION_ID } from 'client/containers/Providers/Form/Create/Steps/Locations'
|
||||
import { STEP_FORM_SCHEMA } from './schema'
|
||||
|
||||
export const STEP_ID = 'provider'
|
||||
@@ -33,7 +35,7 @@ const Provider = () => ({
|
||||
useEffect(() => { fetchRequest() }, [])
|
||||
|
||||
const handleClick = (nameTemplate, isSelected) => {
|
||||
setFormData({ location: undefined, connection: undefined })
|
||||
setFormData({ [LOCATION_ID]: undefined, [CONNECTION_ID]: undefined })
|
||||
isSelected ? handleUnselect(nameTemplate) : handleSelect(nameTemplate)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import { PATH } from 'client/router/provision'
|
||||
|
||||
function ProviderCreateForm () {
|
||||
const history = useHistory()
|
||||
const { createProvider } = useProvision()
|
||||
const { createProvider, providersTemplates } = useProvision()
|
||||
const { steps, defaultValues, resolvers } = Steps()
|
||||
|
||||
const methods = useForm({
|
||||
@@ -22,8 +22,24 @@ function ProviderCreateForm () {
|
||||
})
|
||||
|
||||
const onSubmit = formData => {
|
||||
console.log('formData', formData)
|
||||
createProvider({ data: formData })
|
||||
const { provider, location, connection } = formData
|
||||
const providerSelected = provider[0]
|
||||
const locationSelected = location[0]
|
||||
|
||||
const providerTemplate = providersTemplates
|
||||
.find(({ name }) => name === providerSelected) ?? {}
|
||||
|
||||
const formatData = {
|
||||
name: `${providerSelected}_${locationSelected}`,
|
||||
connection: {
|
||||
...connection,
|
||||
[providerTemplate.location_key]: locationSelected,
|
||||
[`${providerTemplate.location_key}_extra`]:
|
||||
providerTemplate.locations[locationSelected]
|
||||
}
|
||||
}
|
||||
|
||||
createProvider({ data: formatData })
|
||||
.then(() => history.push(PATH.PROVIDERS.LIST))
|
||||
}
|
||||
|
||||
@@ -36,8 +52,4 @@ function ProviderCreateForm () {
|
||||
)
|
||||
}
|
||||
|
||||
ProviderCreateForm.propTypes = {}
|
||||
|
||||
ProviderCreateForm.defaultProps = {}
|
||||
|
||||
export default ProviderCreateForm
|
||||
@@ -1,50 +1,67 @@
|
||||
import React, { useEffect } from 'react'
|
||||
|
||||
import { useHistory } from 'react-router-dom'
|
||||
import { Container, Box } from '@material-ui/core'
|
||||
import { Alert } from '@material-ui/lab'
|
||||
import { Container, Box, Typography, Divider } from '@material-ui/core'
|
||||
import RefreshIcon from '@material-ui/icons/Autorenew'
|
||||
|
||||
import { PATH } from 'client/router/provision'
|
||||
import useProvision from 'client/hooks/useProvision'
|
||||
import useFetch from 'client/hooks/useFetch'
|
||||
|
||||
import SubmitButton from 'client/components/FormControl/SubmitButton'
|
||||
import ListCards from 'client/components/List/ListCards'
|
||||
import AlertError from 'client/components/Alerts/Error'
|
||||
import { ProviderCard } from 'client/components/Cards'
|
||||
import { Tr } from 'client/components/HOC'
|
||||
|
||||
const Providers = () => {
|
||||
import { Tr } from 'client/components/HOC'
|
||||
import { Providers as ProvidersLabel } from 'client/constants/translates'
|
||||
|
||||
function Providers () {
|
||||
const history = useHistory()
|
||||
const { providers, getProviders } = useProvision()
|
||||
const { fetchRequest, loading, error } = useFetch(getProviders)
|
||||
const {
|
||||
error,
|
||||
fetchRequest,
|
||||
loading,
|
||||
reloading
|
||||
} = 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>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Container disableGutters>
|
||||
<Box p={3}>
|
||||
<ListCards
|
||||
list={providers}
|
||||
isLoading={providers.length === 0 && loading}
|
||||
handleCreate={() => history.push(PATH.PROVIDERS.CREATE)}
|
||||
CardComponent={ProviderCard}
|
||||
cardsProps={({ value: { ID } }) => ({
|
||||
handleEdit: () =>
|
||||
history.push(PATH.PROVIDERS.EDIT.replace(':id', ID)),
|
||||
handleRemove: undefined
|
||||
})}
|
||||
<Box p={3} display="flex" alignItems="center">
|
||||
<SubmitButton
|
||||
fab
|
||||
onClick={() => fetchRequest(undefined, true)}
|
||||
isSubmitting={loading || reloading}
|
||||
label={<RefreshIcon />}
|
||||
/>
|
||||
<Typography variant="h5" style={{ marginLeft: 8 }}>
|
||||
{Tr(ProvidersLabel)}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Divider />
|
||||
<Box p={3}>
|
||||
{error ? (
|
||||
<AlertError>
|
||||
{Tr('Cannot connect to OneProvision server')}
|
||||
</AlertError>
|
||||
) : (
|
||||
<ListCards
|
||||
list={providers}
|
||||
isLoading={providers.length === 0 && loading}
|
||||
handleCreate={() => history.push(PATH.PROVIDERS.CREATE)}
|
||||
CardComponent={ProviderCard}
|
||||
cardsProps={({ value: { ID } }) => ({
|
||||
handleEdit: () =>
|
||||
history.push(PATH.PROVIDERS.EDIT.replace(':id', ID)),
|
||||
handleRemove: undefined
|
||||
})}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
</Container>
|
||||
)
|
||||
|
||||
@@ -1,50 +1,67 @@
|
||||
import React, { useEffect } from 'react'
|
||||
|
||||
import { useHistory } from 'react-router-dom'
|
||||
import { Container, Box } from '@material-ui/core'
|
||||
import { Alert } from '@material-ui/lab'
|
||||
import { Container, Box, Typography, Divider } from '@material-ui/core'
|
||||
import RefreshIcon from '@material-ui/icons/Autorenew'
|
||||
|
||||
import { PATH } from 'client/router/provision'
|
||||
import useProvision from 'client/hooks/useProvision'
|
||||
import useFetch from 'client/hooks/useFetch'
|
||||
|
||||
import SubmitButton from 'client/components/FormControl/SubmitButton'
|
||||
import ListCards from 'client/components/List/ListCards'
|
||||
import AlertError from 'client/components/Alerts/Error'
|
||||
import { ProviderCard } from 'client/components/Cards'
|
||||
import { Tr } from 'client/components/HOC'
|
||||
|
||||
const Provisions = () => {
|
||||
import { Tr } from 'client/components/HOC'
|
||||
import { Providers as ProvidersLabel } from 'client/constants/translates'
|
||||
|
||||
function Provisions () {
|
||||
const history = useHistory()
|
||||
const { provisions, getProvisions } = useProvision()
|
||||
const { fetchRequest, loading, error } = useFetch(getProvisions)
|
||||
const {
|
||||
error,
|
||||
fetchRequest,
|
||||
loading,
|
||||
reloading
|
||||
} = useFetch(getProvisions)
|
||||
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Container disableGutters>
|
||||
<Box p={3}>
|
||||
<ListCards
|
||||
list={provisions}
|
||||
isLoading={provisions.length === 0 && loading}
|
||||
handleCreate={() => history.push(PATH.PROVISIONS.CREATE)}
|
||||
CardComponent={ProviderCard}
|
||||
cardsProps={({ value: { ID } }) => ({
|
||||
handleEdit: () =>
|
||||
history.push(PATH.PROVISIONS.EDIT.replace(':id', ID)),
|
||||
handleRemove: undefined
|
||||
})}
|
||||
<Box p={3} display="flex" alignItems="center">
|
||||
<SubmitButton
|
||||
fab
|
||||
onClick={() => fetchRequest(undefined, true)}
|
||||
isSubmitting={loading || reloading}
|
||||
label={<RefreshIcon />}
|
||||
/>
|
||||
<Typography variant="h5" style={{ marginLeft: 8 }}>
|
||||
{Tr(ProvidersLabel)}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Divider />
|
||||
<Box p={3}>
|
||||
{error ? (
|
||||
<AlertError>
|
||||
{Tr('Cannot connect to OneProvision server')}
|
||||
</AlertError>
|
||||
) : (
|
||||
<ListCards
|
||||
list={provisions}
|
||||
isLoading={provisions.length === 0 && loading}
|
||||
handleCreate={() => history.push(PATH.PROVISIONS.CREATE)}
|
||||
CardComponent={ProviderCard}
|
||||
cardsProps={({ value: { ID } }) => ({
|
||||
handleEdit: () =>
|
||||
history.push(PATH.PROVISIONS.EDIT.replace(':id', ID)),
|
||||
handleRemove: undefined
|
||||
})}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
</Container>
|
||||
)
|
||||
|
||||
@@ -3,33 +3,31 @@ import { useState, useCallback } from 'react'
|
||||
const useRequest = request => {
|
||||
const [data, setData] = useState(undefined)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [reloading, setReloading] = useState(false)
|
||||
const [error, setError] = useState(false)
|
||||
|
||||
const fetchRequest = useCallback(
|
||||
payload => {
|
||||
let ignore = false
|
||||
setLoading(true)
|
||||
setError(false)
|
||||
|
||||
const callRequest = useCallback(
|
||||
payload =>
|
||||
request(payload)
|
||||
.then(response => {
|
||||
if (response !== undefined && !ignore) {
|
||||
if (response !== undefined) {
|
||||
setData(response)
|
||||
} else {
|
||||
setError(true)
|
||||
}
|
||||
})
|
||||
setError(false)
|
||||
} else setError(true)
|
||||
}
|
||||
)
|
||||
.finally(() => {
|
||||
setLoading(false)
|
||||
})
|
||||
|
||||
return () => {
|
||||
ignore = true
|
||||
}
|
||||
},
|
||||
setReloading(false)
|
||||
}),
|
||||
[request]
|
||||
)
|
||||
|
||||
return { data, fetchRequest, loading, error }
|
||||
const fetchRequest = useCallback((payload, reload = false) => {
|
||||
reload ? setReloading(true) : setLoading(true)
|
||||
callRequest(payload)
|
||||
}, [])
|
||||
|
||||
return { data, fetchRequest, loading, reloading, error }
|
||||
}
|
||||
export default useRequest
|
||||
@@ -48,7 +48,10 @@ export default function useOpennebula () {
|
||||
({ end, start } = { end: -1, start: -1 }) =>
|
||||
serviceProvision
|
||||
.getProviders({ filter, end, start })
|
||||
.then(doc => dispatch(setProviders(doc)))
|
||||
.then(doc => {
|
||||
dispatch(setProviders(doc))
|
||||
return doc
|
||||
})
|
||||
.catch(err => {
|
||||
dispatch(enqueueError(err ?? 'Error GET providers'))
|
||||
}),
|
||||
@@ -59,20 +62,12 @@ export default function useOpennebula () {
|
||||
({ data }) =>
|
||||
serviceProvision
|
||||
.createProvider({ data })
|
||||
.then(doc => {
|
||||
/* dispatch(
|
||||
setApplicationsTemplates(
|
||||
filterBy([doc].concat(applicationsTemplates), 'ID')
|
||||
)
|
||||
) */
|
||||
|
||||
return dispatch(enqueueSuccess(`Template created - ID: ${doc?.ID}`))
|
||||
})
|
||||
.catch(err => {
|
||||
dispatch(
|
||||
enqueueError(err?.message ?? 'Error CREATE provider')
|
||||
)
|
||||
}),
|
||||
.then(doc => dispatch(
|
||||
enqueueSuccess(`Template created - ID: ${doc?.ID}`))
|
||||
)
|
||||
.catch(err => dispatch(
|
||||
enqueueError(err?.message ?? 'Error CREATE provider')
|
||||
)),
|
||||
[dispatch, providers]
|
||||
)
|
||||
|
||||
@@ -88,7 +83,10 @@ export default function useOpennebula () {
|
||||
({ end, start } = { end: -1, start: -1 }) =>
|
||||
serviceProvision
|
||||
.getProvisions({ filter, end, start })
|
||||
.then(doc => dispatch(setProvisions(doc)))
|
||||
.then(doc => {
|
||||
dispatch(setProvisions(doc))
|
||||
return doc
|
||||
})
|
||||
.catch(err => {
|
||||
dispatch(enqueueError(err ?? 'Error GET providers'))
|
||||
}),
|
||||
|
||||
@@ -1,23 +1,85 @@
|
||||
import httpCodes from 'server/utils/constants/http-codes'
|
||||
import { httpMethod } from 'server/utils/constants/defaults'
|
||||
import {
|
||||
PROVIDER,
|
||||
PROVISION,
|
||||
PROVISION_TEMPLATE
|
||||
} from 'server/routes/api/provision/string-routes'
|
||||
|
||||
import { requestData } from 'client/utils'
|
||||
import { REQUEST_ACTIONS } from 'client/constants'
|
||||
const { GET, POST, PUT } = httpMethod
|
||||
|
||||
// --------------------------------------------
|
||||
// PROVIDER REQUESTS
|
||||
// --------------------------------------------
|
||||
export const getProvidersTemplates = () => Promise.resolve([])
|
||||
|
||||
export const getProvider = () => Promise.resolve({})
|
||||
export const getProvidersTemplates = ({ filter }) =>
|
||||
requestData(`/api/${PROVIDER}/template`, {
|
||||
data: { filter },
|
||||
method: GET,
|
||||
error: err => err?.message
|
||||
}).then(res => {
|
||||
if (!res?.id || res?.id !== httpCodes.ok.id) throw res
|
||||
|
||||
export const getProviders = () => Promise.resolve([])
|
||||
.then(res => [res?.data?.DOCUMENT_POOL?.DOCUMENT ?? []].flat())
|
||||
return res?.data ?? []
|
||||
})
|
||||
|
||||
export const getProvider = ({ id }) =>
|
||||
requestData(`/api/${PROVIDER}/list/${id}`, {
|
||||
method: GET,
|
||||
error: err => err?.message
|
||||
}).then(res => {
|
||||
if (!res?.id || res?.id !== httpCodes.ok.id) throw res
|
||||
|
||||
return res?.data?.DOCUMENT ?? {}
|
||||
})
|
||||
|
||||
export const getProviders = ({ filter }) =>
|
||||
requestData(`/api/${PROVIDER}/list`, {
|
||||
data: { filter },
|
||||
method: GET,
|
||||
error: err => err?.message
|
||||
}).then(res => {
|
||||
if (!res?.id || res?.id !== httpCodes.ok.id) throw res
|
||||
|
||||
return [res?.data?.DOCUMENT_POOL?.DOCUMENT ?? []].flat()
|
||||
})
|
||||
|
||||
export const createProvider = ({ data = {} }) =>
|
||||
Promise.resolve().then(res => res?.data?.DOCUMENT ?? {})
|
||||
requestData(`/api/${PROVIDER}/create`, {
|
||||
data,
|
||||
method: POST
|
||||
}).then(res => {
|
||||
if (!res?.id || res?.id !== httpCodes.ok.id) throw res
|
||||
|
||||
return res?.data ?? {}
|
||||
})
|
||||
|
||||
// --------------------------------------------
|
||||
// PROVISION REQUESTS
|
||||
// --------------------------------------------
|
||||
export const getProvision = () => Promise.resolve({})
|
||||
|
||||
export const getProvisions = () => Promise.resolve([])
|
||||
.then(res => [res?.data?.DOCUMENT_POOL?.DOCUMENT ?? []].flat())
|
||||
export const getProvision = ({ id }) =>
|
||||
requestData(`/api/${PROVISION}/list/${id}`, {
|
||||
method: GET,
|
||||
error: err => err?.message
|
||||
}).then(res => {
|
||||
if (!res?.id || res?.id !== httpCodes.ok.id) throw res
|
||||
|
||||
return res?.data?.DOCUMENT ?? {}
|
||||
})
|
||||
|
||||
export const getProvisions = ({ filter }) =>
|
||||
requestData(`/api/${PROVISION}/list`, {
|
||||
data: { filter },
|
||||
method: GET,
|
||||
error: err => err?.message
|
||||
}).then(res => {
|
||||
if (!res?.id || res?.id !== httpCodes.ok.id) throw res
|
||||
|
||||
return [res?.data?.DOCUMENT_POOL?.DOCUMENT ?? []].flat()
|
||||
})
|
||||
|
||||
export const createProvision = ({ data = {} }) =>
|
||||
Promise.resolve().then(res => res?.data?.DOCUMENT ?? {})
|
||||
|
||||
Reference in new issue
Block a user