Skip to content

Commit

Permalink
take paramters directly from object
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacov committed Aug 10, 2020
1 parent d82367f commit ec5e845
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ import { FormField, FormFieldType } from '../../form/form-field';
import { iGetFieldValue } from '../../selectors/immutable/field';
import { VMSettingsField } from '../../types';
import { getPlaceholder } from '../../utils/renderable-field-utils';
import { iGet } from '../../../../utils/immutable';

export const ProvisionSourceComponent: React.FC<ProvisionSourceComponentProps> = React.memo(
({
provisionSourceField,
onChange,
goToStorageStep,
goToNetworkingStep,
getProvisionSourceAttribute,
}) => {
({ provisionSourceField, onChange, goToStorageStep, goToNetworkingStep }) => {
const provisionSourceValue = iGetFieldValue(provisionSourceField);
const sources = iGet(provisionSourceField, 'sources');
const storageBtn = (
<Button
isDisabled={!goToStorageStep}
Expand All @@ -37,7 +33,7 @@ export const ProvisionSourceComponent: React.FC<ProvisionSourceComponentProps> =
<strong>Networking</strong>
</Button>
);
const getStorageMsg = () => {
const getStorageMsg = React.useCallback(() => {
switch (provisionSourceValue) {
case ProvisionSource.URL.toString():
return <>Enter URL here or edit the mounted disk in the {storageBtn} step</>;
Expand All @@ -48,7 +44,7 @@ export const ProvisionSourceComponent: React.FC<ProvisionSourceComponentProps> =
default:
return null;
}
};
}, [provisionSourceValue, storageBtn]);

const provisionSourceDiskHelpMsg = (
<div className="pf-c-form__helper-text" aria-live="polite">
Expand All @@ -69,7 +65,7 @@ export const ProvisionSourceComponent: React.FC<ProvisionSourceComponentProps> =
placeholder={getPlaceholder(VMSettingsField.PROVISION_SOURCE_TYPE)}
isDisabled={!!provisionSourceValue}
/>
{(getProvisionSourceAttribute('sources') || []).map((source) => (
{sources.map((source) => (
<FormSelectOption key={source} value={source} label={source} />
))}
</FormSelect>
Expand All @@ -91,5 +87,4 @@ type ProvisionSourceComponentProps = {
onChange: (key: string, value: string | boolean) => void;
goToStorageStep: () => void;
goToNetworkingStep: () => void;
getProvisionSourceAttribute: (attr: string) => any;
};
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,14 @@ export class VMSettingsTabComponent extends React.Component<VMSettingsTabCompone
provisionSourceField={this.getField(VMSettingsField.PROVISION_SOURCE_TYPE)}
onChange={this.props.onFieldChange}
goToStorageStep={
steps[VMWizardTab.STORAGE]?.canJumpTo ? () => goToStep(VMWizardTab.STORAGE) : null
steps[VMWizardTab.STORAGE]?.canJumpTo
? React.useCallback(() => goToStep(VMWizardTab.STORAGE), [goToStep])
: null
}
goToNetworkingStep={
steps[VMWizardTab.NETWORKING]?.canJumpTo ? () => goToStep(VMWizardTab.NETWORKING) : null
}
getProvisionSourceAttribute={(attr: string) =>
this.getFieldAttribute(VMSettingsField.PROVISION_SOURCE_TYPE, attr)
steps[VMWizardTab.NETWORKING]?.canJumpTo
? React.useCallback(() => goToStep(VMWizardTab.NETWORKING), [goToStep])
: null
}
/>
<ContainerSource
Expand Down

0 comments on commit ec5e845

Please sign in to comment.