Skip to content

Commit

Permalink
Added Reset to original functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
hristo-kanchev committed Sep 10, 2019
1 parent a5cc62b commit c4ad679
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ function useEditableValue(initialValue: any): [any, Function] {
) {
if (shouldStringify) {
setEditableValue(JSON.stringify(value));
} else {
setEditableValue(value);
}

setEditableValue(value);
}

return [editableValue, setEditableValueWithStringify];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import {copy} from 'clipboard-js';
import React, {useEffect, useCallback, useState} from 'react';
import React, {useEffect, useMemo, useCallback, useState} from 'react';
import Button from '../Button';
import ButtonIcon from '../ButtonIcon';
import KeyValue from './KeyValue';
Expand Down Expand Up @@ -40,6 +40,12 @@ export default function InspectedElementTree({
}: Props) {
const [entries, setEntries] = useState(null);
const [entryToAdd, setEntryToAdd] = useState(null);
const initialEntries = useMemo(() => {
if (data != null) {
return Object.entries(data).sort(alphaSortEntries);
}
return [];
}, []);

useEffect(
() => {
Expand All @@ -59,6 +65,13 @@ export default function InspectedElementTree({
[data],
);

const handleResetEntries = useCallback(
() => {
setEntries(initialEntries);
},
[data],
);

const handleEntryAdd = useCallback(
() => {
setEntryToAdd({
Expand Down Expand Up @@ -97,16 +110,21 @@ export default function InspectedElementTree({
<div className={styles.InspectedElementTree}>
<div className={styles.HeaderRow}>
<div className={styles.Header}>{label}</div>
{!isEmpty && (
<Button onClick={handleCopy} title="Copy to clipboard">
<ButtonIcon type="copy" />
</Button>
)}
{canAddEntries && (
<Button onClick={handleEntryAdd} title={`Add ${label}`}>
<ButtonIcon type="add" />
</Button>
)}
{canAddEntries && (
<Button onClick={handleResetEntries} title={`Reset ${label}`}>
<ButtonIcon type="undo" />
</Button>
)}
{!isEmpty && (
<Button onClick={handleCopy} title="Copy to clipboard">
<ButtonIcon type="copy" />
</Button>
)}
</div>
{isEmpty && <div className={styles.Empty}>None</div>}
{!isEmpty &&
Expand Down
11 changes: 1 addition & 10 deletions packages/react-devtools-shell/src/app/EditableProps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,7 @@ export default function EditableProps() {
<Fragment>
<h1>Editable props</h1>
<strong>Class</strong>
<StatefulClass
name="Brian"
toggle={true}
newLineStringProp={'Hello \n World'}
nanProp={NaN}
infinityProp={Infinity}
minusInfinityProp={-Infinity}
emptyStringProp={''}
nullProp={null}
/>
<StatefulClass name="Brian" toggle={true} />
<strong>Function</strong>
<StatefulFunction name="Brian" />
<strong>Memoized Class</strong>
Expand Down

0 comments on commit c4ad679

Please sign in to comment.