Skip to content

Commit

Permalink
Refactored logic for rendering data allocation notices
Browse files Browse the repository at this point in the history
Also updated a comment.
  • Loading branch information
jloleysens committed Oct 12, 2020
1 parent 56a4cee commit 9cb0c1e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ export const DataTierAllocation: FunctionComponent<SharedProps> = (props) => {
if (disableDataTierOption && phaseData.dataTierAllocationType === 'default') {
/**
* This is a slight hack because we only know we should disable the "custom" option further
* down the component tree (i.e., before the policy has been deserialized).
* down the component tree (i.e., after the policy has been deserialized).
*
* We reset the value to "custom" if we deserialized to "default.
* We reset the value to "custom" if we deserialized to "default".
*/
setPhaseData('dataTierAllocationType', 'custom');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,63 +57,47 @@ export const DataTierAllocationField: FunctionComponent<Props> = ({
{({ nodesByRoles, nodesByAttributes, isUsingLegacyDataRoleConfig }) => {
const hasNodeAttrs = Boolean(Object.keys(nodesByAttributes ?? {}).length);

const renderDefaultAllocationNotice = () => {
if (phaseData.dataTierAllocationType !== 'default') {
return null;
const renderNotice = () => {
if (phaseData.dataTierAllocationType === 'default') {
const isCloudEnabled = cloud?.isCloudEnabled ?? false;
if (
isCloudEnabled &&
!isUsingLegacyDataRoleConfig &&
phase === 'cold' &&
!nodesByRoles.data_cold?.length
) {
// Tell cloud users they can deploy cold tier nodes.
return (
<>
<EuiSpacer size="s" />
<CloudDataTierCallout />
</>
);
}

const allocationNodeRole = getAvailableNodeRoleForPhase(phase, nodesByRoles);
if (
allocationNodeRole === 'none' ||
!isNodeRoleFirstPreference(phase, allocationNodeRole)
) {
return (
<>
<EuiSpacer size="s" />
<DefaultAllocationNotice phase={phase} targetNodeRole={allocationNodeRole} />
</>
);
}
} else if (phaseData.dataTierAllocationType === 'custom') {
if (!hasNodeAttrs) {
return (
<>
<EuiSpacer size="s" />
<NoNodeAttributesWarning phase={phase} />
</>
);
}
}

const allocationNodeRole = getAvailableNodeRoleForPhase(phase, nodesByRoles);
if (
allocationNodeRole !== 'none' &&
isNodeRoleFirstPreference(phase, allocationNodeRole)
) {
return null;
}

return (
<>
<EuiSpacer size="s" />
<DefaultAllocationNotice phase={phase} targetNodeRole={allocationNodeRole} />
</>
);
};

const renderNodeAttributesWarning = () => {
if (phaseData.dataTierAllocationType !== 'custom') {
return null;
}
if (hasNodeAttrs) {
return null;
}
return (
<>
<EuiSpacer size="s" />
<NoNodeAttributesWarning phase={phase} />
</>
);
};

const renderCloudCallout = () => {
const isCloudEnabled = cloud?.isCloudEnabled ?? false;
if (
!isCloudEnabled ||
isUsingLegacyDataRoleConfig ||
phaseData.dataTierAllocationType !== 'default' ||
phase !== 'cold'
) {
return null;
}

if (nodesByRoles.data_cold?.length) {
return null;
}

return (
<>
<EuiSpacer size="s" />
<CloudDataTierCallout />
</>
);
return null;
};

return (
Expand All @@ -136,9 +120,7 @@ export const DataTierAllocationField: FunctionComponent<Props> = ({
/>

{/* Data tier related warnings and call-to-action notices */}
{renderDefaultAllocationNotice()}
{renderNodeAttributesWarning()}
{renderCloudCallout()}
{renderNotice()}
</>
</EuiFormRow>
</EuiDescribedFormGroup>
Expand Down

0 comments on commit 9cb0c1e

Please sign in to comment.