Device plugin management (2/n): enable/disable, install/uninstall

Summary:
*Stack summary*: this stack adds ability to manage device plugins in the same way as client plugins: install, update, uninstall, enable (star) and disable (unstar) them.

*Diff summary*: implemented all plugin management actions for device plugins.

Changelog: it is now possible to enable/disable and install/uninstall device plugins

Reviewed By: mweststrate

Differential Revision: D26337377

fbshipit-source-id: 7d1ed61a8dc5f3339e5e548c613b67bca0c27f4f
This commit is contained in:
Anton Nikolaev
2021-02-16 10:46:11 -08:00
committed by Facebook GitHub Bot
parent 899fcd0783
commit 4541cdc23b
14 changed files with 281 additions and 62 deletions

View File

@@ -42,6 +42,7 @@ export type State = {
userPreferredPlugin: null | string;
userPreferredApp: null | string;
userStarredPlugins: {[client: string]: string[]};
userStarredDevicePlugins: Set<string>;
clients: Array<Client>;
uninitializedClients: Array<{
client: UninitializedClient;
@@ -115,6 +116,12 @@ export type Action =
selectedApp: string;
};
}
| {
type: 'DEVICE_PLUGIN_STARRED';
payload: {
plugin: PluginDefinition;
};
}
| {
type: 'PLUGIN_UNSTARRED';
payload: {
@@ -122,6 +129,12 @@ export type Action =
selectedApp: string;
};
}
| {
type: 'DEVICE_PLUGIN_UNSTARRED';
payload: {
plugin: PluginDefinition;
};
}
| {
type: 'SELECT_CLIENT';
payload: string | null;
@@ -140,6 +153,7 @@ const INITAL_STATE: State = {
userPreferredPlugin: null,
userPreferredApp: null,
userStarredPlugins: {},
userStarredDevicePlugins: new Set(),
clients: [],
uninitializedClients: [],
deepLinkPayload: null,
@@ -379,6 +393,12 @@ export default (state: State = INITAL_STATE, action: Actions): State => {
}
});
}
case 'DEVICE_PLUGIN_STARRED': {
const {plugin} = action.payload;
return produce(state, (draft) => {
draft.userStarredDevicePlugins.add(plugin.id);
});
}
case 'PLUGIN_UNSTARRED': {
const {plugin, selectedApp} = action.payload;
const selectedPlugin = plugin.id;
@@ -393,6 +413,12 @@ export default (state: State = INITAL_STATE, action: Actions): State => {
}
});
}
case 'DEVICE_PLUGIN_UNSTARRED': {
const {plugin} = action.payload;
return produce(state, (draft) => {
draft.userStarredDevicePlugins.delete(plugin.id);
});
}
default:
return state;
}
@@ -449,6 +475,20 @@ export const pluginStarred = (
},
});
export const devicePluginStarred = (plugin: PluginDefinition): Action => ({
type: 'DEVICE_PLUGIN_STARRED',
payload: {
plugin,
},
});
export const devicePluginUnstarred = (plugin: PluginDefinition): Action => ({
type: 'DEVICE_PLUGIN_UNSTARRED',
payload: {
plugin,
},
});
export const pluginUnstarred = (
plugin: PluginDefinition,
appId: string,
@@ -583,9 +623,13 @@ export function getSelectedPluginKey(state: State): string | undefined {
export function pluginIsStarred(
userStarredPlugins: State['userStarredPlugins'],
userStarredDevicePlugins: State['userStarredDevicePlugins'],
app: string | null,
pluginId: string,
): boolean {
if (userStarredDevicePlugins.has(pluginId)) {
return true;
}
if (!app) {
return false;
}