2018-12-22 03:10:49 +03:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { DEFAULT_STATE } from './redux';
|
|
|
|
import ActionPreviewHeader from './ActionPreviewHeader';
|
|
|
|
import DiffTab from './tabs/DiffTab';
|
|
|
|
import StateTab from './tabs/StateTab';
|
|
|
|
import ActionTab from './tabs/ActionTab';
|
|
|
|
|
2019-01-10 21:51:14 +03:00
|
|
|
const DEFAULT_TABS = [
|
|
|
|
{
|
|
|
|
name: 'Action',
|
|
|
|
component: ActionTab
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Diff',
|
|
|
|
component: DiffTab
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'State',
|
|
|
|
component: StateTab
|
|
|
|
}
|
|
|
|
];
|
2018-12-22 03:10:49 +03:00
|
|
|
|
|
|
|
class ActionPreview extends Component {
|
|
|
|
static defaultProps = {
|
|
|
|
tabName: DEFAULT_STATE.tabName
|
2019-01-10 21:51:14 +03:00
|
|
|
};
|
2018-12-22 03:10:49 +03:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
2019-01-10 21:51:14 +03:00
|
|
|
styling,
|
|
|
|
delta,
|
|
|
|
error,
|
|
|
|
nextState,
|
|
|
|
onInspectPath,
|
|
|
|
inspectedPath,
|
|
|
|
tabName,
|
|
|
|
isWideLayout,
|
|
|
|
onSelectTab,
|
|
|
|
action,
|
|
|
|
actions,
|
|
|
|
selectedActionId,
|
|
|
|
startActionId,
|
|
|
|
computedStates,
|
|
|
|
base16Theme,
|
|
|
|
invertTheme,
|
|
|
|
tabs,
|
|
|
|
dataTypeKey,
|
|
|
|
monitorState,
|
|
|
|
updateMonitorState
|
2018-12-22 03:10:49 +03:00
|
|
|
} = this.props;
|
|
|
|
|
2019-01-10 21:51:14 +03:00
|
|
|
const renderedTabs =
|
|
|
|
typeof tabs === 'function'
|
|
|
|
? tabs(DEFAULT_TABS)
|
|
|
|
: tabs
|
|
|
|
? tabs
|
|
|
|
: DEFAULT_TABS;
|
2018-12-22 03:10:49 +03:00
|
|
|
|
2019-01-10 21:51:14 +03:00
|
|
|
const { component: TabComponent } =
|
|
|
|
renderedTabs.find(tab => tab.name === tabName) ||
|
|
|
|
renderedTabs.find(tab => tab.name === DEFAULT_STATE.tabName);
|
2018-12-22 03:10:49 +03:00
|
|
|
|
|
|
|
return (
|
2019-01-10 20:23:33 +03:00
|
|
|
<div key="actionPreview" {...styling('actionPreview')}>
|
2018-12-22 03:10:49 +03:00
|
|
|
<ActionPreviewHeader
|
|
|
|
tabs={renderedTabs}
|
|
|
|
{...{ styling, inspectedPath, onInspectPath, tabName, onSelectTab }}
|
|
|
|
/>
|
2019-01-10 21:51:14 +03:00
|
|
|
{!error && (
|
2019-01-10 20:23:33 +03:00
|
|
|
<div key="actionPreviewContent" {...styling('actionPreviewContent')}>
|
2018-12-22 03:10:49 +03:00
|
|
|
<TabComponent
|
|
|
|
labelRenderer={this.labelRenderer}
|
|
|
|
{...{
|
|
|
|
styling,
|
|
|
|
computedStates,
|
|
|
|
actions,
|
|
|
|
selectedActionId,
|
|
|
|
startActionId,
|
|
|
|
base16Theme,
|
|
|
|
invertTheme,
|
|
|
|
isWideLayout,
|
|
|
|
dataTypeKey,
|
|
|
|
delta,
|
|
|
|
action,
|
|
|
|
nextState,
|
|
|
|
monitorState,
|
|
|
|
updateMonitorState
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2019-01-10 21:51:14 +03:00
|
|
|
)}
|
|
|
|
{error && <div {...styling('stateError')}>{error}</div>}
|
2018-12-22 03:10:49 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
labelRenderer = ([key, ...rest], nodeType, expanded) => {
|
|
|
|
const { styling, onInspectPath, inspectedPath } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span>
|
2019-01-10 21:51:14 +03:00
|
|
|
<span {...styling('treeItemKey')}>{key}</span>
|
|
|
|
<span
|
|
|
|
{...styling('treeItemPin')}
|
|
|
|
onClick={() =>
|
|
|
|
onInspectPath([
|
|
|
|
...inspectedPath.slice(0, inspectedPath.length - 1),
|
|
|
|
...[key, ...rest].reverse()
|
|
|
|
])
|
|
|
|
}
|
|
|
|
>
|
2018-12-22 03:10:49 +03:00
|
|
|
{'(pin)'}
|
|
|
|
</span>
|
|
|
|
{!expanded && ': '}
|
|
|
|
</span>
|
|
|
|
);
|
2019-01-10 21:51:14 +03:00
|
|
|
};
|
2018-12-22 03:10:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default ActionPreview;
|