Skip to content

Commit 81e5184

Browse files
author
Guillaume Chau
committed
feat(ui): tasks dropdown: open task details
1 parent e81fc65 commit 81e5184

File tree

6 files changed

+81
-20
lines changed

6 files changed

+81
-20
lines changed

packages/@vue/cli-ui/src/components/ProjectTasksDropdown.vue

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,28 @@
3030
v-for="task of tasks"
3131
:key="task.id"
3232
:task="task"
33+
@click.native="openTask(task)"
3334
>
3435
<VueButton
3536
v-if="task.status !== 'running'"
3637
icon-left="play_arrow"
3738
class="icon-button"
3839
v-tooltip="$t('org.vue.views.project-task-details.actions.play')"
39-
@click="runTask(task)"
40+
@click.stop="openTask(task, true)"
4041
/>
4142
<VueButton
4243
v-else
4344
icon-left="stop"
4445
class="icon-button"
4546
v-tooltip="$t('org.vue.views.project-task-details.actions.stop')"
46-
@click="stopTask(task)"
47+
@click.stop="stopTask(task)"
4748
/>
4849
</TaskItem>
50+
51+
<VueLoadingIndicator
52+
v-if="loading"
53+
class="overlay"
54+
/>
4955
</div>
5056
</div>
5157
</VueDropdown>
@@ -55,6 +61,8 @@
5561
import TASK_CHANGED from '../graphql/taskChanged.gql'
5662
import TASK_RUN from '../graphql/taskRun.gql'
5763
import TASK_STOP from '../graphql/taskStop.gql'
64+
import PROJECT_CURRENT from '../graphql/projectCurrent.gql'
65+
import PROJECT_OPEN from '../graphql/projectOpen.gql'
5866
5967
export default {
6068
props: {
@@ -69,7 +77,15 @@ export default {
6977
}
7078
},
7179
80+
data () {
81+
return {
82+
loading: false
83+
}
84+
},
85+
7286
apollo: {
87+
projectCurrent: PROJECT_CURRENT,
88+
7389
$subscribe: {
7490
taskChanged: {
7591
query: TASK_CHANGED
@@ -99,13 +115,31 @@ export default {
99115
},
100116
101117
methods: {
102-
runTask (task) {
103-
this.$apollo.mutate({
104-
mutation: TASK_RUN,
105-
variables: {
106-
id: task.id
107-
}
118+
async openTask (task, run = false) {
119+
this.loading = true
120+
121+
if (task.project.id !== this.projectCurrent.id) {
122+
await this.$apollo.mutate({
123+
mutation: PROJECT_OPEN,
124+
variables: {
125+
id: task.project.id
126+
}
127+
})
128+
}
129+
130+
this.$router.push({
131+
name: 'project-tasks',
132+
query: { id: task.id }
108133
})
134+
135+
if (run) {
136+
await this.$apollo.mutate({
137+
mutation: TASK_RUN,
138+
variables: {
139+
id: task.id
140+
}
141+
})
142+
}
109143
},
110144
111145
stopTask (task) {

packages/@vue/cli-ui/src/graphql/projects.gql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ query projects {
77
id
88
name
99
status
10+
project {
11+
id
12+
}
1013
}
1114
}
1215
}

packages/@vue/cli-ui/src/mixins/RestoreRoute.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isSameRoute } from '../util/route'
12

23
import PROJECT_CURRENT from '../graphql/projectCurrent.gql'
34

@@ -26,12 +27,14 @@ export default function ({
2627

2728
beforeRouteEnter (to, from, next) {
2829
if (lastRoute) {
29-
const { name, params, query } = lastRoute
30-
next({ name, params, query })
30+
if (!to.query) {
31+
const { name, params, query } = lastRoute
32+
next({ name, params, query })
33+
return
34+
}
3135
lastRoute = null
32-
} else {
33-
next()
3436
}
37+
next()
3538
},
3639

3740
beforeRouteLeave (to, from, next) {
@@ -41,7 +44,9 @@ export default function ({
4144

4245
methods: {
4346
replaceBaseRoute () {
44-
if (baseRoute) this.$router.replace(baseRoute)
47+
if (baseRoute && !isSameRoute(this.$route, baseRoute, false)) {
48+
this.$router.replace(baseRoute)
49+
}
4550
}
4651
}
4752
}

packages/@vue/cli-ui/src/util/bus.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,19 @@ export default {
4141

4242
Vue.config.optionMergeStrategies.bus = (parent, child, vm) => {
4343
if (Array.isArray(parent)) {
44-
parent.push(child)
45-
return parent
46-
} else if (parent) {
44+
if (Array.isArray(child)) {
45+
return parent.concat(child)
46+
} else {
47+
parent.push(child)
48+
return parent
49+
}
50+
} else if (Array.isArray(child)) {
51+
child.push(parent)
52+
return child
53+
} else if (parent && child) {
4754
return [parent, child]
55+
} else if (parent) {
56+
return parent
4857
}
4958
return child
5059
}

packages/@vue/cli-ui/src/util/route.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
const trailingSlashRE = /\/?$/
22

3-
export function isSameRoute (a, b) {
3+
export function isSameRoute (a, b, checkQuery = true) {
44
if (!b) {
55
return false
66
} else if (a.path && b.path) {
77
return (
88
a.path.replace(trailingSlashRE, '') === b.path.replace(trailingSlashRE, '') &&
99
a.hash === b.hash &&
10-
isObjectEqual(a.query, b.query)
10+
(!checkQuery || isObjectEqual(a.query, b.query))
1111
)
1212
} else if (a.name && b.name) {
1313
return (
1414
a.name === b.name &&
1515
a.hash === b.hash &&
16-
isObjectEqual(a.query, b.query) &&
17-
isObjectEqual(a.params, b.params)
16+
isObjectEqual(a.params, b.params) &&
17+
(!checkQuery || isObjectEqual(a.query, b.query))
1818
)
1919
} else {
2020
return false

packages/@vue/cli-ui/src/views/ProjectTasks.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<ApolloQuery
77
:query="require('../graphql/tasks.gql')"
88
class="fill-height"
9+
@result="onResult"
910
>
1011
<template slot-scope="{ result: { data, loading } }">
1112
<VueLoadingIndicator
@@ -82,6 +83,15 @@ export default {
8283
task
8384
})
8485
)
86+
},
87+
88+
onResult ({ loading }) {
89+
if (!loading && this.$route.query.id) {
90+
this.$router.replace({
91+
name: 'project-task-details',
92+
params: { id: this.$route.query.id }
93+
})
94+
}
8595
}
8696
}
8797
}

0 commit comments

Comments
 (0)