Skip to content

Fixed up-down navigation in filtered-list #663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cypress/integration/vuex.tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ suite('vuex tab', () => {
it('should filter history', () => {
cy.get('.left .search input').clear().type('inc')
cy.get('.history .entry').should('have.length', 3)
cy.get('.history .entry.inspected').should('have.length', 0)
cy.get('.history .entry.inspected').should('have.length', 1)
cy.get('.history .entry.active').should('have.length', 0)

cy.get('.left .search input').clear().type('/dec/i')
cy.get('.history .entry').should('have.length', 2)
cy.get('.history .entry.inspected.active').should('have.length', 1)
cy.get('.history .entry.inspected').should('have.length', 1)
cy.get('.history .entry.active').should('have.length', 0)

cy.get('.left .search input').clear().type('/dec)/i')
cy.get('.history .entry').should('have.length', 4)
cy.get('.history .entry.inspected.active').should('have.length', 1)
cy.get('.history .entry.inspected').should('have.length', 1)
cy.get('.history .entry.active').should('have.length', 1)

cy.get('.left .search input').clear()
})
Expand Down
12 changes: 8 additions & 4 deletions src/devtools/views/events/EventsHistory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
v-for="(event, index) in filteredEvents"
ref="entries"
:key="index"
:class="{ active: inspectedIndex === events.indexOf(event) }"
:class="{ active: inspectedIndex === filteredEvents.indexOf(event) }"
class="entry list-item"
@click="inspect(events.indexOf(event))"
@click="inspect(filteredEvents.indexOf(event))"
>
<span class="event-name">{{ event.eventName }}</span>
<span class="event-type">{{ event.type }}</span>
Expand Down Expand Up @@ -82,7 +82,7 @@ import Keyboard, {
BACKSPACE
} from '../../mixins/keyboard'
import EntryList from '../../mixins/entry-list'
import { mapState, mapGetters, mapMutations } from 'vuex'
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex'
import { classify, focusInput } from 'src/util'

export default {
Expand Down Expand Up @@ -143,17 +143,21 @@ export default {
},
set (filter) {
this.$store.commit('events/UPDATE_FILTER', filter)
this.$store.commit('events/INSPECT', -1)
}
}
},

methods: {
...mapMutations('events', {
inspect: 'INSPECT',
reset: 'RESET',
toggleRecording: 'TOGGLE'
}),

...mapActions('events', [
'inspect'
]),

displayComponentName (name) {
return this.$shared.classifyComponents ? classify(name) : name
}
Expand Down
17 changes: 12 additions & 5 deletions src/devtools/views/events/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const mutations = {
state.inspectedIndex = -1
},
'INSPECT' (state, index) {
if (index < 0) index = 0
if (index >= state.events.length) index = state.events.length - 1
state.inspectedIndex = index
},
'RESET_NEW_EVENT_COUNT' (state) {
Expand All @@ -45,8 +43,8 @@ const mutations = {
}

const getters = {
activeEvent: state => {
return state.events[state.inspectedIndex]
activeEvent: (state, getters) => {
return getters.filteredEvents[state.inspectedIndex]
},
filteredEvents: (state, getters, rootState) => {
const classifyComponents = SharedData.classifyComponents
Expand All @@ -61,9 +59,18 @@ const getters = {
}
}

const actions = {
inspect: ({ commit, getters }, index) => {
if (index < 0) index = 0
if (index >= getters.filteredEvents.length) index = getters.filteredEvents.length - 1
commit('INSPECT', index)
}
}

export default {
namespaced: true,
state,
mutations,
getters
getters,
actions
}
5 changes: 3 additions & 2 deletions src/devtools/views/vuex/VuexHistory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export default {
},
set (filter) {
this.$store.dispatch('vuex/updateFilter', filter)
this.$store.commit('vuex/INSPECT', -1)
}
}
},
Expand All @@ -244,11 +245,11 @@ export default {
]),

isActive (entry) {
return this.activeIndex === this.history.indexOf(entry)
return this.activeIndex === this.filteredHistory.indexOf(entry)
},

isInspected (entry) {
return this.inspectedIndex === this.history.indexOf(entry)
return this.inspectedIndex === this.filteredHistory.indexOf(entry)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/devtools/views/vuex/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export function revert ({ commit, state }, entry) {
}
}

export function inspect ({ commit, state }, entryOrIndex) {
export function inspect ({ commit, getters }, entryOrIndex) {
let index = typeof entryOrIndex === 'number'
? entryOrIndex
: state.history.indexOf(entryOrIndex)
: getters.filteredHistory.indexOf(entryOrIndex)
if (index < -1) index = -1
if (index >= state.history.length) index = state.history.length - 1
if (index >= getters.filteredHistory.length) index = getters.filteredHistory.length - 1
commit('INSPECT', index)
}

Expand Down
4 changes: 2 additions & 2 deletions src/devtools/views/vuex/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ function escapeStringForRegExp (str) {
}

const getters = {
inspectedState ({ base, history, inspectedIndex }) {
const entry = history[inspectedIndex]
inspectedState ({ base, inspectedIndex }, getters) {
const entry = getters.filteredHistory[inspectedIndex]
const res = {}

if (entry) {
Expand Down