Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(widget-error): apply no-data-table error case & refactor useWidgetFrame #5406

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import { COST_EXPLORER_ROUTE } from '@/services/cost-explorer/routes/route-const

interface OverridableWidgetFrameState {
dateRange?: DateRange | ComputedRef<DateRange>;
errorMessage?: string | ComputedRef<string|undefined>;
widgetLoading?: boolean | ComputedRef<boolean>;
noData?: boolean | ComputedRef<boolean>;
errorMessage?: ComputedRef<string|undefined>;
widgetLoading?: ComputedRef<boolean>;
noData?: ComputedRef<boolean>;
}
type DataTableModel = PublicDataTableModel | PrivateDataTableModel;
const { getProperRouteLocation } = useProperRouteLocation();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { useResizeObserver } from '@vueuse/core/index';
import {
computed, defineExpose, onMounted, reactive, ref, watch,
computed, defineExpose, reactive, ref, watch,
} from 'vue';

import { useQuery } from '@tanstack/vue-query';
Expand All @@ -22,6 +22,7 @@ import type { PrivateDataTableModel } from '@/schema/dashboard/private-data-tabl
import type { PrivateWidgetLoadParameters } from '@/schema/dashboard/private-widget/api-verbs/load';
import type { PublicDataTableModel } from '@/schema/dashboard/public-data-table/model';
import type { PublicWidgetLoadParameters } from '@/schema/dashboard/public-widget/api-verbs/load';
import { i18n } from '@/translations';

import WidgetFrame from '@/common/modules/widgets/_components/WidgetFrame.vue';
import { useWidgetDateRange } from '@/common/modules/widgets/_composables/use-widget-date-range';
Expand Down Expand Up @@ -210,7 +211,10 @@ const queryResult = useQuery({
});

const widgetLoading = computed<boolean>(() => queryResult.isLoading.value);
const errorMessage = computed<string|undefined>(() => queryResult.error?.value?.message);
const errorMessage = computed<string|undefined>(() => {
if (!state.dataTable) return i18n.t('COMMON.WIDGETS.NO_DATA_TABLE_ERROR_MESSAGE');
return queryResult.error?.value?.message;
});

