Install plugins from sidebar

Summary:
This diff adds "download" button to the plugins shown in "Detected in App" section, so they can be downloaded, installed and enabled just in one click.

For now UI is very simple - there is no progress indication and no error handling for failed downloads. I'll add them in next diffs.

Please note that we are explicitly "star" every installed plugin to enable it straight away without additional clicks in "disabled" section.

Reviewed By: mweststrate

Differential Revision: D25393472

fbshipit-source-id: 0a224ea6d03db0ee9a70b7fa35ede9616c03d824
This commit is contained in:
Anton Nikolaev
2020-12-15 09:28:58 -08:00
committed by Facebook GitHub Bot
parent ab441d8226
commit 97d37abbb2
7 changed files with 357 additions and 7 deletions

View File

@@ -76,11 +76,11 @@ export function rootReducer(
}
});
} else if (action.type === 'UPDATE_PLUGIN' && state) {
const plugin = action.payload;
const {plugin, enablePlugin} = action.payload;
if (isDevicePluginDefinition(plugin)) {
return updateDevicePlugin(state, plugin);
} else {
return updateClientPlugin(state, plugin);
return updateClientPlugin(state, plugin, enablePlugin);
}
}
@@ -127,13 +127,33 @@ function startPlugin(
}
}
function updateClientPlugin(state: StoreState, plugin: typeof FlipperPlugin) {
function updateClientPlugin(
state: StoreState,
plugin: typeof FlipperPlugin,
enable: boolean,
) {
const clients = state.connections.clients;
return produce(state, (draft) => {
if (enable) {
clients.forEach((c) => {
let enabledPlugins = draft.connections.userStarredPlugins[c.query.app];
if (
c.supportsPlugin(plugin.id) &&
!enabledPlugins?.includes(plugin.id)
) {
if (!enabledPlugins) {
enabledPlugins = [plugin.id];
draft.connections.userStarredPlugins[c.query.app] = enabledPlugins;
} else {
enabledPlugins.push(plugin.id);
}
}
});
}
const clientsWithEnabledPlugin = clients.filter((c) => {
return (
c.supportsPlugin(plugin.id) &&
state.connections.userStarredPlugins[c.query.app]?.includes(plugin.id)
draft.connections.userStarredPlugins[c.query.app]?.includes(plugin.id)
);
});
// stop plugin for each client where it is enabled