diff --git a/ui/src/app/applications/components/application-parameters/application-parameters.test.tsx b/ui/src/app/applications/components/application-parameters/application-parameters.test.tsx
index 94c27f1d959c2..1507c2479104f 100644
--- a/ui/src/app/applications/components/application-parameters/application-parameters.test.tsx
+++ b/ui/src/app/applications/components/application-parameters/application-parameters.test.tsx
@@ -112,6 +112,31 @@ describe('ApplicationParameters ref-only sources', () => {
expect(screen.getByText(/Source 2: TYPE=Plugin/)).toBeInTheDocument();
});
+ test('retries loading source details without reloading the page', async () => {
+ const app = applicationWithValuesSource({
+ repoURL: 'https://git.example.com/org/value-files.git',
+ targetRevision: 'main',
+ ref: 'values'
+ } as models.ApplicationSource);
+ appDetails.mockRejectedValueOnce(new Error('failed to load application details'));
+ appDetails.mockResolvedValueOnce({
+ type: 'Helm',
+ helm: {name: 'prometheus', valueFiles: [], parameters: [], fileParameters: []}
+ } as models.RepoAppDetails);
+
+ const user = userEvent.setup();
+ render(
+
+
+
+ );
+
+ expect(await screen.findByRole('alert')).toBeInTheDocument();
+ await user.click(screen.getByRole('button', {name: 'Retry'}));
+ await waitFor(() => expect(screen.queryByRole('alert')).not.toBeInTheDocument());
+ expect(appDetails).toHaveBeenCalledTimes(2);
+ });
+
test('makes external values guidance accessible and saves typed files without Enter', async () => {
const app = applicationWithValuesSource({
repoURL: 'https://git.example.com/org/value-files.git',
diff --git a/ui/src/app/applications/components/application-parameters/application-parameters.tsx b/ui/src/app/applications/components/application-parameters/application-parameters.tsx
index fdf081b12ada8..798835946aac8 100644
--- a/ui/src/app/applications/components/application-parameters/application-parameters.tsx
+++ b/ui/src/app/applications/components/application-parameters/application-parameters.tsx
@@ -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 (
- getSingleSource(application)}>
- {({details, error}: SourceDetails) => {
+ getSingleSource(application)}>
+ {({details, error}: SourceDetails, retry, pending) => {
if (!details) {
return null;
}
const attr = gatherDetails(0, details, [], source, app, setRemovedOverrides, removedOverrides, appParamsDeletedState, setAppParamsDeletedState, false);
return (
<>
-
+
{getEditablePanel(attr, details)}
>
);
}}
-
+
);
}
}
@@ -344,12 +348,15 @@ export const ApplicationParameters = (props: {
{isRefOnlySource(app.spec.sources[index]) ? (
getEditablePanelForOneSource(undefined, index, app.spec.sources[index])
) : (
- getSourceFromAppSources(src, app.metadata.name, app.spec.project, index, 0)}>
- {({details, error}: SourceDetails) => getEditablePanelForOneSource(details, index, app.spec.sources[index], error)}
-
+ {({details, error}: SourceDetails, retry, pending) =>
+ getEditablePanelForOneSource(details, index, app.spec.sources[index], error, retry, pending || sourceEditing)
+ }
+
)}
@@ -366,6 +373,12 @@ export const ApplicationParameters = (props: {
return (
{
+ 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 (
}
+ banner={}
+ onModeSwitch={() => {
+ setSourceEditing(current => !current);
+ 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
return {details: null};
}
-const SourceDetailsWarning = ({error}: {error?: Error}) =>
+const SourceDetailsWarning = ({error, onRetry, disabled}: {error?: Error; onRetry?: () => void; disabled?: boolean}) =>
error ? (
{' '}
-
+ {' '}
+ {onRetry && (
+
+ )}
) : null;
+const SourceDetailsLoader = ({
+ input,
+ inputKey,
+ load,
+ children
+}: {
+ input: any;
+ inputKey: string;
+ load: (input: any) => Promise;
+ children: (result: SourceDetails, retry: () => void, pending: boolean) => React.ReactNode;
+}) => {
+ const [attempt, setAttempt] = React.useState(0);
+ const [result, setResult] = React.useState(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) {