/* Util */
const getThreshold = (rawData: WidgetLoadResponse): number => {
Expand Down Expand Up @@ -303,10 +307,10 @@ useResizeObserver(chartContext, throttle(() => {
state.chart?.resize();
}, 500));
useWidgetInitAndRefresh({ props, emit, loadWidget });
onMounted(async () => {
if (!props.dataTableId) return;
state.dataTable = await getWidgetDataTable(props.dataTableId);
});
watch(() => props.dataTableId, async (newDataTableId) => {
if (!newDataTableId) return;
state.dataTable = await getWidgetDataTable(newDataTableId);
}, { immediate: true });
defineExpose<WidgetExpose>({
loadWidget,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import {
computed, defineExpose, onMounted, reactive, watch,
computed, defineExpose, reactive, watch,
} from 'vue';


Expand All @@ -17,6 +17,7 @@ import type { PrivateDataTableModel } from '@/schema/dashboard/private-data-tabl
import type { PrivateWidgetLoadParameters } from '@/schema/dashboard/private-widget/api-verbs/load';
import type { PublicDataTableModel } from '@/schema/dashboard/public-data-table/model';
import type { PublicWidgetLoadParameters } from '@/schema/dashboard/public-widget/api-verbs/load';
import { i18n } from '@/translations';

import WidgetCustomLegend from '@/common/modules/widgets/_components/WidgetCustomLegend.vue';
import WidgetFrame from '@/common/modules/widgets/_components/WidgetFrame.vue';
Expand Down Expand Up @@ -114,7 +115,10 @@ const queryResult = useQuery({
});

const widgetLoading = computed<boolean>(() => queryResult.isLoading.value);
const errorMessage = computed<string|undefined>(() => queryResult.error?.value?.message);
const errorMessage = computed<string|undefined>(() => {
if (!state.dataTable) return i18n.t('COMMON.WIDGETS.NO_DATA_TABLE_ERROR_MESSAGE');
return queryResult.error?.value?.message;
});

const refinedData = computed(() => {
const data = queryResult.data?.value;
Expand Down Expand Up @@ -168,10 +172,10 @@ watch(() => widgetOptionsState.formatRulesInfo, async () => {
}, { immediate: true });

useWidgetInitAndRefresh({ props, emit, loadWidget });
onMounted(async () => {
if (!props.dataTableId) return;
state.dataTable = await getWidgetDataTable(props.dataTableId);
});
watch(() => props.dataTableId, async (newDataTableId) => {
if (!newDataTableId) return;
state.dataTable = await getWidgetDataTable(newDataTableId);
}, { immediate: true });
defineExpose<WidgetExpose>({
loadWidget,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { useResizeObserver } from '@vueuse/core/index';
import {
computed, defineExpose, onMounted, reactive, ref, watch,
computed, defineExpose, reactive, ref, watch,
} from 'vue';

import { useQuery } from '@tanstack/vue-query';
Expand All @@ -15,6 +15,7 @@ import type { PrivateDataTableModel } from '@/schema/dashboard/private-data-tabl
import type { PrivateWidgetLoadParameters } from '@/schema/dashboard/private-widget/api-verbs/load';
import type { PublicDataTableModel } from '@/schema/dashboard/public-data-table/model';
import type { PublicWidgetLoadParameters } from '@/schema/dashboard/public-widget/api-verbs/load';
import { i18n } from '@/translations';

import WidgetCustomLegend from '@/common/modules/widgets/_components/WidgetCustomLegend.vue';
import WidgetFrame from '@/common/modules/widgets/_components/WidgetFrame.vue';
Expand Down Expand Up @@ -146,7 +147,10 @@ const queryResult = useQuery({
});

const widgetLoading = computed<boolean>(() => queryResult.isLoading.value);
const errorMessage = computed<string|undefined>(() => queryResult.error?.value?.message);
const errorMessage = computed<string|undefined>(() => {
if (!state.dataTable) return i18n.t('COMMON.WIDGETS.NO_DATA_TABLE_ERROR_MESSAGE');
return queryResult.error?.value?.message;
});

/* Util */
const loadWidget = async () => {
Expand Down Expand Up @@ -220,7 +224,7 @@ watch(() => widgetOptionsState.formatRulesInfo?.rules, async () => {
const { widgetFrameProps, widgetFrameEventHandlers } = useWidgetFrame(props, emit, {
dateRange,
errorMessage,
widgetLoading: widgetLoading.value,
widgetLoading,
noData: computed(() => (state.data ? !state.data?.results?.length : false)),
});
watch(() => widgetOptionsState, () => {
Expand All @@ -229,10 +233,10 @@ watch(() => widgetOptionsState, () => {

/* Lifecycle */
useWidgetInitAndRefresh({ props, emit, loadWidget });
onMounted(async () => {
if (!props.dataTableId) return;
state.dataTable = await getWidgetDataTable(props.dataTableId);
});
watch(() => props.dataTableId, async (newDataTableId) => {
if (!newDataTableId) return;
state.dataTable = await getWidgetDataTable(newDataTableId);
}, { immediate: true });
defineExpose<WidgetExpose>({
loadWidget,
});
Expand Down
16 changes: 10 additions & 6 deletions apps/web/src/common/modules/widgets/_widgets/gauge/Gauge.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { useResizeObserver } from '@vueuse/core/index';
import {
computed, defineExpose, onMounted, reactive, ref, watch,
computed, defineExpose, reactive, ref, watch,
} from 'vue';

import { useQuery } from '@tanstack/vue-query';
Expand All @@ -18,6 +18,7 @@ import type { PrivateDataTableModel } from '@/schema/dashboard/private-data-tabl
import type { PrivateWidgetLoadParameters } from '@/schema/dashboard/private-widget/api-verbs/load';
import type { PublicDataTableModel } from '@/schema/dashboard/public-data-table/model';
import type { PublicWidgetLoadParameters } from '@/schema/dashboard/public-widget/api-verbs/load';
import { i18n } from '@/translations';

import WidgetFrame from '@/common/modules/widgets/_components/WidgetFrame.vue';
import { useWidgetDateRange } from '@/common/modules/widgets/_composables/use-widget-date-range';
Expand Down Expand Up @@ -169,7 +170,10 @@ const queryResult = useQuery({
});

const widgetLoading = computed<boolean>(() => queryResult.isLoading.value);
const errorMessage = computed<string|undefined>(() => queryResult.error?.value?.message);
const errorMessage = computed<string|undefined>(() => {
if (!state.dataTable) return i18n.t('COMMON.WIDGETS.NO_DATA_TABLE_ERROR_MESSAGE');
return queryResult.error?.value?.message;
});

/* Util */
const drawChart = (rawData: WidgetLoadResponse|null) => {
Expand Down Expand Up @@ -199,10 +203,10 @@ watch([() => state.data, () => props.widgetOptions], ([newData]) => {
});

useWidgetInitAndRefresh({ props, emit, loadWidget });
onMounted(async () => {
if (!props.dataTableId) return;
state.dataTable = await getWidgetDataTable(props.dataTableId);
});
watch(() => props.dataTableId, async (newDataTableId) => {
if (!newDataTableId) return;
state.dataTable = await getWidgetDataTable(newDataTableId);
}, { immediate: true });
defineExpose<WidgetExpose>({
loadWidget,
});
Expand Down
20 changes: 12 additions & 8 deletions apps/web/src/common/modules/widgets/_widgets/geo-map/GeoMap.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { useResizeObserver } from '@vueuse/core/index';
import {
computed, defineExpose, onMounted, reactive, ref, watch,
computed, defineExpose, reactive, ref, watch,
} from 'vue';

import { useQuery } from '@tanstack/vue-query';
Expand All @@ -20,6 +20,7 @@ import type { PrivateDataTableModel } from '@/schema/dashboard/private-data-tabl
import type { PrivateWidgetLoadParameters } from '@/schema/dashboard/private-widget/api-verbs/load';
import type { PublicDataTableModel } from '@/schema/dashboard/public-data-table/model';
import type { PublicWidgetLoadParameters } from '@/schema/dashboard/public-widget/api-verbs/load';
import { i18n } from '@/translations';

import { useAllReferenceStore } from '@/store/reference/all-reference-store';
import type { RegionReferenceMap } from '@/store/reference/region-reference-store';
Expand Down Expand Up @@ -150,8 +151,11 @@ const queryResult = useQuery({
staleTime: WIDGET_LOAD_STALE_TIME,
});

const widgetLoading = computed<boolean>(() => queryResult.isLoading);
const errorMessage = computed<string>(() => queryResult.error?.value?.message);
const widgetLoading = computed<boolean>(() => queryResult.isLoading.value);
const errorMessage = computed<string>(() => {
if (!state.dataTable) return i18n.t('COMMON.WIDGETS.NO_DATA_TABLE_ERROR_MESSAGE');
return queryResult.error?.value?.message;
});

/* Util */
const loadMap = async () => {
Expand Down Expand Up @@ -189,7 +193,7 @@ const loadWidget = async () => {
const { widgetFrameProps, widgetFrameEventHandlers } = useWidgetFrame(props, emit, {
dateRange,
errorMessage,
widgetLoading: widgetLoading.value,
widgetLoading,
});

/* Watcher */
Expand All @@ -208,10 +212,10 @@ useResizeObserver(chartContext, throttle(() => {
state.chart?.resize();
}, 500));
useWidgetInitAndRefresh({ props, emit, loadWidget });
onMounted(async () => {
if (!props.dataTableId) return;
state.dataTable = await getWidgetDataTable(props.dataTableId);
});
watch(() => props.dataTableId, async (newDataTableId) => {
if (!newDataTableId) return;
state.dataTable = await getWidgetDataTable(newDataTableId);
}, { immediate: true });
defineExpose<WidgetExpose>({
loadWidget,
});
Expand Down
20 changes: 12 additions & 8 deletions apps/web/src/common/modules/widgets/_widgets/heatmap/Heatmap.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { useResizeObserver } from '@vueuse/core';
import {
computed, defineExpose, onMounted, reactive, ref, watch,
computed, defineExpose, reactive, ref, watch,
} from 'vue';

import { useQuery } from '@tanstack/vue-query';
Expand All @@ -18,6 +18,7 @@ import type { PrivateDataTableModel } from '@/schema/dashboard/private-data-tabl
import type { PrivateWidgetLoadParameters } from '@/schema/dashboard/private-widget/api-verbs/load';
import type { PublicDataTableModel } from '@/schema/dashboard/public-data-table/model';
import type { PublicWidgetLoadParameters } from '@/schema/dashboard/public-widget/api-verbs/load';
import { i18n } from '@/translations';

import WidgetFrame from '@/common/modules/widgets/_components/WidgetFrame.vue';
import { useWidgetDateRange } from '@/common/modules/widgets/_composables/use-widget-date-range';
Expand Down Expand Up @@ -209,8 +210,11 @@ const queryResult = useQuery({
staleTime: WIDGET_LOAD_STALE_TIME,
});

const widgetLoading = computed<boolean>(() => queryResult.isLoading);
const errorMessage = computed<string>(() => queryResult.error?.value?.message);
const widgetLoading = computed<boolean>(() => queryResult.isLoading.value);
const errorMessage = computed<string>(() => {
if (!state.dataTable) return i18n.t('COMMON.WIDGETS.NO_DATA_TABLE_ERROR_MESSAGE');
return queryResult.error?.value?.message;
});


/* Util */
Expand Down Expand Up @@ -248,18 +252,18 @@ watch([() => state.data, () => props.widgetOptions], ([newData]) => {
const { widgetFrameProps, widgetFrameEventHandlers } = useWidgetFrame(props, emit, {
dateRange,
errorMessage,
widgetLoading: widgetLoading.value,
widgetLoading,
noData: computed(() => (state.data ? !state.data.results?.length : false)),
});

useResizeObserver(chartContext, throttle(() => {
state.chart?.resize();
}, 500));
useWidgetInitAndRefresh({ props, emit, loadWidget });
onMounted(async () => {
if (!props.dataTableId) return;
state.dataTable = await getWidgetDataTable(props.dataTableId);
});
watch(() => props.dataTableId, async (newDataTableId) => {
if (!newDataTableId) return;
state.dataTable = await getWidgetDataTable(newDataTableId);
}, { immediate: true });
defineExpose<WidgetExpose>({
loadWidget,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { useResizeObserver } from '@vueuse/core/index';
import {
computed, defineExpose, onMounted, reactive, ref, watch,
computed, defineExpose, reactive, ref, watch,
} from 'vue';

import { useQuery } from '@tanstack/vue-query';
Expand All @@ -22,6 +22,7 @@ import type { PrivateDataTableModel } from '@/schema/dashboard/private-data-tabl
import type { PrivateWidgetLoadParameters } from '@/schema/dashboard/private-widget/api-verbs/load';
import type { PublicDataTableModel } from '@/schema/dashboard/public-data-table/model';
import type { PublicWidgetLoadParameters } from '@/schema/dashboard/public-widget/api-verbs/load';
import { i18n } from '@/translations';

import WidgetFrame from '@/common/modules/widgets/_components/WidgetFrame.vue';
import { useWidgetDateRange } from '@/common/modules/widgets/_composables/use-widget-date-range';
Expand Down Expand Up @@ -216,7 +217,10 @@ const queryResult = useQuery({
});

const widgetLoading = computed<boolean>(() => queryResult.isLoading.value);
const errorMessage = computed<string|undefined>(() => queryResult.error?.value?.message);
const errorMessage = computed<string|undefined>(() => {
if (!state.dataTable) return i18n.t('COMMON.WIDGETS.NO_DATA_TABLE_ERROR_MESSAGE');
return queryResult.error?.value?.message;
});

/* Util */
const drawChart = (rawData: WidgetLoadResponse|null) => {
Expand Down Expand Up @@ -283,10 +287,10 @@ useResizeObserver(chartContext, throttle(() => {
state.chart?.resize();
}, 500));
useWidgetInitAndRefresh({ props, emit, loadWidget });
onMounted(async () => {
if (!props.dataTableId) return;
state.dataTable = await getWidgetDataTable(props.dataTableId);
});
watch(() => props.dataTableId, async (newDataTableId) => {
if (!newDataTableId) return;
state.dataTable = await getWidgetDataTable(newDataTableId);
}, { immediate: true });
defineExpose<WidgetExpose>({
loadWidget,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { useElementSize, useResizeObserver } from '@vueuse/core';
import {
computed, defineExpose, onMounted, reactive, ref,
computed, defineExpose, reactive, ref, watch,
} from 'vue';

import { useQueries } from '@tanstack/vue-query';
Expand Down Expand Up @@ -218,7 +218,10 @@ const queryResults = useQueries({

const widgetLoading = computed<boolean>(() => queryResults.value?.[0].isLoading);
const previousLoading = computed<string>(() => queryResults.value?.[1].isLoading);
const errorMessage = computed<string>(() => queryResults.value?.[0].error?.message);
const errorMessage = computed<string>(() => {
if (!state.dataTable) return i18n.t('COMMON.WIDGETS.NO_DATA_TABLE_ERROR_MESSAGE');
return queryResults.value?.[0].error?.message;
});

const loadWidget = () => {
state.runQueries = true;
Expand All @@ -235,10 +238,10 @@ useResizeObserver(valueTextRef, throttle(() => {
setValueTextFontSize();
}, 500));
useWidgetInitAndRefresh({ props, emit, loadWidget });
onMounted(async () => {
if (!props.dataTableId) return;
state.dataTable = await getWidgetDataTable(props.dataTableId);
});
watch(() => props.dataTableId, async (newDataTableId) => {
if (!newDataTableId) return;
state.dataTable = await getWidgetDataTable(newDataTableId);
}, { immediate: true });
defineExpose<WidgetExpose>({
loadWidget,
});
Expand Down
Loading
Loading