commit d2264b3bd898b5d38461fa09eba4bf0b43557ae7 Author: Ben Rohlfs Date: Tue Oct 6 17:30:56 2020 +0200 Change the sorting of changes in the 'Your Turn' dashboard section Sort changes for review before owned changes. And then sort changes before others if they are already sitting longer in the attention set queue of the user. Change-Id: I66d544e1735f677ee87720e1226cfcf021be6ba3 diff --git a/polygerrit-ui/app/elements/change-list/gr-dashboard-view/gr-dashboard-view.js b/polygerrit-ui/app/elements/change-list/gr-dashboard-view/gr-dashboard-view.js index 0658e16..4665ef4 100644 --- a/polygerrit-ui/app/elements/change-list/gr-dashboard-view/gr-dashboard-view.js +++ b/polygerrit-ui/app/elements/change-list/gr-dashboard-view/gr-dashboard-view.js @@ -28,9 +28,10 @@ import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-l import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js'; import {PolymerElement} from '@polymer/polymer/polymer-element.js'; import {htmlTemplate} from './gr-dashboard-view_html.js'; -import {GerritNav} from '../../core/gr-navigation/gr-navigation.js'; +import {GerritNav, YOUR_TURN} from '../../core/gr-navigation/gr-navigation.js'; import {appContext} from '../../../services/app-context.js'; import {changeIsOpen} from '../../../utils/change-util.js'; +import {parseDate} from '../../../utils/date-util.js'; const PROJECT_PLACEHOLDER_PATTERN = /\$\{project\}/g; @@ -259,7 +260,7 @@ class GrDashboardView extends GestureEventListeners( name: res.sections[i].name, countLabel: this._computeSectionCountLabel(results), query: res.sections[i].query, - results, + results: this._maybeSortResults(res.sections[i].name, results), isOutgoing: res.sections[i].isOutgoing, }; }).filter((section, i) => i < res.sections.length && ( @@ -268,6 +269,34 @@ class GrDashboardView extends GestureEventListeners( }); } + /** + * Usually we really want to stick to the sorting that the backend provides, + * but for the "Your Turn" section it is important to put the changes at the + * top where the current user is a reviewer. Owned changes are less important. + * And then we want to emphasize the changes where the waiting time is larger. + */ + _maybeSortResults(name, results) { + const userId = this.account && this.account._account_id; + const sortedResults = [...results]; + if (name === YOUR_TURN.name && userId) { + sortedResults.sort((c1, c2) => { + const c1Owner = c1.owner._account_id === userId; + const c2Owner = c2.owner._account_id === userId; + if (c1Owner !== c2Owner) return c1Owner ? 1 : -1; + // Should never happen, because the change is in the 'Your Turn' + // section, so the userId should be found in the attention set of both. + if (!c1.attention_set || !c1.attention_set[userId]) return 0; + if (!c2.attention_set || !c2.attention_set[userId]) return 0; + const c1Update = c1.attention_set[userId].last_update; + const c2Update = c2.attention_set[userId].last_update; + // Should never happen that an attention set entry has no update. + if (!c1Update || !c2Update) return c1Update ? 1 : -1; + return parseDate(c1Update) - parseDate(c2Update); + }); + } + return sortedResults; + } + _computeSectionCountLabel(changes) { if (!changes || !changes.length || changes.length == 0) { return '';