Files
flipper/desktop/flipper-ui-core/src/reducers/pluginManager.tsx
Luke De Feo e47d99a69e Remove unused plugin update command / redux action
Summary:
This command is never actually dispatched so removing to avoid future confusion.

When new plugins are downloaded a check is done here https://fburl.com/code/e3zedljb to see if pluginIsDisabledForAllConnectedClients, if so, load command is queued, which internally calls update (which resets state)

If the plugin is not disabled then a message appears asking user to manually reload.

Reviewed By: aigoncharov

Differential Revision: D44502476

fbshipit-source-id: b796b77f843218c07ee612d9f45cacba073362d3
2023-03-30 10:05:59 -07:00

111 lines
2.4 KiB
TypeScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import type {Actions} from './';
import type {ActivatablePluginDetails} from 'flipper-common';
import type {PluginDefinition} from '../plugin';
import {produce} from 'immer';
export type State = {
pluginCommandsQueue: PluginCommand[];
};
export type PluginCommand =
| LoadPluginAction
| UninstallPluginAction
| SwitchPluginAction;
export type LoadPluginActionPayload = {
plugin: ActivatablePluginDetails;
enable: boolean;
notifyIfFailed: boolean;
};
export type LoadPluginAction = {
type: 'LOAD_PLUGIN';
payload: LoadPluginActionPayload;
};
export type UninstallPluginActionPayload = {
plugin: PluginDefinition;
};
export type UninstallPluginAction = {
type: 'UNINSTALL_PLUGIN';
payload: UninstallPluginActionPayload;
};
export type UpdatePluginActionPayload = {
plugin: PluginDefinition;
enablePlugin: boolean;
};
export type SwitchPluginActionPayload = {
plugin: PluginDefinition;
selectedApp?: string;
};
export type SwitchPluginAction = {
type: 'SWITCH_PLUGIN';
payload: SwitchPluginActionPayload;
};
export type Action =
| {
type: 'PLUGIN_COMMANDS_PROCESSED';
payload: number;
}
| PluginCommand;
const INITIAL_STATE: State = {
pluginCommandsQueue: [],
};
export default function reducer(
state: State = INITIAL_STATE,
action: Actions,
): State {
switch (action.type) {
case 'LOAD_PLUGIN':
case 'UNINSTALL_PLUGIN':
case 'SWITCH_PLUGIN':
return produce(state, (draft) => {
draft.pluginCommandsQueue.push(action);
});
case 'PLUGIN_COMMANDS_PROCESSED':
return produce(state, (draft) => {
draft.pluginCommandsQueue.splice(0, action.payload);
});
default:
return state;
}
}
export const uninstallPlugin = (
payload: UninstallPluginActionPayload,
): Action => ({
type: 'UNINSTALL_PLUGIN',
payload,
});
export const loadPlugin = (payload: LoadPluginActionPayload): Action => ({
type: 'LOAD_PLUGIN',
payload,
});
export const pluginCommandsProcessed = (payload: number): Action => ({
type: 'PLUGIN_COMMANDS_PROCESSED',
payload,
});
export const switchPlugin = (payload: SwitchPluginActionPayload): Action => ({
type: 'SWITCH_PLUGIN',
payload,
});