Skip to content

Commit fd7868c

Browse files
author
Guillaume Chau
committed
refactor(ui): moved project nav routes to backend
1 parent bfa07f6 commit fd7868c

File tree

7 files changed

+73
-31
lines changed

7 files changed

+73
-31
lines changed

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

+10-29
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class="flat big icon-button"
1313
:value="route.name"
1414
:icon-left="route.icon"
15-
v-tooltip.right="renderTooltip(route.tooltip)"
15+
v-tooltip.right="$t(route.tooltip)"
1616
/>
1717
</VueGroup>
1818
</div>
@@ -22,32 +22,19 @@
2222
<script>
2323
import { isSameRoute, isIncludedRoute } from '../util/route'
2424
25-
const BUILTIN_ROUTES = [
26-
{
27-
name: 'project-plugins',
28-
icon: 'widgets',
29-
tooltip: 'plugins'
30-
},
31-
{
32-
name: 'project-configurations',
33-
icon: 'settings_applications',
34-
tooltip: 'configuration'
35-
},
36-
{
37-
name: 'project-tasks',
38-
icon: 'assignment',
39-
tooltip: 'tasks'
40-
}
41-
]
25+
import ROUTES from '../graphql/routes.gql'
4226
4327
export default {
4428
data () {
4529
return {
46-
routes: [
47-
...BUILTIN_ROUTES
48-
// Plugins routes here
49-
// TODO
50-
]
30+
routes: []
31+
}
32+
},
33+
34+
apollo: {
35+
routes: {
36+
query: ROUTES,
37+
fetchPolicy: 'cache-and-network'
5138
}
5239
},
5340
@@ -66,12 +53,6 @@ export default {
6653
}
6754
}
6855
}
69-
},
70-
71-
methods: {
72-
renderTooltip (target) {
73-
return this.$t(`components.project-nav.tooltips.${target}`)
74-
}
7556
}
7657
}
7758
</script>

packages/@vue/cli-ui/src/graphql-api/channels.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ module.exports = {
44
PROGRESS_REMOVED: 'progress_removed',
55
CONSOLE_LOG_ADDED: 'console_log_added',
66
TASK_CHANGED: 'task_changed',
7-
TASK_LOG_ADDED: 'task_log_added'
7+
TASK_LOG_ADDED: 'task_log_added',
8+
ROUTE_ADDED: 'route_added',
9+
ROUTE_REMOVED: 'route_removed',
10+
ROUTE_CHANGED: 'route_changed'
811
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const BUILTIN_ROUTES = [
2+
{
3+
id: 'project-plugins',
4+
name: 'project-plugins',
5+
icon: 'widgets',
6+
tooltip: 'components.project-nav.tooltips.plugins'
7+
},
8+
{
9+
id: 'project-configurations',
10+
name: 'project-configurations',
11+
icon: 'settings_applications',
12+
tooltip: 'components.project-nav.tooltips.configuration'
13+
},
14+
{
15+
id: 'project-tasks',
16+
name: 'project-tasks',
17+
icon: 'assignment',
18+
tooltip: 'components.project-nav.tooltips.tasks'
19+
}
20+
]
21+
22+
let routes = [
23+
...BUILTIN_ROUTES
24+
]
25+
26+
function list (context) {
27+
return routes
28+
}
29+
30+
module.exports = {
31+
list
32+
}

packages/@vue/cli-ui/src/graphql-api/resolvers.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const tasks = require('./connectors/tasks')
1414
const configurations = require('./connectors/configurations')
1515
const git = require('./connectors/git')
1616
const files = require('./connectors/files')
17+
const routes = require('./connectors/routes')
1718

1819
// Prevent code from exiting server process
1920
exit.exitProcess = false
@@ -61,7 +62,8 @@ module.exports = {
6162
task: (root, { id }, context) => tasks.findOne(id, context),
6263
configurations: (root, args, context) => configurations.list(context),
6364
configuration: (root, { id }, context) => configurations.findOne(id, context),
64-
fileDiffs: (root, args, context) => git.getDiffs(context)
65+
fileDiffs: (root, args, context) => git.getDiffs(context),
66+
routes: (root, args, context) => routes.list(context)
6567
},
6668

6769
Mutation: {

packages/@vue/cli-ui/src/graphql-api/type-defs.js

+11
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ input OpenInEditorInput {
249249
gitPath: Boolean
250250
}
251251
252+
type Route {
253+
id: ID!
254+
name: String!
255+
icon: String!
256+
tooltip: String
257+
}
258+
252259
type Query {
253260
progress (id: ID!): Progress
254261
cwd: String!
@@ -266,6 +273,7 @@ type Query {
266273
configurations: [Configuration]
267274
configuration (id: ID!): Configuration
268275
fileDiffs: [FileDiff]
276+
routes: [Route]
269277
}
270278
271279
type Mutation {
@@ -303,5 +311,8 @@ type Subscription {
303311
cwdChanged: String!
304312
taskChanged: Task
305313
taskLogAdded (id: ID!): TaskLog
314+
routeAdded: Route
315+
routeRemoved: Route
316+
routeChanged: Route
306317
}
307318
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fragment route on Route {
2+
id
3+
name
4+
icon
5+
tooltip
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#import "./routeFragment.gql"
2+
3+
query routes {
4+
routes {
5+
...route
6+
}
7+
}

0 commit comments

Comments
 (0)