mirror of
https://github.com/OpenNebula/one.git
synced 2026-12-06 15:13:39 +09:00
1 parent
95bc7095ef
commit
c4c24d6965
26 files changed
+288
-109
No files matched your search
@@ -56,10 +56,7 @@ DatastoreCard.propTypes = {
|
||||
actions: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
handleClick: PropTypes.func.isRequired,
|
||||
icon: PropTypes.object.isRequired,
|
||||
iconColor: PropTypes.oneOf([
|
||||
'inherit', 'primary', 'secondary', 'action', 'error', 'disabled'
|
||||
]),
|
||||
icon: PropTypes.node.isRequired,
|
||||
cy: PropTypes.string
|
||||
})
|
||||
)
|
||||
|
||||
@@ -59,10 +59,7 @@ HostCard.propTypes = {
|
||||
actions: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
handleClick: PropTypes.func.isRequired,
|
||||
icon: PropTypes.object.isRequired,
|
||||
iconColor: PropTypes.oneOf([
|
||||
'inherit', 'primary', 'secondary', 'action', 'error', 'disabled'
|
||||
]),
|
||||
icon: PropTypes.node.isRequired,
|
||||
cy: PropTypes.string
|
||||
})
|
||||
)
|
||||
|
||||
@@ -34,10 +34,7 @@ NetworkCard.propTypes = {
|
||||
actions: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
handleClick: PropTypes.func.isRequired,
|
||||
icon: PropTypes.object.isRequired,
|
||||
iconColor: PropTypes.oneOf([
|
||||
'inherit', 'primary', 'secondary', 'action', 'error', 'disabled'
|
||||
]),
|
||||
icon: PropTypes.node.isRequired,
|
||||
cy: PropTypes.string
|
||||
})
|
||||
)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import React, { memo, useState, useEffect } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { Avatar, IconButton } from '@material-ui/core'
|
||||
import { Avatar } from '@material-ui/core'
|
||||
import ProviderIcon from '@material-ui/icons/Public'
|
||||
import ProvisionIcon from '@material-ui/icons/Cloud'
|
||||
|
||||
import SelectCard from 'client/components/Cards/SelectCard'
|
||||
import Action from 'client/components/Cards/SelectCard/Action'
|
||||
import { STATIC_FILES_URL } from 'client/constants'
|
||||
|
||||
const ProvisionCard = memo(
|
||||
@@ -31,18 +32,12 @@ const ProvisionCard = memo(
|
||||
evt.target.src = `${STATIC_FILES_URL}/${DEFAULT_IMAGE}`
|
||||
}
|
||||
|
||||
const renderAction = ({ handleClick, icon: Icon, iconProps, cy }) => (
|
||||
<IconButton key={cy} data-cy={cy} onClick={handleClick}>
|
||||
<Icon {...iconProps} />
|
||||
</IconButton>
|
||||
)
|
||||
|
||||
return (
|
||||
<SelectCard
|
||||
title={`${ID} - ${NAME}`}
|
||||
isSelected={isSelected}
|
||||
handleClick={handleClick}
|
||||
action={actions?.map(action => renderAction(action))}
|
||||
action={actions?.map(action => <Action key={action?.cy} {...action} />)}
|
||||
icon={isProvider ? <ProviderIcon /> : <ProvisionIcon />}
|
||||
{...(imgAsAvatar
|
||||
? {
|
||||
@@ -82,11 +77,6 @@ ProvisionCard.propTypes = {
|
||||
PropTypes.shape({
|
||||
handleClick: PropTypes.func.isRequired,
|
||||
icon: PropTypes.object.isRequired,
|
||||
iconProps: PropTypes.shape({
|
||||
color: PropTypes.oneOf([
|
||||
'inherit', 'primary', 'secondary', 'action', 'error', 'disabled'
|
||||
])
|
||||
}),
|
||||
cy: PropTypes.string
|
||||
})
|
||||
)
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import React, { memo } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import useFetch from 'client/hooks/useFetch'
|
||||
import SubmitButton from 'client/components/FormControl/SubmitButton'
|
||||
|
||||
const Action = memo(({ handleClick, icon, cy }) => {
|
||||
const { fetchRequest, loading } = useFetch(
|
||||
() => Promise.resolve(handleClick())
|
||||
)
|
||||
|
||||
return (
|
||||
<SubmitButton
|
||||
data-cy={cy}
|
||||
icon
|
||||
isSubmitting={loading}
|
||||
label={icon}
|
||||
onClick={() => fetchRequest()}
|
||||
/>
|
||||
)
|
||||
})
|
||||
|
||||
Action.propTypes = {
|
||||
handleClick: PropTypes.func.isRequired,
|
||||
icon: PropTypes.node.isRequired,
|
||||
cy: PropTypes.string
|
||||
}
|
||||
|
||||
Action.defaultProps = {
|
||||
handleClick: () => undefined,
|
||||
icon: undefined,
|
||||
cy: 'action-card'
|
||||
}
|
||||
|
||||
Action.displayName = 'ActionCard'
|
||||
|
||||
export default Action
|
||||
+5
-14
@@ -3,12 +3,13 @@ import PropTypes from 'prop-types'
|
||||
import clsx from 'clsx'
|
||||
|
||||
import {
|
||||
makeStyles, Card, CardActionArea, CardHeader, CardActions, IconButton, CardMedia
|
||||
makeStyles, Card, CardActionArea, CardHeader, CardActions, CardMedia
|
||||
} from '@material-ui/core'
|
||||
import { Skeleton } from '@material-ui/lab'
|
||||
|
||||
import useNearScreen from 'client/hooks/useNearScreen'
|
||||
import ConditionalWrap from 'client/components/HOC/ConditionalWrap'
|
||||
import Action from 'client/components/Cards/SelectCard/Action'
|
||||
|
||||
const useStyles = makeStyles(theme => ({
|
||||
root: { height: '100%' },
|
||||
@@ -39,8 +40,7 @@ const useStyles = makeStyles(theme => ({
|
||||
display: '-webkit-box',
|
||||
lineClamp: 2,
|
||||
boxOrient: 'vertical'
|
||||
},
|
||||
actionsIcon: { margin: theme.spacing(1) }
|
||||
}
|
||||
}))
|
||||
|
||||
const SelectCard = memo(({
|
||||
@@ -63,12 +63,6 @@ const SelectCard = memo(({
|
||||
distance: '100px'
|
||||
})
|
||||
|
||||
const renderAction = ({ handleClick, icon: Icon, iconColor, cy }) => (
|
||||
<IconButton key={cy} data-cy={cy} onClick={handleClick} size="small">
|
||||
<Icon color={iconColor} className={classes.actionsIcon} />
|
||||
</IconButton>
|
||||
)
|
||||
|
||||
return (
|
||||
<ConditionalWrap
|
||||
condition={!observerOff}
|
||||
@@ -138,7 +132,7 @@ const SelectCard = memo(({
|
||||
{/* CARD ACTIONS */}
|
||||
{actions?.length > 0 && (
|
||||
<CardActions>
|
||||
{actions?.map(action => renderAction(action))}
|
||||
{actions?.map(action => <Action key={action?.cy} {...action} />)}
|
||||
</CardActions>
|
||||
)}
|
||||
</ConditionalWrap>
|
||||
@@ -160,10 +154,7 @@ SelectCard.propTypes = {
|
||||
actions: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
handleClick: PropTypes.func.isRequired,
|
||||
icon: PropTypes.object.isRequired,
|
||||
iconColor: PropTypes.oneOf([
|
||||
'inherit', 'primary', 'secondary', 'action', 'error', 'disabled'
|
||||
]),
|
||||
icon: PropTypes.node.isRequired,
|
||||
cy: PropTypes.string
|
||||
})
|
||||
),
|
||||
@@ -61,6 +61,7 @@ const DialogConfirmation = memo(
|
||||
)}
|
||||
{handleAccept && (
|
||||
<SubmitButton
|
||||
color='primary'
|
||||
data-cy="dg-accept-button"
|
||||
onClick={handleAccept}
|
||||
label={Tr(T.Accept)}
|
||||
|
||||
@@ -62,6 +62,7 @@ const DialogForm = memo(
|
||||
)}
|
||||
{onSubmit && (
|
||||
<SubmitButton
|
||||
color='primary'
|
||||
data-cy="dg-form-submit-button"
|
||||
isSubmitting={methods.formState.isSubmitting}
|
||||
onClick={methods.handleSubmit(onSubmit)}
|
||||
|
||||
@@ -15,7 +15,8 @@ const useStyles = makeStyles(theme => ({
|
||||
|
||||
const DialogRequest = ({ request, dialogProps, children }) => {
|
||||
const classes = useStyles()
|
||||
const { data, fetchRequest, loading, error } = useFetch(request)
|
||||
const methods = useFetch(request)
|
||||
const { data, fetchRequest, loading, error } = methods
|
||||
|
||||
useEffect(() => { fetchRequest() }, [])
|
||||
|
||||
@@ -31,7 +32,7 @@ const DialogRequest = ({ request, dialogProps, children }) => {
|
||||
|
||||
return (
|
||||
<DialogConfirmation {...dialogProps}>
|
||||
{children({ data })}
|
||||
{children(methods)}
|
||||
</DialogConfirmation>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import {
|
||||
makeStyles, CircularProgress, Button, Fab, IconButton
|
||||
makeStyles, CircularProgress, Button, IconButton
|
||||
} from '@material-ui/core'
|
||||
import { Tr } from 'client/components/HOC'
|
||||
import { T } from 'client/constants'
|
||||
@@ -62,7 +62,7 @@ SubmitButton.defaultProps = {
|
||||
label: undefined,
|
||||
isSubmitting: false,
|
||||
className: undefined,
|
||||
color: 'primary'
|
||||
color: 'default'
|
||||
}
|
||||
|
||||
export default SubmitButton
|
||||
@@ -58,6 +58,7 @@ const CustomStepper = ({
|
||||
{Tr(T.Back)}
|
||||
</Button>
|
||||
<SubmitButton
|
||||
color='primary'
|
||||
data-cy="stepper-next-button"
|
||||
onClick={handleNext}
|
||||
isSubmitting={isSubmitting}
|
||||
|
||||
@@ -52,18 +52,22 @@ const ListCards = memo(({
|
||||
{/* LIST */}
|
||||
{list.length > 0 ? (
|
||||
<TransitionGroup component={null}>
|
||||
{list?.map((value, index) => (
|
||||
<CSSTransition
|
||||
{list?.map((value, index) => {
|
||||
const key = value[keyProp] ?? value[keyProp.toUpperCase()]
|
||||
|
||||
return (
|
||||
<CSSTransition
|
||||
// use key to render transition (default: id or ID)
|
||||
key={`card-${value[keyProp] ?? value[String(keyProp).toUpperCase()]}`}
|
||||
classNames={classes.item}
|
||||
timeout={400}
|
||||
>
|
||||
<Grid item {...breakpoints}>
|
||||
<CardComponent value={value} {...cardsProps({ index, value })} />
|
||||
</Grid>
|
||||
</CSSTransition>
|
||||
))}
|
||||
key={`card-${key.replace(/\s/g, '')}`}
|
||||
classNames={classes.item}
|
||||
timeout={400}
|
||||
>
|
||||
<Grid item {...breakpoints}>
|
||||
<CardComponent value={value} {...cardsProps({ index, value })} />
|
||||
</Grid>
|
||||
</CSSTransition>
|
||||
)
|
||||
})}
|
||||
</TransitionGroup>
|
||||
) : (
|
||||
(displayEmpty || EmptyComponent) && (
|
||||
|
||||
@@ -36,7 +36,12 @@ const ListHeader = memo(({
|
||||
</Box>
|
||||
<Box className={classes.actions}>
|
||||
{!!(hasAddButton || addButtonProps) && (
|
||||
<SubmitButton icon label={<AddIcon />} {...addButtonProps} />
|
||||
<SubmitButton
|
||||
color='primary'
|
||||
icon
|
||||
label={<AddIcon />}
|
||||
{...addButtonProps}
|
||||
/>
|
||||
)}
|
||||
{!!(hasSearch || searchProps) && (
|
||||
<Box className={classes.search}>
|
||||
|
||||
@@ -49,6 +49,7 @@ const Form = ({ onBack, onSubmit, resolver, fields, error, isLoading, transition
|
||||
</Button>
|
||||
)}
|
||||
<SubmitButton
|
||||
color='primary'
|
||||
data-cy="login-button"
|
||||
isSubmitting={isLoading}
|
||||
label={onBack ? Tr(T.Next) : Tr(T.SignIn)}
|
||||
|
||||
@@ -46,6 +46,7 @@ const Provider = () => ({
|
||||
return (
|
||||
<ListCards
|
||||
list={templates}
|
||||
keyProp='name'
|
||||
isLoading={!templates || loading}
|
||||
EmptyComponent={
|
||||
<EmptyCard title={'Your providers templates list is empty'} />
|
||||
@@ -55,7 +56,6 @@ const Provider = () => ({
|
||||
const isSelected = data?.some(selected => selected === name)
|
||||
|
||||
return {
|
||||
id: name.replace(/\s/g, ''),
|
||||
isProvider: true,
|
||||
isSelected,
|
||||
handleClick: () => handleClick(name, isSelected)
|
||||
|
||||
@@ -50,9 +50,11 @@ function ProviderCreateForm () {
|
||||
.find(({ name }) => name === providerSelected) ?? {}
|
||||
|
||||
if (!providerSelected) {
|
||||
showError(`
|
||||
showError({
|
||||
message: `
|
||||
Cannot found provider template (${providerSelected}),
|
||||
ask your cloud administrator`)
|
||||
ask your cloud administrator`
|
||||
})
|
||||
history.push(PATH.PROVISIONS.LIST)
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ function Providers () {
|
||||
{
|
||||
handleClick: () =>
|
||||
history.push(PATH.PROVIDERS.EDIT.replace(':id', ID)),
|
||||
icon: EditIcon,
|
||||
icon: <EditIcon />,
|
||||
cy: `provider-edit-${ID}`
|
||||
},
|
||||
{
|
||||
@@ -73,8 +73,7 @@ function Providers () {
|
||||
setShowDialog(false)
|
||||
}
|
||||
}),
|
||||
icon: DeleteIcon,
|
||||
iconProps: { color: 'error' },
|
||||
icon: <DeleteIcon color='error' />,
|
||||
cy: `provider-delete-${ID}`
|
||||
}
|
||||
]
|
||||
|
||||
@@ -3,35 +3,45 @@ import PropTypes from 'prop-types'
|
||||
|
||||
import DeleteIcon from '@material-ui/icons/Delete'
|
||||
|
||||
import useFetchAll from 'client/hooks/useFetchAll'
|
||||
import useProvision from 'client/hooks/useProvision'
|
||||
import useOpennebula from 'client/hooks/useOpennebula'
|
||||
import useFetchAll from 'client/hooks/useFetchAll'
|
||||
import ListCards from 'client/components/List/ListCards'
|
||||
import { DatastoreCard } from 'client/components/Cards'
|
||||
|
||||
const Datastores = memo(({ hidden, data }) => {
|
||||
const Datastores = memo(({ hidden, data, fetchRequest }) => {
|
||||
const {
|
||||
datastores
|
||||
} = data?.TEMPLATE?.PROVISION_BODY?.provision?.infrastructure
|
||||
|
||||
const { deleteDatastore } = useProvision()
|
||||
const { getDatastore } = useOpennebula()
|
||||
const { data: list, fetchRequestAll, loading } = useFetchAll()
|
||||
|
||||
useEffect(() => {
|
||||
if (!hidden) {
|
||||
const requests = datastores?.map(getDatastore) ?? []
|
||||
fetchRequestAll(requests)
|
||||
}
|
||||
}, [datastores])
|
||||
|
||||
useEffect(() => {
|
||||
if (!list && !hidden) {
|
||||
const reqs = datastores?.map(({ id }) => getDatastore({ id })) ?? []
|
||||
fetchRequestAll(reqs)
|
||||
const requests = datastores?.map(getDatastore) ?? []
|
||||
fetchRequestAll(requests)
|
||||
}
|
||||
}, [hidden])
|
||||
|
||||
return (
|
||||
<ListCards
|
||||
list={list}
|
||||
isLoading={loading}
|
||||
isLoading={!list && loading}
|
||||
CardComponent={DatastoreCard}
|
||||
cardsProps={({ value: { ID } }) => ({
|
||||
actions: [{
|
||||
handleClick: () => undefined,
|
||||
icon: DeleteIcon,
|
||||
handleClick: () => deleteDatastore({ id: ID })
|
||||
.then(() => fetchRequest(undefined, { reload: true })),
|
||||
icon: <DeleteIcon />,
|
||||
cy: `provision-datastore-delete-${ID}`
|
||||
}]
|
||||
})}
|
||||
@@ -39,16 +49,19 @@ const Datastores = memo(({ hidden, data }) => {
|
||||
breakpoints={{ xs: 12, md: 6 }}
|
||||
/>
|
||||
)
|
||||
}, (prev, next) => prev.hidden === next.hidden)
|
||||
}, (prev, next) =>
|
||||
prev.hidden === next.hidden && prev.data === next.data)
|
||||
|
||||
Datastores.propTypes = {
|
||||
data: PropTypes.object.isRequired,
|
||||
hidden: PropTypes.bool
|
||||
hidden: PropTypes.bool,
|
||||
fetchRequest: PropTypes.func
|
||||
}
|
||||
|
||||
Datastores.defaultProps = {
|
||||
data: {},
|
||||
hidden: false
|
||||
hidden: false,
|
||||
fetchRequest: () => undefined
|
||||
}
|
||||
|
||||
Datastores.displayName = 'Datastores'
|
||||
|
||||
@@ -4,41 +4,51 @@ import PropTypes from 'prop-types'
|
||||
import DeleteIcon from '@material-ui/icons/Delete'
|
||||
import ConfigureIcon from '@material-ui/icons/Build'
|
||||
|
||||
import useFetchAll from 'client/hooks/useFetchAll'
|
||||
import useProvision from 'client/hooks/useProvision'
|
||||
import useOpennebula from 'client/hooks/useOpennebula'
|
||||
import useFetchAll from 'client/hooks/useFetchAll'
|
||||
import ListCards from 'client/components/List/ListCards'
|
||||
import { HostCard } from 'client/components/Cards'
|
||||
|
||||
const Hosts = memo(({ hidden, data }) => {
|
||||
const Hosts = memo(({ hidden, data, fetchRequest }) => {
|
||||
const {
|
||||
hosts
|
||||
} = data?.TEMPLATE?.PROVISION_BODY?.provision?.infrastructure
|
||||
|
||||
const { configureHost, deleteHost } = useProvision()
|
||||
const { getHost } = useOpennebula()
|
||||
const { data: list, fetchRequestAll, loading } = useFetchAll()
|
||||
|
||||
useEffect(() => {
|
||||
if (!hidden) {
|
||||
const requests = hosts?.map(getHost) ?? []
|
||||
fetchRequestAll(requests)
|
||||
}
|
||||
}, [hosts])
|
||||
|
||||
useEffect(() => {
|
||||
if (!list && !hidden) {
|
||||
const reqs = hosts?.map(({ id }) => getHost({ id })) ?? []
|
||||
fetchRequestAll(reqs)
|
||||
const requests = hosts?.map(getHost) ?? []
|
||||
fetchRequestAll(requests)
|
||||
}
|
||||
}, [hidden])
|
||||
|
||||
return (
|
||||
<ListCards
|
||||
list={list}
|
||||
isLoading={loading}
|
||||
isLoading={!list && loading}
|
||||
CardComponent={HostCard}
|
||||
cardsProps={({ value: { ID } }) => ({
|
||||
actions: [
|
||||
{
|
||||
handleClick: () => undefined,
|
||||
icon: ConfigureIcon,
|
||||
handleClick: () => configureHost({ id: ID }),
|
||||
icon: <ConfigureIcon />,
|
||||
cy: `provision-host-configure-${ID}`
|
||||
},
|
||||
{
|
||||
handleClick: () => undefined,
|
||||
icon: DeleteIcon,
|
||||
handleClick: () => deleteHost({ id: ID })
|
||||
.then(() => fetchRequest(undefined, { reload: true })),
|
||||
icon: <DeleteIcon />,
|
||||
cy: `provision-host-delete-${ID}`
|
||||
}
|
||||
]
|
||||
@@ -47,16 +57,19 @@ const Hosts = memo(({ hidden, data }) => {
|
||||
breakpoints={{ xs: 12, md: 6 }}
|
||||
/>
|
||||
)
|
||||
}, (prev, next) => prev.hidden === next.hidden)
|
||||
}, (prev, next) =>
|
||||
prev.hidden === next.hidden && prev.data === next.data)
|
||||
|
||||
Hosts.propTypes = {
|
||||
data: PropTypes.object.isRequired,
|
||||
hidden: PropTypes.bool
|
||||
hidden: PropTypes.bool,
|
||||
fetchRequest: PropTypes.func
|
||||
}
|
||||
|
||||
Hosts.defaultProps = {
|
||||
data: {},
|
||||
hidde: false
|
||||
hidde: false,
|
||||
fetchRequest: () => undefined
|
||||
}
|
||||
|
||||
Hosts.displayName = 'Hosts'
|
||||
|
||||
@@ -19,7 +19,7 @@ const TABS = [
|
||||
{ name: 'hosts', icon: HostIcon, content: HostsTab }
|
||||
]
|
||||
|
||||
const DialogInfo = ({ data }) => {
|
||||
const DialogInfo = ({ data, ...methods }) => {
|
||||
const [tabSelected, setTab] = useState(0)
|
||||
|
||||
const renderTabs = useMemo(() => (
|
||||
@@ -54,21 +54,25 @@ const DialogInfo = ({ data }) => {
|
||||
key={`tab-${name}`}
|
||||
overflow="auto"
|
||||
>
|
||||
<Content hidden={tabSelected !== idx} data={data} />
|
||||
<Content
|
||||
data={data}
|
||||
hidden={tabSelected !== idx}
|
||||
{...methods}
|
||||
/>
|
||||
</Box>
|
||||
)), [tabSelected])}
|
||||
)), [tabSelected, data])}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
DialogInfo.propTypes = {
|
||||
data: PropTypes.object.isRequired,
|
||||
handleClose: PropTypes.func
|
||||
fetchRequest: PropTypes.func
|
||||
}
|
||||
|
||||
DialogInfo.defaultProps = {
|
||||
data: {},
|
||||
handleClose: undefined
|
||||
fetchRequest: undefined
|
||||
}
|
||||
|
||||
export default DialogInfo
|
||||
@@ -3,35 +3,45 @@ import PropTypes from 'prop-types'
|
||||
|
||||
import DeleteIcon from '@material-ui/icons/Delete'
|
||||
|
||||
import useFetchAll from 'client/hooks/useFetchAll'
|
||||
import useProvision from 'client/hooks/useProvision'
|
||||
import useOpennebula from 'client/hooks/useOpennebula'
|
||||
import useFetchAll from 'client/hooks/useFetchAll'
|
||||
import ListCards from 'client/components/List/ListCards'
|
||||
import { NetworkCard } from 'client/components/Cards'
|
||||
|
||||
const Networks = memo(({ hidden, data }) => {
|
||||
const Networks = memo(({ hidden, data, fetchRequest }) => {
|
||||
const {
|
||||
networks
|
||||
} = data?.TEMPLATE?.PROVISION_BODY?.provision?.infrastructure
|
||||
|
||||
const { deleteVNetwork } = useProvision()
|
||||
const { getVNetwork } = useOpennebula()
|
||||
const { data: list, fetchRequestAll, loading } = useFetchAll()
|
||||
|
||||
useEffect(() => {
|
||||
if (!hidden) {
|
||||
const requests = networks?.map(getVNetwork) ?? []
|
||||
fetchRequestAll(requests)
|
||||
}
|
||||
}, [networks])
|
||||
|
||||
useEffect(() => {
|
||||
if (!list && !hidden) {
|
||||
const reqs = networks?.map(({ id }) => getVNetwork({ id })) ?? []
|
||||
fetchRequestAll(reqs)
|
||||
const requests = networks?.map(getVNetwork) ?? []
|
||||
fetchRequestAll(requests)
|
||||
}
|
||||
}, [hidden])
|
||||
|
||||
return (
|
||||
<ListCards
|
||||
list={list}
|
||||
isLoading={loading}
|
||||
isLoading={!list && loading}
|
||||
CardComponent={NetworkCard}
|
||||
cardsProps={({ value: { ID } }) => ({
|
||||
actions: [{
|
||||
handleClick: () => undefined,
|
||||
icon: DeleteIcon,
|
||||
handleClick: () => deleteVNetwork({ id: ID })
|
||||
.then(() => fetchRequest(undefined, { reload: true })),
|
||||
icon: <DeleteIcon />,
|
||||
cy: `provision-vnet-delete-${ID}`
|
||||
}]
|
||||
})}
|
||||
@@ -39,16 +49,19 @@ const Networks = memo(({ hidden, data }) => {
|
||||
breakpoints={{ xs: 12, md: 6 }}
|
||||
/>
|
||||
)
|
||||
}, (prev, next) => prev.hidden === next.hidden)
|
||||
}, (prev, next) =>
|
||||
prev.hidden === next.hidden && prev.data === next.data)
|
||||
|
||||
Networks.propTypes = {
|
||||
data: PropTypes.object.isRequired,
|
||||
hidden: PropTypes.bool
|
||||
hidden: PropTypes.bool,
|
||||
fetchRequest: PropTypes.func
|
||||
}
|
||||
|
||||
Networks.defaultProps = {
|
||||
data: {},
|
||||
hidden: false
|
||||
hidden: false,
|
||||
fetchRequest: () => undefined
|
||||
}
|
||||
|
||||
Networks.displayName = 'Networks'
|
||||
|
||||
@@ -5,7 +5,7 @@ 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 { ListCards } from 'client/components/List'
|
||||
import { EmptyCard, ProvisionTemplateCard } from 'client/components/Cards'
|
||||
import { PATH } from 'client/router/provision'
|
||||
import { Tr } from 'client/components/HOC'
|
||||
@@ -46,6 +46,7 @@ const Provision = () => ({
|
||||
return (
|
||||
<ListCards
|
||||
list={templates}
|
||||
keyProp='name'
|
||||
isLoading={!templates && loading}
|
||||
EmptyComponent={
|
||||
<EmptyCard title={'Your provisions templates list is empty'} />
|
||||
@@ -56,7 +57,6 @@ const Provision = () => ({
|
||||
const { provision: { provider } = {} } = defaults
|
||||
|
||||
return {
|
||||
id: name.replace(/\s/g, ''),
|
||||
isSelected,
|
||||
handleClick: () => handleClick(name, provider, isSelected)
|
||||
}
|
||||
|
||||
@@ -40,9 +40,11 @@ function ProvisionCreateForm () {
|
||||
.find(({ name }) => name === provisionSelected)
|
||||
|
||||
if (!provisionTemplate) {
|
||||
showError(`
|
||||
showError({
|
||||
message: `
|
||||
Cannot found provider template (${provisionSelected}),
|
||||
ask your cloud administrator`)
|
||||
ask your cloud administrator`
|
||||
})
|
||||
history.push(PATH.PROVISIONS.LIST)
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ function Provisions () {
|
||||
|
||||
useEffect(() => { fetchRequest() }, [])
|
||||
|
||||
const handleCancel = () => setShowDialog(false)
|
||||
|
||||
return (
|
||||
<Container disableGutters>
|
||||
<ListHeader
|
||||
@@ -66,8 +68,7 @@ function Provisions () {
|
||||
},
|
||||
content: DialogInfo
|
||||
}),
|
||||
icon: DeleteIcon,
|
||||
iconProps: { color: 'error' },
|
||||
icon: <DeleteIcon color='error' />,
|
||||
cy: `provision-delete-${ID}`
|
||||
}]
|
||||
})}
|
||||
@@ -80,7 +81,7 @@ function Provisions () {
|
||||
request={() => getProvision({ id: showDialog.id })}
|
||||
dialogProps={{
|
||||
title: showDialog.title,
|
||||
handleCancel: () => setShowDialog(false),
|
||||
handleCancel,
|
||||
handleAccept: showDialog.handleAccept,
|
||||
contentProps: {
|
||||
style: {
|
||||
@@ -91,7 +92,7 @@ function Provisions () {
|
||||
}
|
||||
}}
|
||||
>
|
||||
{({ data }) => createElement(showDialog.content, { data })}
|
||||
{props => createElement(showDialog.content, props)}
|
||||
</DialogRequest>
|
||||
)}
|
||||
</Container>
|
||||
|
||||
@@ -172,6 +172,58 @@ export default function useOpennebula () {
|
||||
, [dispatch, provisions]
|
||||
)
|
||||
|
||||
// --------------------------------------------
|
||||
// INFRASTRUCTURES REQUESTS
|
||||
// --------------------------------------------
|
||||
|
||||
const deleteDatastore = useCallback(
|
||||
({ id }) =>
|
||||
serviceProvision
|
||||
.deleteDatastore({ id })
|
||||
.then(doc => {
|
||||
dispatch(enqueueSuccess(`Datastore deleted - ID: ${doc}`))
|
||||
return doc
|
||||
})
|
||||
.catch(err => dispatch(enqueueError(err ?? 'Error DELETE datastore')))
|
||||
, [dispatch, provisions]
|
||||
)
|
||||
|
||||
const deleteVNetwork = useCallback(
|
||||
({ id }) =>
|
||||
serviceProvision
|
||||
.deleteVNetwork({ id })
|
||||
.then(doc => {
|
||||
dispatch(enqueueSuccess(`VNetwork deleted - ID: ${id}`))
|
||||
return doc
|
||||
})
|
||||
.catch(err => dispatch(enqueueError(err ?? 'Error DELETE network')))
|
||||
, [dispatch, provisions]
|
||||
)
|
||||
|
||||
const deleteHost = useCallback(
|
||||
({ id }) =>
|
||||
serviceProvision
|
||||
.deleteHost({ id })
|
||||
.then(doc => {
|
||||
dispatch(enqueueSuccess(`Host deleted - ID: ${id}`))
|
||||
return doc
|
||||
})
|
||||
.catch(err => dispatch(enqueueError(err ?? 'Error DELETE host')))
|
||||
, [dispatch, provisions]
|
||||
)
|
||||
|
||||
const configureHost = useCallback(
|
||||
({ id }) =>
|
||||
serviceProvision
|
||||
.configureHost({ id })
|
||||
.then(doc => {
|
||||
dispatch(enqueueSuccess(`Host configuring - ID: ${id}`))
|
||||
return doc
|
||||
})
|
||||
.catch(err => dispatch(enqueueError(err ?? 'Error CONFIGURE host')))
|
||||
, [dispatch, provisions]
|
||||
)
|
||||
|
||||
return {
|
||||
providersTemplates,
|
||||
getProvidersTemplates,
|
||||
@@ -190,6 +242,11 @@ export default function useOpennebula () {
|
||||
getProvision,
|
||||
getProvisions,
|
||||
createProvision,
|
||||
deleteProvision
|
||||
deleteProvision,
|
||||
|
||||
deleteDatastore,
|
||||
deleteVNetwork,
|
||||
deleteHost,
|
||||
configureHost
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { httpMethod } from 'server/utils/constants/defaults'
|
||||
import { PROVISION } from 'server/routes/api/provision/string-routes'
|
||||
import { requestData } from 'client/utils'
|
||||
|
||||
const { GET, POST, DELETE } = httpMethod
|
||||
const { GET, POST, PUT, DELETE } = httpMethod
|
||||
|
||||
// --------------------------------------------
|
||||
// PROVISIONS TEMPLATES REQUESTS
|
||||
@@ -75,10 +75,62 @@ export const deleteProvision = ({ id }) =>
|
||||
return res?.data ?? {}
|
||||
})
|
||||
|
||||
// --------------------------------------------
|
||||
// INFRASTRUCTURES REQUESTS
|
||||
// --------------------------------------------
|
||||
|
||||
export const deleteDatastore = ({ id }) =>
|
||||
requestData(`/api/${PROVISION}/datastore/${id}`, {
|
||||
method: DELETE,
|
||||
error: err => err?.message
|
||||
}).then(res => {
|
||||
if (!res?.id || res?.id !== httpCodes.ok.id) throw res
|
||||
|
||||
return res?.data ?? {}
|
||||
})
|
||||
|
||||
export const deleteVNetwork = ({ id }) =>
|
||||
requestData(`/api/${PROVISION}/network/${id}`, {
|
||||
method: DELETE,
|
||||
error: err => err?.message
|
||||
}).then(res => {
|
||||
if (!res?.id || res?.id !== httpCodes.ok.id) throw res
|
||||
|
||||
return res?.data ?? {}
|
||||
})
|
||||
|
||||
export const deleteHost = ({ id }) =>
|
||||
requestData(`/api/${PROVISION}/host/${id}`, {
|
||||
method: DELETE,
|
||||
error: err => err?.message
|
||||
}).then(res => {
|
||||
if (!res?.id || res?.id !== httpCodes.ok.id) throw res
|
||||
|
||||
return res?.data ?? {}
|
||||
})
|
||||
|
||||
export const configureHost = ({ id }) =>
|
||||
requestData(`/api/${PROVISION}/host/${id}`, {
|
||||
method: PUT,
|
||||
error: err => err?.message
|
||||
}).then(res => {
|
||||
if (!res?.id || res?.id !== httpCodes.ok.id) {
|
||||
if (res?.id === httpCodes.accepted.id) return res
|
||||
throw res
|
||||
}
|
||||
|
||||
return res?.data ?? {}
|
||||
})
|
||||
|
||||
export default {
|
||||
getProvisionsTemplates,
|
||||
getProvision,
|
||||
getProvisions,
|
||||
createProvision,
|
||||
deleteProvision
|
||||
deleteProvision,
|
||||
|
||||
deleteDatastore,
|
||||
deleteVNetwork,
|
||||
deleteHost,
|
||||
configureHost
|
||||
}
|
||||
Reference in new issue
Block a user