ElementsInspector: Allow for custom row decorations.
Summary: Adds the capability to customize rows in the elements inspector via a callback. Reviewed By: danielbuechele Differential Revision: D15738355 fbshipit-source-id: 27b91a74535736318b7fdb9d2eb44dfa20b4d77b
This commit is contained in:
committed by
Facebook Github Bot
parent
1d38078982
commit
844cabd5d3
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
import {Component} from 'react';
|
import {Component} from 'react';
|
||||||
import FlexRow from '../FlexRow.js';
|
import FlexRow from '../FlexRow.js';
|
||||||
import {Elements} from './elements.js';
|
import {Elements, type DecorateRow} from './elements.js';
|
||||||
import type {ContextMenuExtension} from 'flipper';
|
import type {ContextMenuExtension} from 'flipper';
|
||||||
|
|
||||||
export type ElementID = string;
|
export type ElementID = string;
|
||||||
@@ -65,6 +65,7 @@ export default class ElementsInspector extends Component<{
|
|||||||
useAppSidebar?: boolean,
|
useAppSidebar?: boolean,
|
||||||
alternateRowColor?: boolean,
|
alternateRowColor?: boolean,
|
||||||
contextMenuExtensions?: Array<ContextMenuExtension>,
|
contextMenuExtensions?: Array<ContextMenuExtension>,
|
||||||
|
decorateRow?: DecorateRow,
|
||||||
}> {
|
}> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
alternateRowColor: true,
|
alternateRowColor: true,
|
||||||
@@ -81,6 +82,7 @@ export default class ElementsInspector extends Component<{
|
|||||||
searchResults,
|
searchResults,
|
||||||
alternateRowColor,
|
alternateRowColor,
|
||||||
contextMenuExtensions,
|
contextMenuExtensions,
|
||||||
|
decorateRow,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -96,6 +98,7 @@ export default class ElementsInspector extends Component<{
|
|||||||
elements={elements}
|
elements={elements}
|
||||||
alternateRowColor={alternateRowColor}
|
alternateRowColor={alternateRowColor}
|
||||||
contextMenuExtensions={contextMenuExtensions}
|
contextMenuExtensions={contextMenuExtensions}
|
||||||
|
decorateRow={decorateRow}
|
||||||
/>
|
/>
|
||||||
</FlexRow>
|
</FlexRow>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import type {
|
|||||||
} from './ElementsInspector.js';
|
} from './ElementsInspector.js';
|
||||||
import {reportInteraction} from '../../../utils/InteractionTracker';
|
import {reportInteraction} from '../../../utils/InteractionTracker';
|
||||||
import ContextMenu from '../ContextMenu.js';
|
import ContextMenu from '../ContextMenu.js';
|
||||||
import {PureComponent} from 'react';
|
import {PureComponent, type Element as ReactElement} from 'react';
|
||||||
import FlexRow from '../FlexRow.js';
|
import FlexRow from '../FlexRow.js';
|
||||||
import FlexColumn from '../FlexColumn.js';
|
import FlexColumn from '../FlexColumn.js';
|
||||||
import Glyph from '../Glyph.js';
|
import Glyph from '../Glyph.js';
|
||||||
@@ -205,6 +205,7 @@ type ElementsRowProps = {
|
|||||||
onElementHovered: ?(key: ?ElementID) => void,
|
onElementHovered: ?(key: ?ElementID) => void,
|
||||||
style?: Object,
|
style?: Object,
|
||||||
contextMenuExtensions: Array<ContextMenuExtension>,
|
contextMenuExtensions: Array<ContextMenuExtension>,
|
||||||
|
decorateRow?: DecorateRow,
|
||||||
};
|
};
|
||||||
|
|
||||||
type ElementsRowState = {|
|
type ElementsRowState = {|
|
||||||
@@ -283,6 +284,7 @@ class ElementsRow extends PureComponent<ElementsRowProps, ElementsRowState> {
|
|||||||
style,
|
style,
|
||||||
even,
|
even,
|
||||||
matchingSearchQuery,
|
matchingSearchQuery,
|
||||||
|
decorateRow,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const hasChildren = element.children && element.children.length > 0;
|
const hasChildren = element.children && element.children.length > 0;
|
||||||
|
|
||||||
@@ -312,7 +314,9 @@ class ElementsRow extends PureComponent<ElementsRowProps, ElementsRowState> {
|
|||||||
))
|
))
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const decoration = (() => {
|
const decoration = decorateRow
|
||||||
|
? decorateRow(element)
|
||||||
|
: (() => {
|
||||||
switch (element.decoration) {
|
switch (element.decoration) {
|
||||||
case 'litho':
|
case 'litho':
|
||||||
return <DecorationImage src="icons/litho-logo.png" />;
|
return <DecorationImage src="icons/litho-logo.png" />;
|
||||||
@@ -381,6 +385,8 @@ const ElementsBox = styled(FlexColumn)({
|
|||||||
overflow: 'auto',
|
overflow: 'auto',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export type DecorateRow = Element => ?ReactElement<empty>;
|
||||||
|
|
||||||
type ElementsProps = {|
|
type ElementsProps = {|
|
||||||
root: ?ElementID,
|
root: ?ElementID,
|
||||||
selected: ?ElementID,
|
selected: ?ElementID,
|
||||||
@@ -392,6 +398,7 @@ type ElementsProps = {|
|
|||||||
onElementHovered: ?(key: ?ElementID) => void,
|
onElementHovered: ?(key: ?ElementID) => void,
|
||||||
alternateRowColor?: boolean,
|
alternateRowColor?: boolean,
|
||||||
contextMenuExtensions?: Array<ContextMenuExtension>,
|
contextMenuExtensions?: Array<ContextMenuExtension>,
|
||||||
|
decorateRow?: DecorateRow,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
type ElementsState = {|
|
type ElementsState = {|
|
||||||
@@ -562,6 +569,7 @@ export class Elements extends PureComponent<ElementsProps, ElementsState> {
|
|||||||
focused,
|
focused,
|
||||||
searchResults,
|
searchResults,
|
||||||
contextMenuExtensions,
|
contextMenuExtensions,
|
||||||
|
decorateRow,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const {flatElements} = this.state;
|
const {flatElements} = this.state;
|
||||||
|
|
||||||
@@ -600,6 +608,7 @@ export class Elements extends PureComponent<ElementsProps, ElementsState> {
|
|||||||
elements={elements}
|
elements={elements}
|
||||||
childrenCount={childrenCount}
|
childrenCount={childrenCount}
|
||||||
contextMenuExtensions={contextMenuExtensions || []}
|
contextMenuExtensions={contextMenuExtensions || []}
|
||||||
|
decorateRow={decorateRow}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user