Commit 3066bdd6 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'jivanvl-replace-underscore-lodash-ee-vue-shared' into 'master'

Replace underscore/lodash in ee/vue_shared

Closes #210267

See merge request gitlab-org/gitlab!27925
parents 81ba4565 6057e96e
<script> <script>
import { uniqueId } from 'underscore'; import { uniqueId } from 'lodash';
export default { export default {
created() { created() {
......
<script> <script>
import { uniqueId } from 'underscore'; import { uniqueId } from 'lodash';
import { GlSkeletonLoader } from '@gitlab/ui'; import { GlSkeletonLoader } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
......
<script> <script>
import _ from 'underscore'; import { escape as esc } from 'lodash';
import { __, n__, sprintf } from '~/locale'; import { __, n__, sprintf } from '~/locale';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
...@@ -40,8 +40,8 @@ export default { ...@@ -40,8 +40,8 @@ export default {
return sprintf( return sprintf(
__('%{title} %{operator} %{threshold}'), __('%{title} %{operator} %{threshold}'),
{ {
title: _.escape(this.lastAlert.title), title: esc(this.lastAlert.title),
threshold: `${_.escape(this.lastAlert.threshold)}%`, threshold: `${esc(this.lastAlert.threshold)}%`,
operator: this.lastAlert.operator, operator: this.lastAlert.operator,
}, },
false, false,
......
import Visibility from 'visibilityjs'; import Visibility from 'visibilityjs';
import _ from 'underscore'; import { find } from 'lodash';
import Api from '~/api'; import Api from '~/api';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import Poll from '~/lib/utils/poll'; import Poll from '~/lib/utils/poll';
...@@ -33,7 +33,7 @@ export const addProjectsToDashboard = ({ state, dispatch }) => ...@@ -33,7 +33,7 @@ export const addProjectsToDashboard = ({ state, dispatch }) =>
.catch(() => dispatch('receiveAddProjectsToDashboardError')); .catch(() => dispatch('receiveAddProjectsToDashboardError'));
export const toggleSelectedProject = ({ commit, state }, project) => { export const toggleSelectedProject = ({ commit, state }, project) => {
if (!_.find(state.selectedProjects, { id: project.id })) { if (!find(state.selectedProjects, { id: project.id })) {
commit(types.ADD_SELECTED_PROJECT, project); commit(types.ADD_SELECTED_PROJECT, project);
} else { } else {
commit(types.REMOVE_SELECTED_PROJECT, project); commit(types.REMOVE_SELECTED_PROJECT, project);
......
<script> <script>
import _ from 'underscore'; import { escape as esc } from 'lodash';
import { mapActions, mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
import { s__, sprintf } from '~/locale'; import { s__, sprintf } from '~/locale';
import DeprecatedModal2 from '~/vue_shared/components/deprecated_modal_2.vue'; import DeprecatedModal2 from '~/vue_shared/components/deprecated_modal_2.vue';
...@@ -12,7 +12,7 @@ export default { ...@@ -12,7 +12,7 @@ export default {
computed: { computed: {
...mapState(LICENSE_MANAGEMENT, ['currentLicenseInModal']), ...mapState(LICENSE_MANAGEMENT, ['currentLicenseInModal']),
confirmationText() { confirmationText() {
const name = `<strong>${_.escape(this.currentLicenseInModal.name)}</strong>`; const name = `<strong>${esc(this.currentLicenseInModal.name)}</strong>`;
return sprintf( return sprintf(
s__('LicenseCompliance|You are about to remove the license, %{name}, from this project.'), s__('LicenseCompliance|You are about to remove the license, %{name}, from this project.'),
......
<script> <script>
import _ from 'underscore'; import { escape as esc } from 'lodash';
import EventItem from 'ee/vue_shared/security_reports/components/event_item.vue'; import EventItem from 'ee/vue_shared/security_reports/components/event_item.vue';
import { GlButton } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
...@@ -54,7 +54,7 @@ export default { ...@@ -54,7 +54,7 @@ export default {
const projectLink = const projectLink =
project && project.url && project.value project && project.url && project.value
? `<a href="${_.escape(project.url)}">${_.escape(project.value)}</a>` ? `<a href="${esc(project.url)}">${esc(project.value)}</a>`
: null; : null;
if (pipelineLink && projectLink) { if (pipelineLink && projectLink) {
......
<script> <script>
import _ from 'underscore'; import { escape as esc } from 'lodash';
import EventItem from 'ee/vue_shared/security_reports/components/event_item.vue'; import EventItem from 'ee/vue_shared/security_reports/components/event_item.vue';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
...@@ -24,7 +24,7 @@ export default { ...@@ -24,7 +24,7 @@ export default {
const issueLink = `<a href="${feedback.issue_url}">#${feedback.issue_iid}</a>`; const issueLink = `<a href="${feedback.issue_url}">#${feedback.issue_iid}</a>`;
if (project && project.value && project.url) { if (project && project.value && project.url) {
const projectLink = `<a href="${_.escape(project.url)}">${_.escape(project.value)}</a>`; const projectLink = `<a href="${esc(project.url)}">${esc(project.value)}</a>`;
return sprintf( return sprintf(
__('Created issue %{issueLink} at %{projectLink}'), __('Created issue %{issueLink} at %{projectLink}'),
......
<script> <script>
import _ from 'underscore'; import { escape as esc } from 'lodash';
import EventItem from 'ee/vue_shared/security_reports/components/event_item.vue'; import EventItem from 'ee/vue_shared/security_reports/components/event_item.vue';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
...@@ -24,7 +24,7 @@ export default { ...@@ -24,7 +24,7 @@ export default {
const mergeRequestLink = `<a href="${feedback.merge_request_path}">!${feedback.merge_request_iid}</a>`; const mergeRequestLink = `<a href="${feedback.merge_request_path}">!${feedback.merge_request_iid}</a>`;
if (project && project.value && project.url) { if (project && project.value && project.url) {
const projectLink = `<a href="${_.escape(project.url)}">${_.escape(project.value)}</a>`; const projectLink = `<a href="${esc(project.url)}">${esc(project.value)}</a>`;
return sprintf( return sprintf(
__('Created merge request %{mergeRequestLink} at %{projectLink}'), __('Created merge request %{mergeRequestLink} at %{projectLink}'),
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { uniqueId } from 'underscore';
import { AccordionItem } from 'ee/vue_shared/components/accordion'; import { AccordionItem } from 'ee/vue_shared/components/accordion';
import accordionEventBus from 'ee/vue_shared/components/accordion/accordion_event_bus'; import accordionEventBus from 'ee/vue_shared/components/accordion/accordion_event_bus';
import { uniqueId } from 'lodash';
jest.mock('ee/vue_shared/components/accordion/accordion_event_bus', () => ({ jest.mock('ee/vue_shared/components/accordion/accordion_event_bus', () => ({
$on: jest.fn(), $on: jest.fn(),
...@@ -10,7 +10,7 @@ jest.mock('ee/vue_shared/components/accordion/accordion_event_bus', () => ({ ...@@ -10,7 +10,7 @@ jest.mock('ee/vue_shared/components/accordion/accordion_event_bus', () => ({
$off: jest.fn(), $off: jest.fn(),
})); }));
jest.mock('underscore'); jest.mock('lodash/uniqueId', () => jest.fn().mockReturnValue('mockUniqueId'));
describe('AccordionItem component', () => { describe('AccordionItem component', () => {
const mockUniqueId = 'mockUniqueId'; const mockUniqueId = 'mockUniqueId';
...@@ -43,10 +43,6 @@ describe('AccordionItem component', () => { ...@@ -43,10 +43,6 @@ describe('AccordionItem component', () => {
const content = () => wrapper.find({ ref: 'content' }); const content = () => wrapper.find({ ref: 'content' });
const namespacedCloseOtherAccordionItemsEvent = `${accordionId}.closeOtherAccordionItems`; const namespacedCloseOtherAccordionItemsEvent = `${accordionId}.closeOtherAccordionItems`;
beforeEach(() => {
uniqueId.mockReturnValue(mockUniqueId);
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null; wrapper = null;
...@@ -171,8 +167,7 @@ describe('AccordionItem component', () => { ...@@ -171,8 +167,7 @@ describe('AccordionItem component', () => {
it('contains a expansion trigger element with a unique, namespaced id', () => { it('contains a expansion trigger element with a unique, namespaced id', () => {
expect(uniqueId).toHaveBeenCalledWith('gl-accordion-item-trigger-'); expect(uniqueId).toHaveBeenCalledWith('gl-accordion-item-trigger-');
expect(expansionTrigger().attributes('id')).toBe(mockUniqueId);
expect(expansionTrigger().attributes('id')).toBe('mockUniqueId');
}); });
it('contains a content-container element with a unique, namespaced id', () => { it('contains a content-container element with a unique, namespaced id', () => {
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { Accordion } from 'ee/vue_shared/components/accordion'; import { Accordion } from 'ee/vue_shared/components/accordion';
import { uniqueId } from 'underscore'; jest.mock('lodash/uniqueId', () => () => 'foo');
jest.mock('underscore');
describe('Accordion component', () => { describe('Accordion component', () => {
let wrapper; let wrapper;
...@@ -30,7 +28,6 @@ describe('Accordion component', () => { ...@@ -30,7 +28,6 @@ describe('Accordion component', () => {
it('passes a unique "accordionId" to the default slot', () => { it('passes a unique "accordionId" to the default slot', () => {
const mockUniqueIdValue = 'foo'; const mockUniqueIdValue = 'foo';
uniqueId.mockReturnValueOnce(mockUniqueIdValue);
const defaultSlot = '<span>{{ props.accordionId }}</span>'; const defaultSlot = '<span>{{ props.accordionId }}</span>';
......
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