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
131 lines (123 loc) · 4.24 KB
/
index.tsx
File metadata and controls
131 lines (123 loc) · 4.24 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
import * as React from 'react'
import * as styles from './styles'
import { useAppState } from '../../overmind'
import {
HistoryRecordType,
MutationHistoryRecord,
FlushHistoryRecord,
EffectHistoryRecord,
} from '../../overmind/types'
import ValueInspector from '../ValueInspector'
import {
FaCode,
FaLink,
FaSave,
FaDatabase,
FaClock,
FaCheck,
} from 'react-icons/fa'
const History: React.FunctionComponent = () => {
const state = useAppState()
return (
<div className={styles.wrapper}>
{state.history.map((record, index) => {
switch (record.type) {
case HistoryRecordType.Mutation: {
const mutationRecord = record as MutationHistoryRecord
return (
<div className={styles.recordWrapper} key={index}>
<div className={styles.label}>
<FaDatabase />
</div>
<div className={styles.actionName}>
{mutationRecord.actionName}
</div>
<div className={styles.mutationType}>
{mutationRecord.data.method}
</div>
<div className={styles.mutationPath}>
{mutationRecord.data.path}
</div>
{mutationRecord.data.args.map((arg, index) => (
<div className={styles.arg} key={'arg_' + index}>
<ValueInspector
value={arg}
delimiter={state.currentApp.delimiter}
small
/>
</div>
))}
</div>
)
}
case HistoryRecordType.Flush: {
const flushRecord = record as FlushHistoryRecord
return (
<div className={styles.recordWrapper} key={index}>
<div className={styles.label}>
<FaSave />
</div>
<div className={styles.actionName}>
{flushRecord.actionName}
</div>
<div className={styles.flushDetail}>
{flushRecord.data.components.length} <FaCode />
{flushRecord.data.components.length ? (
<div className={styles.flushPopup}>
{flushRecord.data.components.join(', ')}
</div>
) : null}
</div>
<div className={styles.flushDetail}>
{flushRecord.data.derived.length} <FaLink />
{flushRecord.data.derived.length ? (
<div className={styles.flushPopup}>
{flushRecord.data.derived.join(', ')}
</div>
) : null}
</div>
</div>
)
}
case HistoryRecordType.Effect: {
const effectRecord = record as EffectHistoryRecord
// If the effect was sync, we do not show both start and end
if (
state.history[index - 1] &&
state.history[index - 1].data.effectId ===
effectRecord.data.effectId
) {
return null
}
return (
<div className={styles.recordWrapper} key={index}>
<div className={styles.label}>
{effectRecord.data.isPending ? <FaClock /> : <FaCheck />}
</div>
<div className={styles.actionName}>
{effectRecord.actionName}
</div>
<div className={styles.effectPath}>
{effectRecord.data.name
? effectRecord.data.name + '.' + effectRecord.data.method
: effectRecord.data.method}
</div>
{effectRecord.data.args.map((arg, index) => (
<div className={styles.arg} key={'arg_' + index}>
<ValueInspector
value={arg}
delimiter={state.currentApp.delimiter}
small
/>
</div>
))}
</div>
)
}
}
return null
})}
</div>
)
}
export default History