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
…#8720)

Signed-off-by: Keith Chong <[email protected]>
  • Loading branch information
keithchong authored and alexmt committed Mar 10, 2022
1 parent 88ca5aa commit bca190b
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 @@ -105,6 +105,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 @@ -222,7 +223,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 bca190b

Please sign in to comment.