forked from cerebral/overmind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
204 lines (197 loc) · 6.31 KB
/
index.tsx
File metadata and controls
204 lines (197 loc) · 6.31 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import { createElement, SFC } from 'react'
import { useOvermind } from '../../overmind'
import {
Operator as OperatorType,
EventType,
Effect,
Mutation,
} from '../../overmind/types'
import ValueInspector from '../ValueInspector'
import Icon from '../common/Icon'
import Path from '../ActionPath'
import * as styles from './styles'
import * as actionStyles from '../Action/styles'
import * as textStyles from '../../styles/text'
import { css } from 'emotion'
type Props = {
prevOperator: OperatorType
operator: OperatorType
value: any
operatorIndex: number
}
const ActionOperator: SFC<Props> = ({
prevOperator,
operator,
value,
operatorIndex,
}) => {
const { state, actions } = useOvermind()
const isExpanded = state.expandAllActionDetails || !operator.isCollapsed
return (
<div>
{value === undefined ? null : (
<div className={actionStyles.pipe}>
<Path showPathTag={false} visible={false}>
{operator.path.length ? (
<span className={textStyles.hint}>
<b>{operator.path.join('.')}</b>
</span>
) : null}
</Path>
<ValueInspector value={value} small />
</div>
)}
<div className={actionStyles.pipe}>
<Path
visible={
Boolean(prevOperator) &&
Boolean(operator.path.length) &&
prevOperator.path.join('.') !== operator.path.join('.')
}
>
{operator.path.length ? (
<span className={textStyles.hint}>
<b>{operator.path.join('.')}</b>
</span>
) : null}
</Path>
<div
className={css(
styles.operator(
operator.type === 'action'
? 'var(--color-purple)'
: 'var(--color-primary)'
),
operator.events.length && styles.operatorClickable
)}
onClick={
operator.events.length
? () => actions.toggleCollapsedOperator(operatorIndex)
: null
}
>
<div className={styles.operatorHeader}>
<span
className={css(
textStyles.normal,
textStyles.denseNormal,
styles.operatorType
)}
>
{operator.type}
</span>
<span
className={css(
textStyles.white,
textStyles.normal,
textStyles.denseNormal
)}
>
{operator.name}
</span>
{operator.events.length ? (
<span className={css(textStyles.hint, styles.chevron)}>
{isExpanded ? (
<Icon>chevron-down</Icon>
) : (
<Icon>chevron-up</Icon>
)}
</span>
) : null}
</div>
{isExpanded ? (
<div onClick={(event) => event.stopPropagation()}>
{operator.events.map((event, index) => {
if (event.type === EventType.Effect) {
const effect = event.data as Effect
return (
<div
className={css(
styles.operatorItem,
effect.isPending && styles.pendingOperatorItem
)}
key={index}
>
<span
className={css(
textStyles.description,
textStyles.purple,
textStyles.monospace
)}
>
{effect.name
? effect.name + '.' + effect.method
: effect.method}
</span>
{effect.args.length ? (
<ValueInspector
small
value={
effect.args.length > 1
? effect.args
: effect.args[0]
}
/>
) : null}
{effect.result === undefined && !effect.error ? null : (
<span
className={css(
textStyles.description,
textStyles.monospace
)}
>
=>
</span>
)}
{effect.result === undefined ? null : (
<ValueInspector small value={effect.result} />
)}
{effect.error ? (
<span className={styles.effectError}>
{effect.error}
</span>
) : null}
</div>
)
}
if (event.type === EventType.Mutation) {
const mutation = event.data as Mutation
return (
<div className={styles.operatorItem} key={index}>
<span
className={css(
textStyles.description,
textStyles.yellow,
textStyles.monospace
)}
>
{mutation.method}
</span>
<span
className={css(
textStyles.description,
textStyles.monospace
)}
>
{mutation.path}
</span>
<ValueInspector
small
value={
mutation.args.length > 1
? mutation.args
: mutation.args[0]
}
/>
</div>
)
}
})}
</div>
) : null}
</div>
</div>
</div>
)
}
export default ActionOperator