Skip to content

Commit

Permalink
fix: Retry checkbox unchecked unexpectedly; Sync up with YAML (#8682)
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Chong <kykchong@redhat.com>
  • Loading branch information
keithchong committed Mar 8, 2022
1 parent 6d19813 commit 0e2d4a3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const ApplicationCreatePanel = (props: {
const [yamlMode, setYamlMode] = React.useState(false);
const [explicitPathType, setExplicitPathType] = React.useState<{path: string; type: models.AppSourceType}>(null);
const [destFormat, setDestFormat] = React.useState('URL');
const [retry, setRetry] = React.useState(false);

function normalizeTypeFields(formApi: FormApi, type: models.AppSourceType) {
const app = formApi.getFormState().values;
Expand Down Expand Up @@ -221,7 +222,13 @@ export const ApplicationCreatePanel = (props: {
<div className='argo-form-row'>
<label>Sync Options</label>
<FormField formApi={api} field='spec.syncPolicy.syncOptions' component={ApplicationSyncOptionsField} />
<ApplicationRetryOptions formApi={api} field='spec.syncPolicy.retry' />
<ApplicationRetryOptions
formApi={api}
field='spec.syncPolicy.retry'
retry={retry || (api.getFormState().values.spec.syncPolicy && api.getFormState().values.spec.syncPolicy.retry)}
setRetry={setRetry}
initValues={api.getFormState().values.spec.syncPolicy ? api.getFormState().values.spec.syncPolicy.retry : null}
/>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,20 @@ export const ApplicationRetryForm = ({initValues, field = 'retryStrategy'}: {ini
);
};

export const ApplicationRetryOptions = ({formApi, initValues, field = 'retryStrategy'}: {formApi: FormApi; field?: string; initValues?: models.RetryStrategy}) => {
const [retry, setRetry] = React.useState(!!initValues);
export const ApplicationRetryOptions = ({
formApi,
initValues,
field = 'retryStrategy',
retry,
setRetry
}: {
formApi: FormApi;
field?: string;
initValues?: models.RetryStrategy;
retry?: boolean;
setRetry?: (value: boolean) => any;
}) => {
const [retryInternal, setRetryInternal] = React.useState(!!initValues);

const toggleRetry = (value: boolean) => {
if (!value) {
Expand All @@ -97,15 +109,18 @@ export const ApplicationRetryOptions = ({formApi, initValues, field = 'retryStra
errors: newErrors
});
}

setRetry(value);
if (setRetry != null) {
setRetry(value);
} else {
setRetryInternal(value);
}
};

const isChecked = setRetry != null ? retry : retryInternal;
return (
<div className='application-retry-options'>
<Checkbox id='retry' checked={retry} onChange={val => toggleRetry(val)} />
<Checkbox id='retry' checked={isChecked} onChange={val => toggleRetry(val)} />
<label htmlFor='retry'>Retry</label>
{retry && <ApplicationRetryForm initValues={initValues} field={field} />}
{isChecked && <ApplicationRetryForm initValues={initValues} field={field} />}
</div>
);
};

0 comments on commit 0e2d4a3

Please sign in to comment.