Commit 61e27399 authored by Tim Zallmann's avatar Tim Zallmann

Merge branch 'sh-fix-nil-status-counts' into 'master'

Geo: Fix handling of nil/zero values in admin screen

See merge request gitlab-org/gitlab-ee!3301
parents 8d2aeec8 8322cf53
......@@ -8,6 +8,7 @@ const unknownClass = 'geo-node-unknown';
const healthyIcon = 'fa-check';
const unhealthyIcon = 'fa-times';
const unknownIcon = 'fa-times';
const notAvailable = 'Not Available';
class GeoNodeStatus {
constructor(el) {
......@@ -49,9 +50,21 @@ class GeoNodeStatus {
}
static formatCountAndPercentage(count, total, percentage) {
if (count !== null || total != null) {
return `${gl.text.addDelimiter(count)}/${gl.text.addDelimiter(total)} (${percentage})`;
}
return notAvailable;
}
static formatCount(count) {
if (count !== null) {
gl.text.addDelimiter(count);
}
return notAvailable;
}
getStatus() {
$.getJSON(this.endpoint, (status) => {
this.setStatusIcon(status.healthy);
......@@ -73,21 +86,21 @@ class GeoNodeStatus {
status.repositories_count,
status.repositories_synced_in_percentage);
const repoFailedText = gl.text.addDelimiter(status.repositories_failed_count);
const repoFailedText = GeoNodeStatus.formatCount(status.repositories_failed_count);
const lfsText = GeoNodeStatus.formatCountAndPercentage(
status.lfs_objects_synced_count,
status.lfs_objects_count,
status.lfs_objects_synced_in_percentage);
const lfsFailedText = gl.text.addDelimiter(status.lfs_objects_failed_count);
const lfsFailedText = GeoNodeStatus.formatCount(status.lfs_objects_failed_count);
const attachmentText = GeoNodeStatus.formatCountAndPercentage(
status.attachments_synced_count,
status.attachments_count,
status.attachments_synced_in_percentage);
const attachmentFailedText = gl.text.addDelimiter(status.attachments_failed_count);
const attachmentFailedText = GeoNodeStatus.formatCount(status.attachments_failed_count);
this.$repositoriesSynced.text(repoText);
this.$repositoriesFailed.text(repoFailedText);
......@@ -96,14 +109,14 @@ class GeoNodeStatus {
this.$attachmentsSynced.text(attachmentText);
this.$attachmentsFailed.text(attachmentFailedText);
let eventDate = 'N/A';
let cursorDate = 'N/A';
let eventDate = notAvailable;
let cursorDate = notAvailable;
if (status.last_event_timestamp !== null) {
if (status.last_event_timestamp !== null && status.last_event_timestamp > 0) {
eventDate = gl.utils.formatDate(new Date(status.last_event_timestamp * 1000));
}
if (status.cursor_last_event_timestamp !== null) {
if (status.cursor_last_event_timestamp !== null && status.cursor_last_event_timestamp > 0) {
cursorDate = gl.utils.formatDate(new Date(status.cursor_last_event_timestamp * 1000));
}
......
......@@ -132,7 +132,7 @@ class GeoNodeStatus < ActiveRecord::Base
private
def sync_percentage(total, synced)
return 0 if total.zero?
return 0 if !total.present? || total.zero?
(synced.to_f / total.to_f) * 100.0
end
......
......@@ -218,6 +218,12 @@ describe GeoNodeStatus, :geo do
expect(subject.repositories_synced_in_percentage).to eq(0)
end
it 'returns 0 when project count is unknown' do
allow(subject).to receive(:repositories_count).and_return(nil)
expect(subject.repositories_synced_in_percentage).to eq(0)
end
it 'returns the right percentage with no group restrictions' do
create(:geo_project_registry, :synced, project: project_1)
......
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