Skip to content

Commit

Permalink
F #6123: Add VDC tab to FireEdge Sunstone (#2661)
Browse files Browse the repository at this point in the history
Co-authored-by: Frederick Borges <[email protected]>
  • Loading branch information
jloboescalona2 and Frederick Borges authored Jul 12, 2023
1 parent 201d388 commit b06bd9a
Show file tree
Hide file tree
Showing 79 changed files with 4,483 additions and 89 deletions.
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2970,6 +2970,7 @@ FIREEDGE_SUNSTONE_ETC_VIEW_ADMIN="src/fireedge/etc/sunstone/admin/vm-tab.yaml \
src/fireedge/etc/sunstone/admin/sec-group-tab.yaml\
src/fireedge/etc/sunstone/admin/backup-tab.yaml \
src/fireedge/etc/sunstone/admin/datastore-tab.yaml \
src/fireedge/etc/sunstone/admin/vdc-tab.yaml \
src/fireedge/etc/sunstone/admin/host-tab.yaml"

FIREEDGE_SUNSTONE_ETC_VIEW_USER="src/fireedge/etc/sunstone/user/vm-tab.yaml \
Expand Down
56 changes: 56 additions & 0 deletions src/fireedge/etc/sunstone/admin/vdc-tab.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
# This file describes the information and actions available in the VIRTUAL DATA CENTER tab

# Resource

resource_name: "VIRTUAL-DATA-CENTER"

# Actions - Which buttons are visible to operate over the resources

actions:
create_dialog: true
update_dialog: true
delete: true
edit_labels: true

# Filters - List of criteria to filter the resources

filters:
label: true

# Info Tabs - Which info tabs are used to show extended information

info-tabs:
info:
enabled: true
information_panel:
enabled: true
actions:
rename: true
attributes_panel:
enabled: true
actions:
copy: true
add: true
edit: true
delete: true

groups:
enabled: true
clusters:
enabled: true
datastores:
enabled: true
hosts:
enabled: true
vnets:
enabled: true


# Dialogs
dialogs:
create_dialog:
clusters: true
datastores: true
hosts: true
vnets: true
12 changes: 6 additions & 6 deletions src/fireedge/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 52 additions & 1 deletion src/fireedge/src/client/apps/sunstone/routesOne.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
EmptyPage as TemplateIcon,
Archive as TemplatesIcon,
User as UserIcon,
List as VDCIcon,
Shuffle as VRoutersIcons,
ModernTv as VmsIcons,
MinusPinAlt as ZoneIcon,
Expand Down Expand Up @@ -103,6 +104,10 @@ const CreateDatastores = loadable(
ssr: false,
}
)
const DatastoreDetail = loadable(
() => import('client/containers/Datastores/Detail'),
{ ssr: false }
)

