Skip to content

Commit 2d543e0

Browse files
s4k1btamalsaha
authored andcommitted
Add option filter to by types, fix #6 (#7)
1 parent 0d12f77 commit 2d543e0

File tree

6 files changed

+78
-0
lines changed

6 files changed

+78
-0
lines changed

src/components/FilterType.vue

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<template>
2+
<div class="form-group pull-left">
3+
<label for="filer-org">Type: </label>
4+
<select class="form-control" v-model="filterType" @change="handleTypeChange">
5+
<option value=''>All</option>
6+
<option value="pr">PR</option>
7+
<option value="issue">Issue</option>
8+
</select>
9+
</div>
10+
</template>
11+
12+
<script>
13+
import { mapGetters } from 'vuex';
14+
15+
export default {
16+
computed: {
17+
...mapGetters(['getFilterType']),
18+
filterType: {
19+
get() {
20+
return this.getFilterType;
21+
},
22+
set(type) {
23+
this.$store.dispatch('setFilterType', type);
24+
},
25+
},
26+
},
27+
methods: {
28+
handleTypeChange(e) {
29+
const type = e.currentTarget.value;
30+
const query = {};
31+
if (this.$route.query) {
32+
Object.assign(query, this.$route.query);
33+
}
34+
if (type) {
35+
Object.assign(query, { type });
36+
} else {
37+
delete query.type;
38+
}
39+
40+
if (Object.keys(query).length) {
41+
this.$router.push({ name: 'Search', query });
42+
} else {
43+
this.$router.push({ name: 'MyVuetable' });
44+
}
45+
},
46+
},
47+
};
48+
</script>

src/components/MyVuetable.vue

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
<filter-org></filter-org>
3030
<filter-time></filter-time>
31+
<filter-type></filter-type>
3132
<filter-bar></filter-bar>
3233
</div>
3334
</form>
@@ -124,13 +125,15 @@ import GithubToken from './GithubToken';
124125
import FilterBar from './FilterBar';
125126
import FilterTime from './FilterTime';
126127
import FilterOrg from './FilterOrg';
128+
import FilterType from './FilterType';
127129
import VuetablePaginationBootstrap from './VuetablePaginationBootstrap';
128130
129131
Vue.component('tags-input', VoerroTagsInput);
130132
Vue.use(VueEvents);
131133
Vue.component('github-token', GithubToken);
132134
Vue.component('filter-bar', FilterBar);
133135
Vue.component('filter-time', FilterTime);
136+
Vue.component('filter-type', FilterType);
134137
Vue.component('filter-org', FilterOrg);
135138
136139
export default {
@@ -163,6 +166,11 @@ export default {
163166
} else {
164167
this.$store.dispatch('setFilterTime', '');
165168
}
169+
if (query.type) {
170+
this.$store.dispatch('setFilterType', query.type);
171+
} else {
172+
this.$store.dispatch('setFilterType', '');
173+
}
166174
}
167175
},
168176
props: {

src/store/actions.js

+5
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ const setFilterTime = ({ commit }, filterTime) => {
233233
commit('SET_FILTER_TIME', filterTime);
234234
commit('UPDATE_FILTER_ISSUES');
235235
};
236+
const setFilterType = ({ commit }, filterType) => {
237+
commit('SET_FILTER_TYPE', filterType);
238+
commit('UPDATE_FILTER_ISSUES');
239+
};
236240
const getRepoIssues = ({ state, dispatch }) => {
237241
const orgs = state.orgs && state.orgs.split(',');
238242

@@ -319,6 +323,7 @@ export default {
319323
setFilterText,
320324
setFilterOrg,
321325
setFilterTime,
326+
setFilterType,
322327
getRepoIssues,
323328
issuesUpdateTimer,
324329
};

src/store/getters.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const getCheckboxSelectedIssues = state => state.checkboxSelectedIssues;
55
const getFilterText = state => state.filterText;
66
const getFilterOrg = state => state.filterOrg;
77
const getFilterTime = state => state.filterTime;
8+
const getFilterType = state => state.filterType;
89
const getGithubToken = state => state.githubToken;
910

1011
export default {
@@ -14,5 +15,6 @@ export default {
1415
getFilterText,
1516
getFilterOrg,
1617
getFilterTime,
18+
getFilterType,
1719
getGithubToken,
1820
};

src/store/mutations.js

+14
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ const SET_FILTER_ORG = (state, filterOrg) => {
4545
const SET_FILTER_TIME = (state, filterTime) => {
4646
state.filterTime = filterTime;
4747
};
48+
const SET_FILTER_TYPE = (state, filterType) => {
49+
state.filterType = filterType;
50+
};
4851
const UPDATE_FILTER_ISSUES = (state) => {
4952
let filteredIssues = ''; // [...state.issues]
5053
if (state.filterTime) {
@@ -100,6 +103,16 @@ const UPDATE_FILTER_ISSUES = (state) => {
100103
issue.number.search(regexp) >= 0 ||
101104
issue.repoName.search(regexp) >= 0);
102105
}
106+
107+
if (state.filterType) {
108+
const type = state.filterType;
109+
if (type === 'pr') {
110+
filteredIssues = filteredIssues.filter(issue => issue.isPR);
111+
} else {
112+
filteredIssues = filteredIssues.filter(issue => !issue.isPR);
113+
}
114+
}
115+
103116
state.filteredIssues = filteredIssues;
104117
};
105118

@@ -115,5 +128,6 @@ export default {
115128
SET_FILTER_TEXT,
116129
SET_FILTER_ORG,
117130
SET_FILTER_TIME,
131+
SET_FILTER_TYPE,
118132
UPDATE_FILTER_ISSUES,
119133
};

src/store/store.js

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default new Vuex.Store({
2828
filterText: '',
2929
filterOrg: '',
3030
filterTime: '',
31+
filterType: '',
3132
},
3233

3334
getters,

0 commit comments

Comments
 (0)