Skip to content

Commit c04f69e

Browse files
author
Guillaume Chau
committed
feat(ui): projects: search input
1 parent abd7306 commit c04f69e

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@
77
<template slot-scope="{ result: { data, loading } }">
88
<template v-if="data">
99
<div v-if="data.projects.length">
10+
<div class="toolbar">
11+
<VueInput
12+
v-model="search"
13+
icon-left="search"
14+
class="round"
15+
/>
16+
</div>
17+
1018
<ListFilter
1119
v-for="favorite of [true, false]"
1220
:key="favorite"
13-
:list="data.projects"
21+
:list="filterProjects(data.projects)"
1422
:filter="item => !!item.favorite === favorite"
1523
>
1624
<template slot-scope="{ list }">
@@ -59,13 +67,21 @@
5967
</template>
6068

6169
<script>
70+
import { generateSearchRegex } from '../util/search'
71+
6272
import PROJECTS from '../graphql/projects.gql'
6373
import PROJECT_CURRENT from '../graphql/projectCurrent.gql'
6474
import PROJECT_OPEN from '../graphql/projectOpen.gql'
6575
import PROJECT_REMOVE from '../graphql/projectRemove.gql'
6676
import PROJECT_SET_FAVORITE from '../graphql/projectSetFavorite.gql'
6777
6878
export default {
79+
data () {
80+
return {
81+
search: ''
82+
}
83+
},
84+
6985
apollo: {
7086
projectCurrent: PROJECT_CURRENT
7187
},
@@ -113,6 +129,16 @@ export default {
113129
114130
compareProjects (a, b) {
115131
return a.name.localeCompare(b.name)
132+
},
133+
134+
filterProjects (projects) {
135+
const reg = generateSearchRegex(this.search)
136+
if (reg) {
137+
return projects.filter(
138+
p => reg.test(p.path)
139+
)
140+
}
141+
return projects
116142
}
117143
}
118144
}
@@ -126,4 +152,9 @@ export default {
126152
overflow-y auto
127153
position relative
128154
min-height 400px
155+
156+
.toolbar
157+
h-box()
158+
box-center()
159+
margin-bottom $padding-item
129160
</style>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function generateSearchRegex (text) {
2+
return text && new RegExp(text.trim().replace(/\s+/g, '.{0,5}'), 'i')
3+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
<script>
4343
import RestoreRoute from '../mixins/RestoreRoute'
44+
import { generateSearchRegex } from '../util/search'
4445
4546
import CONFIGS from '../graphql/configurations.gql'
4647
@@ -78,7 +79,7 @@ export default {
7879
generateItems (configurations) {
7980
if (!configurations) return []
8081
81-
const reg = this.search && new RegExp(this.search, 'i')
82+
const reg = generateSearchRegex(this.search)
8283
return configurations.filter(
8384
item => !reg || item.name.match(reg) || item.description.match(reg)
8485
).map(

0 commit comments

Comments
 (0)