Commit 3d2445d4 authored by Coung Ngo's avatar Coung Ngo Committed by Kushal Pandya

Fix sidebar labels scoped label selection bug

parent f98d4700
...@@ -6,6 +6,7 @@ import { GlBreakpointInstance as breakpointInstance } from '@gitlab/ui/dist/util ...@@ -6,6 +6,7 @@ import { GlBreakpointInstance as breakpointInstance } from '@gitlab/ui/dist/util
import $ from 'jquery'; import $ from 'jquery';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import { isFunction, defer } from 'lodash'; import { isFunction, defer } from 'lodash';
import { SCOPED_LABEL_DELIMITER } from '~/vue_shared/components/sidebar/labels_select_widget/constants';
import { convertToCamelCase, convertToSnakeCase } from './text_utility'; import { convertToCamelCase, convertToSnakeCase } from './text_utility';
import { isObject } from './type_utility'; import { isObject } from './type_utility';
import { getLocationHash } from './url_utility'; import { getLocationHash } from './url_utility';
...@@ -685,7 +686,7 @@ export const searchBy = (query = '', searchSpace = {}) => { ...@@ -685,7 +686,7 @@ export const searchBy = (query = '', searchSpace = {}) => {
* @param {Object} label * @param {Object} label
* @returns Boolean * @returns Boolean
*/ */
export const isScopedLabel = ({ title = '' } = {}) => title.indexOf('::') !== -1; export const isScopedLabel = ({ title = '' } = {}) => title.includes(SCOPED_LABEL_DELIMITER);
/** /**
* Returns the base value of the scoped label * Returns the base value of the scoped label
...@@ -696,7 +697,8 @@ export const isScopedLabel = ({ title = '' } = {}) => title.indexOf('::') !== -1 ...@@ -696,7 +697,8 @@ export const isScopedLabel = ({ title = '' } = {}) => title.indexOf('::') !== -1
* @param {Object} label * @param {Object} label
* @returns String * @returns String
*/ */
export const scopedLabelKey = ({ title = '' }) => isScopedLabel({ title }) && title.split('::')[0]; export const scopedLabelKey = ({ title = '' }) =>
isScopedLabel({ title }) && title.split(SCOPED_LABEL_DELIMITER)[0];
// Methods to set and get Cookie // Methods to set and get Cookie
export const setCookie = (name, value) => Cookies.set(name, value, { expires: 365 }); export const setCookie = (name, value) => Cookies.set(name, value, { expires: 365 });
......
import { isScopedLabel, scopedLabelKey } from '~/lib/utils/common_utils'; import { isScopedLabel, scopedLabelKey } from '~/lib/utils/common_utils';
import { SCOPED_LABEL_DELIMITER } from '~/vue_shared/components/sidebar/labels_select_widget/constants';
import { DropdownVariant } from '../constants'; import { DropdownVariant } from '../constants';
import * as types from './mutation_types'; import * as types from './mutation_types';
...@@ -66,10 +67,10 @@ export default { ...@@ -66,10 +67,10 @@ export default {
} }
if (isScopedLabel(candidateLabel)) { if (isScopedLabel(candidateLabel)) {
const scopedBase = scopedLabelKey(candidateLabel); const scopedKeyWithDelimiter = `${scopedLabelKey(candidateLabel)}${SCOPED_LABEL_DELIMITER}`;
const currentActiveScopedLabel = state.labels.find(({ title }) => { const currentActiveScopedLabel = state.labels.find(
return title.startsWith(scopedBase) && title !== '' && title !== candidateLabel.title; ({ title }) => title.startsWith(scopedKeyWithDelimiter) && title !== candidateLabel.title,
}); );
if (currentActiveScopedLabel) { if (currentActiveScopedLabel) {
currentActiveScopedLabel.set = false; currentActiveScopedLabel.set = false;
......
export const SCOPED_LABEL_DELIMITER = '::';
export const DropdownVariant = { export const DropdownVariant = {
Sidebar: 'sidebar', Sidebar: 'sidebar',
Standalone: 'standalone', Standalone: 'standalone',
......
<script> <script>
import { GlLabel, GlButton, GlTooltipDirective } from '@gitlab/ui'; import { GlLabel, GlButton, GlTooltipDirective } from '@gitlab/ui';
import { SCOPED_LABEL_DELIMITER } from '~/vue_shared/components/sidebar/labels_select_widget/constants';
import { DELETE_BUTTON_LABEL, EDIT_BUTTON_LABEL } from '../constants'; import { DELETE_BUTTON_LABEL, EDIT_BUTTON_LABEL } from '../constants';
export default { export default {
...@@ -22,7 +23,7 @@ export default { ...@@ -22,7 +23,7 @@ export default {
}, },
computed: { computed: {
isScoped() { isScoped() {
return this.framework.name.includes('::'); return this.framework.name.includes(SCOPED_LABEL_DELIMITER);
}, },
}, },
i18n: { i18n: {
......
...@@ -157,9 +157,9 @@ describe('LabelsSelect Mutations', () => { ...@@ -157,9 +157,9 @@ describe('LabelsSelect Mutations', () => {
beforeEach(() => { beforeEach(() => {
labels = [ labels = [
{ id: 1, title: 'scoped::test', set: true }, { id: 1, title: 'scoped' },
{ id: 2, set: false, title: 'scoped::one' }, { id: 2, title: 'scoped::one', set: false },
{ id: 3, title: '' }, { id: 3, title: 'scoped::test', set: true },
{ id: 4, title: '' }, { id: 4, title: '' },
]; ];
}); });
...@@ -189,9 +189,9 @@ describe('LabelsSelect Mutations', () => { ...@@ -189,9 +189,9 @@ describe('LabelsSelect Mutations', () => {
}); });
expect(state.labels).toEqual([ expect(state.labels).toEqual([
{ id: 1, title: 'scoped::test', set: false }, { id: 1, title: 'scoped' },
{ id: 2, set: true, title: 'scoped::one', touched: true }, { id: 2, title: 'scoped::one', set: true, touched: true },
{ id: 3, title: '' }, { id: 3, title: 'scoped::test', set: false },
{ id: 4, title: '' }, { id: 4, title: '' },
]); ]);
}); });
......
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