Skip to content

Commit

Permalink
F #5833: Add initial to oneflow in Sunstone (#2069)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Betanzos authored May 23, 2022
1 parent 6c3fe14 commit bcb12e7
Show file tree
Hide file tree
Showing 45 changed files with 2,608 additions and 240 deletions.
76 changes: 75 additions & 1 deletion src/fireedge/src/client/apps/sunstone/routesOne.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import {
ModernTv as VmsIcons,
Shuffle as VRoutersIcons,
Archive as TemplatesIcon,
GoogleDocs as TemplateIcon,
EmptyPage as TemplateIcon,
Packages as ServicesIcon,
MultiplePagesEmpty as ServiceTemplateIcon,
Box as StorageIcon,
Db as DatastoreIcon,
BoxIso as ImageIcon,
Expand Down Expand Up @@ -52,6 +54,14 @@ const VirtualRouters = loadable(
{ ssr: false }
)

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

const VmTemplates = loadable(() => import('client/containers/VmTemplates'), {
ssr: false,
})
Expand All @@ -70,6 +80,17 @@ const VMTemplateDetail = loadable(
// const VrTemplates = loadable(() => import('client/containers/VrTemplates'), { ssr: false })
// const VmGroups = loadable(() => import('client/containers/VmGroups'), { ssr: false })

const ServiceTemplates = loadable(
() => import('client/containers/ServiceTemplates'),
{ ssr: false }
)
// const DeployServiceTemplates = loadable(() => import('client/containers/ServiceTemplates/Instantiate'), { ssr: false })
// const CreateServiceTemplates = loadable(() => import('client/containers/ServiceTemplates/Create'), { ssr: false })
const ServiceTemplateDetail = loadable(
() => import('client/containers/ServiceTemplates/Detail'),
{ ssr: false }
)

const Datastores = loadable(() => import('client/containers/Datastores'), {
ssr: false,
})
Expand Down Expand Up @@ -137,6 +158,10 @@ export const PATH = {
VROUTERS: {
LIST: `/${RESOURCE_NAMES.V_ROUTER}`,
},
SERVICES: {
LIST: `/${RESOURCE_NAMES.SERVICE}`,
DETAIL: `/${RESOURCE_NAMES.SERVICE}/:id`,
},
},
TEMPLATE: {
VMS: {
Expand All @@ -145,6 +170,12 @@ export const PATH = {
CREATE: `/${RESOURCE_NAMES.VM_TEMPLATE}/create`,
DETAIL: `/${RESOURCE_NAMES.VM_TEMPLATE}/:id`,
},
SERVICES: {
LIST: `/${RESOURCE_NAMES.SERVICE_TEMPLATE}`,
DETAIL: `/${RESOURCE_NAMES.SERVICE_TEMPLATE}/:id`,
DEPLOY: `/${RESOURCE_NAMES.SERVICE_TEMPLATE}/deploy/`,
CREATE: `/${RESOURCE_NAMES.SERVICE_TEMPLATE}/create`,
},
},
STORAGE: {
DATASTORES: {
Expand Down Expand Up @@ -231,6 +262,19 @@ const ENDPOINTS = [
icon: VRoutersIcons,
Component: VirtualRouters,
},
{
title: T.Services,
path: PATH.INSTANCE.SERVICES.LIST,
sidebar: true,
icon: ServicesIcon,
Component: Services,
},
{
title: T.Service,
description: (params) => `#${params?.id}`,
path: PATH.INSTANCE.SERVICES.DETAIL,
Component: ServiceDetail,
},
],
},
{
Expand Down Expand Up @@ -265,6 +309,36 @@ const ENDPOINTS = [
path: PATH.TEMPLATE.VMS.DETAIL,
Component: VMTemplateDetail,
},
{
title: T.ServiceTemplates,
path: PATH.TEMPLATE.SERVICES.LIST,
sidebar: true,
icon: ServiceTemplateIcon,
Component: ServiceTemplates,
},
/* {
title: T.DeployServiceTemplate,
description: (_, state) =>
state?.ID !== undefined && `#${state.ID} ${state.NAME}`,
path: PATH.TEMPLATE.SERVICES.DEPLOY,
Component: DeployServiceTemplates,
},
{
title: (_, state) =>
state?.ID !== undefined
? T.UpdateServiceTemplate
: T.CreateServiceTemplate,
description: (_, state) =>
state?.ID !== undefined && `#${state.ID} ${state.NAME}`,
path: PATH.TEMPLATE.SERVICES.CREATE,
Component: CreateServiceTemplates,
}, */
{
title: T.ServiceTemplate,
description: (params) => `#${params?.id}`,
path: PATH.TEMPLATE.SERVICES.DETAIL,
Component: ServiceTemplateDetail,
},
],
},
{
Expand Down
108 changes: 108 additions & 0 deletions src/fireedge/src/client/components/Cards/ServiceCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* ------------------------------------------------------------------------- *
* Copyright 2002-2022, 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 { ReactElement, memo, useMemo } from 'react'
import PropTypes from 'prop-types'

import { WarningCircledOutline as WarningIcon } from 'iconoir-react'
import { Typography } from '@mui/material'

import { useViews } from 'client/features/Auth'
import MultipleTags from 'client/components/MultipleTags'
import Timer from 'client/components/Timer'
import { StatusCircle } from 'client/components/Status'
import { rowStyles } from 'client/components/Tables/styles'

import {
timeFromMilliseconds,
getUniqueLabels,
getColorFromString,
} from 'client/models/Helper'
import { getState } from 'client/models/Service'
import { T, Service, ACTIONS, RESOURCE_NAMES } from 'client/constants'

const ServiceCard = memo(
/**
* @param {object} props - Props
* @param {Service} props.service - Service resource
* @param {object} props.rootProps - Props to root component
* @param {function(string):Promise} [props.onDeleteLabel] - Callback to delete label
* @param {ReactElement} [props.actions] - Actions
* @returns {ReactElement} - Card
*/
({ service, rootProps, actions, onDeleteLabel }) => {
const classes = rowStyles()
const { [RESOURCE_NAMES.SERVICE]: serviceView } = useViews()

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

const {
ID,
NAME,
TEMPLATE: { BODY: { description, labels, start_time: startTime } = {} },
} = service

const { color: stateColor, name: stateName } = getState(service)
const time = useMemo(() => timeFromMilliseconds(+startTime), [startTime])

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

return (
<div {...rootProps} data-cy={`service-template-${ID}`}>
<div className={classes.main}>
<div className={classes.title}>
<StatusCircle color={stateColor} tooltip={stateName} />
<Typography noWrap component="span" title={description}>
{NAME}
</Typography>
<span className={classes.labels}>
<WarningIcon title={description} />
<MultipleTags tags={uniqueLabels} />
</span>
</div>
<div className={classes.caption}>
<span data-cy="id">{`#${ID}`}</span>
<span title={time.toFormat('ff')}>
<Timer translateWord={T.RegisteredAt} initial={time} />
</span>
</div>
</div>
{actions && <div className={classes.actions}>{actions}</div>}
</div>
)
}
)

ServiceCard.propTypes = {
service: PropTypes.object,
rootProps: PropTypes.shape({
className: PropTypes.string,
}),
onDeleteLabel: PropTypes.func,
actions: PropTypes.any,
}

ServiceCard.displayName = 'ServiceCard'

export default ServiceCard
127 changes: 127 additions & 0 deletions src/fireedge/src/client/components/Cards/ServiceTemplateCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/* ------------------------------------------------------------------------- *
* Copyright 2002-2022, 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 { ReactElement, memo, useMemo } from 'react'
import PropTypes from 'prop-types'

import { Network, Package } from 'iconoir-react'
import { Typography } from '@mui/material'

import { useViews } from 'client/features/Auth'
import MultipleTags from 'client/components/MultipleTags'
import Timer from 'client/components/Timer'
import { Tr } from 'client/components/HOC'
import { rowStyles } from 'client/components/Tables/styles'

import {
timeFromMilliseconds,
getUniqueLabels,
getColorFromString,
} from 'client/models/Helper'
import { T, ServiceTemplate, ACTIONS, RESOURCE_NAMES } from 'client/constants'

const ServiceTemplateCard = memo(
/**
* @param {object} props - Props
* @param {ServiceTemplate} props.template - Service Template resource
* @param {object} props.rootProps - Props to root component
* @param {function(string):Promise} [props.onDeleteLabel] - Callback to delete label
* @param {ReactElement} [props.actions] - Actions
* @returns {ReactElement} - Card
*/
({ template, rootProps, actions, onDeleteLabel }) => {
const classes = rowStyles()
const { [RESOURCE_NAMES.SERVICE_TEMPLATE]: serviceView } = useViews()

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

const {
ID,
NAME,
TEMPLATE: {
BODY: {
description,
labels,
networks,
roles,
registration_time: regTime,
} = {},
},
} = template

const numberOfRoles = useMemo(() => roles?.length ?? 0, [roles])

const numberOfNetworks = useMemo(
() => Object.keys(networks)?.length ?? 0,
[networks]
)

const time = useMemo(() => timeFromMilliseconds(+regTime), [regTime])

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

return (
<div {...rootProps} data-cy={`service-template-${ID}`}>
<div className={classes.main}>
<div className={classes.title}>
<Typography noWrap component="span" title={description}>
{NAME}
</Typography>
<span className={classes.labels}>
<MultipleTags tags={uniqueLabels} />
</span>
</div>
<div className={classes.caption}>
<span data-cy="id">{`#${ID}`}</span>
<span title={time.toFormat('ff')}>
<Timer translateWord={T.RegisteredAt} initial={time} />
</span>
<span title={`${Tr(T.Networks)}: ${numberOfNetworks}`}>
<Network width={20} height={20} />
<span data-cy="total-networks">{numberOfNetworks}</span>
</span>
<span title={`${Tr(T.Roles)}: ${numberOfRoles}`}>
<Package width={20} height={20} />
<span data-cy="total-roles">{numberOfRoles}</span>
</span>
</div>
</div>
{actions && <div className={classes.actions}>{actions}</div>}
</div>
)
}
)

ServiceTemplateCard.propTypes = {
template: PropTypes.object,
rootProps: PropTypes.shape({
className: PropTypes.string,
}),
onDeleteLabel: PropTypes.func,
actions: PropTypes.any,
}

ServiceTemplateCard.displayName = 'ServiceTemplateCard'

export default ServiceTemplateCard
4 changes: 4 additions & 0 deletions src/fireedge/src/client/components/Cards/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import ProvisionTemplateCard from 'client/components/Cards/ProvisionTemplateCard
import ScheduleActionCard from 'client/components/Cards/ScheduleActionCard'
import SecurityGroupCard from 'client/components/Cards/SecurityGroupCard'
import SelectCard from 'client/components/Cards/SelectCard'
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 VirtualMachineCard from 'client/components/Cards/VirtualMachineCard'
Expand All @@ -58,6 +60,8 @@ export {
ScheduleActionCard,
SecurityGroupCard,
SelectCard,
ServiceCard,
ServiceTemplateCard,
SnapshotCard,
TierCard,
VirtualMachineCard,
Expand Down
Loading

0 comments on commit bcb12e7

Please sign in to comment.