DEV: Better handling of no results (#205)

When there were no query results it would throw an error due to `this.resultCount` always passing as it is in the format of

```
"INTEGER - results returned"
```

so we need to grab the first index of the string and check if the integer is great than 0
This commit is contained in:
Isaac Janzen 2022-12-20 16:55:11 -06:00 committed by GitHub
parent 4c70cfa100
commit 85c88c5d80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -126,7 +126,7 @@ export default class QueryResult extends Component {
get canShowChart() {
const hasTwoColumns = this.colCount === 2;
const secondColumnContainsNumber =
this.resultCount.length && typeof this.rows[0][1] === "number";
this.resultCount[0] > 0 && typeof this.rows[0][1] === "number";
const secondColumnContainsId = this.colRender[1];
return (

View File

@ -326,5 +326,23 @@ discourseModule(
},
}
);
componentTest("it handles no results", {
template: hbs`<QueryResult @content={{content}} />`,
beforeEach() {
const results = {
colrender: [],
result_count: 0,
columns: ["user_name", "like_count", "post_count"],
rows: [],
};
this.set("content", results);
},
test(assert) {
assert.ok(!exists("table tbody tr"), "renders no results");
},
});
}
);