mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-14 10:35:11 +00:00
replace use of deprecated IToaster and IToastProps
This commit is contained in:
+2
-2
@@ -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<D extends AlertDomain, S extends AlertSpecific<D>>
|
||||
specific: S,
|
||||
onAlert: AlertCallback<D, S>,
|
||||
props: AlertProps<D, S>,
|
||||
): IToastProps {
|
||||
): ToastProps {
|
||||
const create = alertDomains[domain][specific] as unknown as CreateToast<
|
||||
Record<string, unknown> | never,
|
||||
string
|
||||
|
||||
@@ -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<IToastOptions>();
|
||||
|
||||
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!');
|
||||
}
|
||||
|
||||
+3
-3
@@ -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<typeof alertsShowAlert>): Generator {
|
||||
const toaster = yield* getContext<IToaster>('toaster');
|
||||
const toaster = yield* getContext<ToasterInstance>('toaster');
|
||||
|
||||
const key = `${action.domain}.${action.specific}.${JSON.stringify(action.props)}`;
|
||||
|
||||
|
||||
+22
-22
@@ -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<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -231,7 +231,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -281,7 +281,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -349,7 +349,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -413,7 +413,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -480,7 +480,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -540,7 +540,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -606,7 +606,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -689,7 +689,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -755,7 +755,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -854,7 +854,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -962,7 +962,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1110,7 +1110,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1256,7 +1256,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1409,7 +1409,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1457,7 +1457,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1504,7 +1504,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1565,7 +1565,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1627,7 +1627,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1692,7 +1692,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
@@ -1782,7 +1782,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
const saga = new AsyncSaga(flashFirmware, {
|
||||
nextMessageId: createCountFunc(),
|
||||
toaster: mock<IToaster>(),
|
||||
toaster: mock<ToasterInstance>(),
|
||||
});
|
||||
|
||||
// saga is triggered by this action
|
||||
|
||||
@@ -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<HubType, string>([
|
||||
* parent task).
|
||||
*/
|
||||
function* disconnectAndCancel(): SagaGenerator<void> {
|
||||
const toaster = yield* getContext<IToaster>('toaster');
|
||||
const toaster = yield* getContext<ToasterInstance>('toaster');
|
||||
|
||||
toaster.dismiss('firmware.ble.progress');
|
||||
|
||||
@@ -333,7 +333,7 @@ function* loadFirmware(
|
||||
* @param action The action that triggered this saga.
|
||||
*/
|
||||
function* handleFlashFirmware(action: ReturnType<typeof flashFirmware>): Generator {
|
||||
const toaster = yield* getContext<IToaster>('toaster');
|
||||
const toaster = yield* getContext<ToasterInstance>('toaster');
|
||||
|
||||
try {
|
||||
let firmware: Uint8Array | undefined = undefined;
|
||||
@@ -704,7 +704,7 @@ function* handleFlashUsbDfu(action: ReturnType<typeof firmwareFlashUsbDfu>): Gen
|
||||
dfu.dfuseStartAddress = dfuFirmwareStartAddress;
|
||||
const writeProc = dfu.write(1024, firmware, true);
|
||||
|
||||
const toaster = yield* getContext<IToaster>('toaster');
|
||||
const toaster = yield* getContext<ToasterInstance>('toaster');
|
||||
|
||||
defer.push(
|
||||
writeProc.events.on('erase/process', (sent, total) => {
|
||||
|
||||
+4
-4
@@ -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<A extends string> = (action: A) => void;
|
||||
export type CreateToast<
|
||||
P extends Record<string, unknown> = never,
|
||||
A extends string = 'dismiss',
|
||||
> = (onAction: ToastActionHandler<A>, props: P) => IToastProps;
|
||||
> = (onAction: ToastActionHandler<A>, props: P) => ToastProps;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user