Skip to content

Commit

Permalink
Pull out session panel into its own registration function
Browse files Browse the repository at this point in the history
  • Loading branch information
tjlav5 committed Dec 16, 2024
1 parent dee2e48 commit fee3197
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 90 deletions.
2 changes: 1 addition & 1 deletion firebase-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"initialSize": 1
},
{
"id": "firebase.studio",
"id": "firebase.session",
"name": "Account and Project",
"initialSize": 1
},
Expand Down
20 changes: 1 addition & 19 deletions firebase-vscode/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { registerEnv } from "./env";
import { pluginLogger, LogLevel } from "../logger-wrapper";
import { getSettings } from "../utils/settings";
import { setEnabled } from "../../../src/experiments";
import { currentUser, registerUser } from "./user";
import { registerUser } from "./user";
import { currentProjectId, registerProject } from "./project";
import { registerQuickstart } from "./quickstart";
import { registerOptions } from "../options";
Expand All @@ -15,10 +15,7 @@ import { registerWebhooks } from "./webhook";
import { createE2eMockable } from "../utils/test_hooks";
import { runTerminalTask } from "../data-connect/terminal";
import { AnalyticsLogger } from "../analytics";
import { StudioItem, StudioProvider } from "./studio-provider";
import { login } from "../cli";
import { EmulatorsProvider } from "./emulators-provider";
import { effect } from "@preact/signals-core";

export async function registerCore(
broker: ExtensionBrokerImpl,
Expand Down Expand Up @@ -99,28 +96,13 @@ export async function registerCore(
},
);

const studioTree = new StudioProvider(currentUser, currentProjectId);

return [
emulatorsController,
Disposable.from(
openRcCmd,
refreshCmd,
emulatorsController,
initSpy,
{
dispose: effect(() => {
studioTree.updateUser(currentUser.value ?? undefined);
}),
},
{
dispose: effect(() => {
studioTree.updateProject(currentProjectId.value);
}),
},
vscode.window.createTreeView("firebase.studio", {
treeDataProvider: studioTree,
}),
vscode.window.createTreeView("firebase.emulators", {
treeDataProvider: new EmulatorsProvider(),
}),
Expand Down
66 changes: 0 additions & 66 deletions firebase-vscode/src/core/studio-provider.ts

This file was deleted.

7 changes: 3 additions & 4 deletions firebase-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ import {
} from "./utils/settings";
import { registerFdc } from "./data-connect";
import { AuthService } from "./auth/service";
import {
AnalyticsLogger,
IDX_METRIC_NOTICE,
} from "./analytics";
import { AnalyticsLogger, IDX_METRIC_NOTICE } from "./analytics";
import { env } from "./core/env";

import { suggestGraphqlSyntaxExtension } from "./data-connect/graphql-syntax-highlighter";
import { registerSession } from "./session";

// This method is called when your extension is activated
export async function activate(context: vscode.ExtensionContext) {
Expand Down Expand Up @@ -72,6 +70,7 @@ export async function activate(context: vscode.ExtensionContext) {
context,
}),
authService,
registerSession(),
registerFdc(
context,
broker,
Expand Down
25 changes: 25 additions & 0 deletions firebase-vscode/src/session/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { effect } from "@preact/signals-core";
import * as vscode from "vscode";
import { SessionProvider } from "./session-provider";
import { currentUser } from "../core/user";
import { currentProjectId } from "../core/project";

export function registerSession(): vscode.Disposable {
const sessionProvider = new SessionProvider();

return vscode.Disposable.from(
{
dispose: effect(() => {
sessionProvider.updateEmail(currentUser.value?.email);
}),
},
{
dispose: effect(() => {
sessionProvider.updateProjectId(currentProjectId.value);
}),
},
vscode.window.createTreeView("firebase.session", {
treeDataProvider: sessionProvider,
}),
);
}
47 changes: 47 additions & 0 deletions firebase-vscode/src/session/session-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as vscode from "vscode";

export class SessionProvider implements vscode.TreeDataProvider<SessionItem> {
private readonly userItem = new UserItem();
private readonly projectItem = new ProjectItem();

constructor() {}

getTreeItem(element: SessionItem): vscode.TreeItem {
return element;
}

getChildren(): SessionItem[] {
return [this.userItem, this.projectItem];
}

_onDidChangeTreeData = new vscode.EventEmitter<SessionItem | undefined>();
onDidChangeTreeData = this._onDidChangeTreeData.event;

updateEmail(email?: string) {
this.userItem.label = email ?? "Not logged in";
this._onDidChangeTreeData.fire(this.userItem);
}

updateProjectId(projectId?: string) {
this.projectItem.label = projectId ?? "No project selected";
this._onDidChangeTreeData.fire(this.projectItem);
}
}

type SessionItem = UserItem | ProjectItem;

class UserItem extends vscode.TreeItem {
constructor() {
super("", vscode.TreeItemCollapsibleState.None);
}

iconPath = new vscode.ThemeIcon("account");
}

class ProjectItem extends vscode.TreeItem {
constructor() {
super("", vscode.TreeItemCollapsibleState.None);
}

iconPath = new vscode.ThemeIcon("project");
}

0 comments on commit fee3197

Please sign in to comment.