Skip to content

Commit 2bffb9b

Browse files
committed
feat: run task widget
1 parent 57cf974 commit 2bffb9b

File tree

15 files changed

+334
-19
lines changed

15 files changed

+334
-19
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<template>
2+
<div class="run-task">
3+
<template v-if="task">
4+
<TaskItem
5+
:task="task"
6+
class="info"
7+
/>
8+
9+
<div class="actions">
10+
<VueButton
11+
v-if="task.status !== 'running'"
12+
icon-left="play_arrow"
13+
class="primary"
14+
:label="$t('org.vue.views.project-task-details.actions.play')"
15+
@click="runTask()"
16+
/>
17+
18+
<VueButton
19+
v-else
20+
icon-left="stop"
21+
class="primary"
22+
:label="$t('org.vue.views.project-task-details.actions.stop')"
23+
@click="stopTask()"
24+
/>
25+
26+
<VueButton
27+
icon-left="assignment"
28+
:label="$t('org.vue.widgets.run-task.page')"
29+
:to="{ name: 'project-task-details', params: { id: taskId } }"
30+
/>
31+
</div>
32+
</template>
33+
</div>
34+
</template>
35+
36+
<script>
37+
import TASK from '@vue/cli-ui/src/graphql/task.gql'
38+
import TASK_RUN from '@vue/cli-ui/src/graphql/taskRun.gql'
39+
import TASK_STOP from '@vue/cli-ui/src/graphql/taskStop.gql'
40+
import TASK_CHANGED from '@vue/cli-ui/src/graphql/taskChanged.gql'
41+
42+
export default {
43+
inject: [
44+
'widget'
45+
],
46+
47+
apollo: {
48+
task: {
49+
query: TASK,
50+
variables () {
51+
return {
52+
id: this.taskId
53+
}
54+
}
55+
},
56+
57+
$subscribe: {
58+
taskChanged: {
59+
query: TASK_CHANGED
60+
}
61+
}
62+
},
63+
64+
computed: {
65+
taskId () {
66+
return this.widget.data.config.task
67+
}
68+
},
69+
70+
methods: {
71+
runTask () {
72+
this.$apollo.mutate({
73+
mutation: TASK_RUN,
74+
variables: {
75+
id: this.taskId
76+
}
77+
})
78+
},
79+
80+
stopTask () {
81+
this.$apollo.mutate({
82+
mutation: TASK_STOP,
83+
variables: {
84+
id: this.taskId
85+
}
86+
})
87+
}
88+
}
89+
}
90+
</script>
91+
92+
<style lang="stylus" scoped>
93+
@import "~@vue/cli-ui/src/style/imports"
94+
95+
.info
96+
padding ($padding-item + 9px) $padding-item
97+
98+
.actions
99+
h-box()
100+
box-center()
101+
/deep/ > *
102+
&:not(:last-child)
103+
margin-right ($padding-item / 2)
104+
</style>

packages/@vue/cli-ui-addon-widgets/src/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import KillPort from './components/KillPort.vue'
33
import PluginUpdates from './components/PluginUpdates.vue'
44
import DependencyUpdates from './components/DependencyUpdates.vue'
55
import Vulnerability from './components/Vulnerability.vue'
6+
import RunTask from './components/RunTask.vue'
67

78
ClientAddonApi.component('org.vue.widgets.components.welcome', Welcome)
89
ClientAddonApi.component('org.vue.widgets.components.kill-port', KillPort)
910
ClientAddonApi.component('org.vue.widgets.components.plugin-updates', PluginUpdates)
1011
ClientAddonApi.component('org.vue.widgets.components.dependency-updates', DependencyUpdates)
1112
ClientAddonApi.component('org.vue.widgets.components.vulnerability', Vulnerability)
13+
ClientAddonApi.component('org.vue.widgets.components.run-task', RunTask)

packages/@vue/cli-ui/apollo-server/api/widget.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ const schema = createSchema(joi => ({
1818
defaultWidth: joi.number(),
1919
defaultHeight: joi.number(),
2020
// Config
21-
configPrompts: joi.func(),
2221
defaultConfig: joi.func(),
2322
needsUserConfig: joi.boolean(),
2423
// Hooks
2524
onAdded: joi.func(),
2625
onRemoved: joi.func(),
26+
onConfigOpen: joi.func(),
2727
onConfigChanged: joi.func()
2828
}))
2929

