From 58c7c65c102d9e338d5a2265af166cf92d3cc4ca Mon Sep 17 00:00:00 2001 From: christhompsongoogle <106194718+christhompsongoogle@users.noreply.github.com> Date: Wed, 21 Jun 2023 15:24:09 -0700 Subject: [PATCH] Missed a few changes from comments (#6015) * Fixed a bug in the hosting config for emulators. Also fixed an issue where an empty folder creates an issue loading the side panel. * Missed some changes * Update firebase-vscode/webviews/components/EmulatorPanel.tsx Co-authored-by: joehan --------- Co-authored-by: joehan --- firebase-vscode/webviews/SidebarApp.tsx | 2 +- .../{ => components}/EmulatorPanel.tsx | 45 +++++++++++-------- 2 files changed, 28 insertions(+), 19 deletions(-) rename firebase-vscode/webviews/{ => components}/EmulatorPanel.tsx (87%) diff --git a/firebase-vscode/webviews/SidebarApp.tsx b/firebase-vscode/webviews/SidebarApp.tsx index 86a9ef0a3f6..c5f9e9bd77d 100644 --- a/firebase-vscode/webviews/SidebarApp.tsx +++ b/firebase-vscode/webviews/SidebarApp.tsx @@ -9,7 +9,7 @@ import { ServiceAccountUser } from "../common/types"; import { DeployPanel } from "./components/DeployPanel"; import { HostingState } from "./webview-types"; import { ChannelWithId } from "./messaging/types"; -import { EmulatorPanel } from "./EmulatorPanel"; +import { EmulatorPanel } from "./components/EmulatorPanel"; import { webLogger } from "./globals/web-logger"; import { InitFirebasePanel } from "./components/InitPanel"; diff --git a/firebase-vscode/webviews/EmulatorPanel.tsx b/firebase-vscode/webviews/components/EmulatorPanel.tsx similarity index 87% rename from firebase-vscode/webviews/EmulatorPanel.tsx rename to firebase-vscode/webviews/components/EmulatorPanel.tsx index 3d35146a1a7..a894376b989 100644 --- a/firebase-vscode/webviews/EmulatorPanel.tsx +++ b/firebase-vscode/webviews/components/EmulatorPanel.tsx @@ -7,18 +7,18 @@ import { VSCodeTextField, } from "@vscode/webview-ui-toolkit/react"; import React, { useState } from "react"; -import { Spacer } from "./components/ui/Spacer"; -import { broker } from "./globals/html-broker"; -import { PanelSection } from "./components/ui/PanelSection"; -import { FirebaseConfig } from "../../src/firebaseConfig"; +import { Spacer } from "./ui/Spacer"; +import { broker } from "../globals/html-broker"; +import { PanelSection } from "./ui/PanelSection"; +import { FirebaseConfig } from "../../../src/firebaseConfig"; import { RunningEmulatorInfo, EmulatorUiSelections, -} from "../common/messaging/types"; +} from "../../common/messaging/types"; import { VSCodeDropdown } from "@vscode/webview-ui-toolkit/react"; import { VSCodeOption } from "@vscode/webview-ui-toolkit/react"; -import { EmulatorInfo } from "../../src/emulator/types"; -import { webLogger } from "./globals/web-logger"; +import { EmulatorInfo } from "../../../src/emulator/types"; +import { webLogger } from "../globals/web-logger"; const DEFAULT_EMULATOR_UI_SELECTIONS: EmulatorUiSelections = { projectId: "demo-something", @@ -41,7 +41,7 @@ export function EmulatorPanel({ if (!firebaseJson) { throw Error("Expected a valid FirebaseConfig."); } - var defaultState = DEFAULT_EMULATOR_UI_SELECTIONS; + const defaultState = DEFAULT_EMULATOR_UI_SELECTIONS; if (projectId) { defaultState.projectId = getProjectIdForMode(projectId, defaultState.mode); } @@ -83,8 +83,11 @@ export function EmulatorPanel({ webLogger.debug( `notifyEmulatorImportFolder received in sidebar: ${folder}` ); - emulatorUiSelections.importStateFolderPath = folder; - setEmulatorUiSelectionsAndSaveToWorkspace({ ...emulatorUiSelections }); // rerender clone + const newSelections = { + ...emulatorUiSelections, + importStateFolderPath: folder, + }; + setEmulatorUiSelectionsAndSaveToWorkspace(newSelections); }); function launchEmulators() { @@ -145,16 +148,22 @@ export function EmulatorPanel({ function emulatorModeChanged(event: React.ChangeEvent) { webLogger.debug("emulatorModeChanged: " + event.target.value); - const selections: EmulatorUiSelections = emulatorUiSelections; - selections.mode = event.target.value as typeof emulatorUiSelections.mode; - selections.projectId = getProjectIdForMode(projectId, selections.mode); - setEmulatorUiSelectionsAndSaveToWorkspace({...selections}); + const newSelections: EmulatorUiSelections = { ...emulatorUiSelections }; + newSelections.mode = event.target.value as typeof emulatorUiSelections.mode; + newSelections.projectId = getProjectIdForMode( + projectId, + newSelections.mode + ); + setEmulatorUiSelectionsAndSaveToWorkspace(newSelections); } function clearImportFolder() { console.log(`clearImportFolder`); - emulatorUiSelections.importStateFolderPath = ""; - setEmulatorUiSelectionsAndSaveToWorkspace({ ...emulatorUiSelections }); + const newSelections = { + ...emulatorUiSelections, + importStateFolderPath: "", + }; + setEmulatorUiSelectionsAndSaveToWorkspace(newSelections); } // Make it pretty for the screen. Filter out the logging emulator since it's @@ -261,7 +270,7 @@ export function EmulatorPanel({ /** * Formats a project ID with a demo prefix if we're in offline mode, or uses the - * regular ID if we're hosting. + * regular ID if we're in hosting only mode. */ function getProjectIdForMode( projectId: string | undefined, @@ -274,4 +283,4 @@ function getProjectIdForMode( return projectId; } return "demo-" + projectId; -} \ No newline at end of file +}