From 5784a2fcf2034194efc6f4c561756fd0625fbac2 Mon Sep 17 00:00:00 2001 From: Sergio Betanzos Date: Tue, 28 Jun 2022 17:48:07 +0200 Subject: [PATCH] M #~: Implements only_on hypervisor condition (#2198) (cherry picked from commit 3d19709d944f3337189361d402afeb6c7d38af13) --- .../Forms/Vm/AttachDiskForm/CommonFields.js | 6 +++--- .../ImageSteps/AdvancedOptions/index.js | 2 +- .../VolatileSteps/AdvancedOptions/index.js | 2 +- .../VolatileSteps/BasicConfiguration/index.js | 2 +- .../components/Tables/Enhanced/Utils/utils.js | 3 +-- src/fireedge/src/client/models/Helper.js | 13 +++++++++++-- src/fireedge/src/client/utils/helpers.js | 5 ++++- 7 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/CommonFields.js b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/CommonFields.js index fcbfdebdc8..2bfa0a5ed3 100644 --- a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/CommonFields.js +++ b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/CommonFields.js @@ -16,7 +16,7 @@ import { string, number } from 'yup' import { INPUT_TYPES, T, HYPERVISORS, Field } from 'client/constants' -const { kvm, vcenter, firecracker, lxc } = HYPERVISORS +const { vcenter, firecracker, lxc } = HYPERVISORS /** @type {Field[]} List of general fields */ export const GENERAL_FIELDS = [ @@ -126,7 +126,7 @@ export const VCENTER_FIELDS = [ { name: 'VCENTER_ADAPTER_TYPE', label: T.BusAdapterController, - notOnHypervisors: [kvm, firecracker], + onlyOnHypervisors: [vcenter], type: INPUT_TYPES.SELECT, values: [ { text: '', value: '' }, @@ -140,7 +140,7 @@ export const VCENTER_FIELDS = [ { name: 'VCENTER_DISK_TYPE', label: T.DiskProvisioningType, - notOnHypervisors: [kvm, firecracker], + onlyOnHypervisors: [vcenter], type: INPUT_TYPES.SELECT, values: [ { text: '', value: '' }, diff --git a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/AdvancedOptions/index.js b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/AdvancedOptions/index.js index 5049e81d1b..07efe2283b 100644 --- a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/AdvancedOptions/index.js +++ b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/AdvancedOptions/index.js @@ -60,7 +60,7 @@ const Content = ({ hypervisor }) => { const AdvancedOptions = ({ hypervisor } = {}) => ({ id: STEP_ID, label: T.AdvancedOptions, - resolver: () => SCHEMA(hypervisor), + resolver: SCHEMA(hypervisor), optionsValidate: { abortEarly: false }, content: () => Content({ hypervisor }), }) diff --git a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/AdvancedOptions/index.js b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/AdvancedOptions/index.js index b08f0a25d3..f5927b9929 100644 --- a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/AdvancedOptions/index.js +++ b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/AdvancedOptions/index.js @@ -60,7 +60,7 @@ const Content = ({ hypervisor }) => { const AdvancedOptions = ({ hypervisor } = {}) => ({ id: STEP_ID, label: T.AdvancedOptions, - resolver: () => SCHEMA(hypervisor), + resolver: SCHEMA(hypervisor), optionsValidate: { abortEarly: false }, content: () => Content({ hypervisor }), }) diff --git a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/BasicConfiguration/index.js b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/BasicConfiguration/index.js index 7faf7545b8..c3ac924973 100644 --- a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/BasicConfiguration/index.js +++ b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/BasicConfiguration/index.js @@ -42,7 +42,7 @@ const Content = ({ hypervisor }) => { const BasicConfiguration = ({ hypervisor } = {}) => ({ id: STEP_ID, label: T.Configuration, - resolver: () => SCHEMA(hypervisor), + resolver: SCHEMA(hypervisor), optionsValidate: { abortEarly: false }, content: () => Content({ hypervisor }), }) diff --git a/src/fireedge/src/client/components/Tables/Enhanced/Utils/utils.js b/src/fireedge/src/client/components/Tables/Enhanced/Utils/utils.js index 7f7b9eb966..79adde6c5d 100644 --- a/src/fireedge/src/client/components/Tables/Enhanced/Utils/utils.js +++ b/src/fireedge/src/client/components/Tables/Enhanced/Utils/utils.js @@ -49,8 +49,7 @@ export const createColumns = ({ filters = {}, columns = [] }) => { ...((filterById || filterByAccessor) && ( { - // TODO: Add label to filters - // label: createLabelFilter, + // TODO: Implements time filter component time: createTimeFilter, }[`${id}`.toLowerCase()] ?? createCategoryFilter )(column)), diff --git a/src/fireedge/src/client/models/Helper.js b/src/fireedge/src/client/models/Helper.js index 97cde2a887..3b46d0b650 100644 --- a/src/fireedge/src/client/models/Helper.js +++ b/src/fireedge/src/client/models/Helper.js @@ -288,9 +288,18 @@ export const getActionsAvailable = (actions = {}, hypervisor = '') => .filter(([_, action]) => { if (typeof action === 'boolean') return action - const { enabled = false, not_on: notOn = [] } = action || {} + const { + enabled = false, + not_on: notOn = [], + only_on: onlyOn = [], + } = action || {} - return !!enabled && !notOn?.includes?.(hypervisor) + return ( + !!enabled && + ((!notOn && !onlyOn) || + (notOn && !notOn?.includes?.(hypervisor)) || + onlyOn?.includes?.(hypervisor)) + ) }) .map(([actionName, _]) => actionName) diff --git a/src/fireedge/src/client/utils/helpers.js b/src/fireedge/src/client/utils/helpers.js index ddec55ace0..1af3056c08 100644 --- a/src/fireedge/src/client/utils/helpers.js +++ b/src/fireedge/src/client/utils/helpers.js @@ -236,7 +236,10 @@ export const filterFieldsByHypervisor = ( fields .map((field) => (typeof field === 'function' ? field(hypervisor) : field)) .filter( - ({ notOnHypervisors } = {}) => !notOnHypervisors?.includes?.(hypervisor) + ({ notOnHypervisors, onlyOnHypervisors } = {}) => + (!notOnHypervisors && !onlyOnHypervisors) || + (notOnHypervisors && !notOnHypervisors.includes?.(hypervisor)) || + onlyOnHypervisors?.includes?.(hypervisor) ) /**