evidence-dev / evidence

Business intelligence as code: build fast, interactive data visualizations in pure SQL and markdown
https://evidence.dev
MIT License
3.38k stars 164 forks source link

QueryLoad not flagging empty query results, breaks emptySet #1931

Open hughess opened 2 weeks ago

hughess commented 2 weeks ago

emptySet has stopped working, most likely due to changes in the QueryLoad function.

I've set up console logs in this section of QueryLoad and tested it with an empty query:

{#if !data}
    {console.log('!data')}

    <!-- data prop was not provided. Component to handle this prop-related error -->
    <slot loaded={data} />
{:else if !Query.isQuery(data)}
    {console.log('!Query.isQuery(data)')}

    <!-- data prop was provided, but it is not a query store -->
    {#if (Array.isArray(data) || !data) && isEmptyDataset(data) && $$slots.empty}
        <!-- handle case where data is not a query store but is also empty -->
        <slot name="empty" loaded={data} />
    {:else}
        <!-- Not a query store, nothing to be done -->
        <slot loaded={data} />
    {/if}
{:else if !_data || (!_data.dataLoaded && !_data.error)}
    {console.log('!_data || (!_data.dataLoaded && !_data.error)')}

    <slot name="skeleton" loaded={_data}>
        <div class="w-full h-64">
            <Skeleton />
        </div>
    </slot>
{:else if _data.error && $$slots.error}
    {console.log('_data.error && $$slots.error')}

    <slot name="error" loaded={_data} />
{:else if !_data.length && !_data.error && $$slots._empty}
    {console.log('!_data.length && !_data.error && $$slots._empty')}

    <slot name="empty" loaded={_data} />
{:else}
    {console.log('else')}

    <slot loaded={_data} />
{/if}

In my browser console I got:

!_data || (!_data.dataLoaded && !_data.error)

Then a split second later:

else