flipper-plugin
Version:
Flipper Desktop plugin SDK and components
79 lines • 3.17 kB
JavaScript
/**
* 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
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTablePlugin = void 0;
const antd_1 = require("antd");
const react_1 = __importDefault(require("react"));
const PluginContext_1 = require("../plugin/PluginContext");
const atom_1 = require("../state/atom");
const createDataSource_1 = require("../state/createDataSource");
const MasterDetail_1 = require("../ui/MasterDetail");
function createTablePlugin(props) {
function plugin(client) {
const rows = (0, createDataSource_1.createDataSource)([], {
persist: 'rows',
key: props.key,
});
const selection = (0, atom_1.createState)(undefined);
const isPaused = (0, atom_1.createState)(false);
client.onMessage(props.method, (event) => {
if (isPaused.get()) {
return;
}
const record = props.buildRow
? props.buildRow(event)
: event;
if (props.key) {
rows.upsert(record);
}
else {
rows.append(record);
}
});
if (props.resetMethod) {
client.onMessage(props.resetMethod, () => {
rows.clear();
});
}
// help plugin authors with finding out what the events and data shape is from the plugin
const unhandledMessagesSeen = new Set();
client.onUnhandledMessage((message, params) => {
if (unhandledMessagesSeen.has(message)) {
return;
}
unhandledMessagesSeen.add(message);
antd_1.notification.warn({
message: `Unhandled message: ${message}`,
description: (react_1.default.createElement(antd_1.Typography.Paragraph, null,
react_1.default.createElement("pre", null, JSON.stringify(params, null, 2)))),
});
});
return {
selection,
rows,
isPaused,
};
}
function SidebarComponent({ record }) {
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return props.renderSidebar(record);
}
function Component() {
const instance = (0, PluginContext_1.usePlugin)(plugin);
return (react_1.default.createElement(MasterDetail_1.MasterDetail, { columns: props.columns, dataSource: instance.rows, sidebarComponent: props.renderSidebar ? SidebarComponent : undefined, selection: instance.selection, isPaused: instance.isPaused, enableMenuEntries: true, enableClear: true, onCopyRows: props.onCopyRows }));
}
return { plugin, Component };
}
exports.createTablePlugin = createTablePlugin;
//# sourceMappingURL=createTablePlugin.js.map
;