Commit 961983a4 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'tz-optimise-label-select' into 'master'

Optimize Sidebar Label Selector

See merge request gitlab-org/gitlab!65530
parents 235dd4e6 b244efc5
...@@ -315,7 +315,7 @@ export default { ...@@ -315,7 +315,7 @@ export default {
</dropdown-value> </dropdown-value>
<dropdown-button v-show="dropdownButtonVisible" class="gl-mt-2" /> <dropdown-button v-show="dropdownButtonVisible" class="gl-mt-2" />
<dropdown-contents <dropdown-contents
v-show="dropdownButtonVisible && showDropdownContents" v-if="dropdownButtonVisible && showDropdownContents"
ref="dropdownContents" ref="dropdownContents"
:render-on-top="!contentIsOnViewport" :render-on-top="!contentIsOnViewport"
/> />
......
...@@ -20,7 +20,11 @@ export const receiveLabelsFailure = ({ commit }) => { ...@@ -20,7 +20,11 @@ export const receiveLabelsFailure = ({ commit }) => {
message: __('Error fetching labels.'), message: __('Error fetching labels.'),
}); });
}; };
export const fetchLabels = ({ state, dispatch }) => { export const fetchLabels = ({ state, dispatch }, options) => {
if (state.labelsFetched && (!options || !options.refetch)) {
return Promise.resolve();
}
dispatch('requestLabels'); dispatch('requestLabels');
return axios return axios
.get(state.labelsFetchPath) .get(state.labelsFetchPath)
...@@ -46,6 +50,7 @@ export const createLabel = ({ state, dispatch }, label) => { ...@@ -46,6 +50,7 @@ export const createLabel = ({ state, dispatch }, label) => {
}) })
.then(({ data }) => { .then(({ data }) => {
if (data.id) { if (data.id) {
dispatch('fetchLabels', { refetch: true });
dispatch('receiveCreateLabelSuccess'); dispatch('receiveCreateLabelSuccess');
dispatch('toggleDropdownContentsCreateView'); dispatch('toggleDropdownContentsCreateView');
} else { } else {
......
...@@ -36,6 +36,7 @@ export default { ...@@ -36,6 +36,7 @@ export default {
// selectedLabels array. // selectedLabels array.
const selectedLabelIds = state.selectedLabels.map((label) => label.id); const selectedLabelIds = state.selectedLabels.map((label) => label.id);
state.labelsFetchInProgress = false; state.labelsFetchInProgress = false;
state.labelsFetched = true;
state.labels = labels.reduce((allLabels, label) => { state.labels = labels.reduce((allLabels, label) => {
allLabels.push({ allLabels.push({
...label, ...label,
......
export default () => ({ export default () => ({
// Initial Data // Initial Data
labels: [], labels: [],
labelsFetched: false,
selectedLabels: [], selectedLabels: [],
labelsListTitle: '', labelsListTitle: '',
labelsCreateTitle: '', labelsCreateTitle: '',
......
...@@ -330,7 +330,7 @@ export default { ...@@ -330,7 +330,7 @@ export default {
</dropdown-value> </dropdown-value>
<dropdown-button v-show="dropdownButtonVisible" class="gl-mt-2" /> <dropdown-button v-show="dropdownButtonVisible" class="gl-mt-2" />
<dropdown-contents <dropdown-contents
v-show="dropdownButtonVisible && showDropdownContents" v-if="dropdownButtonVisible && showDropdownContents"
ref="dropdownContents" ref="dropdownContents"
:render-on-top="!contentIsOnViewport" :render-on-top="!contentIsOnViewport"
:labels-create-title="labelsCreateTitle" :labels-create-title="labelsCreateTitle"
......
...@@ -214,7 +214,7 @@ describe('LabelsSelect Actions', () => { ...@@ -214,7 +214,7 @@ describe('LabelsSelect Actions', () => {
}); });
describe('on success', () => { describe('on success', () => {
it('dispatches `requestCreateLabel`, `receiveCreateLabelSuccess` & `toggleDropdownContentsCreateView` actions', (done) => { it('dispatches `requestCreateLabel`, `fetchLabels` & `receiveCreateLabelSuccess` & `toggleDropdownContentsCreateView` actions', (done) => {
const label = { id: 1 }; const label = { id: 1 };
mock.onPost(/labels.json/).replyOnce(200, label); mock.onPost(/labels.json/).replyOnce(200, label);
...@@ -225,6 +225,7 @@ describe('LabelsSelect Actions', () => { ...@@ -225,6 +225,7 @@ describe('LabelsSelect Actions', () => {
[], [],
[ [
{ type: 'requestCreateLabel' }, { type: 'requestCreateLabel' },
{ payload: { refetch: true }, type: 'fetchLabels' },
{ type: 'receiveCreateLabelSuccess' }, { type: 'receiveCreateLabelSuccess' },
{ type: 'toggleDropdownContentsCreateView' }, { type: 'toggleDropdownContentsCreateView' },
], ],
......
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