Skip to content

Commit

Permalink
chore: set proper code (#5417)
Browse files Browse the repository at this point in the history
* chore: set proper code

Signed-off-by: yuda <yuda@megazone.com>

* fix: fix dataField

Signed-off-by: yuda <yuda@megazone.com>

---------

Signed-off-by: yuda <yuda@megazone.com>
  • Loading branch information
yuda110 authored Jan 3, 2025
1 parent 77730cb commit e29e284
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
10 changes: 5 additions & 5 deletions apps/web/src/common/modules/widgets/_widgets/gauge/Gauge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ const state = reactive({
isPrivateWidget: computed<boolean>(() => props.widgetId.startsWith('private')),
dataTable: undefined as PublicDataTableModel|PrivateDataTableModel|undefined,
unit: computed<string|undefined>(() => widgetFrameProps.value.unitMap?.[state.dataField]),
unit: computed<string|undefined>(() => {
if (!widgetOptionsState.dataFieldInfo?.data) return undefined;
return widgetFrameProps.value.unitMap?.[widgetOptionsState.dataFieldInfo.data as string];
}),
data: computed<WidgetLoadResponse | null>(() => queryResult?.data?.value || null),
chart: null as EChartsType | null,
chartData: undefined as undefined|number,
Expand Down Expand Up @@ -178,10 +181,7 @@ const errorMessage = computed<string|undefined>(() => {
/* Util */
const drawChart = (rawData: WidgetLoadResponse|null) => {
if (isEmpty(rawData)) return;
// HACK: Change the code below when the backend data is modified
// state.chartData = rawData?.results?.[0]?.[widgetOptionsState.dataFieldInfo?.data as string] || 0;
const _targetData = state.data?.results?.find((d) => !!d[widgetOptionsState.dataFieldInfo?.data as string]);
state.chartData = _targetData?.[widgetOptionsState.dataFieldInfo?.data as string] || 0;
state.chartData = rawData?.results?.[0]?.[widgetOptionsState.dataFieldInfo?.data as string] || 0;
};
const loadWidget = () => {
state.runQueries = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,8 @@ const state = reactive({
data: computed<WidgetLoadResponse | null>(() => queryResults.value?.[0].data || null),
previousData: computed<WidgetLoadResponse | null>(() => queryResults.value?.[1]?.data || null),
unit: computed<string|undefined>(() => widgetFrameProps.value.unitMap?.[widgetOptionsState.dataFieldInfo?.data as string]),
previousValue: computed<number>(() => {
// HACK: Change the code below when the backend data is modified
// return state.previousData?.results?.[0]?.[widgetOptionsState.dataFieldInfo?.data as string] ?? 0;
const _targetData = state.previousData?.results?.find((d) => !!d[widgetOptionsState.dataFieldInfo?.data as string]);
return _targetData?.[widgetOptionsState.dataFieldInfo?.data as string] || 0;
}),
currentValue: computed<number>(() => {
// HACK: Change the code below when the backend data is modified
// return state.data?.results?.[0]?.[widgetOptionsState.dataFieldInfo?.data as string] ?? 0;
const _targetData = state.data?.results?.find((d) => !!d[widgetOptionsState.dataFieldInfo?.data as string]);
return _targetData?.[widgetOptionsState.dataFieldInfo?.data as string] || 0;
}),
previousValue: computed<number>(() => state.previousData?.results?.[0]?.[widgetOptionsState.dataFieldInfo?.data as string] ?? 0),
currentValue: computed<number>(() => state.data?.results?.[0]?.[widgetOptionsState.dataFieldInfo?.data as string] ?? 0),
valueText: computed<string|undefined>(() => getFormattedNumber(state.currentValue, widgetOptionsState.numberFormatInfo?.[widgetOptionsState.dataFieldInfo?.data as string], state.unit)),
iconName: computed<string|undefined>(() => widgetOptionsState.iconInfo?.icon?.name),
Expand Down

0 comments on commit e29e284

Please sign in to comment.