packages/@vue/cli-ui/apollo-server/connectors/prompts.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ function getAnswer (id) {
162162
return get(answers, id)
163163
}
164164

165-
async function reset () {
165+
async function reset (answers = {}) {
166166
prompts = []
167-
await setAnswers({})
167+
await setAnswers(answers)
168168
}
169169

170170
function list () {

packages/@vue/cli-ui/apollo-server/connectors/widgets.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const shortid = require('shortid')
2+
// Conncetors
3+
const prompts = require('./prompts')
24
// Utils
35
const { log } = require('../util/logger')
46

@@ -30,6 +32,7 @@ function getDefaultWidgets () {
3032
let widgetDefs = new Map()
3133
let widgetCount = new Map()
3234
let widgets = []
35+
let currentWidget
3336

3437
let loadPromise, loadResolve
3538

@@ -47,6 +50,7 @@ function reset (context) {
4750
}
4851

4952
function registerDefinition ({ definition }, context) {
53+
definition.hasConfigPrompts = !!definition.onConfigOpen
5054
widgetDefs.set(definition.id, definition)
5155
}
5256

@@ -233,20 +237,37 @@ function move (input, context) {
233237
return widgets
234238
}
235239

236-
function openConfig ({ id }, context) {
237-
// const widget = findById({ id }, context)
238-
// TODO
240+
async function openConfig ({ id }, context) {
241+
const widget = findById({ id }, context)
242+
const definition = findDefinition(widget, context)
243+
console.log('openConfig', widget, definition)
244+
if (definition.onConfigOpen) {
245+
const result = await definition.onConfigOpen({
246+
widget,
247+
definition,
248+
context
249+
})
250+
console.log(result)
251+
await prompts.reset(widget.config || {})
252+
result.prompts.forEach(prompts.add)
253+
await prompts.start()
254+
currentWidget = widget
255+
}
256+
console.log(widget, prompts.list())
257+
return widget
239258
}
240259

241260
function getConfigPrompts ({ id }, context) {
242-
// const widget = findById({ id }, context)
243-
// TODO
261+
return currentWidget && currentWidget.id === id ? prompts.list() : []
244262
}
245263

246264
function saveConfig ({ id }, context) {
247-
// const widget = findById({ id }, context)
248-
// TODO
265+
const widget = findById({ id }, context)
266+
widget.config = prompts.getAnswers()
267+
widget.configured = true
249268
save(context)
269+
currentWidget = null
270+
return widget
250271
}
251272

252273
function resetConfig ({ id }, context) {

packages/@vue/cli-ui/apollo-server/schema/widget.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type WidgetDefinition {
2626
screenshot: String
2727
component: String!
2828
canAddMore: Boolean!
29+
hasConfigPrompts: Boolean!
2930
}
3031
3132
type Widget {

packages/@vue/cli-ui/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ exports.clientAddonConfig = function ({ id, port = 8042 }) {
1818
config.plugins.delete('html')
1919
config.plugins.delete('optimize-css')
2020
config.optimization.splitChunks(false)
21+
22+
config.module
23+
.rule('gql')
24+
.test(/\.(gql|graphql)$/)
25+
.use('gql-loader')
26+
.loader('graphql-tag/loader')
27+
.end()
2128
},
2229
devServer: {
2330
headers: {

packages/@vue/cli-ui/locales/en.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@
180180
}
181181
},
182182
"widget": {
183-
"remove": "Remove widget"
183+
"remove": "Remove widget",
184+
"configure": "Configure",
185+
"save": "Save"
184186
},
185187
"widget-add-pane": {
186188
"title": "Add widgets"
@@ -778,6 +780,14 @@
778780
"loading": "Checking security reports...",
779781
"attention": "{n} vulnerabilities found"
780782
}
783+
},
784+
"run-task": {
785+
"title": "Run task",
786+
"description": "Shortcut to run a task",
787+
"prompts": {
788+
"task": "Select a task"
789+
},
790+
"page": "Go to Task"
781791
}
782792
}
783793
}

0 commit comments

Comments
 (0)