Inspectable complex hook values

This commit is contained in:
Brian Vaughn committed 2019-02-14 21:55:09 -08:00
1 parent 47a5fd59cb
commit 0008bb00d7
4 files changed
+84 -24

No files matched your search

+57 -20
View File
@@ -2,6 +2,7 @@
import React from 'react';
import { getMetaValueLabel } from './utils';
import { KeyValue } from './InspectedElementTree';
import styles from './HooksTree.css';
import type { HooksNode, HooksTree } from 'src/backend/types';
@@ -34,31 +35,67 @@ function HooksNodeView({ hooksNode }: { hooksNode: HooksNode }) {
const isCustomHook = subHooks.length > 0;
// Format data for display to mimic the props/state/context for now.
const type = typeof value;
let displayValue;
if (isCustomHook && value === undefined) {
displayValue = null;
} else if (
type === 'number' ||
type === 'string' ||
type === 'boolean' ||
value == null
) {
let isComplexDisplayValue = false;
// Format data for display to mimic the props/state/context for now.
if (type === 'number' || type === 'string' || type === 'boolean') {
displayValue = value;
} else {
displayValue = getMetaValueLabel(value);
} else if (value === null) {
displayValue = 'null';
} else if (value === undefined) {
displayValue = null;
} else if (Array.isArray(value)) {
isComplexDisplayValue = true;
displayValue = 'Array';
} else if (type === 'object') {
isComplexDisplayValue = true;
displayValue = 'Object';
}
return (
<div className={styles.HooksNode}>
<div className={styles.NameValueRow}>
<span className={styles.Name}>{name}: </span> {/* $FlowFixMe */}
<span className={styles.Value}>{displayValue}</span>
</div>
<InnerHooksTreeView hooksTree={subHooks} />
</div>
);
if (isCustomHook) {
if (isComplexDisplayValue) {
return (
<div className={styles.HooksNode}>
<div className={styles.NameValueRow}>
<span className={styles.Name}>{name}: </span>
</div>
<KeyValue depth={1} name="DebugValue" value={value} />
<InnerHooksTreeView hooksTree={subHooks} />
</div>
);
} else {
return (
<div className={styles.HooksNode}>
<div className={styles.NameValueRow}>
<span className={styles.Name}>{name}: </span> {/* $FlowFixMe */}
<span className={styles.Value}>{displayValue}</span>
</div>
<InnerHooksTreeView hooksTree={subHooks} />
</div>
);
}
} else {
if (isComplexDisplayValue) {
return (
<div className={styles.HooksNode}>
<KeyValue depth={0} name={name} value={value} />
</div>
);
} else {
return (
<div className={styles.HooksNode}>
<div className={styles.NameValueRow}>
<span className={styles.Name}>{name}: </span>
{/* $FlowFixMe */}
<span className={styles.Value}>{displayValue}</span>
</div>
</div>
);
}
}
}
// $FlowFixMe
+6 -1
View File
@@ -47,7 +47,7 @@ type KeyValueProps = {|
value: any,
|};
function KeyValue({ depth, name, value }: KeyValueProps) {
export function KeyValue({ depth, name, value }: KeyValueProps) {
const dataType = typeof value;
const isSimpleType =
dataType === 'number' ||
@@ -64,6 +64,10 @@ function KeyValue({ depth, name, value }: KeyValueProps) {
displayValue = `"${value}"`;
} else if (dataType === 'boolean') {
displayValue = value ? 'true' : 'false';
} else if (value === null) {
displayValue = 'null';
} else if (value === undefined) {
displayValue = 'undefined';
}
children = (
@@ -99,6 +103,7 @@ function KeyValue({ depth, name, value }: KeyValueProps) {
</div>
);
} else {
// $FlowFixMe
children = Object.entries(value).map(([name, value]) => (
<KeyValue key={name} depth={depth + 1} name={name} value={value} />
));
+3 -3
View File
@@ -132,13 +132,13 @@ function updateThemeVariables(theme: Theme): void {
updateStyleHelper(theme, 'color-dim');
updateStyleHelper(theme, 'color-dimmer');
updateStyleHelper(theme, 'color-dimmest');
updateStyleHelper(theme, 'color-search-match');
updateStyleHelper(theme, 'color-search-match-current');
updateStyleHelper(theme, 'color-text-color');
updateStyleHelper(theme, 'color-jsx-arrow-brackets');
updateStyleHelper(theme, 'color-jsx-arrow-brackets-inverted');
updateStyleHelper(theme, 'color-tree-node-selected');
updateStyleHelper(theme, 'color-tree-node-hover');
updateStyleHelper(theme, 'color-search-match');
updateStyleHelper(theme, 'color-search-match-current');
updateStyleHelper(theme, 'color-text-color');
}
export { SettingsContext, SettingsContextController };