From b4d80c3f800666c7331b158e94665c8c52add21e Mon Sep 17 00:00:00 2001 From: Luke De Feo Date: Thu, 26 Oct 2023 05:24:30 -0700 Subject: [PATCH] Add support for complex types Summary: Complex nested arrays and objects are displayed in a modal since there isnt enough space to it practically. Not many attributes in practice fall into this category Reviewed By: lblasa Differential Revision: D50595981 fbshipit-source-id: b1eda93c448de19c8803d64eb4cf105e2b6636a8 --- .../sidebarV2/AttributesInspector.tsx | 74 +++++++++++++++++-- .../ui-debugger/utils/dataTransform.tsx | 2 +- 2 files changed, 68 insertions(+), 8 deletions(-) diff --git a/desktop/plugins/public/ui-debugger/components/sidebarV2/AttributesInspector.tsx b/desktop/plugins/public/ui-debugger/components/sidebarV2/AttributesInspector.tsx index 34d77f6e4..c9ab582aa 100644 --- a/desktop/plugins/public/ui-debugger/components/sidebarV2/AttributesInspector.tsx +++ b/desktop/plugins/public/ui-debugger/components/sidebarV2/AttributesInspector.tsx @@ -7,9 +7,9 @@ * @format */ -import {Divider, Input, Typography} from 'antd'; -import {Panel, theme, Layout, styled} from 'flipper-plugin'; -import React from 'react'; +import {Button, Divider, Input, Modal, Typography} from 'antd'; +import {DataInspector, Panel, theme, Layout, styled} from 'flipper-plugin'; +import React, {useState} from 'react'; import { ClientNode, Color, @@ -23,6 +23,12 @@ import {css, cx} from '@emotion/css'; import {upperFirst, sortBy} from 'lodash'; import {any} from 'lodash/fp'; import {InspectableColor} from '../../ClientTypes'; +import {transformAny} from '../../utils/dataTransform'; + +type ModalData = { + data: unknown; + title: string; +}; export function AttributesInspector({ node, @@ -31,11 +37,21 @@ export function AttributesInspector({ node: ClientNode; metadata: MetadataMap; }) { + const [modalData, setModalData] = useState(null); + + const showComplexTypeModal = (modaldata: ModalData) => { + setModalData(modaldata); + }; + + const handleCancel = () => { + setModalData(null); + }; + const keys = Object.keys(node.attributes); const sections = keys .map((key, _) => { /** - * The node top-level attributes refer to the displayable panels. + * The node top-level attributes refer to the displayable panels aka sections. * The panel name is obtained by querying the metadata. * The inspectable contains the actual attributes belonging to each panel. */ @@ -52,6 +68,7 @@ export function AttributesInspector({ metadata, sectionMetadata.name, sectionAttributes, + showComplexTypeModal, ); }) .filter((section) => section != null); @@ -59,13 +76,28 @@ export function AttributesInspector({ if (sections.length === 0) { return ; } - return <>{sections}; + return ( + <> + {modalData != null && ( + + + + )} + {sections} + + ); } function AttributeSection( metadataMap: MetadataMap, name: string, inspectable: InspectableObject, + onDisplayModal: (modaldata: ModalData) => void, ) { const attributesOrSubSubsections = Object.entries(inspectable.fields).map( ([fieldKey, attributeValue]) => { @@ -108,6 +140,7 @@ function AttributeSection( if (attributeValue.type === 'object') { return ( void; }) { return ( @@ -166,6 +202,7 @@ function SubSection({ return ( void; }) { return ( @@ -205,11 +244,11 @@ function NamedAttribute({ @@ -320,13 +359,16 @@ function NumberGroup({values}: {values: NumberGroupValue[]}) { } function AttributeValue({ + metadataMap, + name, + onDisplayModal, inspectable, }: { + onDisplayModal: (modaldata: ModalData) => void; attributeMetadata: Metadata; metadataMap: MetadataMap; name: string; inspectable: Inspectable; - level: number; }) { switch (inspectable.type) { case 'boolean': @@ -416,6 +458,24 @@ function AttributeValue({ case 'color': return ; + case 'array': + case 'object': + return ( + + ); } return null; } diff --git a/desktop/plugins/public/ui-debugger/utils/dataTransform.tsx b/desktop/plugins/public/ui-debugger/utils/dataTransform.tsx index bbec29194..0adf07ca4 100644 --- a/desktop/plugins/public/ui-debugger/utils/dataTransform.tsx +++ b/desktop/plugins/public/ui-debugger/utils/dataTransform.tsx @@ -16,7 +16,7 @@ import { MetadataId, } from '../ClientTypes'; -function transformAny( +export function transformAny( metadata: Map, inspectable: Inspectable, ): any {