Unify error notifications (#1483)

Summary:
Note: this is to be stacked upon https://github.com/facebook/flipper/pull/1479

Note: this PR will probably not succeed against FB internal flipper, as I'm pretty sure there are more call sites that need to be updated. So consider this WIP

Currently connection errors are managed in the connection reducers, and are displayed through their own means, the error bar. Showing console.errors is also hooked up to this mechanism in FB internal flipper, but not at all in the OSS version, which means that some connection errors are never shown to the user.

Besides that there is a notification system that is used by for example the crash reporter and plugin updater.

Having effectively (at least) two notifications mechanisms is confusing and error prone. This PR unifies both approaches, and rather than having the connection reducer manage it's own errors, it leverages the more generic notifications reducer. Since, in the previous PR, console errors and warnings have become user facing (even in OSS and production builds, which wasn't the case before), there is no need anymore for a separate error bar.

I left the notifications mechanism itself as-is, but as discussed in the Sandy project the notification screen will probably be overhauled, and the system wide notifications will become in-app notifications.

## Changelog

Pull Request resolved: https://github.com/facebook/flipper/pull/1483

Test Plan: Only updated the unit tests at this point. Manual tests still need to be done.

Reviewed By: passy

Differential Revision: D23220896

Pulled By: mweststrate

fbshipit-source-id: 8ea37cf69ce9605dc232ca90afe9e2f70da26652
This commit is contained in:
Michel Weststrate
2020-08-21 10:05:19 -07:00
committed by Facebook GitHub Bot
parent 76b72f3d77
commit 81eb09e7b0
11 changed files with 133 additions and 435 deletions

View File

@@ -14,27 +14,6 @@ import MacDevice from '../../devices/MacDevice';
import {FlipperDevicePlugin} from '../../plugin';
import MetroDevice from '../../devices/MetroDevice';
test('REGISTER_DEVICE doesnt remove error', () => {
const initialState: State = reducer(undefined, {
type: 'SERVER_ERROR',
payload: {message: 'something went wrong'},
});
// Precondition
expect(initialState.errors).toEqual([
{message: 'something went wrong', occurrences: 1},
]);
const endState = reducer(initialState, {
type: 'REGISTER_DEVICE',
payload: new BaseDevice('serial', 'physical', 'title', 'Android'),
});
expect(endState.errors).toEqual([
{message: 'something went wrong', occurrences: 1},
]);
});
test('doing a double REGISTER_DEVICE keeps the last', () => {
const device1 = new BaseDevice('serial', 'physical', 'title', 'Android');
const device2 = new BaseDevice('serial', 'physical', 'title2', 'Android');
@@ -105,71 +84,6 @@ test('triggering REGISTER_DEVICE before REGISTER_PLUGINS still registers device
expect(endState.devices[0].devicePlugins).toEqual(['test']);
});
test('errors are collected on a by name basis', () => {
const initialState: State = reducer(undefined, {
type: 'SERVER_ERROR',
payload: {
message: 'error1',
error: 'stack1',
},
});
expect(initialState.errors).toMatchInlineSnapshot(`
Array [
Object {
"error": "stack1",
"message": "error1",
"occurrences": 1,
},
]
`);
const state2: State = reducer(initialState, {
type: 'SERVER_ERROR',
payload: {
message: 'error2',
error: 'stack2',
},
});
// There are now two errors
expect(state2.errors).toMatchInlineSnapshot(`
Array [
Object {
"error": "stack1",
"message": "error1",
"occurrences": 1,
},
Object {
"error": "stack2",
"message": "error2",
"occurrences": 1,
},
]
`);
const state3: State = reducer(state2, {
type: 'SERVER_ERROR',
payload: {
message: 'error1',
error: 'stack3',
},
});
// Still two errors, but error1 has been updated and occurrences increased
expect(state3.errors).toMatchInlineSnapshot(`
Array [
Object {
"error": "stack3",
"message": "error1",
"occurrences": 2,
},
Object {
"error": "stack2",
"message": "error2",
"occurrences": 1,
},
]
`);
});
test('selectPlugin sets deepLinkPayload correctly', () => {
const state = reducer(
undefined,