Skip to content

Commit

Permalink
fix comments 2
Browse files Browse the repository at this point in the history
Signed-off-by: Anan Zhuang <ananzh@amazon.com>
  • Loading branch information
ananzh committed Aug 14, 2024
1 parent 4fb00b2 commit 2052a66
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 38 deletions.
31 changes: 0 additions & 31 deletions src/core/public/core_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,35 +318,4 @@ export class CoreSystem {
this.workspaces.stop();
this.rootDomElement.textContent = '';
}

public async displayWarning(title: string, text: string) {
const i18n = await this.i18n.start();
const injectedMetadata = this.injectedMetadata.setup();
this.fatalErrorsSetup = this.fatalErrors.setup({
injectedMetadata,
i18n: this.i18n.getContext(),
});
await this.integrations.setup();
this.docLinks.setup();
const http = this.http.setup({ injectedMetadata, fatalErrors: this.fatalErrorsSetup });
const uiSettings = this.uiSettings.setup({ http, injectedMetadata });
const notificationsTargetDomElement = document.createElement('div');
const overlayTargetDomElement = document.createElement('div');
const overlays = this.overlay.start({
i18n,
targetDomElement: overlayTargetDomElement,
uiSettings,
});
if (this.notifications) {
const toasts = await this.notifications.start({
i18n,
overlays,
targetDomElement: notificationsTargetDomElement,
})?.toasts;

if (toasts) {
toasts.addWarning({ title, text });
}
}
}
}
4 changes: 2 additions & 2 deletions src/core/public/osd_bootstrap.test.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ jest.doMock('@osd/i18n', () => ({
},
}));

export const displayWarningMock = jest.fn();
export const coreSystemMock = {
setup: jest.fn().mockResolvedValue({
fatalErrors: fatalErrorMock,
}),
start: jest.fn().mockResolvedValue({
application: applicationServiceMock.createInternalStartContract(),
}),
displayWarning: displayWarningMock,
};
jest.doMock('./core_system', () => ({
CoreSystem: jest.fn().mockImplementation(() => coreSystemMock),
}));

export const consoleWarnMock = jest.spyOn(console, 'warn').mockImplementation(() => {});
6 changes: 3 additions & 3 deletions src/core/public/osd_bootstrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
fatalErrorMock,
i18nLoad,
i18nSetLocale,
displayWarningMock,
consoleWarnMock,
} from './osd_bootstrap.test.mocks';
import { __osdBootstrap__ } from './';
import { getLocaleInUrl } from './locale_helper';
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('osd_bootstrap', () => {

await __osdBootstrap__();

expect(displayWarningMock).toHaveBeenCalledWith('Locale Warning', 'Invalid locale');
expect(consoleWarnMock).toHaveBeenCalledWith('Locale Warning: Invalid locale');
expect((window as any).__localeWarning).toBeUndefined();
});

Expand All @@ -119,7 +119,7 @@ describe('osd_bootstrap', () => {

await __osdBootstrap__();

expect(displayWarningMock).toHaveBeenCalledWith('i18n Warning', 'Translation issue');
expect(consoleWarnMock).toHaveBeenCalledWith('i18n Warning: Translation issue');
expect((window as any).__i18nWarning).toBeUndefined();
});
});
6 changes: 4 additions & 2 deletions src/core/public/osd_bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,16 @@ export async function __osdBootstrap__() {
// Display the i18n warning if it exists
if ((window as any).__i18nWarning) {
const warning = (window as any).__i18nWarning;
coreSystem.displayWarning(warning.title, warning.text);
// eslint-disable-next-line no-console
console.warn(`${warning.title}: ${warning.text}`);
delete (window as any).__i18nWarning;
}

// Display the locale warning if it exists
if ((window as any).__localeWarning) {
const warning = (window as any).__localeWarning;
coreSystem.displayWarning(warning.title, warning.text);
// eslint-disable-next-line no-console
console.warn(`${warning.title}: ${warning.text}`);
delete (window as any).__localeWarning;
}
}

0 comments on commit 2052a66

Please sign in to comment.