Skip to content

Commit 28ddbfb

Browse files
feat(overmind-devtools): runtime and actions called from actions
1 parent 13e4400 commit 28ddbfb

File tree

28 files changed

+429
-55
lines changed

28 files changed

+429
-55
lines changed

packages/node_modules/overmind-devtools/src/components/Action/index.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@ import { createElement, FunctionComponent, Fragment } from 'react'
22
import { useOvermind } from '../../overmind'
33
import * as styles from './styles'
44
import ActionOperator from '../ActionOperator'
5-
import { getOperatorId, nameToColor } from '../../overmind/utils'
6-
import { OperatorsByPath } from '../../overmind/types'
5+
import {
6+
getOperatorId,
7+
nameToColor,
8+
getOperatorsByPath,
9+
} from '../../overmind/utils'
10+
import { OperatorsByPath, Action as TAction } from '../../overmind/types'
711

8-
const Action: FunctionComponent = () => {
12+
type Props = {
13+
action: TAction
14+
inline?: boolean
15+
}
16+
17+
const Action: FunctionComponent<Props> = ({ action, inline }) => {
918
const { state } = useOvermind()
10-
const operatorsByPath = state.currentOperatorsByPath
19+
const operatorsByPath = getOperatorsByPath(action)
1120

1221
function renderOperators(operatorsByPath: OperatorsByPath) {
1322
return operatorsByPath.map((operatorByPath, index) => {
@@ -59,6 +68,17 @@ const Action: FunctionComponent = () => {
5968
})
6069
}
6170

71+
if (inline) {
72+
return (
73+
<div className={styles.innerWrapper}>
74+
<div className={styles.innerTitle}>{action.actionName}</div>
75+
<div className={styles.innerContent}>
76+
{operatorsByPath.map(renderOperators)}
77+
</div>
78+
</div>
79+
)
80+
}
81+
6282
return (
6383
<div className={styles.wrapper}>{operatorsByPath.map(renderOperators)}</div>
6484
)

packages/node_modules/overmind-devtools/src/components/Action/styles.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ export const wrapper = css({
88
boxSizing: 'border-box',
99
})
1010

11+
export const innerWrapper = css({
12+
margin: '0.5rem 0',
13+
padding: 0,
14+
border: `1px solid ${colors.blue}`,
15+
})
16+
17+
export const innerTitle = css({
18+
color: colors.blue,
19+
padding: '0.1rem 0.5rem',
20+
})
21+
22+
export const innerContent = css({
23+
padding: '0.5rem',
24+
})
25+
1126
export const pipe = css({
1227
display: 'flex',
1328
alignItems: 'center',

packages/node_modules/overmind-devtools/src/components/ActionFlush/styles.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const flush = css({
77
borderTopRightRadius: 3,
88
borderBottomRightRadius: 3,
99
position: 'relative',
10+
marginLeft: '0.5rem',
1011
':hover div:nth-child(2)': {
1112
display: 'block',
1213
zIndex: 2,

packages/node_modules/overmind-devtools/src/components/ActionOperator/index.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import * as textStyles from '../../styles/text'
1313
import { css } from 'emotion'
1414
import { colors } from '../../theme'
1515
import ActionFlush from '../ActionFlush'
16+
import Action from '../Action'
17+
import { useOvermind } from 'overmind-devtools/src/overmind'
1618

1719
type Props = {
1820
operator: OperatorType
@@ -25,6 +27,8 @@ const ActionOperator: FunctionComponent<Props> = ({
2527
value,
2628
flush,
2729
}) => {
30+
const { state } = useOvermind()
31+
2832
return (
2933
<div className={actionStyles.pipe}>
3034
<div className={styles.operator}>
@@ -76,7 +80,7 @@ const ActionOperator: FunctionComponent<Props> = ({
7680
<span className={styles.effectArgs}>
7781
(
7882
{effect.args.map((arg, argIndex) => (
79-
<Fragment>
83+
<Fragment key={argIndex}>
8084
<ValueInspector small value={arg} />
8185
{argIndex === effect.args.length - 1 ? null : (
8286
<span>,</span>
@@ -127,12 +131,24 @@ const ActionOperator: FunctionComponent<Props> = ({
127131
>
128132
{mutation.path}
129133
</span>
130-
{mutation.args.map((arg) => (
131-
<ValueInspector small value={arg} />
134+
{mutation.args.map((arg, argIndex) => (
135+
<ValueInspector key={argIndex} small value={arg} />
132136
))}
133137
</div>
134138
)
135139
}
140+
141+
if (event.type === EventType.Action) {
142+
const id = event.data as string
143+
144+
return (
145+
<Action
146+
key={index}
147+
action={state.currentApp.actions[id]}
148+
inline
149+
/>
150+
)
151+
}
136152
})}
137153
{operator.error ? (
138154
<div className={styles.operatorItem}>

packages/node_modules/overmind-devtools/src/components/ActionSelector/styles.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const wrapper = css({
66
position: 'relative',
77
borderTopLeftRadius: 3,
88
borderBottomLeftRadius: 3,
9-
backgroundColor: colors.dark2,
9+
backgroundColor: colors.dark,
1010
display: 'flex',
1111
padding: '0 1rem',
1212
alignItems: 'center',
@@ -25,8 +25,7 @@ export const inputWrapper = css({
2525
export const input = css({
2626
position: 'absolute',
2727
border: 0,
28-
top: '0.25rem',
29-
left: 0,
28+
left: '-1rem',
3029
fontFamily: 'inherit',
3130
outline: 'none',
3231
backgroundColor: 'transparent',
@@ -45,8 +44,7 @@ export const suggestion = css({
4544
position: 'absolute',
4645
display: 'flex',
4746
alignItems: 'center',
48-
top: '0.25rem',
49-
left: 0,
47+
left: '-1rem',
5048
fontSize: 16,
5149
padding: '0.5rem',
5250
opacity: 0.5,
@@ -65,7 +63,6 @@ export const selectedAction = css({
6563

6664
export const noSelectedAction = css({
6765
opacity: 0.5,
68-
padding: '0 1rem',
6966
})
7067

7168
export const resultWrapper = css({

packages/node_modules/overmind-devtools/src/components/Actions/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const Actions: FunctionComponent = () => {
1515
{state.currentAction ? (
1616
<div className={styles.columns}>
1717
<ActionsList />
18-
<Action />
18+
<Action action={state.currentAction} />
1919
</div>
2020
) : (
2121
<div className={styles.centerWrapper}>

packages/node_modules/overmind-devtools/src/components/Actions/styles.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export const centerWrapper = css({
1717

1818
export const columns = css({
1919
display: 'flex',
20-
borderTop: `1px solid hsl(206,57%,16%)`,
2120
'> *:first-child': {
2221
flex: '0 0 300px',
2322
},

packages/node_modules/overmind-devtools/src/components/ActionsTools/styles.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import { css } from 'emotion'
22
import { colors } from '../../theme'
33

44
export const wrapper = css({
5-
padding: '1rem',
5+
margin: '1rem',
66
display: 'flex',
77
alignItems: 'stretch',
8-
backgroundColor: colors.dark,
98
})
109

1110
export const button = css({

packages/node_modules/overmind-devtools/src/components/Apps/styles.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { colors } from '../../theme'
44
export const wrapper = css({
55
position: 'relative',
66
display: 'flex',
7+
paddingTop: '0.5rem',
78
backgroundColor: colors.dark,
89
height: 50,
910
justifyContent: 'center',

packages/node_modules/overmind-devtools/src/components/Devtools/index.tsx

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { createElement, FunctionComponent } from 'react'
1+
import { createElement, FunctionComponent, Fragment } from 'react'
22
import { useOvermind } from '../../overmind'
33
import * as styles from './styles'
44
import * as text from '../../styles/text'
55
import Input from '../common/Input'
66
import Button from '../common/Button'
77
import Workspace from '../Workspace'
88
import { css } from 'emotion'
9+
import Runtime from 'overmind-devtools/src/components/Runtime'
10+
import { colors } from 'overmind-devtools/src/theme'
911

1012
const Devtools: FunctionComponent = () => {
1113
const { state, actions } = useOvermind()
@@ -62,15 +64,35 @@ const Devtools: FunctionComponent = () => {
6264
)
6365
}
6466

65-
if (state.isConnecting) {
66-
return (
67-
<div className={styles.wrapper}>
68-
<h1>Waiting for an app to connect...</h1>
69-
</div>
70-
)
71-
}
72-
73-
return <Workspace />
67+
return (
68+
<Fragment>
69+
{state.isConnecting ? (
70+
<div className={styles.wrapper}>
71+
<h1>Waiting for an app to connect...</h1>
72+
<h2>or</h2>
73+
<input
74+
disabled={state.runtimeLoading}
75+
className={styles.input}
76+
defaultValue={
77+
state.runtimeHost ? state.runtimeHost.split('?')[0] : ''
78+
}
79+
placeholder="Connect to app..."
80+
style={{
81+
borderColor: state.runtimeError ? colors.red : 'transparent',
82+
}}
83+
onKeyDown={(event) => {
84+
if (event.keyCode === 13) {
85+
actions.setRuntimeHost(event.currentTarget.value)
86+
}
87+
}}
88+
/>
89+
</div>
90+
) : (
91+
<Workspace />
92+
)}
93+
<Runtime />
94+
</Fragment>
95+
)
7496
}
7597

7698
export default Devtools

0 commit comments

Comments
 (0)