Explode framework payload attribute into data table columns
Reviewed By: antonk52 Differential Revision: D48562431 fbshipit-source-id: 869e39da41986ee61e6bbebecfb4b36119881c64
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c6dddccd87
commit
c7ad98cba4
@@ -17,7 +17,7 @@ import {
|
|||||||
usePlugin,
|
usePlugin,
|
||||||
useValue,
|
useValue,
|
||||||
} from 'flipper-plugin';
|
} from 'flipper-plugin';
|
||||||
import React, {useCallback, useEffect, useRef} from 'react';
|
import React, {useCallback, useEffect, useMemo, useRef} from 'react';
|
||||||
import {FrameworkEvent, Id, NodeMap} from '../ClientTypes';
|
import {FrameworkEvent, Id, NodeMap} from '../ClientTypes';
|
||||||
import {plugin} from '../index';
|
import {plugin} from '../index';
|
||||||
import {Button, Result, Tooltip} from 'antd';
|
import {Button, Result, Tooltip} from 'antd';
|
||||||
@@ -60,6 +60,21 @@ export function FrameworkEventsTable({
|
|||||||
}
|
}
|
||||||
}, [instance.uiActions, isTree, nodeId]);
|
}, [instance.uiActions, isTree, nodeId]);
|
||||||
|
|
||||||
|
const allColumns = useMemo(() => {
|
||||||
|
const customColumnKeys = instance.frameworkEventsCustomColumns.get();
|
||||||
|
|
||||||
|
const customColumns = [...customColumnKeys].map(
|
||||||
|
(customKey: string) =>
|
||||||
|
({
|
||||||
|
key: customKey,
|
||||||
|
title: startCase(customKey),
|
||||||
|
onRender: (row: AugmentedFrameworkEvent) => row.payload?.[customKey],
|
||||||
|
} as DataTableColumn<AugmentedFrameworkEvent>),
|
||||||
|
);
|
||||||
|
|
||||||
|
return staticColumns.concat(customColumns);
|
||||||
|
}, [instance.frameworkEventsCustomColumns]);
|
||||||
|
|
||||||
const onSelectRow = useCallback(
|
const onSelectRow = useCallback(
|
||||||
(event: FrameworkEvent | undefined): void => {
|
(event: FrameworkEvent | undefined): void => {
|
||||||
instance.uiActions.onFocusNode(event?.nodeId);
|
instance.uiActions.onFocusNode(event?.nodeId);
|
||||||
@@ -72,7 +87,7 @@ export function FrameworkEventsTable({
|
|||||||
dataSource={instance.frameworkEvents}
|
dataSource={instance.frameworkEvents}
|
||||||
tableManagerRef={managerRef}
|
tableManagerRef={managerRef}
|
||||||
onSelect={onSelectRow}
|
onSelect={onSelectRow}
|
||||||
columns={columns}
|
columns={allColumns}
|
||||||
extraActions={
|
extraActions={
|
||||||
<Tooltip title="Back to tree">
|
<Tooltip title="Back to tree">
|
||||||
<Button
|
<Button
|
||||||
@@ -101,7 +116,7 @@ export function FrameworkEventsTable({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const columns: DataTableColumn<AugmentedFrameworkEvent>[] = [
|
const staticColumns: DataTableColumn<AugmentedFrameworkEvent>[] = [
|
||||||
{
|
{
|
||||||
key: 'timestamp',
|
key: 'timestamp',
|
||||||
onRender: (row: FrameworkEvent) => formatTimestampMillis(row.timestamp),
|
onRender: (row: FrameworkEvent) => formatTimestampMillis(row.timestamp),
|
||||||
@@ -139,12 +154,4 @@ const columns: DataTableColumn<AugmentedFrameworkEvent>[] = [
|
|||||||
title: 'Thread',
|
title: 'Thread',
|
||||||
onRender: (row: FrameworkEvent) => startCase(row.thread),
|
onRender: (row: FrameworkEvent) => startCase(row.thread),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
key: 'payload',
|
|
||||||
title: 'Payload',
|
|
||||||
onRender: (row: FrameworkEvent) =>
|
|
||||||
Object.keys(row.payload ?? {}).length > 0
|
|
||||||
? JSON.stringify(row.payload)
|
|
||||||
: null,
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ export function plugin(client: PluginClient<Events>) {
|
|||||||
indices: [['nodeId']],
|
indices: [['nodeId']],
|
||||||
limit: 10000,
|
limit: 10000,
|
||||||
});
|
});
|
||||||
|
const frameworkEventsCustomColumns = createState<Set<string>>(new Set());
|
||||||
|
|
||||||
const frameworkEventMetadata = createState<
|
const frameworkEventMetadata = createState<
|
||||||
Map<FrameworkEventType, FrameworkEventMetadata>
|
Map<FrameworkEventType, FrameworkEventMetadata>
|
||||||
@@ -239,8 +240,14 @@ export function plugin(client: PluginClient<Events>) {
|
|||||||
frameScan: FrameScanEvent,
|
frameScan: FrameScanEvent,
|
||||||
nodes: Map<Id, ClientNode>,
|
nodes: Map<Id, ClientNode>,
|
||||||
) {
|
) {
|
||||||
|
const customColumns = frameworkEventsCustomColumns.get();
|
||||||
for (const frameworkEvent of frameScan.frameworkEvents ?? []) {
|
for (const frameworkEvent of frameScan.frameworkEvents ?? []) {
|
||||||
|
for (const key in frameworkEvent.payload) {
|
||||||
|
customColumns.add(key);
|
||||||
|
}
|
||||||
|
|
||||||
const treeRoot = getNode(frameworkEvent.treeId, nodes);
|
const treeRoot = getNode(frameworkEvent.treeId, nodes);
|
||||||
|
|
||||||
const treeRootFirstChild = getNode(first(treeRoot?.children), nodes);
|
const treeRootFirstChild = getNode(first(treeRoot?.children), nodes);
|
||||||
frameworkEvents.append({
|
frameworkEvents.append({
|
||||||
...frameworkEvent,
|
...frameworkEvent,
|
||||||
@@ -248,6 +255,7 @@ export function plugin(client: PluginClient<Events>) {
|
|||||||
rootComponentName: treeRootFirstChild?.name,
|
rootComponentName: treeRootFirstChild?.name,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
frameworkEventsCustomColumns.set(customColumns);
|
||||||
|
|
||||||
if (uiState.isPaused.get() === true) {
|
if (uiState.isPaused.get() === true) {
|
||||||
return;
|
return;
|
||||||
@@ -323,6 +331,7 @@ export function plugin(client: PluginClient<Events>) {
|
|||||||
nodes: nodesAtom,
|
nodes: nodesAtom,
|
||||||
frameworkEvents,
|
frameworkEvents,
|
||||||
frameworkEventMetadata,
|
frameworkEventMetadata,
|
||||||
|
frameworkEventsCustomColumns,
|
||||||
snapshot,
|
snapshot,
|
||||||
metadata,
|
metadata,
|
||||||
perfEvents,
|
perfEvents,
|
||||||
|
|||||||
Reference in New Issue
Block a user