Skip to content

Commit a93a445

Browse files
feat(overmind-devtools-client): add initial charts handling
1 parent f96e3da commit a93a445

File tree

9 files changed

+138
-10
lines changed

9 files changed

+138
-10
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { FunctionComponent, createElement } from 'react'
2+
import SplitPane from 'react-split-pane'
3+
4+
import { useOvermind } from '../../overmind'
5+
import * as textStyles from '../../styles/text'
6+
import * as styles from './styles'
7+
8+
const Charts: FunctionComponent = () => {
9+
const { state, actions } = useOvermind()
10+
11+
return (
12+
<div className={styles.wrapper}>
13+
{state.currentAction ? (
14+
<div className={styles.columns}>
15+
<SplitPane
16+
split="vertical"
17+
minSize={100}
18+
defaultSize={state.actionsSplitSize}
19+
onChange={(size) => actions.updateActionsSplitSize(size)}
20+
>
21+
<div>List</div>
22+
<div>Chart</div>
23+
</SplitPane>
24+
</div>
25+
) : (
26+
<div className={styles.centerWrapper}>
27+
<span className={textStyles.header}>no actions triggered...</span>
28+
</div>
29+
)}
30+
</div>
31+
)
32+
}
33+
34+
export default Charts
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { css } from 'emotion'
2+
3+
import { colors } from '../../theme'
4+
5+
export const wrapper = css({
6+
position: 'relative',
7+
display: 'flex',
8+
flexDirection: 'column',
9+
height: '100%',
10+
})
11+
12+
export const centerWrapper = css({
13+
display: 'flex',
14+
height: '100%',
15+
alignItems: 'center',
16+
justifyContent: 'center',
17+
})
18+
19+
export const columns = css({
20+
display: 'flex',
21+
'> *:first-child': {
22+
flex: '0 0 300px',
23+
},
24+
'> *:last-child': {
25+
flex: 1,
26+
},
27+
flex: 1,
28+
position: 'relative',
29+
})

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
import { createElement, FunctionComponent } from 'react'
2-
import { useOvermind } from '../../overmind'
3-
import Apps from '../Apps'
4-
import * as styles from './styles'
5-
import { Tab } from '../../overmind/types'
6-
import Tooltip from '../common/Tooltip'
71
import { css } from 'emotion'
2+
import { FunctionComponent, createElement } from 'react'
83
import {
9-
FaDatabase,
10-
FaCogs,
4+
FaChrome,
115
FaCode,
6+
FaCogs,
7+
FaDatabase,
8+
FaHistory,
9+
FaProjectDiagram,
1210
FaSave,
1311
FaTerminal,
14-
FaHistory,
15-
FaChrome,
1612
} from 'react-icons/fa'
13+
14+
import { useOvermind } from '../../overmind'
15+
import { Tab } from '../../overmind/types'
1716
import { colors } from '../../theme'
17+
import Apps from '../Apps'
18+
import Tooltip from '../common/Tooltip'
1819
import RuntimeConfig from '../RuntimeConfig'
20+
import * as styles from './styles'
1921

