Commit a629cd59 authored by Scott Hampton's avatar Scott Hampton

Merge branch 'add-error-handler-dashboard-activity' into 'master'

Display error message when dashboard activity fetch fails

See merge request gitlab-org/gitlab!57935
parents 4bef7e78 4fb6da11
...@@ -2,14 +2,20 @@ ...@@ -2,14 +2,20 @@
import $ from 'jquery'; import $ from 'jquery';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import createFlash from '~/flash';
import { s__ } from '~/locale';
import { localTimeAgo } from './lib/utils/datetime_utility'; import { localTimeAgo } from './lib/utils/datetime_utility';
import Pager from './pager'; import Pager from './pager';
export default class Activities { export default class Activities {
constructor(container = '') { constructor(containerSelector = '') {
this.container = container; this.containerSelector = containerSelector;
this.containerEl = this.containerSelector
? document.querySelector(this.containerSelector)
: undefined;
this.$contentList = $('.content_list');
Pager.init(20, true, false, (data) => data, this.updateTooltips, this.container); this.loadActivities();
$('.event-filter-link').on('click', (e) => { $('.event-filter-link').on('click', (e) => {
e.preventDefault(); e.preventDefault();
...@@ -18,13 +24,30 @@ export default class Activities { ...@@ -18,13 +24,30 @@ export default class Activities {
}); });
} }
loadActivities() {
Pager.init({
limit: 20,
preload: true,
prepareData: (data) => data,
successCallback: () => this.updateTooltips(),
errorCallback: () =>
createFlash({
message: s__(
'Activity|An error occured while retrieving activity. Reload the page to try again.',
),
parent: this.containerEl,
}),
container: this.containerSelector,
});
}
updateTooltips() { updateTooltips() {
localTimeAgo($('.js-timeago', '.content_list')); localTimeAgo($('.js-timeago', '.content_list'));
} }
reloadActivities() { reloadActivities() {
$('.content_list').html(''); this.$contentList.html('');
Pager.init(20, true, false, (data) => data, this.updateTooltips, this.container); this.loadActivities();
} }
toggleFilter(sender) { toggleFilter(sender) {
......
...@@ -10,7 +10,7 @@ export default class CommitsList { ...@@ -10,7 +10,7 @@ export default class CommitsList {
this.$contentList = $('.content_list'); this.$contentList = $('.content_list');
Pager.init(parseInt(limit, 10), false, false, this.processCommits.bind(this)); Pager.init({ limit: parseInt(limit, 10), prepareData: this.processCommits.bind(this) });
this.content = $('#commits-list'); this.content = $('#commits-list');
this.searchField = $('#commits-search'); this.searchField = $('#commits-search');
......
...@@ -8,19 +8,21 @@ const ENDLESS_SCROLL_BOTTOM_PX = 400; ...@@ -8,19 +8,21 @@ const ENDLESS_SCROLL_BOTTOM_PX = 400;
const ENDLESS_SCROLL_FIRE_DELAY_MS = 1000; const ENDLESS_SCROLL_FIRE_DELAY_MS = 1000;
export default { export default {
init( init({
limit = 0, limit = 0,
preload = false, preload = false,
disable = false, disable = false,
prepareData = $.noop, prepareData = $.noop,
callback = $.noop, successCallback = $.noop,
errorCallback = $.noop,
container = '', container = '',
) { } = {}) {
this.limit = limit; this.limit = limit;
this.offset = parseInt(getParameterByName('offset'), 10) || this.limit; this.offset = parseInt(getParameterByName('offset'), 10) || this.limit;
this.disable = disable; this.disable = disable;
this.prepareData = prepareData; this.prepareData = prepareData;
this.callback = callback; this.successCallback = successCallback;
this.errorCallback = errorCallback;
this.loading = $(`${container} .loading`).first(); this.loading = $(`${container} .loading`).first();
if (preload) { if (preload) {
this.offset = 0; this.offset = 0;
...@@ -42,7 +44,7 @@ export default { ...@@ -42,7 +44,7 @@ export default {
}) })
.then(({ data }) => { .then(({ data }) => {
this.append(data.count, this.prepareData(data.html)); this.append(data.count, this.prepareData(data.html));
this.callback(); this.successCallback();
// keep loading until we've filled the viewport height // keep loading until we've filled the viewport height
if (!this.disable && !this.isScrollable()) { if (!this.disable && !this.isScrollable()) {
...@@ -51,7 +53,8 @@ export default { ...@@ -51,7 +53,8 @@ export default {
this.loading.hide(); this.loading.hide();
} }
}) })
.catch(() => this.loading.hide()); .catch((err) => this.errorCallback(err))
.finally(() => this.loading.hide());
}, },
append(count, html) { append(count, html) {
......
import Activities from '~/activities'; import Activities from '~/activities';
document.addEventListener('DOMContentLoaded', () => new Activities()); // eslint-disable-next-line no-new
new Activities();
...@@ -163,6 +163,7 @@ ...@@ -163,6 +163,7 @@
- if profile_tab?(:activity) - if profile_tab?(:activity)
#activity.tab-pane #activity.tab-pane
.flash-container
- if can?(current_user, :read_cross_project) - if can?(current_user, :read_cross_project)
%h4.prepend-top-20 %h4.prepend-top-20
= s_('UserProfile|Most Recent Activity') = s_('UserProfile|Most Recent Activity')
......
---
title: Display error message when dashboard activity fetch fails
merge_request: 57935
author:
type: changed
...@@ -1776,6 +1776,9 @@ msgstr "" ...@@ -1776,6 +1776,9 @@ msgstr ""
msgid "Activity" msgid "Activity"
msgstr "" msgstr ""
msgid "Activity|An error occured while retrieving activity. Reload the page to try again."
msgstr ""
msgid "Add" msgid "Add"
msgstr "" msgstr ""
......
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