const Images = loadable(() => import('client/containers/Images'), {
ssr: false,
Expand Down Expand Up @@ -199,7 +204,17 @@ const Groups = loadable(() => import('client/containers/Groups'), {
const GroupDetail = loadable(() => import('client/containers/Groups/Detail'), {
ssr: false,
})
// const VDCs = loadable(() => import('client/containers/VDCs'), { ssr: false })

const VDCs = loadable(() => import('client/containers/VDCs'), { ssr: false })

const VDCDetail = loadable(() => import('client/containers/VDCs/Detail'), {
ssr: false,
})

const VDCCreate = loadable(() => import('client/containers/VDCs/Create'), {
ssr: false,
})

// const ACLs = loadable(() => import('client/containers/ACLs'), { ssr: false })

export const PATH = {
Expand Down Expand Up @@ -301,6 +316,11 @@ export const PATH = {
LIST: `/${RESOURCE_NAMES.GROUP}`,
DETAIL: `/${RESOURCE_NAMES.GROUP}/:id`,
},
VDCS: {
LIST: `/${RESOURCE_NAMES.VDC}`,
DETAIL: `/${RESOURCE_NAMES.VDC}/:id`,
CREATE: `/${RESOURCE_NAMES.VDC}/create`,
},
},
}

Expand Down Expand Up @@ -424,6 +444,12 @@ const ENDPOINTS = [
path: PATH.STORAGE.DATASTORES.CREATE,
Component: CreateDatastores,
},
{
title: T.Datastore,
description: (params) => `#${params?.id}`,
path: PATH.STORAGE.DATASTORES.DETAIL,
Component: DatastoreDetail,
},
{
title: T.Images,
path: PATH.STORAGE.IMAGES.LIST,
Expand Down Expand Up @@ -609,6 +635,31 @@ const ENDPOINTS = [
path: PATH.SYSTEM.GROUPS.DETAIL,
Component: GroupDetail,
},
{
title: (_, state) =>
state?.ID !== undefined ? T.UpdateVDC : T.CreateVDC,
path: PATH.SYSTEM.VDCS.CREATE,
Component: VDCCreate,
},
{
title: T.VDCs,
path: PATH.SYSTEM.VDCS.LIST,
sidebar: true,
icon: VDCIcon,
Component: VDCs,
},
{
title: T.VDC,
description: (params) => `#${params?.id}`,
path: PATH.SYSTEM.VDCS.DETAIL,
Component: VDCDetail,
},
// {
// title: T.Group,
// description: (params) => `#${params?.id}`,
// path: PATH.SYSTEM.GROUPS.DETAIL,
// Component: GroupDetail,
// },
],
},
]
Expand Down
173 changes: 173 additions & 0 deletions src/fireedge/src/client/components/Cards/VirtualDataCenterCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/* ------------------------------------------------------------------------- *
* Copyright 2002-2023, OpenNebula Project, OpenNebula Systems *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
* not use this file except in compliance with the License. You may obtain *
* a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import PropTypes from 'prop-types'
import { ReactElement, memo, useMemo } from 'react'

import { Typography } from '@mui/material'
import {
Server as ClusterIcon,
Db as DatastoreIcon,
Group as GroupIcon,
HardDrive as HostIcon,
Network as VNetIcon,
} from 'iconoir-react'

import MultipleTags from 'client/components/MultipleTags'
import { useViews } from 'client/features/Auth'

import { Tr } from 'client/components/HOC'
import { StatusCircle } from 'client/components/Status'
import { rowStyles } from 'client/components/Tables/styles'

import { ACTIONS, ALL_SELECTED, RESOURCE_NAMES, T, VDC } from 'client/constants'
import COLOR from 'client/constants/color'
import { getColorFromString, getUniqueLabels } from 'client/models/Helper'

const isAllSelected = (resourceArray) =>
resourceArray.length === 1 && resourceArray[0] === ALL_SELECTED

const VirtualDataCenterCard = memo(
/**
* @param {object} props - Props
* @param {VDC} props.template - Virtual Data Center resource
* @param {object} props.rootProps - Props to root component
* @param {function(string):Promise} [props.onClickLabel] - Callback to click label
* @param {function(string):Promise} [props.onDeleteLabel] - Callback to delete label
* @returns {ReactElement} - Card
*/
({ template, rootProps, onClickLabel, onDeleteLabel }) => {
const classes = rowStyles()
const { [RESOURCE_NAMES.VDC]: vdcView } = useViews()

const enableEditLabels =
vdcView?.actions?.[ACTIONS.EDIT_LABELS] === true && !!onDeleteLabel

const {
ID,
NAME,
GROUPS,
CLUSTERS,
HOSTS,
DATASTORES,
VNETS,
TEMPLATE: { LABELS },
} = template

const groupsCount = useMemo(() => {
const { ID: groupsIds = [] } = GROUPS
const groupsArray = Array.isArray(groupsIds) ? groupsIds : [groupsIds]

return groupsArray.length
}, [GROUPS.ID])

const clustersCount = useMemo(() => {
const { CLUSTER: clustersInfo = [] } = CLUSTERS
const clustersArray = (
Array.isArray(clustersInfo) ? clustersInfo : [clustersInfo]
).map((cluster) => cluster.CLUSTER_ID)

return isAllSelected(clustersArray) ? T.All : clustersArray.length
}, [CLUSTERS.CLUSTER])

const hostsCount = useMemo(() => {
const { HOST: hostsInfo = [] } = HOSTS
const hostsArray = (
Array.isArray(hostsInfo) ? hostsInfo : [hostsInfo]
).map((host) => host.HOST_ID)

return isAllSelected(hostsArray) ? T.All : hostsArray.length
}, [HOSTS.HOST])

const datastoresCount = useMemo(() => {
const { DATASTORE: datastoresInfo = [] } = DATASTORES
const datastoresArray = (
Array.isArray(datastoresInfo) ? datastoresInfo : [datastoresInfo]
).map((ds) => ds.DATASTORE_ID)

return isAllSelected(datastoresArray) ? T.All : datastoresArray.length
}, [DATASTORES.DATASTORE])

const vnetsCount = useMemo(() => {
const { VNET: vnetsInfo = [] } = VNETS
const vnetsArray = (
Array.isArray(vnetsInfo) ? vnetsInfo : [vnetsInfo]
).map((vnet) => vnet.VNET_ID)

return isAllSelected(vnetsArray) ? T.All : vnetsArray.length
}, [VNETS.VNET])

const labels = useMemo(
() =>
getUniqueLabels(LABELS).map((label) => ({
text: label,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: enableEditLabels && onDeleteLabel,
})),
[LABELS, enableEditLabels, onClickLabel, onDeleteLabel]
)

return (
<div {...rootProps} data-cy={`vdc-${ID}`}>
<div className={classes.main}>
<div className={classes.title}>
<StatusCircle color={COLOR.success.main} />
<Typography component="span">{NAME}</Typography>
<span className={classes.labels}>
<MultipleTags tags={labels} />
</span>
</div>
<div className={classes.caption}>
<span>{`#${ID}`}</span>
<span title={`${Tr(T.Groups)}: ${groupsCount}`}>
<GroupIcon />
<span>{` ${groupsCount}`}</span>
</span>
<span title={`${Tr(T.Clusters)}: ${clustersCount}`}>
<ClusterIcon />
<span>{` ${clustersCount}`}</span>
</span>
<span title={`${Tr(T.Hosts)}: ${hostsCount}`}>
<HostIcon />
<span>{` ${hostsCount}`}</span>
</span>
<span title={`${Tr(T.Datastores)}: ${datastoresCount}`}>
<DatastoreIcon />
<span>{` ${datastoresCount}`}</span>
</span>
<span title={`${Tr(T.VirtualNetworks)}: ${vnetsCount}`}>
<VNetIcon />
<span>{` ${vnetsCount}`}</span>
</span>
</div>
</div>
</div>
)
}
)

