/** * 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 React, {memo} from 'react'; import {Typography, Card} from 'antd'; import { Layout, PluginClient, usePlugin, createState, useValue, theme, styled, DataInspector, DetailSidebar, } from 'flipper-plugin'; type Row = { id: number; title: string; url: string; }; type Events = { newRow: Row; }; export function plugin(client: PluginClient) { const rows = createState>({}, {persist: 'rows'}); const selectedID = createState(null, {persist: 'selection'}); client.addMenuEntry( { label: 'Reset Selection', handler: () => { selectedID.set(null); }, }, { action: 'createPaste', handler: async () => { const selection = selectedID.get(); if (selection) { await client.createPaste( JSON.stringify(rows.get()[selection], null, 2), ); } }, }, ); client.onMessage('newRow', (row) => { rows.update((draft) => { draft[row.id] = row; }); }); function setSelection(id: number) { selectedID.set('' + id); } return { rows, selectedID, setSelection, }; } export function Component() { const instance = usePlugin(plugin); const rows = useValue(instance.rows); const selectedID = useValue(instance.selectedID); return ( <> {Object.entries(rows).map(([id, row]) => ( ))} {selectedID && renderSidebar(rows[selectedID])} ); } function renderSidebar(row: Row) { return ( Extras ); } type CardProps = { onSelect: (id: number) => void; selected: boolean; row: Row; }; const MammalCard = memo(({row, selected, onSelect}: CardProps) => { return ( onSelect(row.id)} title={row.title} style={{ width: 150, borderColor: selected ? theme.primaryColor : undefined, }}> ); }); const Image = styled.div({ backgroundSize: 'cover', width: '100%', paddingTop: '100%', });