Skip to content

Commit

Permalink
chore: add homeViewProvider to refreshProviders (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Joli authored Sep 12, 2023
1 parent 7f3f661 commit a886c7d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/commands/refreshAll/registerRefreshAllCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { StateManager } from '../../StateManager'
import { UsagesTreeProvider } from '../../views/usages'
import { EnvironmentsTreeProvider } from '../../views/environments'
import { InspectorViewProvider } from '../../views/inspector'
import { HomeViewProvider } from '../../views/home'

export async function registerRefreshAllCommand(
context: vscode.ExtensionContext,
providers: (UsagesTreeProvider | EnvironmentsTreeProvider | InspectorViewProvider)[]
providers: (UsagesTreeProvider | EnvironmentsTreeProvider | InspectorViewProvider | HomeViewProvider)[]
) {
context.subscriptions.push(
vscode.commands.registerCommand(
Expand Down
14 changes: 7 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
import * as vscode from 'vscode'
import * as path from 'path'
import { KEYS, StateManager } from './StateManager'
import { AuthCLIController, BaseCLIController, getOrganizationId } from './cli'
import { BaseCLIController, getOrganizationId } from './cli'
import { getHoverString } from './components/hoverCard'
import { trackRudderstackEvent } from './RudderStackService'
import { registerStartupViewProvider } from './views/startup'
import { registerLoginViewProvider } from './views/login'
import { UsagesTreeProvider, registerUsagesViewProvider } from './views/usages'
import { EnvironmentsTreeProvider, registerEnvironmentsViewProvider } from './views/environments'
import { registerResourcesViewProvider } from './views/resources'
import { registerHomeViewProvider } from './views/home'
import { HomeViewProvider, registerHomeViewProvider } from './views/home'
import {
executeRefreshAllCommand,
registerRefreshAllCommand,
registerInitCommand,
registerUsagesNodeClickedCommand,
Expand Down Expand Up @@ -72,14 +71,15 @@ export const activate = async (context: vscode.ExtensionContext) => {
const { usagesDataProvider, usagesTreeView } = await registerUsagesViewProvider(context)
const environmentsDataProvider = await registerEnvironmentsViewProvider(context)
const inspectorViewProvider = await registerInspectorViewProvider(context)
const refreshProviders: (UsagesTreeProvider | EnvironmentsTreeProvider | InspectorViewProvider)[] = [
usagesDataProvider,
const homeViewProvider = await registerHomeViewProvider(context)
const refreshProviders: (UsagesTreeProvider | EnvironmentsTreeProvider | InspectorViewProvider | HomeViewProvider)[] = [
usagesDataProvider,
environmentsDataProvider,
inspectorViewProvider
inspectorViewProvider,
homeViewProvider
]

await registerResourcesViewProvider(context)
await registerHomeViewProvider(context)
await registerOpenInspectorViewCommand(context, inspectorViewProvider)
await registerUsagesNodeClickedCommand(context)
await registerInitCommand(context)
Expand Down
35 changes: 34 additions & 1 deletion src/views/home/HomeViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ type HomeViewMessage =
export class HomeViewProvider implements vscode.WebviewViewProvider {
_view?: vscode.WebviewView
_doc?: vscode.TextDocument
isRefreshing: boolean = false
webviewIsDisposed: boolean = false

constructor(private readonly _extensionUri: vscode.Uri) {}

public async resolveWebviewView(webviewView: vscode.WebviewView) {
this._view = webviewView

webviewView.onDidDispose(() => {
this.webviewIsDisposed = true
})

webviewView.webview.options = {
enableScripts: true,

Expand Down Expand Up @@ -55,7 +62,6 @@ export class HomeViewProvider implements vscode.WebviewViewProvider {
const organizationsController = new OrganizationsCLIController(folder)
await organizationsController.selectOrganization(data.value, false)
await executeRefreshAllCommand()
webviewView.webview.html = await this._getHtmlForWebview(webviewView.webview)
})
} else if (data.type === 'project') {
const projectsController = new ProjectsCLIController(folder)
Expand All @@ -77,12 +83,39 @@ export class HomeViewProvider implements vscode.WebviewViewProvider {
}
}
})

this.webviewIsDisposed = false
}

public revive(panel: vscode.WebviewView) {
this._view = panel
}

public async refreshAll() {
if (this.isRefreshing) {
return
}

this.isRefreshing = true

await vscode.window.withProgress(
{
location: { viewId: 'devcycle-home' },
},
async () => {
if (!this._view || this.webviewIsDisposed) {
return
}
this._view.webview.html = await this._getHtmlForWebview(this._view.webview)
}
)
this.isRefreshing = false
}

public async refresh() {
await this.refreshAll()
}

private async getBodyHtml(folder: vscode.WorkspaceFolder, showHeader?: boolean): Promise<string> {
const organizationsController = new OrganizationsCLIController(folder)
const projectsController = new ProjectsCLIController(folder)
Expand Down

0 comments on commit a886c7d

Please sign in to comment.