mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-25 00:29:06 -06:00
feat(ui): projects: search input
This commit is contained in:
@@ -7,10 +7,18 @@
|
||||
<template slot-scope="{ result: { data, loading } }">
|
||||
<template v-if="data">
|
||||
<div v-if="data.projects.length">
|
||||
<div class="toolbar">
|
||||
<VueInput
|
||||
v-model="search"
|
||||
icon-left="search"
|
||||
class="round"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<ListFilter
|
||||
v-for="favorite of [true, false]"
|
||||
:key="favorite"
|
||||
:list="data.projects"
|
||||
:list="filterProjects(data.projects)"
|
||||
:filter="item => !!item.favorite === favorite"
|
||||
>
|
||||
<template slot-scope="{ list }">
|
||||
@@ -59,6 +67,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { generateSearchRegex } from '../util/search'
|
||||
|
||||
import PROJECTS from '../graphql/projects.gql'
|
||||
import PROJECT_CURRENT from '../graphql/projectCurrent.gql'
|
||||
import PROJECT_OPEN from '../graphql/projectOpen.gql'
|
||||
@@ -66,6 +76,12 @@ import PROJECT_REMOVE from '../graphql/projectRemove.gql'
|
||||
import PROJECT_SET_FAVORITE from '../graphql/projectSetFavorite.gql'
|
||||
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
search: ''
|
||||
}
|
||||
},
|
||||
|
||||
apollo: {
|
||||
projectCurrent: PROJECT_CURRENT
|
||||
},
|
||||
@@ -113,6 +129,16 @@ export default {
|
||||
|
||||
compareProjects (a, b) {
|
||||
return a.name.localeCompare(b.name)
|
||||
},
|
||||
|
||||
filterProjects (projects) {
|
||||
const reg = generateSearchRegex(this.search)
|
||||
if (reg) {
|
||||
return projects.filter(
|
||||
p => reg.test(p.path)
|
||||
)
|
||||
}
|
||||
return projects
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,4 +152,9 @@ export default {
|
||||
overflow-y auto
|
||||
position relative
|
||||
min-height 400px
|
||||
|
||||
.toolbar
|
||||
h-box()
|
||||
box-center()
|
||||
margin-bottom $padding-item
|
||||
</style>
|
||||
|
||||
3
packages/@vue/cli-ui/src/util/search.js
Normal file
3
packages/@vue/cli-ui/src/util/search.js
Normal file
@@ -0,0 +1,3 @@
|
||||
export function generateSearchRegex (text) {
|
||||
return text && new RegExp(text.trim().replace(/\s+/g, '.{0,5}'), 'i')
|
||||
}
|
||||
@@ -41,6 +41,7 @@
|
||||
|
||||
<script>
|
||||
import RestoreRoute from '../mixins/RestoreRoute'
|
||||
import { generateSearchRegex } from '../util/search'
|
||||
|
||||
import CONFIGS from '../graphql/configurations.gql'
|
||||
|
||||
@@ -78,7 +79,7 @@ export default {
|
||||
generateItems (configurations) {
|
||||
if (!configurations) return []
|
||||
|
||||
const reg = this.search && new RegExp(this.search, 'i')
|
||||
const reg = generateSearchRegex(this.search)
|
||||
return configurations.filter(
|
||||
item => !reg || item.name.match(reg) || item.description.match(reg)
|
||||
).map(
|
||||
|
||||
Reference in New Issue
Block a user