This repository has been archived by the owner on Jun 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
/
ActionPreview.jsx
109 lines (96 loc) · 2.76 KB
/
ActionPreview.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// @flow
import React, { Component } from 'react';
import ActionPreviewHeader from './ActionPreviewHeader';
import DiffTab from './tabs/DiffTab';
import StateTab from './tabs/StateTab';
import ActionTab from './tabs/ActionTab';
import type { LabelRenderer } from 'react-json-tree';
import type { Tab, TabName } from './types';
type DefaultProps = {
tabName: TabName
};
type Props = DefaultProps & {
tabs: ((defaultTabs: Tab[]) => Tab[]) | Tab[]
};
const DEFAULT_TABS: Tab[] = [{
name: 'Action',
component: ActionTab
}, {
name: 'Diff',
component: DiffTab
}, {
name: 'State',
component: StateTab
}]
class ActionPreview extends Component<DefaultProps, Props, void> {
static defaultProps: DefaultProps = {
tabName: 'Diff'
}
render() {
const {
styling, delta, error, nextState, onInspectPath, inspectedPath, tabName,
isWideLayout, onSelectTab, action, actions, selectedActionId, startActionId,
computedStates, base16Theme, invertTheme, tabs
} = this.props;
const renderedTabs = (typeof tabs === 'function') ?
tabs(DEFAULT_TABS) :
(tabs ? tabs : DEFAULT_TABS);
const tab = renderedTabs.find(tab => tab.name === tabName);
let TabComponent;
if (tab) {
TabComponent = tab.component;
}
return (
<div key='actionPreview' {...styling('actionPreview')}>
<ActionPreviewHeader
tabs={renderedTabs}
{...{ styling, inspectedPath, onInspectPath, tabName, onSelectTab }}
/>
{!error &&
<div key='actionPreviewContent' {...styling('actionPreviewContent')}>
{TabComponent &&
<TabComponent
labelRenderer={this.labelRenderer}
{...{
styling,
computedStates,
actions,
selectedActionId,
startActionId,
base16Theme,
invertTheme,
isWideLayout,
delta,
action,
nextState
}}
/>
}
</div>
}
{error &&
<div {...styling('stateError')}>{error}</div>
}
</div>
);
}
labelRenderer: LabelRenderer = ([key, ...rest], nodeType, expanded) => {
const { styling, onInspectPath, inspectedPath } = this.props;
return (
<span>
<span {...styling('treeItemKey')}>
{key}
</span>
<span {...styling('treeItemPin')}
onClick={() => onInspectPath([
...inspectedPath.slice(0, inspectedPath.length - 1),
...[key, ...rest].reverse()
])}>
{'(pin)'}
</span>
{!expanded && ': '}
</span>
);
}
}
export default ActionPreview;