Skip to content

Allow changing namespace from Server Actions menu when connected to an invalid namespace #1343

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

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,9 @@ export class AtelierAPI {
if (this.ns && this.ns.length && !data.namespaces.includes(this.ns) && checkNs) {
throw {
code: "WrongNamespace",
message: `This server does not have specified namespace '${this.ns}'.\n
You must select one of the following: ${data.namespaces.join(", ")}.`,
message: `This server does not have specified namespace '${
this.ns
}'.\nYou must select one of the following: ${data.namespaces.join(", ")}.`,
};
}
return Promise.all([
Expand Down
17 changes: 11 additions & 6 deletions src/commands/serverActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,10 @@ export async function serverActions(): Promise<void> {
break;
}
case "switchNamespace": {
// NOTE: List of all namespaces except the current one as it doesn't make sense to allow switching to the current one
const allNamespaces: string[] | undefined = await api
.serverInfo()
.then((data) =>
data.result.content.namespaces.filter((ns) => ns.toLowerCase() !== api.config.ns.toLowerCase())
)
// List of all namespaces except the current one as it doesn't make sense to allow switching to the current one
let allNamespaces: string[] | undefined = await api
.serverInfo(false)
.then((data) => data.result.content.namespaces)
.catch((error) => {
let message = `Failed to fetch a list of namespaces.`;
if (error && error.errorText && error.errorText !== "") {
Expand All @@ -94,6 +92,13 @@ export async function serverActions(): Promise<void> {
return;
}

if (!allNamespaces.length) {
vscode.window.showErrorMessage(`You don't have access to any namespaces.`, "Dismiss");
return;
}

// Filter out the current namespace
allNamespaces = allNamespaces.filter((ns) => ns.toLowerCase() != api.config.ns.toLowerCase());
if (!allNamespaces.length) {
vscode.window.showErrorMessage(`You don't have access to any other namespaces.`, "Dismiss");
return;
Expand Down