Skip to content

Commit 2e11306

Browse files
feat(overmind-devtools-client): ability to clear actions and 1s separator
1 parent fcf5c66 commit 2e11306

File tree

5 files changed

+57
-4
lines changed

5 files changed

+57
-4
lines changed

packages/node_modules/overmind-devtools-client/src/components/ActionsList/index.tsx

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
1-
import { createElement, FunctionComponent } from 'react'
1+
import { css } from 'emotion'
2+
import { Fragment, FunctionComponent, createElement } from 'react'
3+
import { FaChevronDown } from 'react-icons/fa'
4+
25
import { useOvermind } from '../../overmind'
36
import { ActionsListItemType } from '../../overmind/types'
47
import { nameToColor } from '../../overmind/utils'
58
import * as textStyles from '../../styles/text'
69
import * as styles from './styles'
7-
import { css } from 'emotion'
810

911
const ActionsList: FunctionComponent = () => {
1012
const { state, actions } = useOvermind()
1113

1214
return (
1315
<div className={styles.wrapper}>
14-
{state.currentApp.actionsList.map((item) => {
16+
{state.currentApp.actionsList.length ? (
17+
<div
18+
className={styles.clearItems}
19+
onClick={() => actions.clearActions()}
20+
>
21+
clear
22+
<FaChevronDown style={{ marginLeft: '0.25rem' }} />
23+
</div>
24+
) : null}
25+
{state.currentApp.actionsList.map((item, index) => {
1526
if (item.type === ActionsListItemType.ACTION) {
1627
const action = state.currentApp.actions[item.id]
28+
const nextItem = state.currentApp.actionsList[index + 1]
29+
const nextAction =
30+
nextItem && nextItem.type === ActionsListItemType.ACTION
31+
? state.currentApp.actions[nextItem.id]
32+
: null
1733

18-
return (
34+
const actionResult = (
1935
<div
2036
className={css(
2137
styles.actionItem,
@@ -41,6 +57,16 @@ const ActionsList: FunctionComponent = () => {
4157
/>
4258
</div>
4359
)
60+
if (nextAction && action.time - nextAction.time >= 1000) {
61+
return (
62+
<Fragment key={item.id}>
63+
{actionResult}
64+
<div className={styles.separator} />
65+
</Fragment>
66+
)
67+
}
68+
69+
return actionResult
4470
}
4571
const mainAction = state.currentApp.actions[item.actionIds[0]]
4672
const groupedActionIds = item.actionIds.slice(1)

packages/node_modules/overmind-devtools-client/src/components/ActionsList/styles.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
import { css } from 'emotion'
2+
23
import { colors } from '../../theme'
34

5+
export const separator = css({
6+
height: 3,
7+
backgroundColor: colors.foreground,
8+
margin: '2px 0',
9+
})
10+
411
export const wrapper = css({
512
padding: '1rem',
613
height: '100%',
714
overflowY: 'scroll',
815
boxSizing: 'border-box',
916
})
1017

18+
export const clearItems = css({
19+
display: 'flex',
20+
alignItems: 'center',
21+
justifyContent: 'flex-end',
22+
padding: '0 1rem 1rem 1rem',
23+
textDecoration: 'underline',
24+
cursor: 'pointer',
25+
opacity: 1,
26+
':hover': {
27+
opacity: 0.9,
28+
},
29+
})
30+
1131
export const actionItem = css({
1232
position: 'relative',
1333
display: 'flex',

packages/node_modules/overmind-devtools-client/src/overmind/actions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,8 @@ export const updateActionsSplitSize: Operator<number> = pipe(
224224
await effects.storage.set('devtool.actionsSplitSize', size)
225225
})
226226
)
227+
228+
export const clearActions: Action = ({ state }) => {
229+
state.currentApp.actionsList = []
230+
state.currentApp.currentActionId = null
231+
}

packages/node_modules/overmind-devtools-client/src/overmind/operators.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export const addAction: () => Operator<StartActionMessage> = () =>
181181
isRunning: true,
182182
operators: {},
183183
hasError: false,
184+
time: Date.now(),
184185
}
185186

186187
if (action.parentExecution) {

packages/node_modules/overmind-devtools-client/src/overmind/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export type Action = {
9090
}
9191
value: any
9292
hasError: boolean
93+
time: number
9394
}
9495

9596
export type Actions = {

0 commit comments

Comments
 (0)