Make sure Sandy plugins are selectable during export
Summary: This diff makes sure Sandy plugins show up as well in the plugin selector when making exports (and in support form as well). Also verified that this works with the Sandy updated section plugin. Note that persisted state now didn't need any changes in the plugin code to work :) Commented / simplified the calculation of available plugins a little bit and fixed a confusing issue where two different redux stores where created in one unit test, which caused an issue in the new implementation. Reviewed By: jknoxville Differential Revision: D22434301 fbshipit-source-id: c911196bc5b105309e82204188f124f40aab487a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
44f99eb304
commit
6fe477f19b
@@ -17,7 +17,6 @@ import {
|
||||
import {State as PluginStatesState} from '../reducers/pluginStates';
|
||||
import {State as PluginsState} from '../reducers/plugins';
|
||||
import {State as PluginMessageQueueState} from '../reducers/pluginMessageQueue';
|
||||
import {PluginDetails} from 'flipper-plugin-lib';
|
||||
import {deconstructPluginKey, deconstructClientId} from './clientUtils';
|
||||
|
||||
type Client = import('../Client').default;
|
||||
@@ -27,14 +26,10 @@ export const defaultEnabledBackgroundPlugins = ['Navigation']; // The navigation
|
||||
export function pluginsClassMap(
|
||||
plugins: PluginsState,
|
||||
): Map<string, PluginDefinition> {
|
||||
const pluginsMap: Map<string, PluginDefinition> = new Map([]);
|
||||
plugins.clientPlugins.forEach((val, key) => {
|
||||
pluginsMap.set(key, val);
|
||||
});
|
||||
plugins.devicePlugins.forEach((val, key) => {
|
||||
pluginsMap.set(key, val);
|
||||
});
|
||||
return pluginsMap;
|
||||
return new Map<string, PluginDefinition>([
|
||||
...plugins.clientPlugins.entries(),
|
||||
...plugins.devicePlugins.entries(),
|
||||
]);
|
||||
}
|
||||
|
||||
export function getPluginKey(
|
||||
@@ -141,65 +136,70 @@ export function getActivePersistentPlugins(
|
||||
plugins: PluginsState,
|
||||
selectedClient?: Client,
|
||||
): {id: string; label: string}[] {
|
||||
const pluginsMap: Map<string, PluginDefinition> = pluginsClassMap(plugins);
|
||||
const pluginsMap = pluginsClassMap(plugins);
|
||||
return getPersistentPlugins(plugins)
|
||||
.map((pluginName) => pluginsMap.get(pluginName)!)
|
||||
.sort(sortPluginsByName)
|
||||
.map((plugin) => {
|
||||
const keys = [
|
||||
...new Set([
|
||||
...Object.keys(pluginsState),
|
||||
...Object.keys(pluginsMessageQueue),
|
||||
]),
|
||||
]
|
||||
.filter((k) => !selectedClient || k.includes(selectedClient.id))
|
||||
.map((key) => deconstructPluginKey(key).pluginName);
|
||||
let result = plugin.id == 'DeviceLogs';
|
||||
const pluginsWithExportPersistedState =
|
||||
plugin && plugin.exportPersistedState != undefined;
|
||||
const pluginsWithReduxData = keys.includes(plugin.id);
|
||||
if (!result && selectedClient) {
|
||||
// If there is a selected client, active persistent plugin is the plugin which is active for selectedClient and also persistent.
|
||||
result =
|
||||
selectedClient.plugins.includes(plugin.id) &&
|
||||
(pluginsWithExportPersistedState || pluginsWithReduxData);
|
||||
} else if (!result && !selectedClient) {
|
||||
// If there is no selected client, active persistent plugin is the plugin which is just persistent.
|
||||
result =
|
||||
(plugin && plugin.exportPersistedState != undefined) ||
|
||||
keys.includes(plugin.id);
|
||||
.filter((plugin) => {
|
||||
if (plugin.id == 'DeviceLogs') {
|
||||
return true;
|
||||
}
|
||||
if (selectedClient) {
|
||||
const pluginKey = getPluginKey(
|
||||
selectedClient.id,
|
||||
{serial: selectedClient.query.device_id},
|
||||
plugin.id,
|
||||
);
|
||||
// If there is a selected client, active persistent plugins are those that (can) have persisted state
|
||||
return (
|
||||
selectedClient.isEnabledPlugin(plugin.id) &&
|
||||
// this plugin can fetch and export state
|
||||
(plugin.exportPersistedState ||
|
||||
// this plugin has some persisted state already
|
||||
pluginsState[pluginKey] ||
|
||||
pluginsMessageQueue[pluginKey] ||
|
||||
// this plugin has some persistable sandy state
|
||||
selectedClient.sandyPluginStates.get(plugin.id)?.isPersistable())
|
||||
);
|
||||
}
|
||||
{
|
||||
// If there is no selected client, active persistent plugin is the plugin which is just persistent.
|
||||
const pluginsWithReduxData = [
|
||||
...new Set([
|
||||
...Object.keys(pluginsState),
|
||||
...Object.keys(pluginsMessageQueue),
|
||||
]),
|
||||
].map((key) => deconstructPluginKey(key).pluginName);
|
||||
return (
|
||||
(plugin && plugin.exportPersistedState != undefined) ||
|
||||
isSandyPlugin(plugin) ||
|
||||
pluginsWithReduxData.includes(plugin.id)
|
||||
);
|
||||
}
|
||||
return (result
|
||||
? {
|
||||
id: plugin.id,
|
||||
label: getPluginTitle(plugin),
|
||||
}
|
||||
: undefined)!;
|
||||
})
|
||||
.filter(Boolean);
|
||||
.map((plugin) => ({
|
||||
id: plugin.id,
|
||||
label: getPluginTitle(plugin),
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all enabled plugins that are potentially exportable
|
||||
* @param plugins
|
||||
*/
|
||||
export function getPersistentPlugins(plugins: PluginsState): Array<string> {
|
||||
const pluginsMap: Map<string, PluginDefinition> = pluginsClassMap(plugins);
|
||||
const pluginsMap = pluginsClassMap(plugins);
|
||||
|
||||
const arr: Array<PluginDetails> = plugins.disabledPlugins.concat(
|
||||
plugins.gatekeepedPlugins,
|
||||
);
|
||||
arr.forEach((plugin: PluginDetails) => {
|
||||
if (pluginsMap.has(plugin.name)) {
|
||||
[...plugins.disabledPlugins, ...plugins.gatekeepedPlugins].forEach(
|
||||
(plugin) => {
|
||||
pluginsMap.delete(plugin.name);
|
||||
}
|
||||
},
|
||||
);
|
||||
plugins.failedPlugins.forEach(([details]) => {
|
||||
pluginsMap.delete(details.id);
|
||||
});
|
||||
|
||||
plugins.failedPlugins.forEach((plugin: [PluginDetails, string]) => {
|
||||
if (plugin[0] && plugin[0].name && pluginsMap.has(plugin[0].name)) {
|
||||
pluginsMap.delete(plugin[0].name);
|
||||
}
|
||||
});
|
||||
|
||||
const activePlugins = [...pluginsMap.keys()];
|
||||
|
||||
return activePlugins.filter((plugin) => {
|
||||
return Array.from(pluginsMap.keys()).filter((plugin) => {
|
||||
const pluginClass = pluginsMap.get(plugin);
|
||||
return (
|
||||
plugin == 'DeviceLogs' ||
|
||||
|
||||
Reference in New Issue
Block a user