Better handle no (valid) plugin selection

Summary: Little ux tweak, there are some rare scenarios where you can end up in an empty plugin screen, made a small message.

Reviewed By: jknoxville

Differential Revision: D22846396

fbshipit-source-id: 0ad19f1c252112d78a5587e6633fee2d9542d5e1
This commit is contained in:
Michel Weststrate
2020-08-20 13:31:17 -07:00
committed by Facebook GitHub Bot
parent 685cc09b3b
commit bce3d48e71
3 changed files with 30 additions and 2 deletions

View File

@@ -325,6 +325,26 @@ class PluginContainer extends PureComponent<Props, State> {
); );
} }
renderNoPluginActive() {
return (
<View grow>
<Waiting>
<VBox>
<Glyph
name="cup"
variant="outline"
size={24}
color={colors.light30}
/>
</VBox>
<VBox>
<Label>No plugin selected</Label>
</VBox>
</Waiting>
</View>
);
}
renderPlugin() { renderPlugin() {
const { const {
pluginState, pluginState,
@@ -338,14 +358,15 @@ class PluginContainer extends PureComponent<Props, State> {
} = this.props; } = this.props;
if (!activePlugin || !target || !pluginKey) { if (!activePlugin || !target || !pluginKey) {
console.warn(`No selected plugin. Rendering empty!`); console.warn(`No selected plugin. Rendering empty!`);
return null; return this.renderNoPluginActive();
} }
let pluginElement: null | React.ReactElement<any>; let pluginElement: null | React.ReactElement<any>;
if (isSandyPlugin(activePlugin)) { if (isSandyPlugin(activePlugin)) {
// Make sure we throw away the container for different pluginKey! // Make sure we throw away the container for different pluginKey!
const instance = target.sandyPluginStates.get(activePlugin.id); const instance = target.sandyPluginStates.get(activePlugin.id);
if (!instance) { if (!instance) {
return null; // happens if we selected a plugin that is not enabled on a specific app or not supported on a specific device.
return this.renderNoPluginActive();
} }
pluginElement = <SandyPluginRenderer key={pluginKey} plugin={instance} />; pluginElement = <SandyPluginRenderer key={pluginKey} plugin={instance} />;
} else { } else {

View File

@@ -11,6 +11,7 @@ import React, {memo, useEffect, createElement} from 'react';
import {SandyPluginContext} from './PluginContext'; import {SandyPluginContext} from './PluginContext';
import {SandyPluginInstance} from './Plugin'; import {SandyPluginInstance} from './Plugin';
import {SandyDevicePluginInstance} from './DevicePlugin'; import {SandyDevicePluginInstance} from './DevicePlugin';
import {BasePluginInstance} from './PluginBase';
type Props = { type Props = {
plugin: SandyPluginInstance | SandyDevicePluginInstance; plugin: SandyPluginInstance | SandyDevicePluginInstance;
@@ -20,6 +21,9 @@ type Props = {
* Component to render a Sandy plugin container * Component to render a Sandy plugin container
*/ */
export const SandyPluginRenderer = memo(({plugin}: Props) => { export const SandyPluginRenderer = memo(({plugin}: Props) => {
if (!plugin || !(plugin instanceof BasePluginInstance)) {
throw new Error('Expected plugin, got ' + plugin);
}
useEffect(() => { useEffect(() => {
plugin.activate(); plugin.activate();
return () => { return () => {

View File

@@ -440,5 +440,8 @@
], ],
"wireless": [ "wireless": [
16 16
],
"cup-outline": [
24
] ]
} }