From 4918d21df83880a4c15c94365566b4a855fc87b3 Mon Sep 17 00:00:00 2001 From: Luke De Feo Date: Mon, 21 Aug 2023 04:24:16 -0700 Subject: [PATCH] Show framework event metadata documentation in detail view and tree select Reviewed By: lblasa Differential Revision: D48348090 fbshipit-source-id: e48547508b78178b278f72ce72fc579c9f015570 --- .../shared/FrameworkEventsTreeSelect.tsx | 46 +++++++++++++++---- .../components/sidebar/Inspector.tsx | 2 + .../inspector/FrameworkEventsInspector.tsx | 28 +++++++++-- .../components/tree/TreeControls.tsx | 8 +++- desktop/plugins/public/ui-debugger/index.tsx | 11 +++++ 5 files changed, 82 insertions(+), 13 deletions(-) diff --git a/desktop/plugins/public/ui-debugger/components/shared/FrameworkEventsTreeSelect.tsx b/desktop/plugins/public/ui-debugger/components/shared/FrameworkEventsTreeSelect.tsx index 7d1a512a1..c598a5c14 100644 --- a/desktop/plugins/public/ui-debugger/components/shared/FrameworkEventsTreeSelect.tsx +++ b/desktop/plugins/public/ui-debugger/components/shared/FrameworkEventsTreeSelect.tsx @@ -7,9 +7,11 @@ * @format */ -import {TreeSelect} from 'antd'; -import {FrameworkEventType} from '../../ClientTypes'; -import React from 'react'; +import React, {ReactNode} from 'react'; +import {InfoCircleOutlined} from '@ant-design/icons'; +import {Tooltip, TreeSelect} from 'antd'; +import {Layout, theme} from 'flipper-plugin'; +import {FrameworkEventMetadata, FrameworkEventType} from '../../ClientTypes'; export function FrameworkEventsTreeSelect({ treeData, @@ -55,7 +57,8 @@ export function FrameworkEventsTreeSelect({ } type TreeSelectNode = { - title: string; + title: ReactNode; + titleValue: string; key: string; value: string; children: TreeSelectNode[]; @@ -84,8 +87,11 @@ export const frameworkEventSeparator = '.'; /** * transformed flat event type data structure into tree */ -export function buildTreeSelectData(eventTypes: string[]): TreeSelectNode[] { - const root: TreeSelectNode = buildTreeSelectNode('root', 'root'); +export function buildTreeSelectData( + eventTypes: string[], + metadata: Map, +): TreeSelectNode[] { + const root: TreeSelectNode = buildTreeSelectNode('root', 'root', metadata); eventTypes.forEach((eventType) => { const eventSubtypes = eventType.split(frameworkEventSeparator); @@ -95,7 +101,7 @@ export function buildTreeSelectData(eventTypes: string[]): TreeSelectNode[] { for (let i = 0; i < eventSubtypes.length - 1; i++) { let foundChild = false; for (const child of currentNode.children) { - if (child.title === eventSubtypes[i]) { + if (child.titleValue === eventSubtypes[i]) { currentNode = child; foundChild = true; break; @@ -105,6 +111,7 @@ export function buildTreeSelectData(eventTypes: string[]): TreeSelectNode[] { const newNode: TreeSelectNode = buildTreeSelectNode( eventSubtypes[i], eventSubtypes.slice(0, i + 1).join(frameworkEventSeparator), + metadata, ); currentNode.children.push(newNode); @@ -118,6 +125,7 @@ export function buildTreeSelectData(eventTypes: string[]): TreeSelectNode[] { eventSubtypes .slice(0, eventSubtypes.length) .join(frameworkEventSeparator), + metadata, ), ); }); @@ -125,9 +133,29 @@ export function buildTreeSelectData(eventTypes: string[]): TreeSelectNode[] { return root.children; } -function buildTreeSelectNode(title: string, fullValue: string): TreeSelectNode { +function buildTreeSelectNode( + title: string, + fullValue: string, + metadata: Map, +): TreeSelectNode { + const documentation = metadata.get(fullValue)?.documentation; return { - title: title, + title: ( + + {title} + {documentation && ( + + + + )} + + ), + titleValue: title, key: fullValue, value: fullValue, children: [], diff --git a/desktop/plugins/public/ui-debugger/components/sidebar/Inspector.tsx b/desktop/plugins/public/ui-debugger/components/sidebar/Inspector.tsx index 69353765b..03bec41ba 100644 --- a/desktop/plugins/public/ui-debugger/components/sidebar/Inspector.tsx +++ b/desktop/plugins/public/ui-debugger/components/sidebar/Inspector.tsx @@ -43,6 +43,7 @@ export const Inspector: React.FC = ({ const instance = usePlugin(plugin); const selectedNodeId = useValue(instance.uiState.selectedNode)?.id; + const frameworkEventMetadata = useValue(instance.frameworkEventMetadata); const selectedNode = selectedNodeId ? nodes.get(selectedNodeId) : undefined; if (!selectedNode) { return ; @@ -122,6 +123,7 @@ export const Inspector: React.FC = ({ }> void; + frameworkEventMetadata: Map; }; export const FrameworkEventsInspector: React.FC = ({ node, events, showExtra, + frameworkEventMetadata, }) => { const allThreads = uniqBy(events, 'thread').map((event) => event.thread); const [filteredThreads, setFilteredThreads] = useState>( @@ -62,7 +69,10 @@ export const FrameworkEventsInspector: React.FC = ({ { setFilteredEventTypes((cur) => @@ -100,7 +110,11 @@ export const FrameworkEventsInspector: React.FC = ({ const event = filteredEvents[idx]; showExtra?.( 'Event details', - , + , ); }} timeline={{ @@ -122,7 +136,9 @@ export const FrameworkEventsInspector: React.FC = ({ function EventDetails({ event, node, + frameworkEventMetadata, }: { + frameworkEventMetadata?: FrameworkEventMetadata; event: FrameworkEvent; node: ClientNode; }) { @@ -138,6 +154,12 @@ function EventDetails({ {event.type} + {frameworkEventMetadata && ( + + {frameworkEventMetadata?.documentation} + + )} + {event.thread} diff --git a/desktop/plugins/public/ui-debugger/components/tree/TreeControls.tsx b/desktop/plugins/public/ui-debugger/components/tree/TreeControls.tsx index d51577306..df03d5104 100644 --- a/desktop/plugins/public/ui-debugger/components/tree/TreeControls.tsx +++ b/desktop/plugins/public/ui-debugger/components/tree/TreeControls.tsx @@ -17,7 +17,7 @@ import { SearchOutlined, } from '@ant-design/icons'; import {usePlugin, useValue, Layout} from 'flipper-plugin'; -import {FrameworkEventType} from '../../ClientTypes'; +import {FrameworkEventMetadata, FrameworkEventType} from '../../ClientTypes'; import { buildTreeSelectData, FrameworkEventsTreeSelect, @@ -35,6 +35,8 @@ export const TreeControls: React.FC = () => { instance.uiState.frameworkEventMonitoring, ); + const frameworkEventMetadata = useValue(instance.frameworkEventMetadata); + const [showFrameworkEventsModal, setShowFrameworkEventsModal] = useState(false); @@ -72,6 +74,7 @@ export const TreeControls: React.FC = () => { }> ; visible: boolean; onCancel: () => void; onSetEventMonitored: ( @@ -113,6 +118,7 @@ function FrameworkEventsMonitoringModal({ const treeData = buildTreeSelectData( frameworkEventTypes.map(([type]) => type), + metadata, ); return ( diff --git a/desktop/plugins/public/ui-debugger/index.tsx b/desktop/plugins/public/ui-debugger/index.tsx index 6187ff096..006013386 100644 --- a/desktop/plugins/public/ui-debugger/index.tsx +++ b/desktop/plugins/public/ui-debugger/index.tsx @@ -19,6 +19,7 @@ import { PerformanceStatsEvent, SnapshotInfo, ClientNode, + FrameworkEventMetadata, } from './ClientTypes'; import { UIState, @@ -50,6 +51,10 @@ export function plugin(client: PluginClient) { limit: 10000, }); + const frameworkEventMetadata = createState< + Map + >(new Map()); + const uiState: UIState = createUIState(); //this is the client data is what drives all of desktop UI @@ -78,6 +83,11 @@ export function plugin(client: PluginClient) { draft.set(frameworkEventMeta.type, false); }); }); + frameworkEventMetadata.update((draft) => { + event.frameworkEventMetadata?.forEach((frameworkEventMeta) => { + draft.set(frameworkEventMeta.type, frameworkEventMeta); + }); + }); }); client.onConnect(() => { @@ -301,6 +311,7 @@ export function plugin(client: PluginClient) { uiActions: uiActions(uiState, nodesAtom, snapshot, mutableLiveClientData), nodes: nodesAtom, frameworkEvents, + frameworkEventMetadata, snapshot, metadata, perfEvents,