Environments page - Showing oldest deployment instead of latest

Summary

On the Deployments > Environments page: the "Latest Deployed" deployment shown for each environment is incorrect, it is showing the oldest deployment instead of showing the latest.

This has been happening since this page redesign launched (#343584 (closed) )

Steps to reproduce

  1. Go to /environments
  2. Unfold one of the environments

Example Project

What is the current bug behavior?

The environment details on the Environments page show the oldest successful deployment

What is the expected correct behavior?

The environment details on the Environments page show the latest successful deployment

Relevant logs and/or screenshots

Environments page: image

Environment details page for example shown above, showing first page (latest deployment):
image

Last page of deployments on Environment details shows that the oldest successful deployment is the one shown in the environments list page: image

Output of checks

This bug happens on GitLab.com

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes