Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions locales/en/plugin__nmstate-console-plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.</0><1><0>{{kind}}</0><1>metadata</1><2>ownerReferences</2></1>": "<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.</0><1><0>{{kind}}</0><1>metadata</1><2>ownerReferences</2></1>",
"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",
Expand Down
10 changes: 7 additions & 3 deletions src/utils/components/PolicyForm/PolicyWizard/InterfacesStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -31,7 +31,7 @@ const InterfacesStep: FC<InterfacesStepProps> = ({ 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) {
Expand Down Expand Up @@ -83,7 +83,11 @@ const InterfacesStep: FC<InterfacesStepProps> = ({ policy, setPolicy, interfaceT
onClick={addNewInterface}
variant={ButtonVariant.link}
>
<span>{t('Add another {{label}} interface', { label: label.toLowerCase() })}</span>
<span>
{t(`Add ${noCurrentStepInterfaces ? '' : 'another '}{{label}} interface`, {
label: label.toLowerCase(),
})}
Comment on lines +87 to +89

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will not be translated correctly. You should have two distinct translations here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added another translation. Did I miss anything?

</span>
</Button>
</Content>
</div>
Expand Down
19 changes: 18 additions & 1 deletion src/utils/resources/policies/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
) || [];
Original file line number Diff line number Diff line change
@@ -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}`,
Expand All @@ -15,20 +10,7 @@ export const initialPolicy: V1NodeNetworkConfigurationPolicy = {
},
spec: {
desiredState: {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed default interface

interfaces: [
{
name: 'br0',
type: InterfaceType.LINUX_BRIDGE,
state: NETWORK_STATES.Up,
bridge: {
options: {
stp: {
enabled: false,
},
},
},
} as NodeNetworkConfigurationInterface,
],
interfaces: [],
},
},
};
Expand Down