rclement / datasette-dashboards

Datasette plugin providing data dashboards from metadata
https://datasette-dashboards-demo.vercel.app
Apache License 2.0
137 stars 7 forks source link

Error when trying to render a table #169

Closed jesus-hergueta closed 2 months ago

jesus-hergueta commented 1 year ago

I'm receiving this error: TypeError: Cannot convert undefined or null to object

In this line:

https://github.com/rclement/datasette-dashboards/blob/79af345455f9fc5f995f6c8a472faff25688c089/datasette_dashboards/static/dashboards.js#L141

It just happen the first time I load the dashboard, I have multiples tables and all of them are rendering good.

I'm declaring my tables like this:

my-list:
          title: my list is cool
          db: my_db
          query: |-
            select * from my_table;
          library: table
          display: null
jesus-hergueta commented 1 year ago

I make a little debug and found that the query is no returning a single value as response, so maybe the bug is that the table is not rendering a default table when empty

{
    "ok": true,
    "database": "my_db",
    "query_name": null,
    "rows": [],
    "truncated": false,
    "columns": [
        "restaurant_name",
        "active_date"
    ],
    "query": {
        "sql": "select * from my_table",
        "params": {}
    },
    "error": null,
    "private": false,
    "allow_execute_sql": true,
    "query_ms": 375.5116881802678
}
rclement commented 1 year ago

Thanks @jesus-hergueta for submitting this issue! Indeed, currently chart components do not have any fallback in case no rows are returned by the SQL query, the table chart included.

I'll look into an implementation to handle empty queries by displaying a warning message

mh2818 commented 2 months ago

if (data.rows && data.rows.length > 0) { Object.keys(data.rows[0]).forEach(col => { // Your existing code }); } else { console.error('No rows returned by the query or data.rows is undefined'); }