Skip to content

Commit

Permalink
move callout to above the form
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Sep 9, 2020
1 parent 1a85d85 commit 4bb3af6
Showing 1 changed file with 57 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export const PolicyStepLogistics: React.FunctionComponent<StepProps> = ({

const { i18n, history } = useServices();

const [showRepositoryNotFoundWarning, setShowRepositoryNotFoundWarning] = useState<boolean>(
false
);

// State for touched inputs
const [touched, setTouched] = useState({
name: false,
Expand Down Expand Up @@ -258,62 +262,42 @@ export const PolicyStepLogistics: React.FunctionComponent<StepProps> = ({
}
}

const policyRepositoryExists =
const doesRepositoryExist =
!!policy.repository &&
repositories.some((r: { name: string }) => r.name === policy.repository);

if (!policyRepositoryExists && !errors.repository) {
if (!doesRepositoryExist && !errors.repository) {
updatePolicy(policy, { repositoryDoesNotExist: true });
}

if (showRepositoryNotFoundWarning !== !doesRepositoryExist) {
setShowRepositoryNotFoundWarning(!doesRepositoryExist);
}

return (
<>
{!policyRepositoryExists && (
<>
<EuiCallOut
data-test-subj="repositoryNotFoundWarning"
title={
<FormattedMessage
id="xpack.snapshotRestore.policyForm.stepLogistics.selectRepository.policyRepositoryNotFoundTitle"
defaultMessage="Repository not found"
/>
}
color="danger"
iconType="alert"
>
<FormattedMessage
id="xpack.snapshotRestore.policyForm.stepLogistics.selectRepository.policyRepositoryNotFoundDescription"
defaultMessage="Repository {repo} does not exist. Please select an existing repository."
values={{ repo: <EuiCode>{policy.repository}</EuiCode> }}
/>
</EuiCallOut>
<EuiSpacer size="m" />
</>
)}
<EuiSelect
options={repositories.map(({ name }: Repository) => ({
value: name,
text: name,
}))}
hasNoInitialSelection={!policyRepositoryExists}
value={!policyRepositoryExists ? '' : policy.repository}
onBlur={() => setTouched({ ...touched, repository: true })}
onChange={(e) => {
updatePolicy(
{
repository: e.target.value,
},
{
managedRepository,
isEditing,
policyName: policy.name,
}
);
}}
fullWidth
data-test-subj="repositorySelect"
/>
</>
<EuiSelect
options={repositories.map(({ name }: Repository) => ({
value: name,
text: name,
}))}
hasNoInitialSelection={!doesRepositoryExist}
value={!doesRepositoryExist ? '' : policy.repository}
onBlur={() => setTouched({ ...touched, repository: true })}
onChange={(e) => {
updatePolicy(
{
repository: e.target.value,
},
{
managedRepository,
isEditing,
policyName: policy.name,
}
);
}}
fullWidth
data-test-subj="repositorySelect"
/>
);
};

Expand Down Expand Up @@ -576,8 +560,31 @@ export const PolicyStepLogistics: React.FunctionComponent<StepProps> = ({
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="l" />

{showRepositoryNotFoundWarning && (
<>
<EuiSpacer size="m" />
<EuiCallOut
data-test-subj="repositoryNotFoundWarning"
title={
<FormattedMessage
id="xpack.snapshotRestore.policyForm.stepLogistics.selectRepository.policyRepositoryNotFoundTitle"
defaultMessage="Repository not found"
/>
}
color="danger"
iconType="alert"
>
<FormattedMessage
id="xpack.snapshotRestore.policyForm.stepLogistics.selectRepository.policyRepositoryNotFoundDescription"
defaultMessage="Repository {repo} does not exist. Please select an existing repository."
values={{ repo: <EuiCode>{policy.repository}</EuiCode> }}
/>
</EuiCallOut>
</>
)}

<EuiSpacer size="l" />
{renderNameField()}
{renderSnapshotNameField()}
{renderRepositoryField()}
Expand Down

0 comments on commit 4bb3af6

Please sign in to comment.