/**
* 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 {Input, Typography} from 'antd';
import {Panel, theme, Layout} from 'flipper-plugin';
import React from 'react';
import {
ClientNode,
Inspectable,
InspectableObject,
Metadata,
} from '../../ClientTypes';
import {MetadataMap} from '../../DesktopTypes';
import {NoData} from '../sidebar/inspector/NoData';
import {css, cx} from '@emotion/css';
import {upperFirst} from 'lodash';
export function AttributesInspector({
node,
metadata,
}: {
node: ClientNode;
metadata: MetadataMap;
}) {
const keys = Object.keys(node.attributes);
const sections = keys
.map((key, _) => {
/**
* The node top-level attributes refer to the displayable panels.
* The panel name is obtained by querying the metadata.
* The inspectable contains the actual attributes belonging to each panel.
*/
const metadataId: number = Number(key);
const sectionMetadata = metadata.get(metadataId);
if (sectionMetadata == null) {
return null;
}
const sectionAttributes = node.attributes[
metadataId
] as InspectableObject;
return AttributeSection(
metadata,
sectionMetadata.name,
sectionAttributes,
);
})
.filter((section) => section != null);
if (sections.length === 0) {
return ;
}
return <>{sections}>;
}
function AttributeSection(
metadataMap: MetadataMap,
name: string,
inspectable: InspectableObject,
) {
const children = Object.keys(inspectable.fields)
.map((key) => {
const metadataId: number = Number(key);
const attributeMetadata = metadataMap.get(metadataId);
if (attributeMetadata == null) {
return null;
}
const attributeValue = inspectable.fields[metadataId];
const attributeName =
upperFirst(attributeMetadata?.name) ?? String(metadataId);
return (
{attributeName}
);
})
.filter((attr) => attr != null);
if (children.length > 0) {
return (
{...children}
);
} else {
return null;
}
}
/**
* disables hover and focsued states
*/
const readOnlyInput = css`
:hover {
border-color: ${theme.disabledColor} !important;
}
:focus {
border-color: ${theme.disabledColor} !important;
box-shadow: none !important;
}
box-shadow: none !important;
border-color: ${theme.disabledColor} !important;
padding: 2px 4px 2px 4px;
min-height: 20px !important; //this is for text area
`;
function StyledInput({
value,
color,
mutable,
rightAddon,
}: {
value: any;
color: string;
mutable: boolean;
rightAddon?: string;
}) {
return (
);
}
function StyledTextArea({
value,
color,
mutable,
}: {
value: any;
color: string;
mutable: boolean;
rightAddon?: string;
}) {
return (
);
}
const boolColor = '#C41D7F';
const stringColor = '#AF5800';
const enumColor = '#006D75';
const numberColor = '#003EB3';
type NumberGroupValue = {value: number; addonText: string};
function NumberGroup({values}: {values: NumberGroupValue[]}) {
return (
{values.map(({value, addonText}, idx) => (
))}
);
}
function AttributeValue({
inspectable,
}: {
attributeMetadata: Metadata;
metadataMap: MetadataMap;
name: string;
inspectable: Inspectable;
level: number;
}) {
switch (inspectable.type) {
case 'boolean':
return (
);
case 'text':
return (
);
case 'number':
return (
);
case 'enum':
return (
);
case 'size':
return (
);
case 'coordinate':
return (
);
case 'coordinate3d':
return (
);
case 'space':
return (
);
case 'bounds':
return (
);
}
return null;
}