Skip to content

Commit 83b84f0

Browse files
committed
Addressed comments
1 parent 927dadd commit 83b84f0

File tree

5 files changed

+71
-14
lines changed

5 files changed

+71
-14
lines changed

packages/database/src/api/Database.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ import {
3131
EmulatorMockTokenOptions,
3232
getDefaultEmulatorHostnameAndPort,
3333
isCloudWorkstation,
34-
pingServer
34+
pingServer,
35+
updateEmulatorBanner
3536
} from '@firebase/util';
3637

3738
import { AppCheckTokenProvider } from '../core/AppCheckTokenProvider';
@@ -56,6 +57,7 @@ import { TransportManager } from '../realtime/TransportManager';
5657
import { WebSocketConnection } from '../realtime/WebSocketConnection';
5758

5859
import { ReferenceImpl } from './Reference_impl';
60+
import { updateStrings } from 'yargs';
5961

6062
export { EmulatorMockTokenOptions } from '@firebase/util';
6163
/**
@@ -393,6 +395,7 @@ export function connectDatabaseEmulator(
393395
// Workaround to get cookies in Firebase Studio
394396
if (isCloudWorkstation(host)) {
395397
void pingServer(host);
398+
updateEmulatorBanner('Database', true);
396399
}
397400

398401
// Modify the repo to apply emulator settings

packages/database/src/core/Repo.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
import {
1919
assert,
2020
contains,
21+
isCloudWorkstation,
2122
isEmpty,
2223
map,
2324
safeGet,
24-
stringify
25+
stringify,
26+
updateEmulatorBanner
2527
} from '@firebase/util';
2628

2729
import { ValueEventRegistration } from '../api/Reference_impl';
@@ -328,6 +330,9 @@ export function repoStart(
328330
repo.server_.unlisten(query, tag);
329331
}
330332
});
333+
if (isCloudWorkstation(repo.repoInfo_.host)) {
334+
updateEmulatorBanner('Database', repo.repoInfo_.isUsingEmulator);
335+
}
331336
}
332337

333338
/**

packages/functions/src/service.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ import { Provider } from '@firebase/component';
3030
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
3131
import { MessagingInternalComponentName } from '@firebase/messaging-interop-types';
3232
import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
33-
import { isCloudWorkstation, pingServer } from '@firebase/util';
33+
import {
34+
isCloudWorkstation,
35+
pingServer,
36+
updateEmulatorBanner
37+
} from '@firebase/util';
3438

3539
export const DEFAULT_REGION = 'us-central1';
3640

@@ -182,6 +186,7 @@ export function connectFunctionsEmulator(
182186
// Workaround to get cookies in Firebase Studio
183187
if (useSsl) {
184188
void pingServer(functionsInstance.emulatorOrigin);
189+
updateEmulatorBanner('Functions', true);
185190
}
186191
}
187192

@@ -195,6 +200,7 @@ export function httpsCallable<RequestData, ResponseData, StreamData = unknown>(
195200
name: string,
196201
options?: HttpsCallableOptions
197202
): HttpsCallable<RequestData, ResponseData, StreamData> {
203+
updateEmulatorBanner('Functions', functionsInstance.emulatorOrigin !== null);
198204
const callable = (
199205
data?: RequestData | null
200206
): Promise<HttpsCallableResult> => {
@@ -225,6 +231,7 @@ export function httpsCallableFromURL<
225231
url: string,
226232
options?: HttpsCallableOptions
227233
): HttpsCallable<RequestData, ResponseData, StreamData> {
234+
updateEmulatorBanner('Functions', functionsInstance.emulatorOrigin !== null);
228235
const callable = (
229236
data?: RequestData | null
230237
): Promise<HttpsCallableResult> => {

packages/storage/src/service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ import {
4646
createMockUserToken,
4747
EmulatorMockTokenOptions,
4848
isCloudWorkstation,
49-
pingServer
49+
pingServer,
50+
updateEmulatorBanner
5051
} from '@firebase/util';
5152
import { Connection, ConnectionType } from './implementation/connection';
53+
import { updateEmail } from '@firebase/auth';
5254

5355
export function isUrl(path?: string): boolean {
5456
return /^[A-Za-z]+:\/\//.test(path as string);
@@ -150,6 +152,7 @@ export function connectStorageEmulator(
150152
// Workaround to get cookies in Firebase Studio
151153
if (useSsl) {
152154
void pingServer(`https://${storage.host}`);
155+
updateEmulatorBanner('Storage', true);
153156
}
154157
storage._isUsingEmulator = true;
155158
storage._protocol = useSsl ? 'https' : 'http';
@@ -324,6 +327,7 @@ export class FirebaseStorageImpl implements FirebaseStorage {
324327
appCheckToken: string | null,
325328
retry = true
326329
): Request<O> {
330+
updateEmulatorBanner('Service', this._isUsingEmulator);
327331
if (!this._deleted) {
328332
const request = makeRequest(
329333
requestInfo,

packages/util/src/emulator.ts

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ export function createMockUserToken(
141141
].join('.');
142142
}
143143

144-
interface EmulatorStatuses {
144+
interface EmulatorStatusMap {
145145
[name: string]: boolean;
146146
}
147-
const emulatorStatus: EmulatorStatuses = {};
147+
const emulatorStatus: EmulatorStatusMap = {};
148148

149149
interface EmulatorSummary {
150150
prod: string[];
@@ -197,6 +197,10 @@ export function updateEmulatorBanner(
197197
}
198198

199199
emulatorStatus[name] = isRunningEmulator;
200+
201+
function prefixedId(id: string) {
202+
return `__firebase__banner__${id}`;
203+
}
200204
const bannerId = '__firebase__banner';
201205
const summary = getEmulatorSummary();
202206
const showError = summary.prod.length > 0;
@@ -210,9 +214,17 @@ export function updateEmulatorBanner(
210214

211215
function setupDom(): void {
212216
const banner = getOrCreateEl(bannerId);
217+
const firebaseTextId = prefixedId('text');
213218
const firebaseText: HTMLSpanElement =
214-
document.getElementById('__firebase__text') ||
215-
document.createElement('span');
219+
document.getElementById(firebaseTextId) || document.createElement('span');
220+
const learnMoreId = prefixedId('learnmore');
221+
const learnMoreLink: HTMLAnchorElement =
222+
(document.getElementById(learnMoreId) as HTMLAnchorElement) ||
223+
document.createElement('a');
224+
const prependIconId = prefixedId('preprendIcon');
225+
const prependIcon =
226+
document.getElementById(prependIconId) ||
227+
document.createElementNS('http://www.w3.org/2000/svg', 'svg');
216228
if (banner.created) {
217229
// update styles
218230
const bannerEl = banner.element;
@@ -231,19 +243,45 @@ export function updateEmulatorBanner(
231243
closeBtn.onclick = () => {
232244
tearDown();
233245
};
246+
learnMoreLink.setAttribute('id', learnMoreId);
247+
learnMoreLink.href =
248+
'http://firebase.google.com/docs/studio/deploy-app#emulator ';
249+
bannerEl.appendChild(prependIcon);
234250
bannerEl.appendChild(firebaseText);
251+
bannerEl.appendChild(learnMoreLink);
235252
bannerEl.appendChild(closeBtn);
253+
prependIcon.setAttribute('width', '24');
254+
prependIcon.setAttribute('id', prependIconId);
255+
prependIcon.setAttribute('height', '24');
256+
prependIcon.setAttribute('viewBox', '0 0 24 24');
257+
prependIcon.setAttribute('fill', 'none');
236258
document.body.appendChild(bannerEl);
237259
}
260+
238261
if (showError) {
239-
banner.element.style.background = '#cd5c5c';
240-
firebaseText.innerText = `Product${
241-
summary.prod.length > 0 ? 's' : ''
242-
} Running in Production: ${summary.prod.join(', ')}`;
262+
firebaseText.innerText = `Running in Production`;
263+
prependIcon.innerHTML = `<g clip-path="url(#clip0_6013_33858)">
264+
<path d="M4.8 17.6L12 5.6L19.2 17.6H4.8ZM6.91667 16.4H17.0833L12 7.93333L6.91667 16.4ZM12 15.6C12.1667 15.6 12.3056 15.5444 12.4167 15.4333C12.5389 15.3111 12.6 15.1667 12.6 15C12.6 14.8333 12.5389 14.6944 12.4167 14.5833C12.3056 14.4611 12.1667 14.4 12 14.4C11.8333 14.4 11.6889 14.4611 11.5667 14.5833C11.4556 14.6944 11.4 14.8333 11.4 15C11.4 15.1667 11.4556 15.3111 11.5667 15.4333C11.6889 15.5444 11.8333 15.6 12 15.6ZM11.4 13.6H12.6V10.4H11.4V13.6Z" fill="#212121"/>
265+
</g>
266+
<defs>
267+
<clipPath id="clip0_6013_33858">
268+
<rect width="24" height="24" fill="white"/>
269+
</clipPath>
270+
</defs>`;
243271
} else {
244-
firebaseText.innerText = 'Running in this workspace';
272+
prependIcon.innerHTML = `<g clip-path="url(#clip0_6083_34804)">
273+
<path d="M11.4 15.2H12.6V11.2H11.4V15.2ZM12 10C12.1667 10 12.3056 9.94444 12.4167 9.83333C12.5389 9.71111 12.6 9.56667 12.6 9.4C12.6 9.23333 12.5389 9.09444 12.4167 8.98333C12.3056 8.86111 12.1667 8.8 12 8.8C11.8333 8.8 11.6889 8.86111 11.5667 8.98333C11.4556 9.09444 11.4 9.23333 11.4 9.4C11.4 9.56667 11.4556 9.71111 11.5667 9.83333C11.6889 9.94444 11.8333 10 12 10ZM12 18.4C11.1222 18.4 10.2944 18.2333 9.51667 17.9C8.73889 17.5667 8.05556 17.1111 7.46667 16.5333C6.88889 15.9444 6.43333 15.2611 6.1 14.4833C5.76667 13.7056 5.6 12.8778 5.6 12C5.6 11.1111 5.76667 10.2833 6.1 9.51667C6.43333 8.73889 6.88889 8.06111 7.46667 7.48333C8.05556 6.89444 8.73889 6.43333 9.51667 6.1C10.2944 5.76667 11.1222 5.6 12 5.6C12.8889 5.6 13.7167 5.76667 14.4833 6.1C15.2611 6.43333 15.9389 6.89444 16.5167 7.48333C17.1056 8.06111 17.5667 8.73889 17.9 9.51667C18.2333 10.2833 18.4 11.1111 18.4 12C18.4 12.8778 18.2333 13.7056 17.9 14.4833C17.5667 15.2611 17.1056 15.9444 16.5167 16.5333C15.9389 17.1111 15.2611 17.5667 14.4833 17.9C13.7167 18.2333 12.8889 18.4 12 18.4ZM12 17.2C13.4444 17.2 14.6722 16.6944 15.6833 15.6833C16.6944 14.6722 17.2 13.4444 17.2 12C17.2 10.5556 16.6944 9.32778 15.6833 8.31667C14.6722 7.30555 13.4444 6.8 12 6.8C10.5556 6.8 9.32778 7.30555 8.31667 8.31667C7.30556 9.32778 6.8 10.5556 6.8 12C6.8 13.4444 7.30556 14.6722 8.31667 15.6833C9.32778 16.6944 10.5556 17.2 12 17.2Z" fill="#212121"/>
274+
</g>
275+
<defs>
276+
<clipPath id="clip0_6083_34804">
277+
<rect width="24" height="24" fill="white"/>
278+
</clipPath>
279+
</defs>`;
280+
firebaseText.innerText = 'Using emulated backend';
281+
learnMoreLink.href =
282+
'https://firebase.google.com/docs/studio/solution-build-with-ai';
245283
}
246-
firebaseText.setAttribute('id', '__firebase__text');
284+
firebaseText.setAttribute('id', firebaseTextId);
247285
}
248286
if (document.readyState === 'loading') {
249287
window.addEventListener('DOMContentLoaded', setupDom);

0 commit comments

Comments
 (0)