diff --git a/locales/en/plugin__nmstate-console-plugin.json b/locales/en/plugin__nmstate-console-plugin.json index fbcea950..cc1d9c0c 100644 --- a/locales/en/plugin__nmstate-console-plugin.json +++ b/locales/en/plugin__nmstate-console-plugin.json @@ -19,6 +19,7 @@ "<0>List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller.<1><0>{{kind}}<1>metadata<2>ownerReferences": "<0>List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller.<1><0>{{kind}}<1>metadata<2>ownerReferences", "Aborted": "Aborted", "Actions": "Actions", + "Add {{label}} interface": "Add {{label}} interface", "Add another {{label}} interface": "Add another {{label}} interface", "Add another interface to the policy": "Add another interface to the policy", "Add Label": "Add Label", diff --git a/src/utils/components/PolicyForm/PolicyWizard/InterfacesStep.tsx b/src/utils/components/PolicyForm/PolicyWizard/InterfacesStep.tsx index 16676a64..dd1b46d0 100644 --- a/src/utils/components/PolicyForm/PolicyWizard/InterfacesStep.tsx +++ b/src/utils/components/PolicyForm/PolicyWizard/InterfacesStep.tsx @@ -10,7 +10,7 @@ import { V1NodeNetworkConfigurationPolicy, } from '@types'; import { useNMStateTranslation } from '@utils/hooks/useNMStateTranslation'; -import { getPolicyInterfaces } from '@utils/resources/policies/utils'; +import { getPolicyInterfaces, getPolicyInterfacesByType } from '@utils/resources/policies/utils'; import PolicyFormOVSBridgeMapping from '../components/PolicyFormOVSBridgeMapping'; import { doesOVSBridgeExist } from '../utils'; @@ -31,7 +31,7 @@ const InterfacesStep: FC = ({ policy, setPolicy, interfaceT const firstInterfaceType = interfaceTypes?.[0]; const isOVSBridge = isBindingStep && doesOVSBridgeExist(policy); - + const noCurrentStepInterfaces = getPolicyInterfacesByType(policy, interfaceTypes[0]).length === 0; const addNewInterface = () => { setPolicy((draftPolicy) => { if (!draftPolicy.spec?.desiredState?.interfaces) { @@ -83,7 +83,11 @@ const InterfacesStep: FC = ({ policy, setPolicy, interfaceT onClick={addNewInterface} variant={ButtonVariant.link} > - {t('Add another {{label}} interface', { label: label.toLowerCase() })} + + {t(`Add ${noCurrentStepInterfaces ? '' : 'another '}{{label}} interface`, { + label: label.toLowerCase(), + })} + diff --git a/src/utils/resources/policies/utils.ts b/src/utils/resources/policies/utils.ts index c859ec31..ba708682 100644 --- a/src/utils/resources/policies/utils.ts +++ b/src/utils/resources/policies/utils.ts @@ -39,13 +39,30 @@ export const getPolicyInterfaces = ( policy: V1NodeNetworkConfigurationPolicy, ): NodeNetworkConfigurationInterface[] => policy.spec?.desiredState?.interfaces || []; +export const getPolicyInterfacesByType = ( + policy: V1NodeNetworkConfigurationPolicy, + interfaceType: InterfaceType, +): NodeNetworkConfigurationInterface[] => { + switch (interfaceType) { + case InterfaceType.ETHERNET: + return getPolicyEthernetInterfaces(policy); + case InterfaceType.BOND: + return getPolicyBondingInterfaces(policy); + case InterfaceType.LINUX_BRIDGE: + case InterfaceType.OVS_BRIDGE: + return getPolicyBridgingInterfaces(policy); + default: + return []; + } +}; + export const getPolicyEthernetInterfaces = (policy): NodeNetworkConfigurationInterface[] => getPolicyInterfaces(policy)?.filter((iface) => iface.type === InterfaceType.ETHERNET) || []; export const getPolicyBondingInterfaces = (policy): NodeNetworkConfigurationInterface[] => getPolicyInterfaces(policy)?.filter((iface) => iface.type === InterfaceType.BOND) || []; -export const getPolicyBrdigingInterfaces = (policy): NodeNetworkConfigurationInterface[] => +export const getPolicyBridgingInterfaces = (policy): NodeNetworkConfigurationInterface[] => getPolicyInterfaces(policy)?.filter((iface) => [InterfaceType.LINUX_BRIDGE, InterfaceType.OVS_BRIDGE].includes(iface.type), ) || []; diff --git a/src/views/nodenetworkconfiguration/components/TopologySidebar/constants.ts b/src/views/nodenetworkconfiguration/components/TopologySidebar/constants.ts index e7f11dbb..d4d0cc4b 100644 --- a/src/views/nodenetworkconfiguration/components/TopologySidebar/constants.ts +++ b/src/views/nodenetworkconfiguration/components/TopologySidebar/constants.ts @@ -1,11 +1,6 @@ import NodeNetworkConfigurationPolicyModel from 'src/console-models/NodeNetworkConfigurationPolicyModel'; -import { - InterfaceType, - NodeNetworkConfigurationInterface, - V1NodeNetworkConfigurationPolicy, -} from '@types'; -import { NETWORK_STATES } from '@utils/components/PolicyForm/constants'; +import { V1NodeNetworkConfigurationPolicy } from '@types'; export const initialPolicy: V1NodeNetworkConfigurationPolicy = { apiVersion: `${NodeNetworkConfigurationPolicyModel.apiGroup}/${NodeNetworkConfigurationPolicyModel.apiVersion}`, @@ -15,20 +10,7 @@ export const initialPolicy: V1NodeNetworkConfigurationPolicy = { }, spec: { desiredState: { - interfaces: [ - { - name: 'br0', - type: InterfaceType.LINUX_BRIDGE, - state: NETWORK_STATES.Up, - bridge: { - options: { - stp: { - enabled: false, - }, - }, - }, - } as NodeNetworkConfigurationInterface, - ], + interfaces: [], }, }, };