Rename star/unstar actions to enable/disable/switch
Summary: Renamed actions "star" and "unstar" everywhere to "enable", "disable" and "switch". The logic behind original "star" action changed significantly, so this rename just makes everything much clearer. Please note that as a part of rename persisted state fields "userStarredPlugins" and "userStarredDevicePlugins" were renamed. I've added a "redux-persist" migration for seamless transition. Reviewed By: passy Differential Revision: D26606459 fbshipit-source-id: 83ad475f9b0231194701c40a2cdbda36f02c3d10
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e9bab76614
commit
fa3ff83595
@@ -23,7 +23,7 @@ import pluginMessageQueue, {
|
||||
queueMessages,
|
||||
} from '../../reducers/pluginMessageQueue';
|
||||
import {registerPlugins} from '../../reducers/plugins';
|
||||
import {starPlugin} from '../../reducers/pluginManager';
|
||||
import {switchPlugin} from '../../reducers/pluginManager';
|
||||
|
||||
interface PersistedState {
|
||||
count: 1;
|
||||
@@ -54,9 +54,9 @@ class TestPlugin extends FlipperPlugin<any, any, any> {
|
||||
}
|
||||
}
|
||||
|
||||
function starTestPlugin(store: Store, client: Client) {
|
||||
function switchTestPlugin(store: Store, client: Client) {
|
||||
store.dispatch(
|
||||
starPlugin({
|
||||
switchPlugin({
|
||||
plugin: TestPlugin,
|
||||
selectedApp: client.query.app,
|
||||
}),
|
||||
@@ -174,8 +174,8 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
|
||||
[pluginKey]: [],
|
||||
});
|
||||
|
||||
// unstar, but, messages still arrives because selected
|
||||
starTestPlugin(store, client);
|
||||
// disable, but, messages still arrives because selected
|
||||
switchTestPlugin(store, client);
|
||||
selectTestPlugin(store, client);
|
||||
sendMessage('inc', {delta: 3});
|
||||
client.flushMessageBuffer();
|
||||
@@ -186,14 +186,14 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
|
||||
},
|
||||
});
|
||||
|
||||
// different plugin, and not starred, message will never arrive
|
||||
// different plugin, and not enabled, message will never arrive
|
||||
selectDeviceLogs(store);
|
||||
sendMessage('inc', {delta: 4});
|
||||
client.flushMessageBuffer();
|
||||
expect(store.getState().pluginMessageQueue).toEqual({});
|
||||
|
||||
// star again, plugin still not selected, message is queued
|
||||
starTestPlugin(store, client);
|
||||
switchTestPlugin(store, client);
|
||||
sendMessage('inc', {delta: 5});
|
||||
client.flushMessageBuffer();
|
||||
|
||||
@@ -686,14 +686,14 @@ test('queue - messages that have not yet flushed be lost when disabling the plug
|
||||
`);
|
||||
|
||||
// disable
|
||||
starTestPlugin(store, client);
|
||||
switchTestPlugin(store, client);
|
||||
expect(client.messageBuffer).toMatchInlineSnapshot(`Object {}`);
|
||||
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(
|
||||
`Object {}`,
|
||||
);
|
||||
|
||||
// re-enable, no messages arrive
|
||||
starTestPlugin(store, client);
|
||||
switchTestPlugin(store, client);
|
||||
client.flushMessageBuffer();
|
||||
processMessageQueue(TestPlugin, pluginKey, store);
|
||||
expect(store.getState().pluginStates).toMatchInlineSnapshot(`Object {}`);
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
PluginClient,
|
||||
_SandyPluginInstance,
|
||||
} from 'flipper-plugin';
|
||||
import {starPlugin} from '../../reducers/pluginManager';
|
||||
import {switchPlugin} from '../../reducers/pluginManager';
|
||||
|
||||
type Events = {
|
||||
inc: {
|
||||
@@ -57,9 +57,9 @@ const TestPlugin = new _SandyPluginDefinition(
|
||||
},
|
||||
);
|
||||
|
||||
function starTestPlugin(store: Store, client: Client) {
|
||||
function switchTestPlugin(store: Store, client: Client) {
|
||||
store.dispatch(
|
||||
starPlugin({
|
||||
switchPlugin({
|
||||
plugin: TestPlugin,
|
||||
selectedApp: client.query.app,
|
||||
}),
|
||||
@@ -184,8 +184,8 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
|
||||
[pluginKey]: [],
|
||||
});
|
||||
|
||||
// unstar. Messages don't arrive anymore
|
||||
starTestPlugin(store, client);
|
||||
// disable. Messages don't arrive anymore
|
||||
switchTestPlugin(store, client);
|
||||
// weird state...
|
||||
selectTestPlugin(store, client);
|
||||
sendMessage('inc', {delta: 3});
|
||||
@@ -193,7 +193,7 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
|
||||
// active, immediately processed
|
||||
expect(client.sandyPluginStates.has(TestPlugin.id)).toBe(false);
|
||||
|
||||
// different plugin, and not starred, message will never arrive
|
||||
// different plugin, and not enabled, message will never arrive
|
||||
selectDeviceLogs(store);
|
||||
sendMessage('inc', {delta: 4});
|
||||
client.flushMessageBuffer();
|
||||
@@ -201,7 +201,7 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
|
||||
expect(store.getState().pluginMessageQueue).toEqual({});
|
||||
|
||||
// star again, plugin still not selected, message is queued
|
||||
starTestPlugin(store, client);
|
||||
switchTestPlugin(store, client);
|
||||
sendMessage('inc', {delta: 5});
|
||||
client.flushMessageBuffer();
|
||||
|
||||
@@ -230,13 +230,12 @@ test('queue - events ARE processed immediately if plugin is NOT selected / enabl
|
||||
selectDeviceLogs(store);
|
||||
expect(store.getState().connections.selectedPlugin).toBe('DeviceLogs');
|
||||
store.dispatch(
|
||||
starPlugin({
|
||||
switchPlugin({
|
||||
plugin: NavigationPlugin,
|
||||
selectedApp: client.query.app,
|
||||
}),
|
||||
);
|
||||
expect(store.getState().connections.userStarredPlugins)
|
||||
.toMatchInlineSnapshot(`
|
||||
expect(store.getState().connections.enabledPlugins).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"TestApp": Array [],
|
||||
}
|
||||
@@ -728,14 +727,14 @@ test('queue - messages that have not yet flushed be lost when disabling the plug
|
||||
`);
|
||||
|
||||
// disable
|
||||
starTestPlugin(store, client);
|
||||
switchTestPlugin(store, client);
|
||||
expect(client.messageBuffer).toMatchInlineSnapshot(`Object {}`);
|
||||
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(
|
||||
`Object {}`,
|
||||
);
|
||||
|
||||
// re-enable, no messages arrive
|
||||
starTestPlugin(store, client);
|
||||
switchTestPlugin(store, client);
|
||||
client.flushMessageBuffer();
|
||||
processMessageQueue(
|
||||
client.sandyPluginStates.get(TestPlugin.id)!,
|
||||
|
||||
@@ -802,7 +802,7 @@ export function importDataToStore(source: string, data: string, store: Store) {
|
||||
});
|
||||
archivedDevice.loadDevicePlugins(
|
||||
store.getState().plugins.devicePlugins,
|
||||
store.getState().connections.userStarredDevicePlugins,
|
||||
store.getState().connections.enabledDevicePlugins,
|
||||
deserializeObject(device.pluginStates),
|
||||
);
|
||||
store.dispatch({
|
||||
|
||||
@@ -47,9 +47,7 @@ export function initializeFlipperLibImplementation(
|
||||
if (
|
||||
store
|
||||
.getState()
|
||||
.connections.userStarredPlugins[client.query.app]?.includes(
|
||||
pluginId,
|
||||
)
|
||||
.connections.enabledPlugins[client.query.app]?.includes(pluginId)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
DEFAULT_MAX_QUEUE_SIZE,
|
||||
} from '../reducers/pluginMessageQueue';
|
||||
import {IdlerImpl} from './Idler';
|
||||
import {pluginIsStarred, getSelectedPluginKey} from '../reducers/connections';
|
||||
import {isPluginEnabled, getSelectedPluginKey} from '../reducers/connections';
|
||||
import {deconstructPluginKey} from './clientUtils';
|
||||
import {defaultEnabledBackgroundPlugins} from './pluginUtils';
|
||||
import {batch, Idler, _SandyPluginInstance} from 'flipper-plugin';
|
||||
@@ -133,9 +133,9 @@ export function processMessagesLater(
|
||||
case plugin instanceof _SandyPluginInstance:
|
||||
case plugin instanceof FlipperDevicePlugin:
|
||||
case (plugin as any).prototype instanceof FlipperDevicePlugin:
|
||||
case pluginIsStarred(
|
||||
store.getState().connections.userStarredPlugins,
|
||||
store.getState().connections.userStarredDevicePlugins,
|
||||
case isPluginEnabled(
|
||||
store.getState().connections.enabledPlugins,
|
||||
store.getState().connections.enabledDevicePlugins,
|
||||
deconstructPluginKey(pluginKey).client,
|
||||
pluginId,
|
||||
):
|
||||
|
||||
@@ -83,8 +83,8 @@ export function getExportablePlugins(
|
||||
undefined,
|
||||
client,
|
||||
state.plugins,
|
||||
state.connections.userStarredPlugins,
|
||||
state.connections.userStarredDevicePlugins,
|
||||
state.connections.enabledPlugins,
|
||||
state.connections.enabledDevicePlugins,
|
||||
);
|
||||
|
||||
return [
|
||||
@@ -179,8 +179,8 @@ export function computePluginLists(
|
||||
metroDevice: BaseDevice | undefined,
|
||||
client: Client | undefined,
|
||||
plugins: State['plugins'],
|
||||
userStarredPlugins: State['connections']['userStarredPlugins'],
|
||||
userStarredDevicePlugins: Set<string>,
|
||||
enabledPluginsState: State['connections']['enabledPlugins'],
|
||||
enabledDevicePluginsState: Set<string>,
|
||||
_pluginsChanged?: number, // this argument is purely used to invalidate the memoization cache
|
||||
) {
|
||||
const uninstalledMarketplacePlugins = filterNewestVersionOfEachPlugin(
|
||||
@@ -191,12 +191,12 @@ export function computePluginLists(
|
||||
...plugins.devicePlugins.values(),
|
||||
]
|
||||
.filter((p) => device?.supportsPlugin(p))
|
||||
.filter((p) => userStarredDevicePlugins.has(p.id));
|
||||
.filter((p) => enabledDevicePluginsState.has(p.id));
|
||||
const metroPlugins: DevicePluginDefinition[] = [
|
||||
...plugins.devicePlugins.values(),
|
||||
]
|
||||
.filter((p) => metroDevice?.supportsPlugin(p))
|
||||
.filter((p) => userStarredDevicePlugins.has(p.id));
|
||||
.filter((p) => enabledDevicePluginsState.has(p.id));
|
||||
const enabledPlugins: ClientPluginDefinition[] = [];
|
||||
const disabledPlugins: PluginDefinition[] = [
|
||||
...plugins.devicePlugins.values(),
|
||||
@@ -206,7 +206,7 @@ export function computePluginLists(
|
||||
device?.supportsPlugin(p.details) ||
|
||||
metroDevice?.supportsPlugin(p.details),
|
||||
)
|
||||
.filter((p) => !userStarredDevicePlugins.has(p.id));
|
||||
.filter((p) => !enabledDevicePluginsState.has(p.id));
|
||||
const unavailablePlugins: [plugin: PluginDetails, reason: string][] = [];
|
||||
const downloadablePlugins: (
|
||||
| DownloadablePluginDetails
|
||||
@@ -263,7 +263,7 @@ export function computePluginLists(
|
||||
device,
|
||||
client,
|
||||
clientPlugins,
|
||||
client && userStarredPlugins[client.query.app],
|
||||
client && enabledPluginsState[client.query.app],
|
||||
true,
|
||||
);
|
||||
clientPlugins.forEach((plugin) => {
|
||||
@@ -323,7 +323,7 @@ function getFavoritePlugins(
|
||||
device: BaseDevice,
|
||||
client: Client,
|
||||
allPlugins: PluginDefinition[],
|
||||
starredPlugins: undefined | string[],
|
||||
enabledPlugins: undefined | string[],
|
||||
returnFavoredPlugins: boolean, // if false, unfavoried plugins are returned
|
||||
): PluginDefinition[] {
|
||||
if (device.isArchived) {
|
||||
@@ -335,11 +335,11 @@ function getFavoritePlugins(
|
||||
(plugin) => client.plugins.indexOf(plugin.id) !== -1,
|
||||
);
|
||||
}
|
||||
if (!starredPlugins || !starredPlugins.length) {
|
||||
if (!enabledPlugins || !enabledPlugins.length) {
|
||||
return returnFavoredPlugins ? [] : allPlugins;
|
||||
}
|
||||
return allPlugins.filter((plugin) => {
|
||||
const idx = starredPlugins.indexOf(plugin.id);
|
||||
const idx = enabledPlugins.indexOf(plugin.id);
|
||||
return idx === -1 ? !returnFavoredPlugins : returnFavoredPlugins;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user