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
87 lines (80 loc) · 2.54 KB
/
index.tsx
File metadata and controls
87 lines (80 loc) · 2.54 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
import * as React from 'react'
import { useAppState } from '../../overmind'
import * as styles from './styles'
import ActionOperator from '../ActionOperator'
import {
getOperatorId,
nameToColor,
getOperatorsByPath,
} from '../../overmind/utils'
import { OperatorsByPath, Action as TAction } from '../../overmind/types'
type Props = {
action: TAction
inline?: boolean
}
const Action: React.FunctionComponent<Props> = ({ action, inline }) => {
const state = useAppState()
const operatorsByPath = getOperatorsByPath(action)
function renderOperators(operatorsByPath: OperatorsByPath) {
return operatorsByPath.map((operatorByPath, index) => {
const flushReference =
state.currentApp.flushByOperatorId[
getOperatorId(operatorByPath.operator)
]
const flush =
flushReference && state.currentApp.flushes[flushReference.flushId]
return (
<div
key={operatorByPath.path + index}
style={{
opacity: operatorByPath.operator.isSkipped ? 0.5 : 1,
}}
>
<ActionOperator
operator={operatorByPath.operator}
flush={flush}
value={operatorByPath.value}
/>
{operatorByPath.operator.isIntercepted ? (
<div className={styles.breakStyle}>break</div>
) : null}
{operatorByPath.childrenByPath.length
? operatorByPath.childrenByPath.map(
(childOperatorsByPath, index) => (
<div key={index} className={styles.operatorChildren}>
<div
className={styles.path}
style={{
backgroundColor: nameToColor(
childOperatorsByPath[0].path
),
}}
>
{childOperatorsByPath[0].path}
</div>
<div className={styles.pathOperators}>
{renderOperators(childOperatorsByPath)}
</div>
</div>
)
)
: null}
</div>
)
})
}
if (inline) {
return (
<div className={styles.innerWrapper}>
<div className={styles.innerTitle}>{action.actionName}</div>
<div className={styles.innerContent}>
{operatorsByPath.map(renderOperators)}
</div>
</div>
)
}
return (
<div className={styles.wrapper}>{operatorsByPath.map(renderOperators)}</div>
)
}
export default Action