diff --git a/desktop/app/src/utils/flipperLibImplementation.tsx b/desktop/app/src/utils/flipperLibImplementation.tsx index 01a9cd657..742990bcc 100644 --- a/desktop/app/src/utils/flipperLibImplementation.tsx +++ b/desktop/app/src/utils/flipperLibImplementation.tsx @@ -10,6 +10,7 @@ import type {FlipperLib} from 'flipper-plugin'; import type {Logger} from '../fb-interfaces/Logger'; import type {Store} from '../reducers'; +import createPaste from '../fb-stubs/createPaste'; let flipperLibInstance: FlipperLib | undefined; @@ -23,6 +24,7 @@ export function initializeFlipperLibImplementation( enableMenuEntries(entries) { addSandyPluginEntries(entries); }, + createPaste, }; } diff --git a/desktop/flipper-plugin/src/__tests__/test-utils.node.tsx b/desktop/flipper-plugin/src/__tests__/test-utils.node.tsx index 8f9145808..d301e8aae 100644 --- a/desktop/flipper-plugin/src/__tests__/test-utils.node.tsx +++ b/desktop/flipper-plugin/src/__tests__/test-utils.node.tsx @@ -328,3 +328,21 @@ test('plugins can register menu entries', async () => { `"No menu entry found with action: Non Existing"`, ); }); + +test('plugins can create pastes', async () => { + const plugin = TestUtils.startPlugin({ + plugin(client: PluginClient) { + return { + doIt() { + client.createPaste('test'); + }, + }; + }, + Component() { + return null; + }, + }); + + plugin.instance.doIt(); + expect(plugin.flipperLib.createPaste).toBeCalledWith('test'); +}); diff --git a/desktop/flipper-plugin/src/plugin/FlipperLib.tsx b/desktop/flipper-plugin/src/plugin/FlipperLib.tsx index 7c4c3e6e5..4e6ecdff6 100644 --- a/desktop/flipper-plugin/src/plugin/FlipperLib.tsx +++ b/desktop/flipper-plugin/src/plugin/FlipperLib.tsx @@ -14,4 +14,5 @@ import {NormalizedMenuEntry} from './MenuEntry'; */ export interface FlipperLib { enableMenuEntries(menuEntries: NormalizedMenuEntry[]): void; + createPaste(input: string): Promise; } diff --git a/desktop/flipper-plugin/src/plugin/PluginBase.tsx b/desktop/flipper-plugin/src/plugin/PluginBase.tsx index 40865489b..ed5ae9325 100644 --- a/desktop/flipper-plugin/src/plugin/PluginBase.tsx +++ b/desktop/flipper-plugin/src/plugin/PluginBase.tsx @@ -38,6 +38,12 @@ export interface BasePluginClient { * Register menu entries in the Flipper toolbar */ addMenuEntry(...entry: MenuEntry[]): void; + + /** + * Creates a Paste (similar to a Github Gist). + * Facebook only function. Resolves to undefined if creating a paste failed. + */ + createPaste(input: string): Promise; } let currentPluginInstance: BasePluginInstance | undefined = undefined; @@ -123,6 +129,7 @@ export abstract class BasePluginInstance { this.menuEntries.push(normalizeMenuEntry(entry)); } }, + createPaste: this.flipperLib.createPaste, }; } diff --git a/desktop/flipper-plugin/src/test-utils/test-utils.tsx b/desktop/flipper-plugin/src/test-utils/test-utils.tsx index e789789cf..96a7dda2b 100644 --- a/desktop/flipper-plugin/src/test-utils/test-utils.tsx +++ b/desktop/flipper-plugin/src/test-utils/test-utils.tsx @@ -324,6 +324,7 @@ export function renderDevicePlugin( export function createMockFlipperLib(): FlipperLib { return { enableMenuEntries: jest.fn(), + createPaste: jest.fn(), }; } diff --git a/desktop/plugins/seamammals/src/index.tsx b/desktop/plugins/seamammals/src/index.tsx index 393298fec..4cb21c788 100644 --- a/desktop/plugins/seamammals/src/index.tsx +++ b/desktop/plugins/seamammals/src/index.tsx @@ -59,8 +59,14 @@ export function plugin(client: FlipperClient) { }, { action: 'createPaste', - handler: () => { - console.log('creating paste'); + handler: async () => { + const selection = selectedID.get(); + if (selection) { + const url = await client.createPaste( + JSON.stringify(rows.get()[selection], null, 2), + ); + alert(url); // TODO: use notifications T69990351 + } }, }, );