Add UI to select plugins
Summary: Adds UI to the select the plugin to export. It lists the plugins which has currently some data in the redux store and it also lists those plugins which has implemented `exportPersistedState` function, as it might happen that the redux store may not have the data for a plugin but it will still export the data by calling `exportPersistedState`, which will ping the mobile client to get the data at point while we export the flipper trace. Reviewed By: jknoxville Differential Revision: D16468408 fbshipit-source-id: 452a7caf7199dd2b8df330bbb10d0a90008e92ec
This commit is contained in:
committed by
Facebook Github Bot
parent
aa470a9aef
commit
e7198040ea
@@ -5,9 +5,39 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {getActivePluginNames} from '../pluginUtils';
|
||||
import {getPersistentPlugins, getActivePersistentPlugins} from '../pluginUtils';
|
||||
import type {State as PluginsState} from '../../reducers/plugins.js';
|
||||
import type {State as PluginStatesState} from '../../reducers/pluginStates.js';
|
||||
import type {PluginDefinition} from '../../dispatcher/plugins';
|
||||
import {FlipperBasePlugin} from '../../..';
|
||||
import type {MiddlewareAPI} from '../../reducers/index.js';
|
||||
class MockFlipperPluginWithDefaultPersistedState extends FlipperBasePlugin<
|
||||
*,
|
||||
*,
|
||||
{msg: string},
|
||||
> {
|
||||
static defaultPersistedState = {msg: 'MockFlipperPluginWithPersistedState'};
|
||||
}
|
||||
|
||||
class MockFlipperPluginWithExportPersistedState extends FlipperBasePlugin<
|
||||
*,
|
||||
*,
|
||||
{msg: string},
|
||||
> {
|
||||
static exportPersistedState = (
|
||||
callClient: (string, ?Object) => Promise<Object>,
|
||||
persistedState: ?{msg: string},
|
||||
store: ?MiddlewareAPI,
|
||||
): Promise<?{msg: string}> => {
|
||||
return Promise.resolve({msg: 'MockFlipperPluginWithExportPersistedState'});
|
||||
};
|
||||
}
|
||||
|
||||
class MockFlipperPluginWithNoPersistedState extends FlipperBasePlugin<
|
||||
*,
|
||||
*,
|
||||
*,
|
||||
> {}
|
||||
|
||||
function mockPluginState(
|
||||
gatekeepedPlugins: Array<PluginDefinition>,
|
||||
@@ -16,16 +46,16 @@ function mockPluginState(
|
||||
): PluginsState {
|
||||
return {
|
||||
devicePlugins: new Map([
|
||||
//$FlowFixMe: Class instance won't be used in the test
|
||||
['DevicePlugin1', undefined],
|
||||
//$FlowFixMe: Class instance won't be used in the test
|
||||
['DevicePlugin2', undefined],
|
||||
//$FlowFixMe: Just for testing
|
||||
['DevicePlugin1', MockFlipperPluginWithDefaultPersistedState],
|
||||
//$FlowFixMe: Just for testing
|
||||
['DevicePlugin2', MockFlipperPluginWithDefaultPersistedState],
|
||||
]),
|
||||
clientPlugins: new Map([
|
||||
//$FlowFixMe: Class instance won't be used in the test
|
||||
['ClientPlugin1', undefined],
|
||||
//$FlowFixMe: Class instance won't be used in the test
|
||||
['ClientPlugin2', undefined],
|
||||
//$FlowFixMe: Just for testing
|
||||
['ClientPlugin1', MockFlipperPluginWithDefaultPersistedState],
|
||||
//$FlowFixMe: Just for testing
|
||||
['ClientPlugin2', MockFlipperPluginWithDefaultPersistedState],
|
||||
]),
|
||||
gatekeepedPlugins,
|
||||
disabledPlugins,
|
||||
@@ -41,19 +71,19 @@ function mockPluginDefinition(name: string): PluginDefinition {
|
||||
};
|
||||
}
|
||||
|
||||
test('getActivePluginNames with the plugins getting excluded', () => {
|
||||
test('getPersistentPlugins with the plugins getting excluded', () => {
|
||||
const state = mockPluginState(
|
||||
[mockPluginDefinition('DevicePlugin1')],
|
||||
[mockPluginDefinition('ClientPlugin1')],
|
||||
[[mockPluginDefinition('DevicePlugin2'), 'DevicePlugin2']],
|
||||
);
|
||||
const list = getActivePluginNames(state);
|
||||
const list = getPersistentPlugins(state);
|
||||
expect(list).toEqual(['ClientPlugin2']);
|
||||
});
|
||||
|
||||
test('getActivePluginNames with the no plugins getting excluded', () => {
|
||||
test('getPersistentPlugins with no plugins getting excluded', () => {
|
||||
const state = mockPluginState([], [], []);
|
||||
const list = getActivePluginNames(state);
|
||||
const list = getPersistentPlugins(state);
|
||||
expect(list).toEqual([
|
||||
'ClientPlugin1',
|
||||
'ClientPlugin2',
|
||||
@@ -61,3 +91,110 @@ test('getActivePluginNames with the no plugins getting excluded', () => {
|
||||
'DevicePlugin2',
|
||||
]);
|
||||
});
|
||||
|
||||
test('getPersistentPlugins, where the plugins with exportPersistedState not getting excluded', () => {
|
||||
const state: PluginsState = {
|
||||
devicePlugins: new Map([
|
||||
//$FlowFixMe: Just for testing
|
||||
['DevicePlugin1', MockFlipperPluginWithExportPersistedState],
|
||||
//$FlowFixMe: Just for testing
|
||||
['DevicePlugin2', MockFlipperPluginWithExportPersistedState],
|
||||
]),
|
||||
clientPlugins: new Map([
|
||||
//$FlowFixMe: Just for testing
|
||||
['ClientPlugin1', MockFlipperPluginWithExportPersistedState],
|
||||
//$FlowFixMe: Just for testing
|
||||
['ClientPlugin2', MockFlipperPluginWithExportPersistedState],
|
||||
]),
|
||||
gatekeepedPlugins: [],
|
||||
disabledPlugins: [],
|
||||
failedPlugins: [],
|
||||
selectedPlugins: [],
|
||||
};
|
||||
const list = getPersistentPlugins(state);
|
||||
expect(list).toEqual([
|
||||
'ClientPlugin1',
|
||||
'ClientPlugin2',
|
||||
'DevicePlugin1',
|
||||
'DevicePlugin2',
|
||||
]);
|
||||
});
|
||||
|
||||
test('getPersistentPlugins, where the non persistent plugins getting excluded', () => {
|
||||
const state: PluginsState = {
|
||||
devicePlugins: new Map([
|
||||
//$FlowFixMe: Just for testing
|
||||
['DevicePlugin1', MockFlipperPluginWithNoPersistedState],
|
||||
//$FlowFixMe: Just for testing
|
||||
['DevicePlugin2', MockFlipperPluginWithDefaultPersistedState],
|
||||
]),
|
||||
clientPlugins: new Map([
|
||||
//$FlowFixMe: Just for testing
|
||||
['ClientPlugin1', MockFlipperPluginWithDefaultPersistedState],
|
||||
//$FlowFixMe: Just for testing
|
||||
['ClientPlugin2', MockFlipperPluginWithNoPersistedState],
|
||||
]),
|
||||
gatekeepedPlugins: [],
|
||||
disabledPlugins: [],
|
||||
failedPlugins: [],
|
||||
selectedPlugins: [],
|
||||
};
|
||||
const list = getPersistentPlugins(state);
|
||||
expect(list).toEqual(['ClientPlugin1', 'DevicePlugin2']);
|
||||
});
|
||||
|
||||
test('getActivePersistentPlugins, where the non persistent plugins getting excluded', () => {
|
||||
const state: PluginsState = {
|
||||
devicePlugins: new Map([
|
||||
//$FlowFixMe: Just for testing
|
||||
['DevicePlugin1', MockFlipperPluginWithNoPersistedState],
|
||||
//$FlowFixMe: Just for testing
|
||||
['DevicePlugin2', MockFlipperPluginWithDefaultPersistedState],
|
||||
]),
|
||||
clientPlugins: new Map([
|
||||
//$FlowFixMe: Just for testing
|
||||
['ClientPlugin1', MockFlipperPluginWithDefaultPersistedState],
|
||||
//$FlowFixMe: Just for testing
|
||||
['ClientPlugin2', MockFlipperPluginWithNoPersistedState],
|
||||
]),
|
||||
gatekeepedPlugins: [],
|
||||
disabledPlugins: [],
|
||||
failedPlugins: [],
|
||||
selectedPlugins: [],
|
||||
};
|
||||
const plugins: PluginStatesState = {
|
||||
'serial#app#DevicePlugin1': {msg: 'DevicePlugin1'},
|
||||
'serial#app#DevicePlugin2': {msg: 'DevicePlugin2'},
|
||||
'serial#app#ClientPlugin1': {msg: 'ClientPlugin1'},
|
||||
'serial#app#ClientPlugin2': {msg: 'ClientPlugin2'},
|
||||
};
|
||||
const list = getActivePersistentPlugins(plugins, state);
|
||||
expect(list).toEqual(['ClientPlugin1', 'DevicePlugin2']);
|
||||
});
|
||||
|
||||
test('getActivePersistentPlugins, where the plugins not in pluginState gets excluded', () => {
|
||||
const state: PluginsState = {
|
||||
devicePlugins: new Map([
|
||||
//$FlowFixMe: Just for testing
|
||||
['DevicePlugin1', MockFlipperPluginWithDefaultPersistedState],
|
||||
//$FlowFixMe: Just for testing
|
||||
['DevicePlugin2', MockFlipperPluginWithDefaultPersistedState],
|
||||
]),
|
||||
clientPlugins: new Map([
|
||||
//$FlowFixMe: Just for testing
|
||||
['ClientPlugin1', MockFlipperPluginWithDefaultPersistedState],
|
||||
//$FlowFixMe: Just for testing
|
||||
['ClientPlugin2', MockFlipperPluginWithDefaultPersistedState],
|
||||
]),
|
||||
gatekeepedPlugins: [],
|
||||
disabledPlugins: [],
|
||||
failedPlugins: [],
|
||||
selectedPlugins: [],
|
||||
};
|
||||
const plugins: PluginStatesState = {
|
||||
'serial#app#DevicePlugin1': {msg: 'DevicePlugin1'},
|
||||
'serial#app#ClientPlugin2': {msg: 'ClientPlugin2'},
|
||||
};
|
||||
const list = getActivePersistentPlugins(plugins, state);
|
||||
expect(list).toEqual(['ClientPlugin2', 'DevicePlugin1']);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user