FIX: handles not found reports in bulk loading (#6582)

This commit is contained in:
Joffrey JAFFEUX 2018-11-12 13:47:24 +01:00 committed by GitHub
parent 7c4d4331bc
commit 9c616e0679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 58 additions and 8 deletions

View File

@ -111,7 +111,12 @@ export default Ember.Component.extend({
unregisterHoverTooltip($(".info[data-tooltip]"));
},
showError: Ember.computed.or("showTimeoutError", "showExceptionError"),
showError: Ember.computed.or(
"showTimeoutError",
"showExceptionError",
"showNotFoundError"
),
showNotFoundError: Ember.computed.equal("model.error", "not_found"),
showTimeoutError: Ember.computed.equal("model.error", "timeout"),
showExceptionError: Ember.computed.equal("model.error", "exception"),
@ -274,7 +279,7 @@ export default Ember.Component.extend({
if (!this.get("startDate") || !this.get("endDate")) {
report = sort(filteredReports)[0];
} else {
let reportKey = this.get("reportKey");
const reportKey = this.get("reportKey");
report = sort(
filteredReports.filter(r => r.report_key.includes(reportKey))
@ -283,6 +288,10 @@ export default Ember.Component.extend({
if (!report) return;
}
if (report.error === "not_found") {
this.set("showFilteringUI", false);
}
this._renderReport(
report,
this.get("forcedModes"),

View File

@ -10,9 +10,13 @@
{{i18n "admin.dashboard.all_reports"}}
{{/link-to}}
</li>
<li class="item separator">|</li>
{{#unless showNotFoundError}}
<li class="item separator">|</li>
{{/unless}}
{{/if}}
{{#unless showNotFoundError}}
<li class="item report">
<a href="{{model.reportUrl}}" class="report-url">
{{model.title}}
@ -24,6 +28,7 @@
</span>
{{/if}}
</li>
{{/unless}}
</ul>
{{/if}}
@ -94,6 +99,13 @@
<span>{{i18n "admin.dashboard.exception_error"}}</span>
</div>
{{/if}}
{{#if showNotFoundError}}
<div class="alert alert-error report-alert not-found">
{{d-icon "exclamation-triangle"}}
<span>{{i18n "admin.dashboard.not_found_error"}}</span>
</div>
{{/if}}
{{/unless}}
</div>

View File

@ -39,7 +39,12 @@ class Admin::ReportsController < Admin::AdminController
Report.cache(report, 35.minutes)
end
reports << report if report
if report.blank?
report = Report._get(report_type, args)
report.error = :not_found
end
reports << report
end
end

View File

@ -2840,6 +2840,7 @@ en:
timeout_error: Sorry, query is taking too long, please pick a shorter interval
exception_error: Sorry, an error occurred while executing the query
too_many_requests: Youve performed this action too many times. Please wait before trying again.
not_found_error: Sorry, this report doesnt exist
reports:
trend_title: "%{percent} change. Currently %{current}, was %{prev} in previous period."

View File

@ -31,17 +31,18 @@ describe Admin::ReportsController do
context "invalid params" do
context "inexisting report" do
it "returns only existing reports" do
it "returns not found reports" do
get "/admin/reports/bulk.json", params: {
reports: {
topics: { limit: 10 },
xxx: { limit: 10 }
not_found: { limit: 10 }
}
}
expect(response.status).to eq(200)
expect(JSON.parse(response.body)["reports"].count).to eq(1)
expect(JSON.parse(response.body)["reports"].count).to eq(2)
expect(JSON.parse(response.body)["reports"][0]["type"]).to eq("topics")
expect(JSON.parse(response.body)["reports"][1]["type"]).to eq("not_found")
end
end
end

View File

@ -152,3 +152,14 @@ componentTest("rate limited", {
);
}
});
componentTest("not found", {
template: "{{admin-report dataSourceName='not_found'}}",
test(assert) {
assert.ok(
exists(".alert-error.not-found"),
"it displays a not found error"
);
}
});

View File

@ -86,6 +86,11 @@ signups_fixture.type = "signups_timeout";
signups_fixture.error = "timeout";
const signups_timeout = signups_fixture;
signups_fixture = JSON.parse(JSON.stringify(signups));
signups_fixture.type = "not_found";
signups_fixture.error = "not_found";
const signups_not_found = signups_fixture;
const startDate = moment()
.locale("en")
.utc()
@ -177,6 +182,12 @@ const page_view_total_reqs = {
export default {
"/admin/reports/bulk": {
reports: [signups, signups_exception, signups_timeout, page_view_total_reqs]
reports: [
signups,
signups_not_found,
signups_exception,
signups_timeout,
page_view_total_reqs
]
}
};