diff --git a/packages/ui/core-components/src/lib/molecules/timeseries-panel/MetricTable.svelte b/packages/ui/core-components/src/lib/molecules/timeseries-panel/MetricTable.svelte index 37b50030e..70eb1a097 100644 --- a/packages/ui/core-components/src/lib/molecules/timeseries-panel/MetricTable.svelte +++ b/packages/ui/core-components/src/lib/molecules/timeseries-panel/MetricTable.svelte @@ -7,10 +7,7 @@ export let selectedMetric; export let data; export let fmt = 'num0'; - export let store - - let metricsStore = $store.metricsStore - + export let metricsStore; const [send, receive] = crossfade({ duration: 200, diff --git a/packages/ui/core-components/src/lib/molecules/timeseries-panel/TimeSeriesPanel.stories.svelte b/packages/ui/core-components/src/lib/molecules/timeseries-panel/TimeSeriesPanel.stories.svelte index 8dd657eea..3f2c47700 100644 --- a/packages/ui/core-components/src/lib/molecules/timeseries-panel/TimeSeriesPanel.stories.svelte +++ b/packages/ui/core-components/src/lib/molecules/timeseries-panel/TimeSeriesPanel.stories.svelte @@ -132,7 +132,11 @@ metrics={['arr', 'wau', 'cloud_wau', 'week_4_retention', 'gh_stars']} x="date" > - + - + diff --git a/packages/ui/core-components/src/lib/molecules/timeseries-panel/TimeSeriesPanelChart.svelte b/packages/ui/core-components/src/lib/molecules/timeseries-panel/TimeSeriesPanelChart.svelte index 96922b3e5..e0aa6a986 100644 --- a/packages/ui/core-components/src/lib/molecules/timeseries-panel/TimeSeriesPanelChart.svelte +++ b/packages/ui/core-components/src/lib/molecules/timeseries-panel/TimeSeriesPanelChart.svelte @@ -173,7 +173,7 @@
{selectedMetric}
diff --git a/packages/ui/core-components/src/lib/molecules/timeseries-panel/_TimeSeriesPanel.svelte b/packages/ui/core-components/src/lib/molecules/timeseries-panel/_TimeSeriesPanel.svelte index 02c4e2d90..a1f71a21b 100644 --- a/packages/ui/core-components/src/lib/molecules/timeseries-panel/_TimeSeriesPanel.svelte +++ b/packages/ui/core-components/src/lib/molecules/timeseries-panel/_TimeSeriesPanel.svelte @@ -7,33 +7,39 @@ import TimeSeriesPanelChart from './TimeSeriesPanelChart.svelte'; import { getContext, onMount } from 'svelte'; import { Skeleton } from '../../atoms/skeletons'; + import ErrorChart from '../../unsorted/viz/core/ErrorChart.svelte'; export let data = undefined; export let x = undefined; export let fmt = undefined; export let defaultTimeRange = undefined; export let selectedMetric; - export let metricsStore = []; const store = getContext('store'); $: store.updateData(data, x); - $: if ($store.metricsStore.length > 0 && !selectedMetric) { - selectedMetric = $store.metricsStore[0].label; - + $: if ($store.value.metricsStore.length > 0 && !selectedMetric) { + selectedMetric = $store.value.metricsStore[0].label; } - -{#if $store.data.length > 0 && $store.metricsStore.length > 0} +{#if $store.value.data.length > 0 && $store.value.metricsStore.length > 0}
- - + + +
+{:else if $store.error} +
+
{:else}
-
{/if} diff --git a/packages/ui/core-components/src/lib/molecules/timeseries-panel/timeSeriesStore.js b/packages/ui/core-components/src/lib/molecules/timeseries-panel/timeSeriesStore.js index 72dc59483..2e72c3d5e 100644 --- a/packages/ui/core-components/src/lib/molecules/timeseries-panel/timeSeriesStore.js +++ b/packages/ui/core-components/src/lib/molecules/timeseries-panel/timeSeriesStore.js @@ -16,8 +16,11 @@ export class TimeSeriesStore { #lastDate = new Date(); #filteredData = []; + #value = { data: this.#data, metricsStore: this.#metricStore }; + #error = undefined; + //runs whenever data changes updateData = async (data, x) => { //need to fix update data re-running probably due to metrics causing a update each time it get updated @@ -61,12 +64,11 @@ export class TimeSeriesStore { // Try to create and execute the query const queryResult = Query.create(newQueryBuild.toString(), query); - if (queryResult.error) { - throw new Error('Error creating query: ' + queryResult.error); - } - this.#data = await queryResult.fetch(); + if (queryResult.error) { + this.#error = queryResult.error; + } // Set the last date based on the fetched data this.#lastDate = this.#data.length > 0 @@ -142,7 +144,7 @@ export class TimeSeriesStore { */ subscribe = (fn) => { this.#subscribers.add(fn); - fn(this.#value); + fn({ value: this.#value, error: this.#error }); return () => this.#subscribers.delete(fn); }; @@ -153,7 +155,7 @@ export class TimeSeriesStore { publish = () => { if (this.#publishIdx++ > 100000) throw new Error('Query published too many times.'); - this.#subscribers.forEach((fn) => fn(this.#value)); + this.#subscribers.forEach((fn) => fn({ value: this.#value, error: this.#error })); }; ////////////////////////////////////// /// ///