-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1138 from sgratch/add-preserveStaticIPs-flag-to-plan
🐾 Add the preserveStaticIPs flag to vSphere's plan details section
- Loading branch information
Showing
8 changed files
with
162 additions
and
0 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
53 changes: 53 additions & 0 deletions
53
...lans/views/details/components/SettingsSection/components/PreserveStaticIPsDetailsItem.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,53 @@ | ||
import React from 'react'; | ||
import { useModal } from 'src/modules/Providers/modals'; | ||
import { DetailsItem } from 'src/modules/Providers/utils'; | ||
import { useForkliftTranslation } from 'src/utils/i18n'; | ||
|
||
import { Label } from '@patternfly/react-core'; | ||
|
||
import { PlanDetailsItemProps } from '../../DetailsSection'; | ||
import { EditPlanPreserveStaticIPs } from '../modals/EditPlanPreserveStaticIPs'; | ||
|
||
export const PreserveStaticIPsDetailsItem: React.FC<PlanDetailsItemProps> = ({ | ||
resource, | ||
canPatch, | ||
helpContent, | ||
destinationProvider, | ||
}) => { | ||
const { t } = useForkliftTranslation(); | ||
const { showModal } = useModal(); | ||
|
||
const defaultHelpContent = t( | ||
`Preserve the static IPs that the VM runs with in vSphere provider's environment.`, | ||
); | ||
|
||
const trueLabel = ( | ||
<Label isCompact color={'green'}> | ||
Preserve static IPs | ||
</Label> | ||
); | ||
const falseLabel = ( | ||
<Label isCompact color={'blue'}> | ||
Use system default | ||
</Label> | ||
); | ||
|
||
return ( | ||
<DetailsItem | ||
title={t('Preserve static IPs')} | ||
content={resource?.spec?.preserveStaticIPs ? trueLabel : falseLabel} | ||
helpContent={helpContent ?? defaultHelpContent} | ||
crumbs={['spec', 'preserveStaticIPs']} | ||
onEdit={ | ||
canPatch && | ||
(() => | ||
showModal( | ||
<EditPlanPreserveStaticIPs | ||
resource={resource} | ||
destinationProvider={destinationProvider} | ||
/>, | ||
)) | ||
} | ||
/> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
...ole-plugin/src/modules/Plans/views/details/components/SettingsSection/components/index.ts
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
91 changes: 91 additions & 0 deletions
91
...components/SettingsSection/modals/EditPlanPreserveStaticIPs/EditPlanPreserveStaticIPs.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,91 @@ | ||
import React from 'react'; | ||
import { | ||
EditModal, | ||
EditModalProps, | ||
ModalInputComponentType, | ||
OnConfirmHookType, | ||
} from 'src/modules/Providers/modals'; | ||
import { useForkliftTranslation } from 'src/utils/i18n'; | ||
|
||
import { Modify, PlanModel, V1beta1Plan, V1beta1Provider } from '@kubev2v/types'; | ||
import { K8sModel, k8sPatch } from '@openshift-console/dynamic-plugin-sdk'; | ||
import { Switch } from '@patternfly/react-core'; | ||
|
||
const onConfirm: OnConfirmHookType = async ({ resource, model, newValue }) => { | ||
const plan = resource as V1beta1Plan; | ||
|
||
const resourceValue = plan?.spec?.preserveStaticIPs; | ||
const op = resourceValue ? 'replace' : 'add'; | ||
|
||
const obj = await k8sPatch({ | ||
model: model, | ||
resource: resource, | ||
data: [ | ||
{ | ||
op, | ||
path: '/spec/preserveStaticIPs', | ||
value: newValue === 'true' || undefined, | ||
}, | ||
], | ||
}); | ||
|
||
return obj; | ||
}; | ||
|
||
interface SwitchRendererProps { | ||
value: string | number; | ||
onChange: (string) => void; | ||
} | ||
|
||
const PreserveStaticIPsInputFactory: () => ModalInputComponentType = () => { | ||
const SwitchRenderer: React.FC<SwitchRendererProps> = ({ value, onChange }) => { | ||
const onChangeInternal = (v) => { | ||
onChange(v ? 'true' : 'false'); | ||
}; | ||
|
||
return ( | ||
<Switch | ||
id="simple-switch" | ||
label="Preserve the static IPs that the VM runs with in vSphere provider's environment." | ||
labelOff="Do not try to preserve the static IPs that the VM runs with in vSphere provider's environment." | ||
isChecked={value === 'true'} | ||
onChange={onChangeInternal} | ||
/> | ||
); | ||
}; | ||
|
||
return SwitchRenderer; | ||
}; | ||
|
||
const EditPlanPreserveStaticIPs_: React.FC<EditPlanPreserveStaticIPsProps> = (props) => { | ||
const { t } = useForkliftTranslation(); | ||
|
||
return ( | ||
<EditModal | ||
{...props} | ||
jsonPath={(obj: V1beta1Plan) => (obj.spec.preserveStaticIPs ? 'true' : 'false')} | ||
title={props?.title || t('Set to preserve the static IPs')} | ||
label={props?.label || t('Whether to preserve the static IPs')} | ||
model={PlanModel} | ||
onConfirmHook={onConfirm} | ||
body={t(`Preserve the static IPs that the VM runs with in vSphere provider's environment.`)} | ||
InputComponent={PreserveStaticIPsInputFactory()} | ||
/> | ||
); | ||
}; | ||
|
||
export type EditPlanPreserveStaticIPsProps = Modify< | ||
EditModalProps, | ||
{ | ||
resource: V1beta1Plan; | ||
title?: string; | ||
label?: string; | ||
model?: K8sModel; | ||
jsonPath?: string | string[]; | ||
destinationProvider: V1beta1Provider; | ||
} | ||
>; | ||
|
||
export const EditPlanPreserveStaticIPs: React.FC<EditPlanPreserveStaticIPsProps> = (props) => { | ||
return <EditPlanPreserveStaticIPs_ {...props} />; | ||
}; |
3 changes: 3 additions & 0 deletions
3
.../Plans/views/details/components/SettingsSection/modals/EditPlanPreserveStaticIPs/index.ts
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,3 @@ | ||
// @index(['./*', /style/g], f => `export * from '${f.path}';`) | ||
export * from './EditPlanPreserveStaticIPs'; | ||
// @endindex |
1 change: 1 addition & 0 deletions
1
...console-plugin/src/modules/Plans/views/details/components/SettingsSection/modals/index.ts
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