From b447bd7a3a5c7afc4bee301f84783ba93339fe74 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Tue, 6 Sep 2022 10:56:38 -0500 Subject: [PATCH] replace use of deprecated IToaster and IToastProps --- src/alerts.ts | 4 +-- src/alerts/sagas.test.ts | 6 ++--- src/alerts/sagas.ts | 6 ++--- src/firmware/sagas.test.ts | 44 ++++++++++++++++----------------- src/firmware/sagas.ts | 8 +++--- src/i18nToaster.tsx | 8 +++--- src/notifications/sagas.test.ts | 4 +-- src/notifications/sagas.ts | 12 ++++++--- 8 files changed, 49 insertions(+), 43 deletions(-) diff --git a/src/alerts.ts b/src/alerts.ts index a203bbff..32f31825 100644 --- a/src/alerts.ts +++ b/src/alerts.ts @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2022 The Pybricks Authors -import { IToastProps } from '@blueprintjs/core'; +import { ToastProps } from '@blueprintjs/core'; import alerts from './alerts/alerts'; import ble from './ble/alerts'; import explorer from './explorer/alerts'; @@ -79,7 +79,7 @@ export function getAlertProps> specific: S, onAlert: AlertCallback, props: AlertProps, -): IToastProps { +): ToastProps { const create = alertDomains[domain][specific] as unknown as CreateToast< Record | never, string diff --git a/src/alerts/sagas.test.ts b/src/alerts/sagas.test.ts index 07c582e1..1553c7ad 100644 --- a/src/alerts/sagas.test.ts +++ b/src/alerts/sagas.test.ts @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2022 The Pybricks Authors -import { IToastOptions, IToastProps, IToaster } from '@blueprintjs/core'; +import { IToastOptions, ToastProps, ToasterInstance } from '@blueprintjs/core'; import { waitFor } from '@testing-library/dom'; import { AsyncSaga } from '../../test'; import { alertsDidShowAlert, alertsShowAlert } from './actions'; @@ -11,14 +11,14 @@ afterEach(() => { jest.clearAllMocks(); }); -class TestToaster implements IToaster { +class TestToaster implements ToasterInstance { private toasts = new Array(); public getToasts(): IToastOptions[] { return this.toasts; } - public show(props: IToastProps, key?: string): string { + public show(props: ToastProps, key?: string): string { if (!key) { throw new Error('key is required!'); } diff --git a/src/alerts/sagas.ts b/src/alerts/sagas.ts index 421b8c11..66a0ea69 100644 --- a/src/alerts/sagas.ts +++ b/src/alerts/sagas.ts @@ -1,17 +1,17 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2022 The Pybricks Authors -import { IToaster } from '@blueprintjs/core'; +import { ToasterInstance } from '@blueprintjs/core'; import { eventChannel } from 'redux-saga'; import { delay, getContext, put, take, takeEvery } from 'typed-redux-saga/macro'; import { getAlertProps } from '../alerts'; import { alertsDidShowAlert, alertsShowAlert } from './actions'; -export type AlertsSagaContext = { toaster: IToaster }; +export type AlertsSagaContext = { toaster: ToasterInstance }; /** Shows an alert to the user and avoids duplicate alerts. */ function* handleShowAlert(action: ReturnType): Generator { - const toaster = yield* getContext('toaster'); + const toaster = yield* getContext('toaster'); const key = `${action.domain}.${action.specific}.${JSON.stringify(action.props)}`; diff --git a/src/firmware/sagas.test.ts b/src/firmware/sagas.test.ts index e9ae1c9c..dcc8e1cd 100644 --- a/src/firmware/sagas.test.ts +++ b/src/firmware/sagas.test.ts @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2021-2022 The Pybricks Authors -import { IToaster } from '@blueprintjs/core'; +import { ToasterInstance } from '@blueprintjs/core'; import { FirmwareMetadata, FirmwareReaderError, @@ -81,7 +81,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -231,7 +231,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -281,7 +281,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -349,7 +349,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -413,7 +413,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -480,7 +480,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -540,7 +540,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -606,7 +606,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -689,7 +689,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -755,7 +755,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -854,7 +854,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -962,7 +962,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -1110,7 +1110,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -1256,7 +1256,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -1409,7 +1409,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -1457,7 +1457,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -1504,7 +1504,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -1565,7 +1565,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -1627,7 +1627,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -1692,7 +1692,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action @@ -1782,7 +1782,7 @@ describe('flashFirmware', () => { const saga = new AsyncSaga(flashFirmware, { nextMessageId: createCountFunc(), - toaster: mock(), + toaster: mock(), }); // saga is triggered by this action diff --git a/src/firmware/sagas.ts b/src/firmware/sagas.ts index f0e6f7e9..9c9bdb80 100644 --- a/src/firmware/sagas.ts +++ b/src/firmware/sagas.ts @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2020-2022 The Pybricks Authors -import { IToaster } from '@blueprintjs/core'; +import { ToasterInstance } from '@blueprintjs/core'; import { FirmwareReader, FirmwareReaderError, @@ -95,7 +95,7 @@ const firmwareZipMap = new Map([ * parent task). */ function* disconnectAndCancel(): SagaGenerator { - const toaster = yield* getContext('toaster'); + const toaster = yield* getContext('toaster'); toaster.dismiss('firmware.ble.progress'); @@ -333,7 +333,7 @@ function* loadFirmware( * @param action The action that triggered this saga. */ function* handleFlashFirmware(action: ReturnType): Generator { - const toaster = yield* getContext('toaster'); + const toaster = yield* getContext('toaster'); try { let firmware: Uint8Array | undefined = undefined; @@ -704,7 +704,7 @@ function* handleFlashUsbDfu(action: ReturnType): Gen dfu.dfuseStartAddress = dfuFirmwareStartAddress; const writeProc = dfu.write(1024, firmware, true); - const toaster = yield* getContext('toaster'); + const toaster = yield* getContext('toaster'); defer.push( writeProc.events.on('erase/process', (sent, total) => { diff --git a/src/i18nToaster.tsx b/src/i18nToaster.tsx index 72829afc..98415b65 100644 --- a/src/i18nToaster.tsx +++ b/src/i18nToaster.tsx @@ -1,19 +1,19 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2021-2022 The Pybricks Authors -import { IToastProps, IToaster, Toaster } from '@blueprintjs/core'; +import { ToastProps, Toaster, ToasterInstance } from '@blueprintjs/core'; import { I18nContext, I18nManager } from '@shopify/react-i18n'; import React from 'react'; import ReactDOM from 'react-dom'; /** - * Creates an `IToaster` for static usage similar to `Toaster.create()` except + * Creates an `ToasterInstance` for static usage similar to `Toaster.create()` except * that it is wrapped in an `I18nContext.Provider` so that messages can be * translated. * * @param i18n The i18n manager object. */ -export function create(i18n: I18nManager): IToaster { +export function create(i18n: I18nManager): ToasterInstance { const containerElement = document.createElement('div'); document.body.appendChild(containerElement); @@ -54,4 +54,4 @@ export type ToastActionHandler = (action: A) => void; export type CreateToast< P extends Record = never, A extends string = 'dismiss', -> = (onAction: ToastActionHandler, props: P) => IToastProps; +> = (onAction: ToastActionHandler, props: P) => ToastProps; diff --git a/src/notifications/sagas.test.ts b/src/notifications/sagas.test.ts index 4ad88de6..b76599ea 100644 --- a/src/notifications/sagas.test.ts +++ b/src/notifications/sagas.test.ts @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2021-2022 The Pybricks Authors -import { IToaster } from '@blueprintjs/core'; +import { ToasterInstance } from '@blueprintjs/core'; import { FirmwareReaderError, FirmwareReaderErrorCode } from '@pybricks/firmware'; import { I18nManager } from '@shopify/react-i18n'; import { AnyAction } from 'redux'; @@ -37,7 +37,7 @@ import { add } from './actions'; import { I18nId } from './i18n'; import notification from './sagas'; -function createTestToasterSaga(): { toaster: IToaster; saga: AsyncSaga } { +function createTestToasterSaga(): { toaster: ToasterInstance; saga: AsyncSaga } { const i18n = new I18nManager({ locale: 'en' }); const toaster = i18nToaster.create(i18n); diff --git a/src/notifications/sagas.ts b/src/notifications/sagas.ts index 89a84665..43ef72bb 100644 --- a/src/notifications/sagas.ts +++ b/src/notifications/sagas.ts @@ -3,7 +3,13 @@ // Saga for managing notifications (toasts) -import { ActionProps, IToaster, IconName, Intent, LinkProps } from '@blueprintjs/core'; +import { + ActionProps, + IconName, + Intent, + LinkProps, + ToasterInstance, +} from '@blueprintjs/core'; import { Replacements } from '@shopify/react-i18n'; import React from 'react'; import { channel } from 'redux-saga'; @@ -34,7 +40,7 @@ import { add as addNotification } from './actions'; import { I18nId } from './i18n'; type NotificationContext = { - toaster: IToaster; + toaster: ToasterInstance; }; /** @@ -81,7 +87,7 @@ function mapIcon(level: Level): IconName | undefined { } /** - * Converts a URL to an action that can be passed to `IToaster.show()`. + * Converts a URL to an action that can be passed to `ToasterInstance.show()`. * @param helpUrl A URL. */ function helpAction(helpUrl: string): ActionProps & LinkProps {