From 4bb3af68eac8c3b6501090017ec4d96e0e5f7be2 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Wed, 9 Sep 2020 12:14:36 +0200 Subject: [PATCH] move callout to above the form --- .../policy_form/steps/step_logistics.tsx | 107 ++++++++++-------- 1 file changed, 57 insertions(+), 50 deletions(-) diff --git a/x-pack/plugins/snapshot_restore/public/application/components/policy_form/steps/step_logistics.tsx b/x-pack/plugins/snapshot_restore/public/application/components/policy_form/steps/step_logistics.tsx index 7656d5ba7c65d..f825c7b1f3d98 100644 --- a/x-pack/plugins/snapshot_restore/public/application/components/policy_form/steps/step_logistics.tsx +++ b/x-pack/plugins/snapshot_restore/public/application/components/policy_form/steps/step_logistics.tsx @@ -56,6 +56,10 @@ export const PolicyStepLogistics: React.FunctionComponent = ({ const { i18n, history } = useServices(); + const [showRepositoryNotFoundWarning, setShowRepositoryNotFoundWarning] = useState( + false + ); + // State for touched inputs const [touched, setTouched] = useState({ name: false, @@ -258,62 +262,42 @@ export const PolicyStepLogistics: React.FunctionComponent = ({ } } - 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 && ( - <> - - } - color="danger" - iconType="alert" - > - {policy.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" - /> - + ({ + 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" + /> ); }; @@ -576,8 +560,31 @@ export const PolicyStepLogistics: React.FunctionComponent = ({ - + {showRepositoryNotFoundWarning && ( + <> + + + } + color="danger" + iconType="alert" + > + {policy.repository} }} + /> + + + )} + + {renderNameField()} {renderSnapshotNameField()} {renderRepositoryField()}