diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2019-02-26 20:12:45 +0300 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2019-02-26 20:12:45 +0300 |
commit | 3a29b6af828da63ff7142183135d5ddbbd90d940 (patch) | |
tree | 99f858f11545a88253857b7a2c7c2ce2e9c51e89 /app | |
parent | cb3324d30d193a17ff5536f119dc2bc49488f012 (diff) | |
parent | fa882a674a389fc41a155f5ba72e757a7ea02d7a (diff) |
Merge branch '46750-ci-empty-environment-is-created-even-when-a-job-isn-t-run-when-manual' into 'master'
Sort Environments by Last Updated
Closes #46750
See merge request gitlab-org/gitlab-ce!25260
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/environments/components/environments_table.vue | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/app/assets/javascripts/environments/components/environments_table.vue b/app/assets/javascripts/environments/components/environments_table.vue index e2c304de00a..eef141a07ba 100644 --- a/app/assets/javascripts/environments/components/environments_table.vue +++ b/app/assets/javascripts/environments/components/environments_table.vue @@ -3,6 +3,7 @@ * Render environments table. */ import { GlLoadingIcon } from '@gitlab/ui'; +import _ from 'underscore'; import environmentItem from './environment_item.vue'; export default { @@ -24,6 +25,15 @@ export default { default: false, }, }, + computed: { + sortedEnvironments() { + return this.sortEnvironments(this.environments).map(env => + this.shouldRenderFolderContent(env) + ? { ...env, children: this.sortEnvironments(env.children) } + : env, + ); + }, + }, methods: { folderUrl(model) { return `${window.location.pathname}/folders/${model.folderName}`; @@ -31,6 +41,30 @@ export default { shouldRenderFolderContent(env) { return env.isFolder && env.isOpen && env.children && env.children.length > 0; }, + sortEnvironments(environments) { + /* + * The sorting algorithm should sort in the following priorities: + * + * 1. folders first, + * 2. last updated descending, + * 3. by name ascending, + * + * the sorting algorithm must: + * + * 1. Sort by name ascending, + * 2. Reverse (sort by name descending), + * 3. Sort by last deployment ascending, + * 4. Reverse (last deployment descending, name ascending), + * 5. Put folders first. + */ + return _.chain(environments) + .sortBy(env => (env.isFolder ? env.folderName : env.name)) + .reverse() + .sortBy(env => (env.last_deployment ? env.last_deployment.created_at : '0000')) + .reverse() + .sortBy(env => (env.isFolder ? -1 : 1)) + .value(); + }, }, }; </script> @@ -53,7 +87,7 @@ export default { {{ s__('Environments|Updated') }} </div> </div> - <template v-for="(model, i) in environments" :model="model"> + <template v-for="(model, i) in sortedEnvironments" :model="model"> <div is="environment-item" :key="`environment-item-${i}`" |