Remove active project code

This commit is contained in:
alexweininger 2021-07-20 07:14:04 -07:00
parent 6ca2a91f08
commit 911ce7d98d
7 changed files with 42 additions and 52 deletions

View file

@ -353,6 +353,11 @@
], ],
"menus": { "menus": {
"view/title": [ "view/title": [
{
"command": "vscode-appwrite.addProject",
"when": "view == Projects",
"group": "navigation"
},
{ {
"command": "vscode-appwrite.OpenUsersDocumentation", "command": "vscode-appwrite.OpenUsersDocumentation",
"when": "view == Users", "when": "view == Users",
@ -512,11 +517,6 @@
"when": "viewItem =~ /^(permission)$/", "when": "viewItem =~ /^(permission)$/",
"group": "inline" "group": "inline"
}, },
{
"command": "vscode-appwrite.setActiveProject",
"when": "viewItem =~ /^(appwriteProject)$/",
"group": "inline"
},
{ {
"command": "vscode-appwrite.removeProject", "command": "vscode-appwrite.removeProject",
"when": "viewItem =~ /(appwriteProject)/" "when": "viewItem =~ /(appwriteProject)/"

View file

@ -1,14 +0,0 @@
import { setActiveProjectId } from '../../settings';
import { ProjectTreeItem } from "../../tree/projects/ProjectTreeItem";
export async function setActiveProject(treeItem: ProjectTreeItem): Promise<void> {
if (treeItem === undefined) {
return;
}
if (!(treeItem instanceof ProjectTreeItem)) {
return;
}
await setActiveProjectId(treeItem.project.projectId);
}

View file

@ -23,26 +23,25 @@ import { openUserInConsole } from "./users/openUserInConsole";
import { refreshUsersList } from "./users/refreshUsersList"; import { refreshUsersList } from "./users/refreshUsersList";
import { viewUserPrefs } from "./users/viewUserPrefs"; import { viewUserPrefs } from "./users/viewUserPrefs";
import { editPermission } from "./database/permissions/editPermission"; import { editPermission } from "./database/permissions/editPermission";
import { setActiveProject } from "./project/setActiveProject";
import { removeProject } from "./project/removeProject"; import { removeProject } from "./project/removeProject";
import { createTag } from './functions/createTag'; import { createTag } from "./functions/createTag";
import { createExecution } from './functions/createExecution'; import { createExecution } from "./functions/createExecution";
import { activateTag } from './functions/activateTag'; import { activateTag } from "./functions/activateTag";
import { editValue } from './common/editValue'; import { editValue } from "./common/editValue";
import { deleteFunction } from './functions/deleteFunction'; import { deleteFunction } from "./functions/deleteFunction";
import { createFunction } from './functions/createFunction'; import { createFunction } from "./functions/createFunction";
import { createFunctionVar } from './functions/createFunctionVar'; import { createFunctionVar } from "./functions/createFunctionVar";
import { deleteFunctionVar } from './functions/deleteFunctionVar'; import { deleteFunctionVar } from "./functions/deleteFunctionVar";
import { deleteTag } from './functions/deleteTag'; import { deleteTag } from "./functions/deleteTag";
import { viewExecutionErrors } from './functions/viewExecutionErrors'; import { viewExecutionErrors } from "./functions/viewExecutionErrors";
import { viewExecutionOutput } from './functions/viewExecutionOutput'; import { viewExecutionOutput } from "./functions/viewExecutionOutput";
import { copyExecutionErrors } from './functions/copyExecutionErrors'; import { copyExecutionErrors } from "./functions/copyExecutionErrors";
import { copyExecutionOutput } from './functions/copyExecutionOutput'; import { copyExecutionOutput } from "./functions/copyExecutionOutput";
import { openExecutionsInBrowser } from './functions/openExecutionsInBrowser'; import { openExecutionsInBrowser } from "./functions/openExecutionsInBrowser";
import { openFunctionSettingsInBrowser } from './functions/openFunctionSettingsInBrowser'; import { openFunctionSettingsInBrowser } from "./functions/openFunctionSettingsInBrowser";
import { openFunctionTagsInBrowser } from './functions/openFunctionTagsInBrowser'; import { openFunctionTagsInBrowser } from "./functions/openFunctionTagsInBrowser";
import { viewMore } from './common/viewMore'; import { viewMore } from "./common/viewMore";
class CommandRegistrar { class CommandRegistrar {
constructor(private readonly context: ExtensionContext) {} constructor(private readonly context: ExtensionContext) {}
@ -116,7 +115,6 @@ export function registerCommands(context: ExtensionContext): void {
/** Projects **/ /** Projects **/
registerCommand("addProject", connectAppwrite, "all"); registerCommand("addProject", connectAppwrite, "all");
registerCommand("setActiveProject", setActiveProject, "all");
registerCommand("refreshProjects", undefined, "projects"); registerCommand("refreshProjects", undefined, "projects");
registerCommand("removeProject", removeProject, "all"); registerCommand("removeProject", removeProject, "all");

View file

@ -30,7 +30,6 @@ export async function addProjectConfiguration(projectConfig: AppwriteProjectConf
const projects = await getAppwriteProjects(); const projects = await getAppwriteProjects();
await configuration.update("projects", [...projects, projectConfig], true); await configuration.update("projects", [...projects, projectConfig], true);
await setActiveProjectId(projectConfig.projectId);
} }
export async function getActiveProjectId(): Promise<string> { export async function getActiveProjectId(): Promise<string> {
@ -53,21 +52,9 @@ export async function getActiveProjectConfiguration(): Promise<AppwriteProjectCo
activeConfig = config; activeConfig = config;
} }
}); });
if (activeConfig === undefined) {
activeConfig = configurations[0];
setActiveProjectId(configurations[0].projectId);
}
return activeConfig; return activeConfig;
} }
export async function setActiveProjectId(projectId: string): Promise<void> {
const configuration = workspace.getConfiguration("appwrite");
await configuration.update("activeProjectId", projectId, true);
const active = await getActiveProjectConfiguration();
createAppwriteClient(active);
}
export async function updateActiveProjectId(): Promise<void> { export async function updateActiveProjectId(): Promise<void> {
const projects = await getAppwriteProjects(); const projects = await getAppwriteProjects();
if (projects.length > 0) { if (projects.length > 0) {

View file

@ -0,0 +1,16 @@
import { ThemeIcon, TreeItem } from "vscode";
export class AddProjectTreeItem extends TreeItem {
iconPath = new ThemeIcon("add");
constructor() {
super("Add Appwrite project");
}
contextValue = "";
command = {
command: "vscode-appwrite.addProject",
title: "Add Appwrite project",
};
}

View file

@ -17,6 +17,7 @@ export class ProjectTreeItem extends AppwriteTreeItemBase {
const name = project.nickname ?? "Project"; const name = project.nickname ?? "Project";
this.label = `${name}`; this.label = `${name}`;
this.contextValue = `appwriteProject${active ? "_active" : ""}`; this.contextValue = `appwriteProject${active ? "_active" : ""}`;
this.description = project.endpoint;
this.sdk = createAppwriteSdk(project); this.sdk = createAppwriteSdk(project);
} }

View file

@ -36,6 +36,8 @@ export class ProjectsTreeItemProvider implements vscode.TreeDataProvider<vscode.
return []; return [];
} }
const activeProjectId = await getActiveProjectId(); const activeProjectId = await getActiveProjectId();
return configs.map((config) => new ProjectTreeItem(config, config.projectId === activeProjectId)); const projectTreeItems = configs.map((config) => new ProjectTreeItem(config, config.projectId === activeProjectId));
return projectTreeItems;
} }
} }