Commit 94cb80a2 authored by Laura Montemayor's avatar Laura Montemayor Committed by Paul Slaughter

Replaces underscore with lodash in approvals

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/28166
parent 626f1415
<script>
import $ from 'jquery';
import 'select2/select2';
import _ from 'underscore';
import { escape as esc, debounce } from 'lodash';
import Api from 'ee/api';
import { __ } from '~/locale';
import { TYPE_USER, TYPE_GROUP } from '../constants';
......@@ -12,7 +12,7 @@ function addType(type) {
}
function formatSelection(group) {
return _.escape(group.full_name || group.name);
return esc(group.full_name || group.name);
}
function formatResultUser(result) {
......@@ -25,8 +25,8 @@ function formatResultUser(result) {
${avatar}
</div>
<div class="user-info">
<div class="user-name">${_.escape(name)}</div>
<div class="user-username">@${_.escape(username)}</div>
<div class="user-name">${esc(name)}</div>
<div class="user-username">@${esc(username)}</div>
</div>
</div>
`;
......@@ -42,8 +42,8 @@ function formatResultGroup(result) {
${avatar}
</div>
<div class="group-info">
<div class="group-name">${_.escape(fullName)}</div>
<div class="group-path">${_.escape(fullPath)}</div>
<div class="group-name">${esc(fullName)}</div>
<div class="group-path">${esc(fullPath)}</div>
</div>
</div>
`;
......@@ -105,10 +105,7 @@ export default {
closeOnSelect: false,
formatResult,
formatSelection,
query: _.debounce(
({ term, callback }) => this.fetchGroupsAndUsers(term).then(callback),
250,
),
query: debounce(({ term, callback }) => this.fetchGroupsAndUsers(term).then(callback), 250),
id: ({ type, id }) => `${type}${id}`,
})
.on('change', e => this.onChange(e));
......
<script>
import $ from 'jquery';
import 'select2/select2';
import _ from 'underscore';
import { debounce } from 'lodash';
import Api from 'ee/api';
import { __ } from '~/locale';
......@@ -62,7 +62,7 @@ export default {
formatResult,
formatSelection,
initSelection: (element, callback) => this.initialOption(element, callback),
query: _.debounce(({ term, callback }) => this.fetchBranches(term).then(callback), 250),
query: debounce(({ term, callback }) => this.fetchBranches(term).then(callback), 250),
id: ({ type, id }) => `${type}${id}`,
})
.on('change', e => this.onChange(e))
......
<script>
import { mapActions, mapState } from 'vuex';
import _ from 'underscore';
import { escape as esc } from 'lodash';
import { sprintf, n__, s__ } from '~/locale';
import GlModalVuex from '~/vue_shared/components/gl_modal_vuex.vue';
......@@ -33,7 +33,7 @@ export default {
'ApprovalRuleRemove|You are about to remove the %{name} approver group which has %{nMembers}.',
),
{
name: `<strong>${_.escape(this.rule.name)}</strong>`,
name: `<strong>${esc(this.rule.name)}</strong>`,
nMembers: `<strong>${nMembers}</strong>`,
},
false,
......
<script>
import { mapState, mapActions } from 'vuex';
import _ from 'underscore';
import { groupBy, isNumber } from 'lodash';
import { sprintf, __ } from '~/locale';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import ApproversList from './approvers_list.vue';
......@@ -49,7 +49,7 @@ export default {
computed: {
...mapState(['settings']),
approversByType() {
return _.groupBy(this.approvers, x => x.type);
return groupBy(this.approvers, x => x.type);
},
users() {
return this.approversByType[TYPE_USER] || [];
......@@ -88,7 +88,7 @@ export default {
return !this.name ? __('Please provide a name') : '';
},
invalidApprovalsRequired() {
if (!_.isNumber(this.approvalsRequired)) {
if (!isNumber(this.approvalsRequired)) {
return __('Please enter a valid number');
}
......
import _ from 'underscore';
import { memoize, uniqBy, uniqueId, flatten } from 'lodash';
import createFlash from '~/flash';
import { __ } from '~/locale';
import Api from '~/api';
......@@ -7,15 +7,15 @@ import * as types from './mutation_types';
import { RULE_TYPE_ANY_APPROVER } from '../../../constants';
import { mapMRApprovalSettingsResponse } from '../../../mappers';
const fetchGroupMembers = _.memoize(id => Api.groupMembers(id).then(response => response.data));
const fetchGroupMembers = memoize(id => Api.groupMembers(id).then(response => response.data));
const fetchApprovers = ({ userRecords, groups }) => {
const groupUsersAsync = Promise.all(groups.map(fetchGroupMembers));
return groupUsersAsync
.then(_.flatten)
.then(flatten)
.then(groupUsers => groupUsers.concat(userRecords))
.then(users => _.uniq(users, false, x => x.id));
.then(users => uniqBy(users, x => x.id));
};
const seedApprovers = rule =>
......@@ -44,7 +44,7 @@ const seedNewRule = rule => {
...rule,
isNew: true,
name,
id: _.uniqueId('new'),
id: uniqueId('new'),
};
};
......
import _ from 'underscore';
import base from '../base/mutations';
import * as types from './mutation_types';
import { RULE_TYPE_ANY_APPROVER } from '../../../constants';
......@@ -6,7 +5,7 @@ import { RULE_TYPE_ANY_APPROVER } from '../../../constants';
export default {
...base,
[types.DELETE_RULE](state, id) {
const idx = _.findIndex(state.rules, x => x.id === id);
const idx = state.rules.findIndex(x => x.id === id);
if (idx < 0) {
return;
......@@ -35,7 +34,7 @@ export default {
state.rules = [newRule];
},
[types.PUT_RULE](state, { id, ...newRule }) {
const idx = _.findIndex(state.rules, x => x.id === id);
const idx = state.rules.findIndex(x => x.id === id);
if (idx < 0) {
return;
......
......@@ -68,6 +68,7 @@ describe('Approvals ApproversSelect', () => {
};
const search = (term = '') => {
$input.select2('search', term);
jasmine.clock().mockDate();
jasmine.clock().tick(DEBOUNCE_TIME);
};
......
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