Skip to content

Commit

Permalink
fix: Retry checkbox unchecked unexpectedly; Sync up with YAML (argopr…
Browse files Browse the repository at this point in the history
…oj#8682) (argoproj#8720)

Signed-off-by: Keith Chong <kykchong@redhat.com>
Signed-off-by: wojtekidd <wojtek.cichon@protonmail.com>
  • Loading branch information
keithchong authored and wojtekidd committed Apr 25, 2022
1 parent 8bf91a5 commit bc1670b
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 bc1670b

Please sign in to comment.