Provide standardised MasterDetail

Summary:
Noticed in reviews during the convertathon there is still quite some boilerplate in things that happen on the boundary of UI and plugin state, such as setting up menu entries and providing common functionality like clear, master/detail layout, etc.

This diff introduces the `MasterDetail` component, which takes a higher level approach by merely needing to provide the state atoms and desired features, and taking care of the wiring.

Applied it to createTablePlugin, to prove that going from `createTablePlugin` to `MasterDetail` will be a much smaller step now.

Verified on the funnel logger plugin

Reviewed By: passy

Differential Revision: D28090362

fbshipit-source-id: 146f8c315fea903901ad4e3e46711642f16cf0e6
This commit is contained in:
Michel Weststrate
2021-04-29 07:30:56 -07:00
committed by Facebook GitHub Bot
parent e7cdbcbe85
commit e26a8c5ad0
9 changed files with 347 additions and 126 deletions

View File

@@ -11,7 +11,7 @@ import {SandyPluginDefinition} from './SandyPluginDefinition';
import {BasePluginInstance, BasePluginClient} from './PluginBase';
import {FlipperLib} from './FlipperLib';
import {DeviceType as PluginDeviceType} from 'flipper-plugin-lib';
import {Atom} from '../state/atom';
import {Atom, ReadOnlyAtom} from '../state/atom';
export type DeviceLogListener = (entry: DeviceLogEntry) => void;
@@ -60,6 +60,9 @@ export interface DevicePluginClient extends BasePluginClient {
* opens a different plugin by id, optionally providing a deeplink to bring the plugin to a certain state
*/
selectPlugin(pluginId: string, deeplinkPayload?: unknown): void;
readonly isConnected: boolean;
readonly connected: ReadOnlyAtom<boolean>;
}
/**
@@ -103,6 +106,10 @@ export class SandyDevicePluginInstance extends BasePluginInstance {
flipperLib.selectPlugin(realDevice, null, pluginId, deeplink);
}
},
get isConnected() {
return realDevice.connected.get();
},
connected: realDevice.connected,
};
this.initializePlugin(() =>
definition.asDevicePluginModule().devicePlugin(this.client),