Commit 71e66603 authored by Alexander Turinske's avatar Alexander Turinske Committed by Natalia Tepluhina

Replace underscore with lodash in env folder

- replaced underscore functions with lodash equivalents
- moved chain to flow as the babel plugin for lodash
  does not support chain
- used composition instead https://medium.com/making-internets/why-using-chain-is-a-mistake-9bc1f80d51ba
- used partial right for sortBy
  https://stackoverflow.com/questions/56324387/jest-throwing-typererror-expected-a-function-when-using-lodash-pipe-flow
- escape, isFunction, isUndefined, isNull, omit, chain, isEqual,
  and isEmpty
parent a9b05ffc
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Render modal to confirm rollback/redeploy. * Render modal to confirm rollback/redeploy.
*/ */
import _ from 'underscore'; import { escape as esc } from 'lodash';
import { GlModal } from '@gitlab/ui'; import { GlModal } from '@gitlab/ui';
import { s__, sprintf } from '~/locale'; import { s__, sprintf } from '~/locale';
...@@ -30,7 +30,7 @@ export default { ...@@ -30,7 +30,7 @@ export default {
: s__('Environments|Rollback environment %{name}?'); : s__('Environments|Rollback environment %{name}?');
return sprintf(title, { return sprintf(title, {
name: _.escape(this.environment.name), name: esc(this.environment.name),
}); });
}, },
...@@ -50,10 +50,10 @@ export default { ...@@ -50,10 +50,10 @@ export default {
}, },
modalText() { modalText() {
const linkStart = `<a class="commit-sha mr-0" href="${_.escape(this.commitUrl)}">`; const linkStart = `<a class="commit-sha mr-0" href="${esc(this.commitUrl)}">`;
const commitId = _.escape(this.commitShortSha); const commitId = esc(this.commitShortSha);
const linkEnd = '</a>'; const linkEnd = '</a>';
const name = _.escape(this.name); const name = esc(this.name);
const body = this.environment.isLastDeployment const body = this.environment.isLastDeployment
? s__( ? s__(
'Environments|This action will relaunch the job for commit %{linkStart}%{commitId}%{linkEnd}, putting the environment in a previous version. Are you sure you want to continue?', 'Environments|This action will relaunch the job for commit %{linkStart}%{commitId}%{linkEnd}, putting the environment in a previous version. Are you sure you want to continue?',
......
<script> <script>
/* eslint-disable @gitlab/vue-require-i18n-strings */ /* eslint-disable @gitlab/vue-require-i18n-strings */
import _ from 'underscore'; import { isEmpty } from 'lodash';
import { GlTooltipDirective } from '@gitlab/ui'; import { GlTooltipDirective } from '@gitlab/ui';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
...@@ -79,7 +79,7 @@ export default { ...@@ -79,7 +79,7 @@ export default {
* @returns {Boolean} * @returns {Boolean}
*/ */
hasLastDeploymentKey() { hasLastDeploymentKey() {
if (this.model && this.model.last_deployment && !_.isEmpty(this.model.last_deployment)) { if (this.model && this.model.last_deployment && !isEmpty(this.model.last_deployment)) {
return true; return true;
} }
return false; return false;
...@@ -390,8 +390,8 @@ export default { ...@@ -390,8 +390,8 @@ export default {
deploymentHasUser() { deploymentHasUser() {
return ( return (
this.model && this.model &&
!_.isEmpty(this.model.last_deployment) && !isEmpty(this.model.last_deployment) &&
!_.isEmpty(this.model.last_deployment.user) !isEmpty(this.model.last_deployment.user)
); );
}, },
...@@ -404,8 +404,8 @@ export default { ...@@ -404,8 +404,8 @@ export default {
deploymentUser() { deploymentUser() {
if ( if (
this.model && this.model &&
!_.isEmpty(this.model.last_deployment) && !isEmpty(this.model.last_deployment) &&
!_.isEmpty(this.model.last_deployment.user) !isEmpty(this.model.last_deployment.user)
) { ) {
return this.model.last_deployment.user; return this.model.last_deployment.user;
} }
...@@ -431,8 +431,8 @@ export default { ...@@ -431,8 +431,8 @@ export default {
shouldRenderBuildName() { shouldRenderBuildName() {
return ( return (
!this.isFolder && !this.isFolder &&
!_.isEmpty(this.model.last_deployment) && !isEmpty(this.model.last_deployment) &&
!_.isEmpty(this.model.last_deployment.deployable) !isEmpty(this.model.last_deployment.deployable)
); );
}, },
...@@ -473,7 +473,7 @@ export default { ...@@ -473,7 +473,7 @@ export default {
shouldRenderDeploymentID() { shouldRenderDeploymentID() {
return ( return (
!this.isFolder && !this.isFolder &&
!_.isEmpty(this.model.last_deployment) && !isEmpty(this.model.last_deployment) &&
this.model.last_deployment.iid !== undefined this.model.last_deployment.iid !== undefined
); );
}, },
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Render environments table. * Render environments table.
*/ */
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import _ from 'underscore'; import { flow, reverse, sortBy } from 'lodash/fp';
import environmentTableMixin from 'ee_else_ce/environments/mixins/environments_table_mixin'; import environmentTableMixin from 'ee_else_ce/environments/mixins/environments_table_mixin';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
...@@ -102,13 +102,13 @@ export default { ...@@ -102,13 +102,13 @@ export default {
* 4. Reverse (last deployment descending, name ascending), * 4. Reverse (last deployment descending, name ascending),
* 5. Put folders first. * 5. Put folders first.
*/ */
return _.chain(environments) return flow(
.sortBy(env => (env.isFolder ? env.folderName : env.name)) sortBy(env => (env.isFolder ? env.folderName : env.name)),
.reverse() reverse,
.sortBy(env => (env.last_deployment ? env.last_deployment.created_at : '0000')) sortBy(env => (env.last_deployment ? env.last_deployment.created_at : '0000')),
.reverse() reverse,
.sortBy(env => (env.isFolder ? -1 : 1)) sortBy(env => (env.isFolder ? -1 : 1)),
.value(); )(environments);
}, },
}, },
}; };
......
/** /**
* Common code between environmets app and folder view * Common code between environmets app and folder view
*/ */
import _ from 'underscore'; import { isEqual, isFunction, omitBy } from 'lodash';
import Visibility from 'visibilityjs'; import Visibility from 'visibilityjs';
import EnvironmentsStore from 'ee_else_ce/environments/stores/environments_store'; import EnvironmentsStore from 'ee_else_ce/environments/stores/environments_store';
import Poll from '../../lib/utils/poll'; import Poll from '../../lib/utils/poll';
...@@ -54,7 +54,7 @@ export default { ...@@ -54,7 +54,7 @@ export default {
const response = this.filterNilValues(resp.config.params); const response = this.filterNilValues(resp.config.params);
const request = this.filterNilValues(this.requestData); const request = this.filterNilValues(this.requestData);
if (_.isEqual(response, request)) { if (isEqual(response, request)) {
this.store.storeAvailableCount(resp.data.available_count); this.store.storeAvailableCount(resp.data.available_count);
this.store.storeStoppedCount(resp.data.stopped_count); this.store.storeStoppedCount(resp.data.stopped_count);
this.store.storeEnvironments(resp.data.environments); this.store.storeEnvironments(resp.data.environments);
...@@ -64,7 +64,7 @@ export default { ...@@ -64,7 +64,7 @@ export default {
}, },
filterNilValues(obj) { filterNilValues(obj) {
return _.omit(obj, value => _.isUndefined(value) || _.isNull(value)); return omitBy(obj, value => value === undefined || value === null);
}, },
/** /**
...@@ -109,7 +109,7 @@ export default { ...@@ -109,7 +109,7 @@ export default {
.then(() => this.fetchEnvironments()) .then(() => this.fetchEnvironments())
.catch(err => { .catch(err => {
this.isLoading = false; this.isLoading = false;
Flash(_.isFunction(errorMessage) ? errorMessage(err.response.data) : errorMessage); Flash(isFunction(errorMessage) ? errorMessage(err.response.data) : errorMessage);
}); });
} }
}, },
......
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