Skip to content

Commit f34b837

Browse files
feat(overmind-devtools-vscode): trigger devtool client on codelense
1 parent bff0bbf commit f34b837

File tree

9 files changed

+60
-5
lines changed

9 files changed

+60
-5
lines changed

packages/node_modules/overmind-devtools-client/DevtoolBackend.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ class DevtoolBackend {
104104
)
105105
})
106106
}
107+
sendMessageToDevtool(message) {
108+
console.log('Sending message to devtool!')
109+
this.devtoolSocket.send(
110+
JSON.stringify({
111+
type: 'message',
112+
data: message,
113+
})
114+
)
115+
}
107116
onClientMessage(message) {
108117
if (this.options.onMessage) {
109118
this.options.onMessage(message)

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
1-
import { createElement, FunctionComponent, Fragment } from 'react'
1+
import {
2+
createElement,
3+
FunctionComponent,
4+
Fragment,
5+
useEffect,
6+
useRef,
7+
} from 'react'
28
import * as styles from './styles'
39
import { useOvermind } from '../../overmind'
410
import { nameToColor } from '../../overmind/utils'
511
import { css } from 'emotion'
612

713
const ActionSelector: FunctionComponent = () => {
814
const { state, actions } = useOvermind()
15+
const queryActionRef = useRef(null)
916
const app = state.currentApp
1017

18+
useEffect(
19+
() => {
20+
if (app.isQueryingAction) {
21+
setTimeout(() => {
22+
queryActionRef.current.focus()
23+
})
24+
}
25+
},
26+
[app.isQueryingAction]
27+
)
28+
1129
if (app.isQueryingAction) {
1230
return (
1331
<div className={styles.wrapper}>
@@ -31,6 +49,7 @@ const ActionSelector: FunctionComponent = () => {
3149
</div>
3250
<input
3351
autoFocus
52+
ref={queryActionRef}
3453
placeholder="Search for action..."
3554
onBlur={() => actions.toggleQueryingAction()}
3655
className={css(

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Action, pipe, Operator, AsyncAction } from 'overmind'
1+
import { Action, pipe, Operator, AsyncAction, mutate, run } from 'overmind'
22
import {
33
Message,
44
Tab,
@@ -32,6 +32,13 @@ 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.RUN_ACTION]: mutate(({ state }, message) => {
36+
console.log('GOT THE MESSAGE!!!')
37+
state.currentTab = Tab.Actions
38+
state.currentApp.actionQuery = message.data
39+
state.currentApp.actionQueryPayload = ''
40+
state.currentApp.isQueryingAction = true
41+
}),
3542
})
3643
)
3744

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
export const ensureCurrentApp: () => Operator<Message> = () =>
3838
mutate(({ state }, message) => {
3939
if (!state.currentAppName) {
40+
console.log(JSON.stringify(message))
4041
state.currentAppName = message.appName
4142
}
4243
})

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ export enum ExecutionType {
212212
ACTION_END = 'action:end',
213213
GETTER = 'getter',
214214
STATE = 'state',
215+
RUN_ACTION = 'runAction',
215216
}
216217

217218
export enum AppMessageType {

packages/node_modules/overmind-devtools-vscode/src/DevtoolsPanel.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,7 @@ export class DevtoolsPanel {
6464
)
6565
this._panel.webview.html = content
6666
}
67+
reveal() {
68+
this._panel.reveal()
69+
}
6770
}

packages/node_modules/overmind-devtools-vscode/src/extension.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,18 @@ export function activate(context: vscode.ExtensionContext) {
3939
context,
4040
appName,
4141
devtoolBackend.clientSockets[appName],
42-
actions
42+
actions,
43+
(name) => {
44+
devtoolsPanel.reveal()
45+
console.log('Sending runAction!', name)
46+
devtoolBackend.sendMessageToDevtool({
47+
appName,
48+
message: {
49+
type: 'runAction',
50+
data: name,
51+
},
52+
})
53+
}
4354
)
4455
}
4556
},

packages/node_modules/overmind-devtools-vscode/src/runActions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export const initRunActions = (
77
context: vscode.ExtensionContext,
88
appName: string,
99
appNameConnection: { send(payload: string): void },
10-
avaiableActions: string[]
10+
avaiableActions: string[],
11+
reveal: (name: string) => void
1112
) => {
1213
const sendExecuteMessage = (actionName: string, payload: any = undefined) => {
1314
appNameConnection.send(
@@ -60,6 +61,8 @@ export const initRunActions = (
6061
vscode.commands.registerCommand(
6162
'overmind-devtools.runAction',
6263
(preSelectActionName: string, needsPayload: boolean) => {
64+
reveal(preSelectActionName)
65+
/*
6366
const foundAction = getExactOrSingleMatch(preSelectActionName)
6467
if (foundAction) {
6568
executeAction(foundAction, needsPayload)
@@ -80,6 +83,7 @@ export const initRunActions = (
8083
quickPick.onDidHide(() => quickPick.dispose())
8184
quickPick.show()
8285
}
86+
*/
8387
}
8488
)
8589
)

packages/overmind-website/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const overmind = createOvermind(
1515
devtools: false,
1616
}
1717
: {
18-
devtools: 'localhost:3032',
18+
devtools: 'localhost:3031',
1919
}
2020
)
2121
setConfig({

0 commit comments

Comments
 (0)