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
7 changed files with 58 additions and 8 deletions

View File

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

View File

@ -10,9 +10,13 @@
{{i18n "admin.dashboard.all_reports"}} {{i18n "admin.dashboard.all_reports"}}
{{/link-to}} {{/link-to}}
</li> </li>
<li class="item separator">|</li>
{{#unless showNotFoundError}}
<li class="item separator">|</li>
{{/unless}}
{{/if}} {{/if}}
{{#unless showNotFoundError}}
<li class="item report"> <li class="item report">
<a href="{{model.reportUrl}}" class="report-url"> <a href="{{model.reportUrl}}" class="report-url">
{{model.title}} {{model.title}}
@ -24,6 +28,7 @@
</span> </span>
{{/if}} {{/if}}
</li> </li>
{{/unless}}
</ul> </ul>
{{/if}} {{/if}}
@ -94,6 +99,13 @@
<span>{{i18n "admin.dashboard.exception_error"}}</span> <span>{{i18n "admin.dashboard.exception_error"}}</span>
</div> </div>
{{/if}} {{/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}} {{/unless}}
</div> </div>

View File

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

View File

@ -2840,6 +2840,7 @@ en:
timeout_error: Sorry, query is taking too long, please pick a shorter interval timeout_error: Sorry, query is taking too long, please pick a shorter interval
exception_error: Sorry, an error occurred while executing the query exception_error: Sorry, an error occurred while executing the query
too_many_requests: You’ve performed this action too many times. Please wait before trying again. too_many_requests: You’ve performed this action too many times. Please wait before trying again.
not_found_error: Sorry, this report doesn’t exist
reports: reports:
trend_title: "%{percent} change. Currently %{current}, was %{prev} in previous period." 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 "invalid params" do
context "inexisting report" do context "inexisting report" do
it "returns only existing reports" do it "returns not found reports" do
get "/admin/reports/bulk.json", params: { get "/admin/reports/bulk.json", params: {
reports: { reports: {
topics: { limit: 10 }, topics: { limit: 10 },
xxx: { limit: 10 } not_found: { limit: 10 }
} }
} }
expect(response.status).to eq(200) 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"][0]["type"]).to eq("topics")
expect(JSON.parse(response.body)["reports"][1]["type"]).to eq("not_found")
end end
end 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"; signups_fixture.error = "timeout";
const signups_timeout = signups_fixture; 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() const startDate = moment()
.locale("en") .locale("en")
.utc() .utc()
@ -177,6 +182,12 @@ const page_view_total_reqs = {
export default { export default {
"/admin/reports/bulk": { "/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
]
} }
}; };