import React from 'react'; import { connect } from 'react-redux'; import { hideHint } from 'Duck/components/player'; import { connectPlayer, selectStorageType, STORAGE_TYPES, selectStorageListNow, selectStorageList, } from 'Player/store'; 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 DiffRow from './DiffRow'; import cn from 'classnames'; import stl from './storage.module.css'; import { Tooltip } from 'react-tippy' // 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: 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(); state = { showDiffs: false }; 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) { // we don't have state before first action return
; } const stateDiff = diff(prevItem.state, item.state); if (!stateDiff) { return (
No diff
); } return (
{stateDiff.map((d, i) => this.renderDiffs(d, i))}
); } renderDiffs(diff, i) { const path = this.createPath(diff); return ( ); } createPath = (diff) => { let path = []; if (diff.path) { path = path.concat(diff.path); } if (typeof diff.index !== 'undefined') { path.push(diff.index); } const pathStr = path.length ? path.join('.') : ''; return pathStr; }; ensureString(actionType) { if (typeof actionType === 'string') return actionType; return 'UNKNOWN'; } goNext = () => { const { list, listNow } = this.props; jump(list[listNow.length].time, list[listNow.length]._index); }; renderTab() { const { listNow } = this.props; if (listNow.length === 0) { return 'Not initialized'; //? } return ; } renderItem(item, i, prevItem) { const { type, listNow, list } = this.props; let src; let name; switch (type) { case STORAGE_TYPES.REDUX: case STORAGE_TYPES.NGRX: src = item.action; name = src && src.type; break; case STORAGE_TYPES.VUEX: src = item.mutation; name = src && src.type; break; case STORAGE_TYPES.MOBX: src = item.payload; name = `@${item.type} ${src && src.type}`; break; case STORAGE_TYPES.ZUSTAND: src = null; name = item.mutation.join(''); } if (src !== null && !this.state.showDiffs) { this.setState({ showDiffs: true }) } return (
{src === null ? (
{' '} {name}{' '}
) : ( <> {this.renderDiff(item, prevItem)}
)}
{typeof item.duration === 'number' && (
{formatMs(item.duration)}
)}
{i + 1 < listNow.length && ( )} {i + 1 === listNow.length && i + 1 < list.length && ( )}
); } render() { const { type, listNow, list, hintIsHidden } = this.props; const showStore = type !== STORAGE_TYPES.MOBX; return ( {list.length > 0 && (
{showStore &&

{'STATE'}

} {this.state.showDiffs ? (

DIFFS

) : null}

{getActionsName(type)}

TTE

)}
{ 'Inspect your application state while you’re replaying your users sessions. OpenReplay supports ' } Redux {', '} VueX {', '} Pinia {', '} Zustand {', '} MobX {' and '} NgRx .

) : null } size="small" show={listNow.length === 0} > {showStore && (
{listNow.length === 0 ? (
{'Empty state.'}
) : ( this.renderTab() )}
)}
{listNow.map((item, i) => this.renderItem(item, i, i > 0 ? listNow[i - 1] : undefined) )}
); } }