Refresh tree after adding or removing project (#7)

* refresh tree after adding or removing project

* Always check if client is defined

* fix lint errors

* remove extra nodejs versions from pipeline
This commit is contained in:
Alex Weininger 2021-04-30 02:53:24 -07:00 committed by GitHub
parent 070d0b1a58
commit 354b635701
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 171 additions and 132 deletions

View file

@ -8,13 +8,35 @@
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
"semi": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_"
}
],
"no-unused-vars": "off",
"no-useless-escape": "off",
"no-inner-declarations": "off",
"no-case-declarations": "off",
"@typescript-eslint/prefer-regexp-exec": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-explicit-any": "off"
},
"ignorePatterns": [
"**/*.d.ts"

View file

@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 15.x]
node-version: [12.x, 14.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:

View file

@ -1,14 +1,12 @@
import { Client, Collection, CreatedCollection, CreatedRule, DatabaseClient, Rule, SDK } from "../appwrite";
import { CreateRuleWizardContext } from "../ui/createRuleWizard";
import { Client, Collection, CreatedCollection, CreatedRule, DatabaseClient, Rule } from "../appwrite";
import { AppwriteSDK } from '../constants';
import AppwriteCall from "../utils/AppwriteCall";
const sdk: SDK = require("node-appwrite");
export class Database {
private readonly database: DatabaseClient;
constructor(client: Client) {
this.database = new sdk.Database(client);
this.database = new AppwriteSDK.Database(client);
}
public async getCollection(collectionId: string): Promise<Collection | undefined> {

View file

@ -1,12 +1,11 @@
import { MarkdownString } from 'vscode';
import { AppwriteHealth, Client, HealthClient, SDK } from "../appwrite";
const sdk: SDK = require("node-appwrite");
import { AppwriteHealth, Client, HealthClient } from "../appwrite";
import { AppwriteSDK } from '../constants';
export class Health {
private readonly health: HealthClient;
constructor(client: Client) {
this.health = new sdk.Health(client);
this.health = new AppwriteSDK.Health(client);
}
/**

View file

@ -1,14 +1,12 @@
import { Client, Collection, CreatedCollection, CreatedRule, DatabaseClient, File, FilesList, Rule, SDK, StorageClient } from "../appwrite";
import { CreateRuleWizardContext } from "../ui/createRuleWizard";
import { Client, FilesList, StorageClient } from "../appwrite";
import { AppwriteSDK } from '../constants';
import AppwriteCall from "../utils/AppwriteCall";
const sdk: SDK = require("node-appwrite");
export class Storage {
private readonly storage: StorageClient;
constructor(client: Client) {
this.storage = new sdk.Storage(client);
this.storage = new AppwriteSDK.Storage(client);
}
public async listFiles(): Promise<FilesList | undefined> {

View file

@ -1,14 +1,13 @@
import { window } from "vscode";
import { Client, Log, SDK, User, UsersClient } from "../appwrite";
import { ext } from "../extensionVariables";
import { Client, Log, User, UsersClient } from "../appwrite";
import { AppwriteSDK } from "../constants";
import AppwriteCall from "../utils/AppwriteCall";
const sdk: SDK = require("node-appwrite");
export class Users {
private readonly users: UsersClient;
constructor(client: Client) {
this.users = new sdk.Users(client);
this.users = new AppwriteSDK.Users(client);
}
public async createNewUser(context: CreateUserContext): Promise<void> {
await AppwriteCall<User, void>(this.users.create(context.email, context.password, context.name), (user) => {
@ -23,7 +22,7 @@ export class Users {
}
public async getLogs(userId: string): Promise<Log[]> {
return await AppwriteCall<Log[], Log[]>(this.users.getLogs(userId)) ?? [];
return (await AppwriteCall<Log[], Log[]>(this.users.getLogs(userId))) ?? [];
}
}

View file

@ -1,21 +1,20 @@
import { Client, SDK } from "./appwrite";
import { Client } from "./appwrite";
import { Database } from "./appwrite/Database";
import { Health } from "./appwrite/Health";
import { Storage } from "./appwrite/Storage";
import { Users } from "./appwrite/Users";
import { AppwriteSDK } from "./constants";
import { AppwriteProjectConfiguration } from "./settings";
const sdk: SDK = require("node-appwrite");
export let client: Client;
export let clientConfig: { endpoint: string; projectId: string; secret: string };
export let usersClient: Users;
export let healthClient: Health;
export let databaseClient: Database;
export let storageClient: Storage;
export let usersClient: Users | undefined;
export let healthClient: Health | undefined;
export let databaseClient: Database | undefined;
export let storageClient: Storage | undefined;
export function initAppwriteClient({ endpoint, projectId, secret }: AppwriteProjectConfiguration) {
client = new sdk.Client();
function initAppwriteClient({ endpoint, projectId, secret }: AppwriteProjectConfiguration) {
client = new AppwriteSDK.Client();
clientConfig = { endpoint, projectId, secret };
client.setEndpoint(endpoint).setProject(projectId).setKey(secret);
@ -26,3 +25,15 @@ export function initAppwriteClient({ endpoint, projectId, secret }: AppwriteProj
return client;
}
export function createAppwriteClient(config?: AppwriteProjectConfiguration): void {
if (config) {
initAppwriteClient(config);
return;
}
usersClient = undefined;
healthClient = undefined;
databaseClient = undefined;
storageClient = undefined;
}

View file

@ -1,13 +1,13 @@
import { initAppwriteClient } from "../client";
import { createAppwriteClient } from "../client";
import { addProjectConfiguration } from '../settings';
import { addProjectWizard } from "../ui/AddProjectWizard";
import { refreshTree } from '../utils/refreshTree';
export async function connectAppwrite() {
export async function connectAppwrite(): Promise<void> {
const projectConfiguration = await addProjectWizard();
if (projectConfiguration) {
addProjectConfiguration(projectConfiguration);
initAppwriteClient(projectConfiguration);
createAppwriteClient(projectConfiguration);
refreshTree();
}
}

View file

@ -1,9 +1,13 @@
import { window } from 'vscode';
import { databaseClient } from '../../client';
import { window } from "vscode";
import { databaseClient } from "../../client";
export async function createCollection(): Promise<void> {
if (!databaseClient) {
return;
}
const name = await window.showInputBox({
prompt: 'Collection name'
prompt: "Collection name",
});
if (name && name.length > 0) {

View file

@ -5,6 +5,11 @@ import { createRuleWizard } from "../../ui/createRuleWizard";
import { refreshTree } from '../../utils/refreshTree';
export async function createRule(rulesTreeItem: RulesTreeItem): Promise<void> {
if (!databaseClient) {
return;
}
const ruleContext = await createRuleWizard();
const collection = rulesTreeItem.parent.collection;

View file

@ -4,6 +4,9 @@ import { CollectionTreeItem } from "../../tree/database/CollectionTreeItem";
import { confirmDialog } from "../../ui/confirmDialog";
export async function deleteCollection(collectionTreeItem: CollectionTreeItem): Promise<void> {
if (!databaseClient) {
return;
}
const collection = collectionTreeItem.collection;
try {
const shouldDelete = await confirmDialog(`Delete collection "${collection.name}"?`);

View file

@ -4,13 +4,16 @@ import { DocumentTreeItem } from "../../tree/database/DocumentTreeItem";
import { confirmDialog } from "../../ui/confirmDialog";
export async function deleteDocument(documentTreeItem: DocumentTreeItem): Promise<void> {
if (!databaseClient) {
return;
}
const document = documentTreeItem.document;
const collection = documentTreeItem.parent.parent.collection;
try {
const shouldDelete = await confirmDialog(`Delete document "${document["$id"]}" from ${collection.name}?`);
if (shouldDelete) {
await databaseClient.deleteDocument(collection.$id, document["$id"]);
documentTreeItem.parent.window.showInformationMessage(`Deleted document "${document["$id"]}" from ${collection.name}.`);
window.showInformationMessage(`Deleted document "${document["$id"]}" from ${collection.name}.`);
}
} catch (e) {
window.showErrorMessage(e);

View file

@ -1,8 +1,6 @@
import { window } from "vscode";
import { databaseClient } from '../../../client';
import { CollapsableTreeItem } from '../../../tree/CollapsableTreeItem';
import { databaseClient } from "../../../client";
import { PermissionsTreeItem } from "../../../tree/database/settings/PermissionsTreeItem";
import { PermissionTreeItem } from "../../../tree/database/settings/PermissionTreeItem";
export type CreatePermissionWizardContext = {
kind: "read" | "write";
@ -25,7 +23,9 @@ export async function createPermissionWizard(kind?: "read" | "write"): Promise<C
}
export async function createPermission(treeItem: PermissionsTreeItem): Promise<void> {
if (!databaseClient) {
return;
}
const collection = treeItem.parent.collection;
const context = await createPermissionWizard(undefined);
@ -37,7 +37,7 @@ export async function createPermission(treeItem: PermissionsTreeItem): Promise<v
const read = Array.from(collection.$permissions.read);
const write = Array.from(collection.$permissions.write);
if (context.kind === 'read') {
if (context.kind === "read") {
read.push(context.permission);
} else {
write.push(context.permission);

View file

@ -2,6 +2,9 @@ import { databaseClient } from "../../../client";
import { PermissionTreeItem } from "../../../tree/database/settings/PermissionTreeItem";
export async function deletePermission(treeItem: PermissionTreeItem): Promise<void> {
if (!databaseClient) {
return;
}
const collection = treeItem.parent.parent.collection;
const kind = treeItem.kind;

View file

@ -1,8 +1,11 @@
import { window } from 'vscode';
import { databaseClient } from '../../../client';
import { PermissionTreeItem } from '../../../tree/database/settings/PermissionTreeItem';
import { window } from "vscode";
import { databaseClient } from "../../../client";
import { PermissionTreeItem } from "../../../tree/database/settings/PermissionTreeItem";
export async function editPermission(treeItem: PermissionTreeItem): Promise<void> {
if (!databaseClient) {
return;
}
const editedPermission = await window.showInputBox({
value: treeItem.permission,
});

View file

@ -1,5 +1,5 @@
import { CollectionTreeItem } from "../../tree/database/CollectionTreeItem";
export async function refreshCollection(collectionTreeItem: CollectionTreeItem) {
export async function refreshCollection(collectionTreeItem: CollectionTreeItem): Promise<void> {
await collectionTreeItem.refresh();
}

View file

@ -3,6 +3,9 @@ import { RuleTreeItem } from '../../tree/database/settings/RuleTreeItem';
import { refreshTree } from '../../utils/refreshTree';
export async function removeRule(ruleItem: RuleTreeItem): Promise<void> {
if (!databaseClient) {
return;
}
const rule = ruleItem.rule;
const collection = ruleItem.parent.parent.collection;
await databaseClient.removeRule(collection, rule);

View file

@ -1,12 +1,12 @@
import { window } from "vscode";
import { initAppwriteClient } from "../../client";
import { createAppwriteClient } from '../../client';
import { addProjectWizard } from "../../ui/AddProjectWizard";
export async function addProject() {
export async function addProject(): Promise<void> {
const projectConfiguration = await addProjectWizard();
if (projectConfiguration) {
initAppwriteClient(projectConfiguration);
createAppwriteClient(projectConfiguration);
}
window.showInformationMessage("Connected to Appwrite project.");

View file

@ -1,11 +1,8 @@
import { window } from "vscode";
import { initAppwriteClient } from "../../client";
import { removeProjectConfig } from '../../settings';
import { ProjectTreeItem } from '../../tree/projects/ProjectTreeItem';
import { addProjectWizard } from "../../ui/AddProjectWizard";
import { removeProjectConfig } from "../../settings";
import { ProjectTreeItem } from "../../tree/projects/ProjectTreeItem";
export async function removeProject(project: ProjectTreeItem | string) {
if (typeof project === 'string') {
export async function removeProject(project: ProjectTreeItem | string): Promise<void> {
if (typeof project === "string") {
await removeProjectConfig(project);
return;
}

View file

@ -1,9 +1,7 @@
import { window } from "vscode";
import { initAppwriteClient } from "../../client";
import { setActiveProjectId } from '../../settings';
import { ProjectTreeItem } from "../../tree/projects/ProjectTreeItem";
export async function setActiveProject(treeItem: ProjectTreeItem) {
export async function setActiveProject(treeItem: ProjectTreeItem): Promise<void> {
if (treeItem === undefined) {
return;
}

View file

@ -1,5 +1,5 @@
import { commands, ExtensionContext } from "vscode";
import { AppwriteTree, ext } from "../extensionVariables";
import { AppwriteTree } from "../extensionVariables";
import { refreshAllViews, refreshTree } from "../utils/refreshTree";
import { connectAppwrite } from "./connectAppwrite";
import { createCollection } from "./database/createCollection";
@ -24,7 +24,7 @@ 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 { removeProject } from "./project/removeProject";
class CommandRegistrar {
constructor(private readonly context: ExtensionContext) {}
@ -57,7 +57,7 @@ export function registerCommands(context: ExtensionContext): void {
};
/** General **/
registerCommand("Connect", connectAppwrite);
registerCommand("Connect", connectAppwrite, "all");
/** Users **/
registerCommand("openUserInConsole", openUserInConsole);
@ -86,11 +86,11 @@ export function registerCommands(context: ExtensionContext): void {
registerCommand("editPermission", editPermission, "database");
/** Health **/
registerCommand("refreshHealth", () => {}, "health");
registerCommand("refreshHealth", undefined, "health");
registerCommand("openHealthDocumentation", () => openDocumentation("health"));
/** Storage **/
registerCommand("refreshStorage", () => {}, "storage");
registerCommand("refreshStorage", undefined, "storage");
registerCommand("openStorageDocumentation", () => openDocumentation("storage"));
/** Projects **/

View file

@ -3,6 +3,9 @@ import { usersClient } from '../../client';
import { ext } from '../../extensionVariables';
export async function createUser(): Promise<void> {
if (!usersClient) {
return;
}
const email = await window.showInputBox({
ignoreFocusOut: true,
placeHolder: "jane.doe@hotmail.com",

View file

@ -5,6 +5,9 @@ import { DialogResponses } from "../../ui/DialogResponses";
import { refreshTree } from "../../utils/refreshTree";
export async function deleteUser(userTreeItem: UserTreeItem): Promise<void> {
if (!usersClient) {
return;
}
const user = userTreeItem.user;
const userId = user.$id;
const shouldDeleteUser = await window.showWarningMessage(

View file

@ -3,6 +3,9 @@ import { UserTreeItem } from "../../tree/users/UserTreeItem";
import { openReadOnlyJson } from '../../ui/openReadonlyContent';
export async function getUserLogs(treeItem: UserTreeItem): Promise<void> {
if (!usersClient) {
return;
}
const userId = treeItem.user.$id;
const logs = await usersClient.getLogs(userId);

View file

@ -12,7 +12,7 @@ function getUserUrl(userId: string, endpoint: string, projectId: string): string
return `${getConsoleUrlFromEndpoint(endpoint)}/users/user?id=${userId}&project=${projectId}`;
}
export async function openUserInConsole(item: UserTreeItem) {
export async function openUserInConsole(item: UserTreeItem): Promise<void> {
const url = getUserUrl(item.user.$id, clientConfig.endpoint, clientConfig.projectId);
await commands.executeCommand("vscode.open", Uri.parse(url));

View file

@ -1,5 +1,5 @@
import { ext } from "../../extensionVariables";
export async function refreshUsersList() {
export async function refreshUsersList(): Promise<void> {
ext.tree?.users?.refresh();
}

View file

@ -2,7 +2,7 @@ import { UserPrefsTreeItem } from "../../tree/users/properties/UserPrefsTreeItem
import { UserTreeItem } from '../../tree/users/UserTreeItem';
import { openReadOnlyJson } from "../../ui/openReadonlyContent";
export async function viewUserPrefs(item: UserPrefsTreeItem | UserTreeItem) {
export async function viewUserPrefs(item: UserPrefsTreeItem | UserTreeItem): Promise<void> {
const userItem = item instanceof UserPrefsTreeItem ? item.parent : item;
const prefs = userItem.user.prefs;

View file

@ -1,3 +1,4 @@
import type { SDK } from './appwrite';
// eslint-disable-next-line @typescript-eslint/no-var-requires
export const AppwriteSDK: SDK = require('node-appwrite') as SDK;

View file

@ -1,12 +1,11 @@
import * as vscode from "vscode";
import { workspace } from 'vscode';
import { initAppwriteClient } from "./client";
import { createAppwriteClient } from "./client";
import { registerCommands } from "./commands/registerCommands";
import { ext } from "./extensionVariables";
import { getActiveProjectConfiguration, getActiveProjectId, getDefaultProject } from "./settings";
import { getActiveProjectConfiguration } from "./settings";
import { DatabaseTreeItemProvider } from "./tree/database/DatabaseTreeItemProvider";
import { HealthTreeItemProvider } from "./tree/health/HealthTreeItemProvider";
import { ProjectsTreeItemProvider } from './tree/projects/ProjectsTreeItemProvider';
import { ProjectsTreeItemProvider } from "./tree/projects/ProjectsTreeItemProvider";
import { StorageTreeItemProvider } from "./tree/storage/StorageTreeItemProvider";
import { UserTreeItemProvider } from "./tree/users/UserTreeItemProvider";
import { createAppwriteOutputChannel } from "./ui/AppwriteOutputChannel";
@ -25,9 +24,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
vscode.window.registerTreeDataProvider("Projects", projectsTreeItemProvider);
const activeProject = await getActiveProjectConfiguration();
if (activeProject) {
initAppwriteClient(activeProject);
}
createAppwriteClient(activeProject);
ext.context = context;
ext.outputChannel = createAppwriteOutputChannel("Appwrite", "appwrite");
@ -37,10 +34,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
health: healthTreeItemProvider,
database: databaseTreeItemProvider,
storage: storageTreeItemProvider,
projects: projectsTreeItemProvider
projects: projectsTreeItemProvider,
};
registerCommands(context);
}
export function deactivate() {}

View file

@ -1,4 +1,4 @@
import { ExtensionContext, OutputChannel } from "vscode";
import { ExtensionContext } from "vscode";
import { DatabaseTreeItemProvider } from './tree/database/DatabaseTreeItemProvider';
import { HealthTreeItemProvider } from './tree/health/HealthTreeItemProvider';
import { ProjectsTreeItemProvider } from './tree/projects/ProjectsTreeItemProvider';

View file

@ -1,5 +1,5 @@
import { workspace } from "vscode";
import { initAppwriteClient } from "./client";
import { createAppwriteClient } from "./client";
export type AppwriteProjectConfiguration = {
nickname?: string;
@ -64,9 +64,7 @@ export async function setActiveProjectId(projectId: string): Promise<void> {
const configuration = workspace.getConfiguration("appwrite");
await configuration.update("activeProjectId", projectId, true);
const active = await getActiveProjectConfiguration();
if (active) {
initAppwriteClient(active);
}
createAppwriteClient(active);
}
export async function updateActiveProjectId(): Promise<void> {
@ -75,17 +73,12 @@ export async function updateActiveProjectId(): Promise<void> {
const configuration = workspace.getConfiguration("appwrite");
await configuration.update("activeProjectId", projects[0].projectId, true);
const active = await getActiveProjectConfiguration();
if (active) {
initAppwriteClient(active);
}
createAppwriteClient(active);
}
}
export async function removeProjectConfig(projectId: string): Promise<void> {
const projects = await getAppwriteProjects();
const activeProjectId = await getActiveProjectId();
const updatedProjects = projects.filter((project) => project.projectId !== projectId);
const configuration = workspace.getConfiguration("appwrite");
await configuration.update("projects", updatedProjects, true);

View file

@ -1,6 +1,5 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
import { TreeItem, TreeItemCollapsibleState } from "vscode";
import { AppwriteTreeItemBase } from "../ui/AppwriteTreeItemBase";
import { ChildTreeItem } from "./ChildTreeItem";
export class CollapsableTreeItem<Parent> extends AppwriteTreeItemBase<Parent> {
constructor(parent: Parent, item: Partial<TreeItem> & { label: string }, private readonly children: TreeItem[], public readonly brand?: string) {

View file

@ -1,11 +1,11 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
import { Collection } from "../../appwrite";
import { databaseClient } from '../../client';
import { AppwriteTreeItemBase } from '../../ui/AppwriteTreeItemBase';
import { DatabaseTreeItemProvider } from './DatabaseTreeItemProvider';
import { DocumentsTreeItem } from './DocumentsTreeItem';
import { PermissionsTreeItem } from './settings/PermissionsTreeItem';
import { RulesTreeItem } from './settings/RulesTreeItem';
import { databaseClient } from "../../client";
import { AppwriteTreeItemBase } from "../../ui/AppwriteTreeItemBase";
import { DatabaseTreeItemProvider } from "./DatabaseTreeItemProvider";
import { DocumentsTreeItem } from "./DocumentsTreeItem";
import { PermissionsTreeItem } from "./settings/PermissionsTreeItem";
import { RulesTreeItem } from "./settings/RulesTreeItem";
export class CollectionTreeItem extends AppwriteTreeItemBase {
constructor(public collection: Collection, public readonly provider: DatabaseTreeItemProvider) {
@ -17,7 +17,10 @@ export class CollectionTreeItem extends AppwriteTreeItemBase {
}
public async refresh(): Promise<void> {
this.collection = await databaseClient.getCollection(this.collection.$id) ?? this.collection;
if (!databaseClient) {
return;
}
this.collection = (await databaseClient.getCollection(this.collection.$id)) ?? this.collection;
this.provider.refreshChild(this);
}
@ -25,5 +28,5 @@ export class CollectionTreeItem extends AppwriteTreeItemBase {
contextValue = "collection";
iconPath = new ThemeIcon('folder');
iconPath = new ThemeIcon("folder");
}

View file

@ -1,7 +1,7 @@
import * as vscode from "vscode";
import { client } from "../../client";
import AppwriteCall from "../../utils/AppwriteCall";
import { Collection, CollectionsList, DocumentsList } from "../../appwrite";
import { Collection, CollectionsList } from "../../appwrite";
import { CollectionTreeItem } from "./CollectionTreeItem";
import { AppwriteSDK } from "../../constants";
import { AppwriteTreeItemBase } from "../../ui/AppwriteTreeItemBase";
@ -14,8 +14,6 @@ export class DatabaseTreeItemProvider implements vscode.TreeDataProvider<vscode.
readonly onDidChangeTreeData: vscode.Event<vscode.TreeItem | undefined | void> = this._onDidChangeTreeData.event;
constructor() {}
refresh(): void {
ext.outputChannel?.appendLine('refresh database');
this._onDidChangeTreeData.fire();
@ -39,7 +37,7 @@ export class DatabaseTreeItemProvider implements vscode.TreeDataProvider<vscode.
return parent.getChildren?.() ?? [];
}
let databaseSdk = new AppwriteSDK.Database(client);
const databaseSdk = new AppwriteSDK.Database(client);
const collectionsList = await AppwriteCall<CollectionsList, CollectionsList>(databaseSdk.listCollections());
if (collectionsList) {

View file

@ -3,6 +3,7 @@ import { ChildTreeItem } from '../ChildTreeItem';
import { DocumentsTreeItem } from './DocumentsTreeItem';
export class DocumentTreeItem extends ChildTreeItem<DocumentsTreeItem> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(parent: DocumentsTreeItem, public readonly document: Record<string, any>) {
super(parent, {
label: document['$id'],

View file

@ -9,13 +9,12 @@ import { CollectionTreeItem } from "./CollectionTreeItem";
import { DocumentTreeItem } from "./DocumentTreeItem";
export class DocumentsTreeItem extends AppwriteTreeItemBase<CollectionTreeItem> {
window: any;
constructor(parent: CollectionTreeItem) {
super(parent, "Documents");
}
public async getChildren(): Promise<TreeItem[]> {
let databaseSdk = new AppwriteSDK.Database(client);
const databaseSdk = new AppwriteSDK.Database(client);
const documentList = await AppwriteCall<DocumentsList>(databaseSdk.listDocuments(this.parent.collection.$id));
if (documentList === undefined) {
return [];

View file

@ -1,4 +1,3 @@
import { AppwriteTreeItemBase } from "../../../ui/AppwriteTreeItemBase";
import { ChildTreeItem } from "../../ChildTreeItem";
import { PermissionsTreeItem } from "./PermissionsTreeItem";

View file

@ -1,4 +1,3 @@
import { TreeItem } from "vscode";
import { Rule } from "../../../appwrite";
import { ChildTreeItem } from "../../ChildTreeItem";
import { RulesTreeItem } from "./RulesTreeItem";

View file

@ -2,7 +2,7 @@ import * as vscode from "vscode";
import { MarkdownString } from 'vscode';
export class HealthTreeItem extends vscode.TreeItem {
constructor(public readonly label: string, status: any, tooltip?: string | MarkdownString | undefined) {
constructor(public readonly label: string, status: "check" | "error" | any, tooltip?: string | MarkdownString | undefined) {
super(label);
console.log(status);
this.label = label;

View file

@ -3,15 +3,12 @@ import { healthClient } from "../../client";
import { ext } from "../../extensionVariables";
import { HealthTreeItem } from "./HealthTreeItem";
import * as dayjs from "dayjs";
import * as relativeTime from "dayjs/plugin/relativeTime";
import * as localizedFormat from "dayjs/plugin/localizedFormat";
import { healthTooltips } from "../../appwrite/Health";
import { AppwriteHealth } from "../../appwrite";
// dayjs.extend(relativeTime);
dayjs.extend(localizedFormat);
type PartialRecord<K extends string | number | symbol, T> = { [P in K]?: T };
export class HealthTreeItemProvider implements vscode.TreeDataProvider<vscode.TreeItem> {
private _onDidChangeTreeData: vscode.EventEmitter<HealthTreeItem | undefined | void> = new vscode.EventEmitter<
HealthTreeItem | undefined | void
@ -21,8 +18,6 @@ export class HealthTreeItemProvider implements vscode.TreeDataProvider<vscode.Tr
readonly onDidChangeTreeData: vscode.Event<HealthTreeItem | undefined | void> = this._onDidChangeTreeData.event;
constructor() {}
refresh(): void {
this._onDidChangeTreeData.fire();
}

View file

@ -1,6 +1,6 @@
import * as vscode from "vscode";
import { getActiveProjectId, getAppwriteProjects } from '../../settings';
import { ProjectTreeItem } from './ProjectTreeItem';
import { getActiveProjectId, getAppwriteProjects } from "../../settings";
import { ProjectTreeItem } from "./ProjectTreeItem";
export class ProjectsTreeItemProvider implements vscode.TreeDataProvider<vscode.TreeItem> {
private _onDidChangeTreeData: vscode.EventEmitter<vscode.TreeItem | undefined | void> = new vscode.EventEmitter<
@ -9,7 +9,13 @@ export class ProjectsTreeItemProvider implements vscode.TreeDataProvider<vscode.
readonly onDidChangeTreeData: vscode.Event<vscode.TreeItem | undefined | void> = this._onDidChangeTreeData.event;
constructor() {}
constructor() {
vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration("appwrite")) {
this.refresh();
}
});
}
refresh(): void {
this._onDidChangeTreeData.fire();
@ -19,7 +25,7 @@ export class ProjectsTreeItemProvider implements vscode.TreeDataProvider<vscode.
return element;
}
async getChildren(element?: vscode.TreeItem): Promise<vscode.TreeItem[]> {
async getChildren(_element?: vscode.TreeItem): Promise<vscode.TreeItem[]> {
const configs = await getAppwriteProjects();
if (configs === undefined || configs.length === 0) {
return [];

View file

@ -9,8 +9,6 @@ export class StorageTreeItemProvider implements vscode.TreeDataProvider<vscode.T
readonly onDidChangeTreeData: vscode.Event<vscode.TreeItem | undefined | void> = this._onDidChangeTreeData.event;
constructor() {}
refresh(): void {
this._onDidChangeTreeData.fire();
}
@ -19,7 +17,7 @@ export class StorageTreeItemProvider implements vscode.TreeDataProvider<vscode.T
return element;
}
async getChildren(element?: vscode.TreeItem): Promise<vscode.TreeItem[]> {
async getChildren(_element?: vscode.TreeItem): Promise<vscode.TreeItem[]> {
if (storageClient === undefined) {
return [];
}

View file

@ -6,6 +6,7 @@ import { ThemeIcon } from "vscode";
import { UserPrefsTreeItem } from "./properties/UserPrefsTreeItem";
import { ChildTreeItem } from "../ChildTreeItem";
import { UserTreeItem } from "./UserTreeItem";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const sdk = require("node-appwrite");
export class UserTreeItemProvider implements vscode.TreeDataProvider<vscode.TreeItem> {
@ -15,8 +16,6 @@ export class UserTreeItemProvider implements vscode.TreeDataProvider<vscode.Tree
readonly onDidChangeTreeData: vscode.Event<UserTreeItem | undefined | void> = this._onDidChangeTreeData.event;
constructor() {}
refresh(): void {
this._onDidChangeTreeData.fire();
}
@ -63,10 +62,10 @@ export class UserTreeItemProvider implements vscode.TreeDataProvider<vscode.Tree
return Promise.resolve(items);
}
let usersSdk = new sdk.Users(client);
const usersSdk = new sdk.Users(client);
const usersList = await AppwriteCall<UsersList, UsersList>(usersSdk.list());
if (usersList) {
const userTreeItems = usersList.users.map((user: any) => new UserTreeItem(user)) ?? [];
const userTreeItems = usersList.users.map((user: User) => new UserTreeItem(user)) ?? [];
const headerItem: vscode.TreeItem = {
label: `Total users: ${usersList.sum}`,
};

View file

@ -6,7 +6,7 @@
import { OutputChannel, ViewColumn, window, workspace, WorkspaceConfiguration } from "vscode";
// tslint:disable-next-line: export-name
export function createAppwriteOutputChannel(name: string, extensionPrefix: string) {
export function createAppwriteOutputChannel(name: string, extensionPrefix: string): AppwriteOutputChannel {
return new AppwriteOutputChannel(name, extensionPrefix);
}
@ -50,8 +50,8 @@ export class AppwriteOutputChannel {
public show(preserveFocus?: boolean | undefined): void;
public show(column?: ViewColumn | undefined, preserveFocus?: boolean | undefined): void;
// tslint:disable-next-line: no-any
public show(_column?: any, preserveFocus?: boolean | undefined): void {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
public show(_column?: unknown, preserveFocus?: boolean | undefined): void {
this._outputChannel.show(preserveFocus);
}

View file

@ -1,4 +1,4 @@
import { TreeDataProvider, TreeItem } from "vscode";
import { TreeItem } from "vscode";
export abstract class AppwriteTreeItemBase<Parent = void> extends TreeItem {
constructor(public readonly parent: Parent, label: string) {

View file

@ -93,7 +93,7 @@ export abstract class BaseEditor<ContextT> implements vscode.Disposable {
}
private async updateEditor(data: string, textEditor?: vscode.TextEditor): Promise<void> {
if (!!textEditor) {
if (textEditor) {
await BaseEditor.writeToEditor(textEditor, data);
this.ignoreSave = true;
try {

View file

@ -1,5 +1,4 @@
import { QuickPickItem, window } from "vscode";
import { AppwriteProjectConfiguration } from "../settings";
export type CreateRuleWizardContext = {
label: string;

View file

@ -8,8 +8,8 @@ export function refreshTree(...trees: (keyof AppwriteTree)[]): void {
export function refreshAllViews(): void {
if (ext.tree) {
Object.keys(ext.tree).forEach((tree) => {
for (const tree in ext.tree) {
refreshTree(tree as keyof AppwriteTree);
});
}
}
}