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": {
"view/title": [
{
"command": "vscode-appwrite.addProject",
"when": "view == Projects",
"group": "navigation"
},
{
"command": "vscode-appwrite.OpenUsersDocumentation",
"when": "view == Users",
@ -512,11 +517,6 @@
"when": "viewItem =~ /^(permission)$/",
"group": "inline"
},
{
"command": "vscode-appwrite.setActiveProject",
"when": "viewItem =~ /^(appwriteProject)$/",
"group": "inline"
},
{
"command": "vscode-appwrite.removeProject",
"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 { viewUserPrefs } from "./users/viewUserPrefs";
import { editPermission } from "./database/permissions/editPermission";
import { setActiveProject } from "./project/setActiveProject";
import { removeProject } from "./project/removeProject";
import { createTag } from './functions/createTag';
import { createExecution } from './functions/createExecution';
import { activateTag } from './functions/activateTag';
import { editValue } from './common/editValue';
import { deleteFunction } from './functions/deleteFunction';
import { createFunction } from './functions/createFunction';
import { createFunctionVar } from './functions/createFunctionVar';
import { deleteFunctionVar } from './functions/deleteFunctionVar';
import { deleteTag } from './functions/deleteTag';
import { viewExecutionErrors } from './functions/viewExecutionErrors';
import { viewExecutionOutput } from './functions/viewExecutionOutput';
import { copyExecutionErrors } from './functions/copyExecutionErrors';
import { copyExecutionOutput } from './functions/copyExecutionOutput';
import { openExecutionsInBrowser } from './functions/openExecutionsInBrowser';
import { openFunctionSettingsInBrowser } from './functions/openFunctionSettingsInBrowser';
import { openFunctionTagsInBrowser } from './functions/openFunctionTagsInBrowser';
import { createTag } from "./functions/createTag";
import { createExecution } from "./functions/createExecution";
import { activateTag } from "./functions/activateTag";
import { editValue } from "./common/editValue";
import { deleteFunction } from "./functions/deleteFunction";
import { createFunction } from "./functions/createFunction";
import { createFunctionVar } from "./functions/createFunctionVar";
import { deleteFunctionVar } from "./functions/deleteFunctionVar";
import { deleteTag } from "./functions/deleteTag";
import { viewExecutionErrors } from "./functions/viewExecutionErrors";
import { viewExecutionOutput } from "./functions/viewExecutionOutput";
import { copyExecutionErrors } from "./functions/copyExecutionErrors";
import { copyExecutionOutput } from "./functions/copyExecutionOutput";
import { openExecutionsInBrowser } from "./functions/openExecutionsInBrowser";
import { openFunctionSettingsInBrowser } from "./functions/openFunctionSettingsInBrowser";
import { openFunctionTagsInBrowser } from "./functions/openFunctionTagsInBrowser";
import { viewMore } from './common/viewMore';
import { viewMore } from "./common/viewMore";
class CommandRegistrar {
constructor(private readonly context: ExtensionContext) {}
@ -116,7 +115,6 @@ export function registerCommands(context: ExtensionContext): void {
/** Projects **/
registerCommand("addProject", connectAppwrite, "all");
registerCommand("setActiveProject", setActiveProject, "all");
registerCommand("refreshProjects", undefined, "projects");
registerCommand("removeProject", removeProject, "all");

View file

@ -30,7 +30,6 @@ export async function addProjectConfiguration(projectConfig: AppwriteProjectConf
const projects = await getAppwriteProjects();
await configuration.update("projects", [...projects, projectConfig], true);
await setActiveProjectId(projectConfig.projectId);
}
export async function getActiveProjectId(): Promise<string> {
@ -53,21 +52,9 @@ export async function getActiveProjectConfiguration(): Promise<AppwriteProjectCo
activeConfig = config;
}
});
if (activeConfig === undefined) {
activeConfig = configurations[0];
setActiveProjectId(configurations[0].projectId);
}
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> {
const projects = await getAppwriteProjects();
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";
this.label = `${name}`;
this.contextValue = `appwriteProject${active ? "_active" : ""}`;
this.description = project.endpoint;
this.sdk = createAppwriteSdk(project);
}

View file

@ -36,6 +36,8 @@ export class ProjectsTreeItemProvider implements vscode.TreeDataProvider<vscode.
return [];
}
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;
}
}