import React from 'react'; import { connect } from 'react-redux'; import { hideHint } from 'Duck/components/player'; import { connectPlayer, selectStorageType, STORAGE_TYPES, selectStorageListNow, selectStorageList, } from 'Player'; import { JSONTree, NoContent } from 'UI'; import { formatMs } from 'App/date'; import { diff } from 'deep-diff'; import { jump } from 'Player'; import Autoscroll from '../Autoscroll'; import BottomBlock from '../BottomBlock/index'; import stl from './storage.module.css'; // const STATE = 'STATE'; // const DIFF = 'DIFF'; // const TABS = [ DIFF, STATE ].map(tab => ({ text: tab, key: tab })); function getActionsName(type) { switch(type) { case STORAGE_TYPES.MOBX: return "MUTATIONS"; case STORAGE_TYPES.VUEX: return "MUTATIONS"; default: return "ACTIONS"; } } @connectPlayer(state => ({ type: selectStorageType(state), list: selectStorageList(state), listNow: selectStorageListNow(state), })) @connect(state => ({ hintIsHidden: state.getIn(['components', 'player', 'hiddenHints', 'storage']), }), { hideHint }) //@withEnumToggle('activeTab', 'setActiveTab', DIFF) export default class Storage extends React.PureComponent { lastBtnRef = React.createRef() focusNextButton() { if (this.lastBtnRef.current) { this.lastBtnRef.current.focus(); } } componentDidMount() { this.focusNextButton(); } componentDidUpdate(prevProps) { if (prevProps.listNow.length !== this.props.listNow.length) { this.focusNextButton(); } } renderDiff(item, prevItem) { if (!prevItem) { return
} const stateDiff = diff(prevItem.state, item.state) console.log(item.state, prevItem.state, stateDiff) const greenPaths = [] const redPaths = [] const yellowPaths = [] if (!stateDiff) { return No diff } // stateDiff.forEach(d => { // try { // let { path, kind, rhs: value } = d; // if (kind === 'A') { // path.slice().push(d.index); // kind = d.item.kind; // value = d.item.rhs; // } // if (kind === 'N') greenPaths.push(d.path.slice().reverse()); // if (kind === 'D') redPaths.push(d.path.slice().reverse()); // if (kind === 'E') yellowPaths.push(d.path.slice().reverse()); // } catch (e) { // console.error(e) // } // }); function renderDiffs(diff, i) { const oldValue = diff.item ? JSON.stringify(diff.item.lhs) : JSON.stringify(diff.lhs) const newValue = diff.item ? JSON.stringify(diff.item.rhs) : JSON.stringify(diff.rhs) const createPath = () => { let path = []; if (diff.path) { path = path.concat(diff.path); } if (typeof(diff.index) !== 'undefined') { path.push(diff.index); } return path.length ? path.join('.') : ''; } return (