VirtualDataCenterCard.propTypes = {
template: PropTypes.object,
rootProps: PropTypes.shape({
className: PropTypes.string,
}),
onClickLabel: PropTypes.func,
onDeleteLabel: PropTypes.func,
}

VirtualDataCenterCard.displayName = 'VirtualDataCenterCard'

export default VirtualDataCenterCard
2 changes: 2 additions & 0 deletions src/fireedge/src/client/components/Cards/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import ServiceCard from 'client/components/Cards/ServiceCard'
import ServiceTemplateCard from 'client/components/Cards/ServiceTemplateCard'
import SnapshotCard from 'client/components/Cards/SnapshotCard'
import TierCard from 'client/components/Cards/TierCard'
import VirtualDataCenterCard from 'client/components/Cards/VirtualDataCenterCard'
import VirtualMachineCard from 'client/components/Cards/VirtualMachineCard'
import VmTemplateCard from 'client/components/Cards/VmTemplateCard'
import WavesCard from 'client/components/Cards/WavesCard'
Expand Down Expand Up @@ -70,6 +71,7 @@ export {
ServiceTemplateCard,
SnapshotCard,
TierCard,
VirtualDataCenterCard,
VirtualMachineCard,
VmTemplateCard,
WavesCard,
Expand Down
Loading

0 comments on commit b06bd9a

Please sign in to comment.