Repository navigation
fix(ui): retry loading source repository details #31240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,6 +167,7 @@ export const ApplicationParameters = (props: { | |
| const [isAddingSource, setIsAddingSource] = React.useState(false); | ||
| const [isSavingSource, setIsSavingSource] = React.useState(false); | ||
| const [appParamsDeletedState, setAppParamsDeletedState] = React.useState([]); | ||
| const [sourceEditing, setSourceEditing] = React.useState(false); | ||
|
|
||
| if (app.spec.sources?.length > 0 && !props.details) { | ||
| // For multi-source case only | ||
|
|
@@ -281,20 +282,23 @@ export const ApplicationParameters = (props: { | |
| // For single source field, details page where we have to do the load to retrieve repo details | ||
| // Input changes frequently due to updates higher in the tree, do not show loading state when reloading | ||
| return ( | ||
| <DataLoader noLoaderOnInputChange={true} input={app} load={application => getSingleSource(application)}> | ||
| {({details, error}: SourceDetails) => { | ||
| <SourceDetailsLoader | ||
| input={app} | ||
| inputKey={JSON.stringify([app.metadata.name, app.spec.project, app.spec.source, app.spec.sourceHydrator])} | ||
| load={application => getSingleSource(application)}> | ||
| {({details, error}: SourceDetails, retry, pending) => { | ||
| if (!details) { | ||
| return null; | ||
| } | ||
| const attr = gatherDetails(0, details, [], source, app, setRemovedOverrides, removedOverrides, appParamsDeletedState, setAppParamsDeletedState, false); | ||
| return ( | ||
| <> | ||
| <SourceDetailsWarning error={error} /> | ||
| <SourceDetailsWarning error={error} onRetry={retry} disabled={pending || sourceEditing} /> | ||
| {getEditablePanel(attr, details)} | ||
| </> | ||
| ); | ||
| }} | ||
| </DataLoader> | ||
| </SourceDetailsLoader> | ||
| ); | ||
| } | ||
| } | ||
|
|
@@ -344,12 +348,15 @@ export const ApplicationParameters = (props: { | |
| {isRefOnlySource(app.spec.sources[index]) ? ( | ||
| getEditablePanelForOneSource(undefined, index, app.spec.sources[index]) | ||
| ) : ( | ||
| <DataLoader | ||
| <SourceDetailsLoader | ||
| key={'app_params_source_' + index} | ||
| input={app.spec.sources[index]} | ||
| inputKey={JSON.stringify([app.metadata.name, app.spec.project, index, app.spec.sources[index]])} | ||
| load={src => getSourceFromAppSources(src, app.metadata.name, app.spec.project, index, 0)}> | ||
| {({details, error}: SourceDetails) => getEditablePanelForOneSource(details, index, app.spec.sources[index], error)} | ||
| </DataLoader> | ||
| {({details, error}: SourceDetails, retry, pending) => | ||
| getEditablePanelForOneSource(details, index, app.spec.sources[index], error, retry, pending || sourceEditing) | ||
| } | ||
| </SourceDetailsLoader> | ||
| )} | ||
| </div> | ||
| </div> | ||
|
|
@@ -366,6 +373,12 @@ export const ApplicationParameters = (props: { | |
| return ( | ||
| <div className='application-parameters'> | ||
| <EditablePanel | ||
| onModeSwitch={() => { | ||
| setSourceEditing(current => !current); | ||
| if (repoAppDetails?.plugin) { | ||
| setAppParamsDeletedState([]); | ||
| } | ||
| }} | ||
| save={ | ||
| props.save && | ||
| (async (input: models.Application) => { | ||
|
|
@@ -435,12 +448,6 @@ export const ApplicationParameters = (props: { | |
|
|
||
| return errors; | ||
| }} | ||
| onModeSwitch={ | ||
| repoAppDetails?.plugin && | ||
| (() => { | ||
| setAppParamsDeletedState([]); | ||
| }) | ||
| } | ||
| title={repoAppDetails?.type?.toLocaleUpperCase()} | ||
| items={items as EditablePanelItem[]} | ||
| noReadonlyMode={props.noReadonlyMode} | ||
|
|
@@ -450,7 +457,14 @@ export const ApplicationParameters = (props: { | |
| ); | ||
| } | ||
|
|
||
| function getEditablePanelForOneSource(repoAppDetails: models.RepoAppDetails | undefined, ind: number, src: models.ApplicationSource, detailsError?: Error): any { | ||
| function getEditablePanelForOneSource( | ||
| repoAppDetails: models.RepoAppDetails | undefined, | ||
| ind: number, | ||
| src: models.ApplicationSource, | ||
| detailsError?: Error, | ||
| onRetry?: () => void, | ||
| retryDisabled = false | ||
| ): any { | ||
| let floatingTitle: string; | ||
| const lowerPanelAttributes: EditablePanelItem[] = []; | ||
| const upperPanelAttributes: EditablePanelItem[] = []; | ||
|
|
@@ -520,7 +534,13 @@ export const ApplicationParameters = (props: { | |
| return ( | ||
| <ApplicationParametersSource | ||
| index={ind} | ||
| banner={<SourceDetailsWarning error={detailsError} />} | ||
| banner={<SourceDetailsWarning error={detailsError} onRetry={onRetry} disabled={retryDisabled} />} | ||
| onModeSwitch={() => { | ||
| setSourceEditing(current => !current); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Track editing state per source so Retry stays disabled while any source editor is open.
Replace the shared toggle with explicit state. Either track the set of source indices that are in edit mode, or make each source report its enter and exit state. Retry should be disabled while that set is non-empty.
|
||
| if (repoAppDetails?.plugin) { | ||
| setAppParamsDeletedState([]); | ||
| } | ||
| }} | ||
| saveTop={props.save} | ||
| saveBottom={ | ||
| props.save && | ||
|
|
@@ -596,12 +616,6 @@ export const ApplicationParameters = (props: { | |
|
|
||
| return errors; | ||
| }} | ||
| onModeSwitch={ | ||
| repoAppDetails?.plugin && | ||
| (() => { | ||
| setAppParamsDeletedState([]); | ||
| }) | ||
| } | ||
| titleBottom={repoAppDetails?.type?.toLocaleUpperCase()} | ||
| titleTop={'SOURCE ' + (ind + 1)} | ||
| floatingTitle={floatingTitle ? floatingTitle : null} | ||
|
|
@@ -1152,14 +1166,66 @@ async function getSingleSource(app: models.Application): Promise<SourceDetails> | |
| return {details: null}; | ||
| } | ||
|
|
||
| const SourceDetailsWarning = ({error}: {error?: Error}) => | ||
| const SourceDetailsWarning = ({error, onRetry, disabled}: {error?: Error; onRetry?: () => void; disabled?: boolean}) => | ||
| error ? ( | ||
| <p role='alert'> | ||
| <i className='fa fa-exclamation-triangle' style={{color: ARGO_WARNING_COLOR}} />{' '} | ||
| <ErrorNotification title='Unable to load repository details. The source settings shown may be incomplete' e={error} /> | ||
| <ErrorNotification title='Unable to load repository details. The source settings shown may be incomplete' e={error} />{' '} | ||
| {onRetry && ( | ||
| <button type='button' className='argo-button argo-button--base-o' onClick={onRetry} disabled={disabled}> | ||
| Retry | ||
| </button> | ||
| )} | ||
| </p> | ||
| ) : null; | ||
|
|
||
| const SourceDetailsLoader = ({ | ||
| input, | ||
| inputKey, | ||
| load, | ||
| children | ||
| }: { | ||
| input: any; | ||
| inputKey: string; | ||
| load: (input: any) => Promise<SourceDetails>; | ||
| children: (result: SourceDetails, retry: () => void, pending: boolean) => React.ReactNode; | ||
| }) => { | ||
| const [attempt, setAttempt] = React.useState(0); | ||
| const [result, setResult] = React.useState<SourceDetails | null>(null); | ||
| const [pending, setPending] = React.useState(false); | ||
| const loadRef = React.useRef(load); | ||
| loadRef.current = load; | ||
| const inputRef = React.useRef(input); | ||
| inputRef.current = input; | ||
| React.useEffect(() => { | ||
| let active = true; | ||
| setPending(true); | ||
| loadRef | ||
| .current(inputRef.current) | ||
| .then(next => { | ||
| if (active) { | ||
| setResult(next); | ||
| setPending(false); | ||
| } | ||
| }) | ||
| .catch(error => { | ||
| if (active) { | ||
| setResult({details: null, error: error as Error}); | ||
| setPending(false); | ||
| } | ||
| }); | ||
| return () => { | ||
| active = false; | ||
| }; | ||
| }, [inputKey, attempt]); | ||
|
|
||
| if (!result) { | ||
| return null; | ||
| } | ||
|
|
||
| return <>{children(result, () => setAttempt(current => current + 1), pending)}</>; | ||
| }; | ||
|
|
||
| function applyExplicitSourceType(source: models.ApplicationSource, details: models.RepoAppDetails): models.RepoAppDetails { | ||
| const explicitDetails = getExplicitSourceDetails(source); | ||
| if (!hasExplicitSourceType(source) || details.type === explicitDetails.type) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear the source edit state when an editor closes without an exit event.
sourceEditingchanges only throughonModeSwitchtoggles. Collapsing an expanded source unmounts itsEditablePanelwithout callingonModeSwitch. The Boolean staystrue, and every expanded source keeps its Retry button disabled. The next edit-mode toggle on another source then flips the stale value tofalse, which enables Retry while an editor is open.Track edit state so that it matches the open editors. Use an explicit enter or exit signal, or report exit when an editing panel unmounts. Choose the mechanism that fits the shared
EditablePanelcontract.