This repository has been archived by the owner on Nov 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Matan Schatzman <[email protected]>
- Loading branch information
Showing
10 changed files
with
213 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/utils/components/PolicyForm/PolicyFormOVSBridgeMapping.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { FC } from 'react'; | ||
import { Updater } from 'use-immer'; | ||
|
||
import { Button, ButtonVariant, Popover, Text } from '@patternfly/react-core'; | ||
import { HelpIcon, PlusCircleIcon } from '@patternfly/react-icons'; | ||
import { V1NodeNetworkConfigurationPolicy } from '@types'; | ||
import { useNMStateTranslation } from '@utils/hooks/useNMStateTranslation'; | ||
|
||
import PolicyFormOVSBridgeMappingExpandable from './PolicyFormOVSBridgeMappingExpandable'; | ||
|
||
type PolicyFormOVSBridgeMappingProps = { | ||
policy: V1NodeNetworkConfigurationPolicy; | ||
setPolicy: Updater<V1NodeNetworkConfigurationPolicy>; | ||
}; | ||
|
||
const PolicyFormOVSBridgeMapping: FC<PolicyFormOVSBridgeMappingProps> = ({ policy, setPolicy }) => { | ||
const { t } = useNMStateTranslation(); | ||
|
||
return ( | ||
<div> | ||
<Text className="pf-u-primary-color-100 pf-u-font-weight-bold pf-u-font-size-lg"> | ||
{t('Open vSwitch bridge mapping')}{' '} | ||
<Popover | ||
aria-label={'Help'} | ||
bodyContent={t( | ||
'The Open vSwitch bridge mapping is a list of Open vSwitch bridges and the physical interfaces that are connected to them.', | ||
)} | ||
> | ||
<HelpIcon /> | ||
</Popover> | ||
</Text> | ||
<Text className="policy-form-content__add-new-interface pf-u-mt-md"> | ||
<Button | ||
className="pf-m-link--align-left pf-u-ml-md" | ||
onClick={() => | ||
setPolicy((draftPolicy) => { | ||
draftPolicy.spec.desiredState.ovn['bridge-mapping'].unshift({ | ||
bridge: '', | ||
localnet: '', | ||
state: 'present', | ||
}); | ||
}) | ||
} | ||
variant={ButtonVariant.link} | ||
> | ||
<PlusCircleIcon /> <span className="pf-u-ml-sm">{t('Add mapping')}</span> | ||
</Button> | ||
</Text> | ||
<PolicyFormOVSBridgeMappingExpandable policy={policy} setPolicy={setPolicy} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PolicyFormOVSBridgeMapping; |
76 changes: 76 additions & 0 deletions
76
src/utils/components/PolicyForm/PolicyFormOVSBridgeMappingExpandable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React, { FC, FormEvent } from 'react'; | ||
import { Updater } from 'use-immer'; | ||
|
||
import { | ||
Button, | ||
ButtonVariant, | ||
Flex, | ||
FlexItem, | ||
PageSection, | ||
PageSectionVariants, | ||
TextInput, | ||
Title, | ||
} from '@patternfly/react-core'; | ||
import { MinusCircleIcon } from '@patternfly/react-icons'; | ||
import { V1NodeNetworkConfigurationPolicy } from '@types'; | ||
import { useNMStateTranslation } from '@utils/hooks/useNMStateTranslation'; | ||
|
||
type PolicyFormOVSBridgeMappingExpandableProps = { | ||
policy: V1NodeNetworkConfigurationPolicy; | ||
setPolicy: Updater<V1NodeNetworkConfigurationPolicy>; | ||
}; | ||
|
||
const PolicyFormOVSBridgeMappingExpandable: FC<PolicyFormOVSBridgeMappingExpandableProps> = ({ | ||
policy, | ||
setPolicy, | ||
}) => { | ||
const { t } = useNMStateTranslation(); | ||
|
||
const onChange = | ||
(index: number, field: string) => (_: FormEvent<HTMLInputElement>, value: string) => { | ||
setPolicy((draftPolicy) => { | ||
draftPolicy.spec.desiredState.ovn['bridge-mapping'][index] = { | ||
...draftPolicy.spec.desiredState.ovn['bridge-mapping'][index], | ||
[field]: value, | ||
}; | ||
}); | ||
}; | ||
|
||
const onRemove = (index: number) => { | ||
setPolicy((draftPolicy) => { | ||
draftPolicy.spec.desiredState.ovn['bridge-mapping'].splice(index, 1); | ||
}); | ||
}; | ||
|
||
return policy?.spec?.desiredState?.ovn?.['bridge-mapping']?.map((bridgeMapping, index) => { | ||
return ( | ||
<PageSection variant={PageSectionVariants.light} key={index}> | ||
<Flex alignItems={{ default: 'alignItemsFlexEnd' }} marginWidth={20}> | ||
<FlexItem grow={{ default: 'grow' }} spacer={{ default: 'spacer4xl' }}> | ||
<Title headingLevel="h6" size="md"> | ||
{t('OVN localnet name')} | ||
</Title> | ||
<TextInput value={bridgeMapping?.localnet} onChange={onChange(index, 'localnet')} /> | ||
</FlexItem> | ||
<FlexItem grow={{ default: 'grow' }}> | ||
<Title headingLevel="h6" size="md"> | ||
{t('OVS bridge name')} | ||
</Title> | ||
<TextInput value={bridgeMapping?.bridge} onChange={onChange(index, 'bridge')} /> | ||
</FlexItem> | ||
<FlexItem> | ||
<Button | ||
variant={ButtonVariant.plain} | ||
aria-label={t('Remove')} | ||
onClick={() => onRemove(index)} | ||
> | ||
<MinusCircleIcon /> | ||
</Button> | ||
</FlexItem> | ||
</Flex> | ||
</PageSection> | ||
); | ||
}); | ||
}; | ||
|
||
export default PolicyFormOVSBridgeMappingExpandable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.