1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

F OpenNebula/one#6648: Only display system labels (#3145)

available in user template

Signed-off-by: Victor Hansson <vhansson@opennebula.io>
Co-authored-by: Tino Vázquez <cvazquez@opennebula.io>
This commit is contained in:
vichansson 2024-07-09 17:34:54 +03:00 committed by GitHub
parent e34cc7008f
commit cabc9264d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 183 additions and 84 deletions

View File

@ -33,6 +33,7 @@ import { Group, HighPriority, Lock, User } from 'iconoir-react'
import COLOR from 'client/constants/color'
import PropTypes from 'prop-types'
import { useAuth } from 'client/features/Auth'
const haveValues = function (object) {
return Object.values(object).length > 0
@ -49,6 +50,7 @@ const BackupJobCard = memo(
*/
({ template, rootProps, onClickLabel, onDeleteLabel }) => {
const classes = rowStyles()
const { labels: userLabels } = useAuth()
const {
ID,
@ -118,13 +120,19 @@ const BackupJobCard = memo(
const labels = useMemo(
() =>
getUniqueLabels(LABELS).map((label) => ({
text: label,
dataCy: `label-${label}`,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: onDeleteLabel,
})),
getUniqueLabels(LABELS).reduce((acc, label) => {
if (userLabels?.includes(label)) {
acc.push({
text: label,
dataCy: `label-${label}`,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: onDeleteLabel,
})
}
return acc
}, []),
[LABELS, onClickLabel, onDeleteLabel]
)

View File

@ -48,7 +48,7 @@ import {
getErrorMessage,
getUniqueLabels,
} from 'client/models/Helper'
import { useViews } from 'client/features/Auth'
import { useAuth, useViews } from 'client/features/Auth'
const DatastoreCard = memo(
/**
@ -61,6 +61,7 @@ const DatastoreCard = memo(
*/
({ datastore: ds, rootProps, onClickLabel, onDeleteLabel }) => {
const classes = rowStyles()
const { labels: userLabels } = useAuth()
const { [RESOURCE_NAMES.DATASTORE]: dsView } = useViews()
const enableEditLabels =
@ -88,13 +89,19 @@ const DatastoreCard = memo(
const labels = useMemo(
() =>
getUniqueLabels(LABELS).map((label) => ({
text: label,
dataCy: `label-${label}`,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: enableEditLabels && onDeleteLabel,
})),
getUniqueLabels(LABELS).reduce((acc, label) => {
if (userLabels?.includes(label)) {
acc.push({
text: label,
dataCy: `label-${label}`,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: enableEditLabels && onDeleteLabel,
})
}
return acc
}, []),
[LABELS, enableEditLabels, onClickLabel, onDeleteLabel]
)

View File

@ -32,6 +32,7 @@ import { getColorFromString, getUniqueLabels } from 'client/models/Helper'
import { Host, HOST_THRESHOLD, T } from 'client/constants'
import { getAllocatedInfo, getState } from 'client/models/Host'
import { useAuth } from 'client/features/Auth'
const HostCard = memo(
/**
@ -45,6 +46,7 @@ const HostCard = memo(
*/
({ host, rootProps, actions, onClickLabel, onDeleteLabel }) => {
const classes = rowStyles()
const { labels: userLabels } = useAuth()
const {
ID,
NAME,
@ -57,13 +59,19 @@ const HostCard = memo(
const labels = useMemo(
() =>
getUniqueLabels(LABELS).map((label) => ({
text: label,
dataCy: `label-${label}`,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: onDeleteLabel,
})),
getUniqueLabels(LABELS).reduce((acc, label) => {
if (userLabels?.includes(label)) {
acc.push({
text: label,
dataCy: `label-${label}`,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: onDeleteLabel,
})
}
return acc
}, []),
[LABELS, onClickLabel, onDeleteLabel]
)

View File

@ -19,7 +19,7 @@ import PropTypes from 'prop-types'
import { Lock, User, Group, Cart } from 'iconoir-react'
import { Typography } from '@mui/material'
import { useViews } from 'client/features/Auth'
import { useAuth, useViews } from 'client/features/Auth'
import MultipleTags from 'client/components/MultipleTags'
import { StatusCircle, StatusChip } from 'client/components/Status'
import { Tr } from 'client/components/HOC'
@ -46,6 +46,7 @@ const MarketplaceAppCard = memo(
*/
({ app, rootProps, onClickLabel, onDeleteLabel }) => {
const classes = rowStyles()
const { labels: userLabels } = useAuth()
const { [RESOURCE_NAMES.VM]: vmView } = useViews()
const enableEditLabels =
@ -72,13 +73,19 @@ const MarketplaceAppCard = memo(
const labels = useMemo(
() =>
getUniqueLabels(LABELS).map((label) => ({
text: label,
dataCy: `label-${label}`,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: enableEditLabels && onDeleteLabel,
})),
getUniqueLabels(LABELS).reduce((acc, label) => {
if (userLabels?.includes(label)) {
acc.push({
text: label,
dataCy: `label-${label}`,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: enableEditLabels && onDeleteLabel,
})
}
return acc
}, []),
[LABELS, enableEditLabels, onClickLabel, onDeleteLabel]
)

View File

@ -25,7 +25,7 @@ import {
} from 'iconoir-react'
import { Box, Stack, Typography, Tooltip } from '@mui/material'
import { useViews } from 'client/features/Auth'
import { useAuth, useViews } from 'client/features/Auth'
import MultipleTags from 'client/components/MultipleTags'
import {
StatusCircle,
@ -65,6 +65,7 @@ const NetworkCard = memo(
*/
({ network, rootProps, actions, onClickLabel, onDeleteLabel }) => {
const classes = rowStyles()
const { labels: userLabels } = useAuth()
const { [RESOURCE_NAMES.VM]: vmView } = useViews()
const enableEditLabels =
@ -91,12 +92,19 @@ const NetworkCard = memo(
const labels = useMemo(
() =>
getUniqueLabels(LABELS).map((label) => ({
text: label,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: enableEditLabels && onDeleteLabel,
})),
getUniqueLabels(LABELS).reduce((acc, label) => {
if (userLabels?.includes(label)) {
acc.push({
text: label,
dataCy: `label-${label}`,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: enableEditLabels && onDeleteLabel,
})
}
return acc
}, []),
[LABELS, enableEditLabels, onDeleteLabel]
)

View File

@ -23,6 +23,7 @@ import MultipleTags from 'client/components/MultipleTags'
import { rowStyles } from 'client/components/Tables/styles'
import { SecurityGroup, T } from 'client/constants'
import { getColorFromString, getUniqueLabels } from 'client/models/Helper'
import { useAuth } from 'client/features/Auth'
import { Tr } from 'client/components/HOC'
const getTotalOfResources = (resources) =>
@ -40,6 +41,7 @@ const SecurityGroupCard = memo(
*/
({ securityGroup, rootProps, actions, onClickLabel, onDeleteLabel }) => {
const classes = rowStyles()
const { labels: userLabels } = useAuth()
const {
ID,
@ -63,12 +65,19 @@ const SecurityGroupCard = memo(
const labels = useMemo(
() =>
getUniqueLabels(LABELS).map((label) => ({
text: label,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: onDeleteLabel,
})),
getUniqueLabels(LABELS).reduce((acc, label) => {
if (userLabels?.includes(label)) {
acc.push({
text: label,
dataCy: `label-${label}`,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: onDeleteLabel,
})
}
return acc
}, []),
[LABELS, onDeleteLabel]
)

View File

@ -19,7 +19,7 @@ import PropTypes from 'prop-types'
import { Network, Package } from 'iconoir-react'
import { Typography } from '@mui/material'
import { useViews } from 'client/features/Auth'
import { useAuth, useViews } from 'client/features/Auth'
import MultipleTags from 'client/components/MultipleTags'
import Timer from 'client/components/Timer'
import { Tr } from 'client/components/HOC'
@ -43,6 +43,7 @@ const ServiceTemplateCard = memo(
*/
({ template, rootProps, actions, onDeleteLabel }) => {
const classes = rowStyles()
const { labels: userLabels } = useAuth()
const { [RESOURCE_NAMES.SERVICE_TEMPLATE]: serviceView } = useViews()
const enableEditLabels =
@ -73,11 +74,19 @@ const ServiceTemplateCard = memo(
const uniqueLabels = useMemo(
() =>
getUniqueLabels(labels).map((label) => ({
text: label,
stateColor: getColorFromString(label),
onDelete: enableEditLabels && onDeleteLabel,
})),
getUniqueLabels(labels).reduce((acc, label) => {
if (userLabels?.includes(label)) {
acc.push({
text: label,
dataCy: `label-${label}`,
stateColor: getColorFromString(label),
onDelete: enableEditLabels && onDeleteLabel,
})
}
return acc
}, []),
[labels, enableEditLabels, onDeleteLabel]
)

View File

@ -26,7 +26,7 @@ import {
} from 'iconoir-react'
import MultipleTags from 'client/components/MultipleTags'
import { useViews } from 'client/features/Auth'
import { useAuth, useViews } from 'client/features/Auth'
import { Tr } from 'client/components/HOC'
import { StatusCircle } from 'client/components/Status'
@ -50,6 +50,7 @@ const VirtualDataCenterCard = memo(
*/
({ template, rootProps, onClickLabel, onDeleteLabel }) => {
const classes = rowStyles()
const { labels: userLabels } = useAuth()
const { [RESOURCE_NAMES.VDC]: vdcView } = useViews()
const enableEditLabels =
@ -111,12 +112,19 @@ const VirtualDataCenterCard = memo(
const labels = useMemo(
() =>
getUniqueLabels(LABELS).map((label) => ({
text: label,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: enableEditLabels && onDeleteLabel,
})),
getUniqueLabels(LABELS).reduce((acc, label) => {
if (userLabels?.includes(label)) {
acc.push({
text: label,
dataCy: `label-${label}`,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: enableEditLabels && onDeleteLabel,
})
}
return acc
}, []),
[LABELS, enableEditLabels, onClickLabel, onDeleteLabel]
)

View File

@ -33,7 +33,7 @@ import MultipleTags from 'client/components/MultipleTags'
import { StatusChip, StatusCircle } from 'client/components/Status'
import { rowStyles } from 'client/components/Tables/styles'
import Timer from 'client/components/Timer'
import { useViews } from 'client/features/Auth'
import { useAuth, useViews } from 'client/features/Auth'
import { ACTIONS, RESOURCE_NAMES, T, VM } from 'client/constants'
import {
@ -66,6 +66,7 @@ const VirtualMachineCard = memo(
}) => {
const classes = rowStyles()
const { [RESOURCE_NAMES.VM]: vmView } = useViews()
const { labels: userLabels } = useAuth()
const enableEditLabels =
vmView?.actions?.[ACTIONS.EDIT_LABELS] === true && !!onDeleteLabel
@ -129,12 +130,20 @@ const VirtualMachineCard = memo(
const labels = useMemo(
() =>
getUniqueLabels(LABELS).map((label) => ({
text: label,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: enableEditLabels && onDeleteLabel,
})),
getUniqueLabels(LABELS).reduce((acc, label) => {
if (userLabels?.includes(label)) {
acc.push({
text: label,
dataCy: `label-${label}`,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: enableEditLabels && onDeleteLabel,
})
}
return acc
}, []),
[LABELS, enableEditLabels, onClickLabel, onDeleteLabel]
)

View File

@ -19,7 +19,7 @@ import PropTypes from 'prop-types'
import { User, Group, Lock } from 'iconoir-react'
import { Typography } from '@mui/material'
import { useViews } from 'client/features/Auth'
import { useAuth, useViews } from 'client/features/Auth'
import MultipleTags from 'client/components/MultipleTags'
import Timer from 'client/components/Timer'
import Image from 'client/components/Image'
@ -55,6 +55,7 @@ const VmTemplateCard = memo(
({ template, rootProps, onClickLabel, onDeleteLabel }) => {
const classes = rowStyles()
const { [RESOURCE_NAMES.VM_TEMPLATE]: templateView } = useViews()
const { labels: userLabels } = useAuth()
const enableEditLabels =
templateView?.actions?.[ACTIONS.EDIT_LABELS] === true && !!onDeleteLabel
@ -81,12 +82,19 @@ const VmTemplateCard = memo(
const labels = useMemo(
() =>
getUniqueLabels(LABELS).map((label) => ({
text: label,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: enableEditLabels && onDeleteLabel,
})),
getUniqueLabels(LABELS).reduce((acc, label) => {
if (userLabels?.includes(label)) {
acc.push({
text: label,
dataCy: `label-${label}`,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: enableEditLabels && onDeleteLabel,
})
}
return acc
}, []),
[LABELS, enableEditLabels, onClickLabel, onDeleteLabel]
)

View File

@ -15,6 +15,7 @@
* ------------------------------------------------------------------------- */
/* eslint-disable jsdoc/require-jsdoc */
import PropTypes from 'prop-types'
import { useAuth } from 'client/features/Auth'
import { useMemo, useCallback } from 'react'
import imageApi, { useUpdateImageMutation } from 'client/features/OneApi/image'
@ -46,6 +47,7 @@ import * as Helper from 'client/models/Helper'
const Row = ({ original, value, onClickLabel, ...props }) => {
const [update] = useUpdateImageMutation()
const { labels: userLabels } = useAuth()
const state = imageApi.endpoints.getImages.useQueryState(undefined, {
selectFromResult: ({ data = [] }) =>
@ -95,12 +97,19 @@ const Row = ({ original, value, onClickLabel, ...props }) => {
const multiTagLabels = useMemo(
() =>
getUniqueLabels(LABELS).map((label) => ({
text: label,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: handleDeleteLabel,
})),
getUniqueLabels(LABELS).reduce((acc, label) => {
if (userLabels?.includes(label)) {
acc.push({
text: label,
dataCy: `label-${label}`,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: handleDeleteLabel,
})
}
return acc
}, []),
[LABELS, handleDeleteLabel, onClickLabel]
)

View File

@ -95,7 +95,7 @@ const GlobalLabel = ({
)
const allFilterLabels = useMemo(() => {
const all = [...userLabels, ...unknownPageLabels, ...currentLabelFilters]
const all = [...userLabels, ...currentLabelFilters]
const unique = [...new Set(all)]
return sortByFilteredFirst(unique, currentLabelFilters)

View File

@ -28,6 +28,7 @@ import {
import { Typography } from '@mui/material'
import MultipleTags from 'client/components/MultipleTags'
import imageApi, { useUpdateImageMutation } from 'client/features/OneApi/image'
import { useAuth } from 'client/features/Auth'
import Timer from 'client/components/Timer'
import { StatusCircle, StatusChip } from 'client/components/Status'
@ -46,6 +47,8 @@ import * as Helper from 'client/models/Helper'
const Row = ({ original, value, onClickLabel, ...props }) => {
const [update] = useUpdateImageMutation()
const { labels: userLabels } = useAuth()
const classes = rowStyles()
const {
id: ID,
@ -89,12 +92,19 @@ const Row = ({ original, value, onClickLabel, ...props }) => {
const multiTagLabels = useMemo(
() =>
getUniqueLabels(LABELS).map((label) => ({
text: label,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: handleDeleteLabel,
})),
getUniqueLabels(LABELS).reduce((acc, label) => {
if (userLabels?.includes(label)) {
acc.push({
text: label,
dataCy: `label-${label}`,
stateColor: getColorFromString(label),
onClick: onClickLabel,
onDelete: handleDeleteLabel,
})
}
return acc
}, []),
[LABELS, handleDeleteLabel, onClickLabel]
)

View File

@ -129,7 +129,6 @@ const Actions = () => {
accessor: VN_ACTIONS.INSTANTIATE_DIALOG,
dataCy: `vnet-${VN_ACTIONS.INSTANTIATE_DIALOG}`,
tooltip: T.Instantiate,
selected: true,
icon: PlayOutline,
options: [
{