From 8860c2842ecee87504ef3cfafd82fab061e0fc3a Mon Sep 17 00:00:00 2001 From: LianaHus Date: Mon, 18 Jan 2021 12:42:28 +0100 Subject: [PATCH] padding and format --- .../src/lib/vm-debugger/dropdown-panel.tsx | 372 +++++++++--------- 1 file changed, 186 insertions(+), 186 deletions(-) diff --git a/libs/remix-ui/debugger-ui/src/lib/vm-debugger/dropdown-panel.tsx b/libs/remix-ui/debugger-ui/src/lib/vm-debugger/dropdown-panel.tsx index fe79e93539..7a6d35b37b 100644 --- a/libs/remix-ui/debugger-ui/src/lib/vm-debugger/dropdown-panel.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/vm-debugger/dropdown-panel.tsx @@ -6,206 +6,206 @@ import { initialState, reducer } from '../../reducers/calldata' import './styles/dropdown-panel.css' export const DropdownPanel = (props: DropdownPanelProps) => { - const [calldataObj, dispatch] = useReducer(reducer, initialState) - const { dropdownName, dropdownMessage, calldata, header, loading, extractFunc, formatSelfFunc, registerEvent, triggerEvent, loadMoreEvent, loadMoreCompletedEvent } = props - const extractDataDefault: ExtractFunc = (item, parent?) => { - const ret: ExtractData = {} - - if (item instanceof Array) { - ret.children = item.map((item, index) => { - return {key: index, value: item} - }) - ret.self = 'Array' - ret.isNode = true - ret.isLeaf = false - } else if (item instanceof Object) { - ret.children = Object.keys(item).map((key) => { - return {key: key, value: item[key]} - }) - ret.self = 'Object' - ret.isNode = true - ret.isLeaf = false - } else { - ret.self = item - ret.children = null - ret.isNode = false - ret.isLeaf = true - } - return ret + const [calldataObj, dispatch] = useReducer(reducer, initialState) + const { dropdownName, dropdownMessage, calldata, header, loading, extractFunc, formatSelfFunc, registerEvent, triggerEvent, loadMoreEvent, loadMoreCompletedEvent } = props + const extractDataDefault: ExtractFunc = (item, parent?) => { + const ret: ExtractData = {} + + if (item instanceof Array) { + ret.children = item.map((item, index) => { + return { key: index, value: item } + }) + ret.self = 'Array' + ret.isNode = true + ret.isLeaf = false + } else if (item instanceof Object) { + ret.children = Object.keys(item).map((key) => { + return { key: key, value: item[key] } + }) + ret.self = 'Object' + ret.isNode = true + ret.isLeaf = false + } else { + ret.self = item + ret.children = null + ret.isNode = false + ret.isLeaf = true } - const formatSelfDefault = (key: string | number, data: ExtractData) => { - return ( -
- - -
- ) + return ret + } + const formatSelfDefault = (key: string | number, data: ExtractData) => { + return ( +
+ + +
+ ) + } + const [state, setState] = useState({ + header: '', + toggleDropdown: false, + message: { + innerText: 'No data available.', + display: 'block' + }, + dropdownContent: { + innerText: '', + display: 'none' + }, + title: { + innerText: '', + display: 'none' + }, + copiableContent: '', + updating: false, + expandPath: [], + data: null + }) + + useEffect(() => { + registerEvent && registerEvent(loadMoreCompletedEvent, (updatedCalldata) => { + dispatch({ type: 'UPDATE_CALLDATA_SUCCESS', payload: updatedCalldata }) + }) + }, []) + + useEffect(() => { + dispatch({ type: 'FETCH_CALLDATA_SUCCESS', payload: calldata }) + }, [calldata]) + + useEffect(() => { + update(calldata) + }, [calldataObj.calldata]) + + useEffect(() => { + message(dropdownMessage) + }, [dropdownMessage]) + + useEffect(() => { + if (loading && !state.updating) setLoading() + }, [loading]) + + const handleToggle = () => { + setState(prevState => { + return { + ...prevState, + toggleDropdown: !prevState.toggleDropdown + } + }) + } + + const handleExpand = (keyPath) => { + if (!state.expandPath.includes(keyPath)) { + state.expandPath.push(keyPath) + } else { + state.expandPath = state.expandPath.filter(path => !path.startsWith(keyPath)) } - const [state, setState] = useState({ - header: '', - toggleDropdown: false, + } + + const message = (message) => { + if (message === state.message.innerText) return + setState(prevState => { + return { + ...prevState, message: { - innerText: 'No data available.', - display: 'block' + innerText: message, + display: message ? 'block' : '' }, - dropdownContent: { - innerText: '', - display: 'none' + updating: false + } + }) + } + + const setLoading = () => { + setState(prevState => { + return { + ...prevState, + message: { + innerText: '', + display: 'none' }, - title: { - innerText: '', - display: 'none' + dropdownContent: { + ...prevState.dropdownContent, + display: 'none' }, copiableContent: '', - updating: false, - expandPath: [], - data: null + updating: true + } }) + } - useEffect(() => { - registerEvent && registerEvent(loadMoreCompletedEvent, (updatedCalldata) => { - dispatch({ type: 'UPDATE_CALLDATA_SUCCESS', payload: updatedCalldata }) - }) - }, []) - - useEffect(() => { - dispatch({ type: 'FETCH_CALLDATA_SUCCESS', payload: calldata }) - }, [calldata]) - - useEffect(() => { - update(calldata) - }, [calldataObj.calldata]) - - useEffect(() => { - message(dropdownMessage) - }, [dropdownMessage]) - - useEffect(() => { - if (loading && !state.updating) setLoading() - }, [loading]) - - const handleToggle = () => { - setState(prevState => { - return { - ...prevState, - toggleDropdown: !prevState.toggleDropdown - } - }) - } - - const handleExpand = (keyPath) => { - if (!state.expandPath.includes(keyPath)) { - state.expandPath.push(keyPath) - } else { - state.expandPath = state.expandPath.filter(path => !path.startsWith(keyPath)) - } - } - - const message = (message) => { - if (message === state.message.innerText) return - setState(prevState => { - return { - ...prevState, - message: { - innerText: message, - display: message ? 'block' : '' - }, - updating: false - } - }) - } + const update = function (calldata) { + let isEmpty = !calldata ? true : false - const setLoading = () => { - setState(prevState => { - return { - ...prevState, - message: { - innerText: '', - display: 'none' - }, - dropdownContent: { - ...prevState.dropdownContent, - display: 'none' - }, - copiableContent: '', - updating: true - } - }) - } + if (calldata && Array.isArray(calldata) && calldata.length === 0) isEmpty = true + else if (calldata && Object.keys(calldata).length === 0 && calldata.constructor === Object) isEmpty = true - const update = function (calldata) { - let isEmpty = !calldata ? true : false - - if(calldata && Array.isArray(calldata) && calldata.length === 0) isEmpty = true - else if(calldata && Object.keys(calldata).length === 0 && calldata.constructor === Object) isEmpty = true - - setState(prevState => { - return { - ...prevState, - dropdownContent: { - ...prevState.dropdownContent, - display: 'block' - }, - copiableContent: JSON.stringify(calldata, null, '\t'), - message: { - innerText: isEmpty ? 'No data available' : '', - display: isEmpty ? 'block' : 'none' - }, - updating: false, - toggleDropdown: !isEmpty, - data: calldata - } - }) - } + setState(prevState => { + return { + ...prevState, + dropdownContent: { + ...prevState.dropdownContent, + display: 'block' + }, + copiableContent: JSON.stringify(calldata, null, '\t'), + message: { + innerText: isEmpty ? 'No data available' : '', + display: isEmpty ? 'block' : 'none' + }, + updating: false, + toggleDropdown: !isEmpty, + data: calldata + } + }) + } + + const renderData = (item: ExtractData, parent, key: string | number, keyPath: string) => { + const data = extractFunc ? extractFunc(item, parent) : extractDataDefault(item, parent) + const children = (data.children || []).map((child) => { + return ( + renderData(child.value, data, child.key, keyPath + '/' + child.key) + ) + }) - const renderData = (item: ExtractData, parent, key: string | number, keyPath: string) => { - const data = extractFunc ? extractFunc(item, parent) : extractDataDefault(item, parent) - const children = (data.children || []).map((child) => { - return ( - renderData(child.value, data, child.key, keyPath + '/' + child.key) - ) - }) - - if (children && children.length > 0 ) { - return ( - handleExpand(keyPath)} expand={state.expandPath.includes(keyPath)}> - - { children } - { data.hasNext && { triggerEvent(loadMoreEvent, [data.cursor]) }} /> } - - - ) - } else { - return handleExpand(keyPath)} expand={state.expandPath.includes(keyPath)} /> - } + if (children && children.length > 0) { + return ( + handleExpand(keyPath)} expand={state.expandPath.includes(keyPath)}> + + {children} + {data.hasNext && { triggerEvent(loadMoreEvent, [data.cursor]) }} />} + + + ) + } else { + return handleExpand(keyPath)} expand={state.expandPath.includes(keyPath)} /> } - - const uniquePanelName = dropdownName.split(' ').join('') - - return ( -
-
-
-
{dropdownName}
{ header } - -
-
- -
- { - state.data && - - { - Object.keys(state.data).map((innerkey) => renderData(state.data[innerkey], state.data, innerkey, innerkey)) - } - - } -
- -
{ state.message.innerText }
-
+ } + + const uniquePanelName = dropdownName.split(' ').join('') + + return ( +
+
+
+
{dropdownName}
{header} + +
+
+ +
+ { + state.data && + + { + Object.keys(state.data).map((innerkey) => renderData(state.data[innerkey], state.data, innerkey, innerkey)) + } + + }
- ) + +
{state.message.innerText}
+
+
+ ) } export default DropdownPanel \ No newline at end of file