Commit 74393bf0 authored by Jake Lear's avatar Jake Lear Committed by Paul Slaughter

Make "show labels" toggle persist with localStorage

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/34728
parent 6566448f
...@@ -63,8 +63,8 @@ const fetchEpics = ({ endpoints }) => { ...@@ -63,8 +63,8 @@ const fetchEpics = ({ endpoints }) => {
export default { export default {
...actionsCE, ...actionsCE,
toggleShowLabels({ commit }) { setShowLabels({ commit }, val) {
commit(types.TOGGLE_LABELS); commit(types.SET_SHOW_LABELS, val);
}, },
setActiveListId({ commit }, listId) { setActiveListId({ commit }, listId) {
......
...@@ -11,9 +11,9 @@ export const REQUEST_REMOVE_BOARD = 'REQUEST_REMOVE_BOARD'; ...@@ -11,9 +11,9 @@ export const REQUEST_REMOVE_BOARD = 'REQUEST_REMOVE_BOARD';
export const RECEIVE_REMOVE_BOARD_SUCCESS = 'RECEIVE_REMOVE_BOARD_SUCCESS'; export const RECEIVE_REMOVE_BOARD_SUCCESS = 'RECEIVE_REMOVE_BOARD_SUCCESS';
export const RECEIVE_REMOVE_BOARD_ERROR = 'RECEIVE_REMOVE_BOARD_ERROR'; export const RECEIVE_REMOVE_BOARD_ERROR = 'RECEIVE_REMOVE_BOARD_ERROR';
export const TOGGLE_PROMOTION_STATE = 'TOGGLE_PROMOTION_STATE'; export const TOGGLE_PROMOTION_STATE = 'TOGGLE_PROMOTION_STATE';
export const TOGGLE_LABELS = 'TOGGLE_LABELS';
export const TOGGLE_EPICS_SWIMLANES = 'TOGGLE_EPICS_SWIMLANES'; export const TOGGLE_EPICS_SWIMLANES = 'TOGGLE_EPICS_SWIMLANES';
export const RECEIVE_SWIMLANES_SUCCESS = 'RECEIVE_SWIMLANES_SUCCESS'; export const RECEIVE_SWIMLANES_SUCCESS = 'RECEIVE_SWIMLANES_SUCCESS';
export const RECEIVE_SWIMLANES_FAILURE = 'RECEIVE_SWIMLANES_FAILURE'; export const RECEIVE_SWIMLANES_FAILURE = 'RECEIVE_SWIMLANES_FAILURE';
export const RECEIVE_EPICS_SUCCESS = 'RECEIVE_EPICS_SUCCESS'; export const RECEIVE_EPICS_SUCCESS = 'RECEIVE_EPICS_SUCCESS';
export const SET_ACTIVE_LIST_ID = 'SET_ACTIVE_LIST_ID'; export const SET_ACTIVE_LIST_ID = 'SET_ACTIVE_LIST_ID';
export const SET_SHOW_LABELS = 'SET_SHOW_LABELS';
...@@ -8,8 +8,8 @@ const notImplemented = () => { ...@@ -8,8 +8,8 @@ const notImplemented = () => {
export default { export default {
...mutationsCE, ...mutationsCE,
[mutationTypes.TOGGLE_LABELS]: state => { [mutationTypes.SET_SHOW_LABELS]: (state, val) => {
state.isShowingLabels = !state.isShowingLabels; state.isShowingLabels = val;
}, },
[mutationTypes.SET_ACTIVE_LIST_ID]: (state, id) => { [mutationTypes.SET_ACTIVE_LIST_ID]: (state, id) => {
state.activeListId = id; state.activeListId = id;
......
...@@ -3,12 +3,14 @@ import { mapState, mapGetters, mapActions } from 'vuex'; ...@@ -3,12 +3,14 @@ import { mapState, mapGetters, mapActions } from 'vuex';
import { GlToggle } from '@gitlab/ui'; import { GlToggle } from '@gitlab/ui';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import store from '~/boards/stores'; import store from '~/boards/stores';
import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
export default () => export default () =>
new Vue({ new Vue({
el: document.getElementById('js-board-labels-toggle'), el: document.getElementById('js-board-labels-toggle'),
components: { components: {
GlToggle, GlToggle,
LocalStorageSync,
}, },
store, store,
computed: { computed: {
...@@ -16,19 +18,24 @@ export default () => ...@@ -16,19 +18,24 @@ export default () =>
...mapGetters(['getLabelToggleState']), ...mapGetters(['getLabelToggleState']),
}, },
methods: { methods: {
...mapActions(['toggleShowLabels']), ...mapActions(['setShowLabels']),
onToggle() { onToggle(val) {
this.toggleShowLabels(); this.setShowLabels(val);
Tracking.event(document.body.dataset.page, 'toggle', { Tracking.event(document.body.dataset.page, 'toggle', {
label: 'show_labels', label: 'show_labels',
property: this.getLabelToggleState, property: this.getLabelToggleState,
}); });
}, },
onStorageUpdate(val) {
this.setShowLabels(JSON.parse(val));
},
}, },
template: ` template: `
<div class="board-labels-toggle-wrapper d-flex align-items-center prepend-left-10"> <div class="board-labels-toggle-wrapper d-flex align-items-center prepend-left-10">
<local-storage-sync storage-key="gl-show-board-labels" :value="JSON.stringify(isShowingLabels)" @input="onStorageUpdate" />
<gl-toggle <gl-toggle
:value="isShowingLabels" :value="isShowingLabels"
label="Show labels" label="Show labels"
......
---
title: Update the "show labels" toggle on boards to persist using localStorage
merge_request: 34728
author:
type: changed
...@@ -13,13 +13,20 @@ const expectNotImplemented = action => { ...@@ -13,13 +13,20 @@ const expectNotImplemented = action => {
}); });
}; };
describe('toggleShowLabels', () => { describe('setShowLabels', () => {
it('should commit mutation TOGGLE_LABELS', done => { it('should commit mutation SET_SHOW_LABELS', done => {
const state = { const state = {
isShowingLabels: true, isShowingLabels: true,
}; };
testAction(actions.toggleShowLabels, null, state, [{ type: types.TOGGLE_LABELS }], [], done); testAction(
actions.setShowLabels,
false,
state,
[{ type: types.SET_SHOW_LABELS, payload: false }],
[],
done,
);
}); });
}); });
......
...@@ -8,26 +8,16 @@ const expectNotImplemented = action => { ...@@ -8,26 +8,16 @@ const expectNotImplemented = action => {
}); });
}; };
describe('TOGGLE_LABELS', () => { describe('SET_SHOW_LABELS', () => {
it('toggles isShowingLabels from true to false', () => { it('updates isShowingLabels', () => {
const state = { const state = {
isShowingLabels: true, isShowingLabels: true,
}; };
mutations.TOGGLE_LABELS(state); mutations.SET_SHOW_LABELS(state, false);
expect(state.isShowingLabels).toBe(false); expect(state.isShowingLabels).toBe(false);
}); });
it('toggles isShowingLabels from false to true', () => {
const state = {
isShowingLabels: false,
};
mutations.TOGGLE_LABELS(state);
expect(state.isShowingLabels).toBe(true);
});
}); });
describe('SET_ACTIVE_LIST_ID', () => { describe('SET_ACTIVE_LIST_ID', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment