Skip to content

Commit

Permalink
Fix bug in pre-filled form using RPM. Handling form URL/Tag updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
rjpmestre committed Feb 11, 2025
1 parent 6c317e1 commit 4e3d051
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,11 @@ public String updateProxyConfiguration(Request request, Response response, User
return result(response, ResultJson.success("Proxy configuration applied"));
}
catch (RhnRuntimeException e) {
LOG.error("Failed to apply proxy configuration to minion", e);
LOG.error("Failed to apply proxy configuration to minion", e);
return internalServerError(response, e.getMessage());
}
catch (RhnGeneralException e) {
LOG.error("Failed to apply proxy configuration to minion", e);
LOG.error("Failed to apply proxy configuration to minion", e);
return badRequest(response, e.getErrorMessages());
}

Expand Down
37 changes: 28 additions & 9 deletions web/html/src/manager/minion/proxy/proxy-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ const imageNames = [
"registryTftpdURL",
];

const tagMapping = {
registryBaseURL: "registryBaseTag",
registryHttpdURL: "registryHttpdTag",
registrySaltbrokerURL: "registrySaltbrokerTag",
registrySquidURL: "registrySquidTag",
registrySshURL: "registrySshTag",
registryTftpdURL: "registryTftpdTag",
};

export function ProxyConfig({ serverId, isUyuni, parents, currentConfig, initFailMessage }: ProxyConfigProps) {
const [messages, setMessages] = useState<React.ReactNode[]>([]);
const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -150,11 +159,16 @@ export function ProxyConfig({ serverId, isUyuni, parents, currentConfig, initFai
});

useEffect(() => {
imageNames.forEach((url) => {
if (currentConfig[url]) {
retrieveRegistryTags(currentConfig, url);
}
});
if (currentConfig.sourceMode === SourceMode.RPM) {
//work-around to trigger validation for filled forms using RPM
retrieveRegistryTags(currentConfig, null);
} else {
imageNames.forEach((url) => {
if (currentConfig[url]) {
retrieveRegistryTags(currentConfig, url);
}
});
}
if (initFailMessage) {
setSuccess(false);
setMessages([initFailMessage]);
Expand Down Expand Up @@ -352,18 +366,23 @@ export function ProxyConfig({ serverId, isUyuni, parents, currentConfig, initFai

if (response?.success) {
setErrors((prev) => ({ ...prev, [name]: [] }));
setTagOptions((prev) => ({
...prev,
[name]: response.data || [],
}));
setTagOptions((prev) => ({ ...prev, [name]: response.data || [] }));

// Check if the current tag is still in the new options
const currentTag = newModel[tagMapping[name]];
if (currentTag && !response.data.includes(currentTag)) {
setModel((prev) => ({ ...prev, [tagMapping[name]]: "" }));
}
} else {
const errorMessage = response?.messages?.join(", ") || "Validation Failed";
setErrors((prev) => ({ ...prev, [name]: errorMessage }));
setTagOptions((prev) => ({ ...prev, [name]: [] }));
setModel((prev) => ({ ...prev, [tagMapping[name]]: "" }));
}
} catch (error) {
setErrors((prev) => ({ ...prev, [name]: "Error during validation" }));
setTagOptions((prev) => ({ ...prev, [name]: [] }));
setModel((prev) => ({ ...prev, [tagMapping[name]]: "" }));
}
};

Expand Down

0 comments on commit 4e3d051

Please sign in to comment.