Commit bb893a3c authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'lm-replace-underscore-approvals' into 'master'

Replaces underscore with lodash in ./ee/app/assets/javascripts/approvals

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