Skip to content

Commit e34da17

Browse files
UncleBillAkryum
authored andcommitted
fix: up-down navigation in filtered-list (#663)
* fix up-down navigation in filtered-list * fix: deselect current item when filtering history * test: fix e2e
1 parent 7503906 commit e34da17

File tree

6 files changed

+33
-19
lines changed

6 files changed

+33
-19
lines changed

cypress/integration/vuex.tab.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,18 @@ suite('vuex tab', () => {
2929
it('should filter history', () => {
3030
cy.get('.left .search input').clear().type('inc')
3131
cy.get('.history .entry').should('have.length', 3)
32-
cy.get('.history .entry.inspected').should('have.length', 0)
32+
cy.get('.history .entry.inspected').should('have.length', 1)
3333
cy.get('.history .entry.active').should('have.length', 0)
3434

3535
cy.get('.left .search input').clear().type('/dec/i')
3636
cy.get('.history .entry').should('have.length', 2)
37-
cy.get('.history .entry.inspected.active').should('have.length', 1)
37+
cy.get('.history .entry.inspected').should('have.length', 1)
38+
cy.get('.history .entry.active').should('have.length', 0)
3839

3940
cy.get('.left .search input').clear().type('/dec)/i')
4041
cy.get('.history .entry').should('have.length', 4)
41-
cy.get('.history .entry.inspected.active').should('have.length', 1)
42+
cy.get('.history .entry.inspected').should('have.length', 1)
43+
cy.get('.history .entry.active').should('have.length', 1)
4244

4345
cy.get('.left .search input').clear()
4446
})

src/devtools/views/events/EventsHistory.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252
v-for="(event, index) in filteredEvents"
5353
ref="entries"
5454
:key="index"
55-
:class="{ active: inspectedIndex === events.indexOf(event) }"
55+
:class="{ active: inspectedIndex === filteredEvents.indexOf(event) }"
5656
class="entry list-item"
57-
@click="inspect(events.indexOf(event))"
57+
@click="inspect(filteredEvents.indexOf(event))"
5858
>
5959
<span class="event-name">{{ event.eventName }}</span>
6060
<span class="event-type">{{ event.type }}</span>
@@ -82,7 +82,7 @@ import Keyboard, {
8282
BACKSPACE
8383
} from '../../mixins/keyboard'
8484
import EntryList from '../../mixins/entry-list'
85-
import { mapState, mapGetters, mapMutations } from 'vuex'
85+
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex'
8686
import { classify, focusInput } from 'src/util'
8787
8888
export default {
@@ -143,17 +143,21 @@ export default {
143143
},
144144
set (filter) {
145145
this.$store.commit('events/UPDATE_FILTER', filter)
146+
this.$store.commit('events/INSPECT', -1)
146147
}
147148
}
148149
},
149150
150151
methods: {
151152
...mapMutations('events', {
152-
inspect: 'INSPECT',
153153
reset: 'RESET',
154154
toggleRecording: 'TOGGLE'
155155
}),
156156
157+
...mapActions('events', [
158+
'inspect'
159+
]),
160+
157161
displayComponentName (name) {
158162
return this.$shared.classifyComponents ? classify(name) : name
159163
}

src/devtools/views/events/module.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ const mutations = {
2525
state.inspectedIndex = -1
2626
},
2727
'INSPECT' (state, index) {
28-
if (index < 0) index = 0
29-
if (index >= state.events.length) index = state.events.length - 1
3028
state.inspectedIndex = index
3129
},
3230
'RESET_NEW_EVENT_COUNT' (state) {
@@ -45,8 +43,8 @@ const mutations = {
4543
}
4644

4745
const getters = {
48-
activeEvent: state => {
49-
return state.events[state.inspectedIndex]
46+
activeEvent: (state, getters) => {
47+
return getters.filteredEvents[state.inspectedIndex]
5048
},
5149
filteredEvents: (state, getters, rootState) => {
5250
const classifyComponents = SharedData.classifyComponents
@@ -61,9 +59,18 @@ const getters = {
6159
}
6260
}
6361

62+
const actions = {
63+
inspect: ({ commit, getters }, index) => {
64+
if (index < 0) index = 0
65+
if (index >= getters.filteredEvents.length) index = getters.filteredEvents.length - 1
66+
commit('INSPECT', index)
67+
}
68+
}
69+
6470
export default {
6571
namespaced: true,
6672
state,
6773
mutations,
68-
getters
74+
getters,
75+
actions
6976
}

src/devtools/views/vuex/VuexHistory.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ export default {
227227
},
228228
set (filter) {
229229
this.$store.dispatch('vuex/updateFilter', filter)
230+
this.$store.commit('vuex/INSPECT', -1)
230231
}
231232
}
232233
},
@@ -244,11 +245,11 @@ export default {
244245
]),
245246
246247
isActive (entry) {
247-
return this.activeIndex === this.history.indexOf(entry)
248+
return this.activeIndex === this.filteredHistory.indexOf(entry)
248249
},
249250
250251
isInspected (entry) {
251-
return this.inspectedIndex === this.history.indexOf(entry)
252+
return this.inspectedIndex === this.filteredHistory.indexOf(entry)
252253
}
253254
}
254255
}

src/devtools/views/vuex/actions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ export function revert ({ commit, state }, entry) {
3030
}
3131
}
3232

33-
export function inspect ({ commit, state }, entryOrIndex) {
33+
export function inspect ({ commit, getters }, entryOrIndex) {
3434
let index = typeof entryOrIndex === 'number'
3535
? entryOrIndex
36-
: state.history.indexOf(entryOrIndex)
36+
: getters.filteredHistory.indexOf(entryOrIndex)
3737
if (index < -1) index = -1
38-
if (index >= state.history.length) index = state.history.length - 1
38+
if (index >= getters.filteredHistory.length) index = getters.filteredHistory.length - 1
3939
commit('INSPECT', index)
4040
}
4141

src/devtools/views/vuex/module.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ function escapeStringForRegExp (str) {
9191
}
9292

9393
const getters = {
94-
inspectedState ({ base, history, inspectedIndex }) {
95-
const entry = history[inspectedIndex]
94+
inspectedState ({ base, inspectedIndex }, getters) {
95+
const entry = getters.filteredHistory[inspectedIndex]
9696
const res = {}
9797

9898
if (entry) {

0 commit comments

Comments
 (0)