2022
const Tabs: FunctionComponent = () => {
2123
const { state, actions } = useOvermind()
@@ -67,6 +69,17 @@ const Tabs: FunctionComponent = () => {
6769
<FaCogs />
6870
</button>
6971
</Tooltip>
72+
<Tooltip text="Charts">
73+
<button
74+
className={css(
75+
styles.button,
76+
state.currentTab === Tab.Charts && styles.activeButton
77+
)}
78+
onClick={() => actions.changeTab(Tab.Charts)}
79+
>
80+
<FaProjectDiagram />
81+
</button>
82+
</Tooltip>
7083
<Tooltip text="Components">
7184
<button
7285
className={css(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import State from '../State'
1010
import Components from '../Components'
1111
import Flushes from '../Flushes'
1212
import History from '../History'
13+
import Charts from '../Charts'
1314

1415
const pages: { [key in Tab]: SFC } = {
1516
[Tab.Actions]: Actions,
@@ -19,6 +20,7 @@ const pages: { [key in Tab]: SFC } = {
1920
[Tab.Flushes]: Flushes,
2021
[Tab.Remove]: () => null,
2122
[Tab.History]: History,
23+
[Tab.Charts]: Charts,
2224
}
2325

2426
const Workspace: SFC = () => {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const onMessage: Operator<Message> = pipe(
3232
[ExecutionType.ACTION_END]: o.updateAction(),
3333
[ExecutionType.OPERATOR_ASYNC]: o.updateOperatorAsync(),
3434
[ExecutionType.GETTER]: o.runGetterMutation(),
35+
[ExecutionType.CHART]: o.addChart(),
3536
})
3637
)
3738

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
GetterMessage,
2626
StateMessage,
2727
Tab,
28+
ChartMessage,
2829
} from './types'
2930
import {
3031
createApp,
@@ -216,6 +217,20 @@ export const addAction: () => Operator<StartActionMessage> = () =>
216217
}
217218
})
218219

220+
export const addChart: () => Operator<ChartMessage> = () =>
221+
mutate(({ state }, message) => {
222+
const app = state.apps[message.appName]
223+
const data = message.data
224+
const chartId = data.path.join('.')
225+
const isSelectingFirstChart = !app.currentChartId
226+
227+
app.charts[chartId] = data
228+
229+
if (isSelectingFirstChart) {
230+
app.currentChartId = chartId
231+
}
232+
})
233+
219234
export const addOperator: () => Operator<StartOperatorMessage> = () =>
220235
mutate(({ state }, message) => {
221236
const operatorData = message.data

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
EffectMessage,
1818
EffectHistoryRecord,
1919
OperatorsByPath,
20+
Chart,
2021
} from './types'
2122

2223
type State = {
@@ -29,6 +30,7 @@ type State = {
2930
currentTab: Tab
3031
showApps: boolean
3132
currentAction: Derive<State, Action>
33+
currentChart: Derive<State, Chart>
3234
currentApp: Derive<State, App>
3335
componentsMounted: Derive<State, Component[]>
3436
componentsUpdateCount: Derive<State, number>
@@ -98,6 +100,8 @@ const state: State = {
98100
}, []).length,
99101
currentAction: (state) =>
100102
state.currentApp.actions[state.currentApp.currentActionId],
103+
currentChart: (state) =>
104+
state.currentApp.charts[state.currentApp.currentChartId],
101105
groupedComponents(state) {
102106
const components = state.componentsMounted
103107

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ export type EffectHistoryRecord = HistoryRecord<
163163
Effect
164164
>
165165

166+
export type Charts = {
167+
[path: string]: Chart
168+
}
169+
166170
export type App = {
167171
name: string
168172
messages: AppMessage<any>[]
@@ -177,8 +181,10 @@ export type App = {
177181
[id: string]: FlushReference
178182
}
179183
actions: Actions
184+
charts: Charts
180185
actionsList: ActionsListItem[]
181186
currentActionId: string
187+
currentChartId: string
182188
actionQuery: string
183189
actionQuerySuggestion: string
184190
selectedActionQuery: string
@@ -213,6 +219,7 @@ export enum ExecutionType {
213219
ACTION_END = 'action:end',
214220
GETTER = 'getter',
215221
STATE = 'state',
222+
CHART = 'chart',
216223
}
217224

218225
export enum AppMessageType {
@@ -289,6 +296,8 @@ export type StartActionMessage = AppMessage<{
289296
parentExecution?: any
290297
}>
291298

299+
export type ChartMessage = AppMessage<Chart>
300+
292301
export type StartOperatorMessage = AppMessage<{
293302
actionId: number
294303
actionName: string
@@ -366,6 +375,7 @@ export enum Tab {
366375
Flushes = 'Flushes',
367376
Remove = 'Remove',
368377
History = 'History',
378+
Charts = 'Charts',
369379
}
370380

371381
export type GroupedComponent = {
@@ -377,3 +387,21 @@ export type GroupedComponent = {
377387
export type GroupedComponents = {
378388
[name: string]: GroupedComponent
379389
}
390+
391+
export type Chart = {
392+
path: string[]
393+
state: string
394+
chart: {
395+
[key: string]: {
396+
entry?: string
397+
exit?: string
398+
on: {
399+
[key: string]:
400+
| string
401+
| {
402+
target: string
403+
}
404+
}
405+
}
406+
}
407+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ export const createApp = (data: Partial<App>): App =>
3939
derived: {},
4040
flushes: {},
4141
actions: {},
42+
charts: {},
4243
actionsList: [],
4344
currentActionId: null,
45+
currentChartId: null,
4446
flushByActionId: {},
4547
flushByOperatorId: {},
4648
actionQuery: '',

0 commit comments

Comments
 (0)