Skip to content

Commit

Permalink
chore: use proper type
Browse files Browse the repository at this point in the history
Signed-off-by: yuda <[email protected]>
  • Loading branch information
yuda110 committed Dec 22, 2024
1 parent b3e31bf commit 1b807cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ import {
import { isDateField } from '@/common/modules/widgets/_helpers/widget-field-helper';
import { getFormattedNumber } from '@/common/modules/widgets/_helpers/widget-helper';
import {
getWidgetLoadApiQuery,
getWidgetLoadApiQueryDateRange,
} from '@/common/modules/widgets/_helpers/widget-load-helper';
import type { AdvancedFormatRulesValue } from '@/common/modules/widgets/_widget-fields/advanced-format-rules/type';
import type { DateRangeValue } from '@/common/modules/widgets/_widget-fields/date-range/type';
import type { GranularityValue } from '@/common/modules/widgets/_widget-fields/granularity/type';
import type { NumberFormatValue } from '@/common/modules/widgets/_widget-fields/number-format/type';
import type { TableDataFieldValue } from '@/common/modules/widgets/_widget-fields/table-data-field/type';
import type { XAxisValue } from '@/common/modules/widgets/_widget-fields/x-axis/type';
import type { DateRange } from '@/common/modules/widgets/types/widget-data-type';
import type { WidgetEmit, WidgetExpose, WidgetProps } from '@/common/modules/widgets/types/widget-display-type';
Expand Down Expand Up @@ -104,11 +102,11 @@ const state = reactive({
legendList: [] as WidgetLegend[],
// required fields
granularity: computed<string>(() => props.widgetOptions?.granularity as string),
xAxisField: computed<string>(() => (props.widgetOptions?.xAxis as XAxisValue)?.value),
xAxisCount: computed<number>(() => (props.widgetOptions?.xAxis as XAxisValue)?.count),
dataFieldInfo: computed<TableDataFieldValue>(() => props.widgetOptions?.tableDataField as TableDataFieldValue),
dynamicFieldInfo: computed<TableDataFieldValue['dynamicFieldInfo']>(() => state.dataFieldInfo?.dynamicFieldInfo),
staticFieldInfo: computed<TableDataFieldValue['staticFieldInfo']>(() => state.dataFieldInfo?.staticFieldInfo),
xAxisField: computed<string|undefined>(() => (props.widgetOptions?.xAxis as XAxisValue)?.data),
xAxisCount: computed<number|undefined>(() => (props.widgetOptions?.xAxis as XAxisValue)?.count),
dataFieldInfo: computed(() => props.widgetOptions?.tableDataField),
dynamicFieldInfo: computed(() => state.dataFieldInfo?.dynamicFieldInfo),
staticFieldInfo: computed(() => state.dataFieldInfo?.staticFieldInfo),
dataField: computed<string|string[]|undefined>(() => {
if (state.dataFieldInfo?.fieldType === 'staticField') return state.staticFieldInfo?.fieldValue;
return state.dynamicFieldInfo?.fieldValue;
Expand Down Expand Up @@ -156,7 +154,7 @@ const fetchWidget = async (): Promise<Data|APIErrorToast|undefined> => {
granularity: state.granularity,
...(!isDateField(state.xAxisField) && { page: { start: 1, limit: state.xAxisCount } }),
...getWidgetLoadApiQueryDateRange(state.granularity, dateRange.value),
...getWidgetLoadApiQuery(state.dataFieldInfo, state.xAxisField),
// ...getWidgetLoadApiQuery(state.dataFieldInfo, state.xAxisField),
},
vars: props.dashboardVars,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import type { DateFormatValue } from '@/common/modules/widgets/_widget-fields/da
import type { DateRangeValue } from '@/common/modules/widgets/_widget-fields/date-range/type';
import type { DisplaySeriesLabelValue } from '@/common/modules/widgets/_widget-fields/display-series-label/type';
import type { GranularityValue } from '@/common/modules/widgets/_widget-fields/granularity/type';
import type { _GroupByValue } from '@/common/modules/widgets/_widget-fields/group-by/type';
import type { GroupByValue } from '@/common/modules/widgets/_widget-fields/group-by/type';
import type { LegendValue } from '@/common/modules/widgets/_widget-fields/legend/type';
import type { NumberFormatValue } from '@/common/modules/widgets/_widget-fields/number-format/type';
import type { PieChartTypeValue } from '@/common/modules/widgets/_widget-fields/pie-chart-type/type';
Expand Down Expand Up @@ -170,14 +170,14 @@ const state = reactive({
// required fields
granularity: computed<string|undefined>(() => (props.widgetOptions?.granularity?.value as GranularityValue)?.granularity),
dataField: computed<string|undefined>(() => (props.widgetOptions?.dataField?.value as DataFieldValue)?.data as string),
groupByField: computed<string|undefined>(() => (props.widgetOptions?.groupBy?.value as _GroupByValue)?.data as string),
groupByCount: computed<number|undefined>(() => (props.widgetOptions?.groupBy?.value as _GroupByValue)?.count),
groupByField: computed<string|undefined>(() => (props.widgetOptions?.groupBy?.value as GroupByValue)?.data as string),
groupByCount: computed<number|undefined>(() => (props.widgetOptions?.groupBy?.value as GroupByValue)?.count),
chartType: computed<string|undefined>(() => (props.widgetOptions?.pieChartType?.value as PieChartTypeValue)?.type),
// optional fields
showLegends: computed<boolean|undefined>(() => (props.widgetOptions?.legend?.value as LegendValue)?.toggleValue),
legendPosition: computed<string|undefined>(() => (props.widgetOptions?.legend?.value as LegendValue)?.position),
dateFormat: computed<string|undefined>(() => {
const _dateFormat = (props.widgetOptions?.dateFormat?.value as DateFormatValue)?.value || 'MMM DD, YYYY';
const _dateFormat = (props.widgetOptions?.dateFormat?.value as DateFormatValue)?.format || 'MMM DD, YYYY';
return DATE_FORMAT?.[_dateFormat]?.[state.granularity];
}),
numberFormat: computed<NumberFormatValue>(() => props.widgetOptions?.numberFormat?.value as NumberFormatValue),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import { getFormattedNumber } from '@/common/modules/widgets/_helpers/widget-hel
import type { ComparisonValue } from '@/common/modules/widgets/_widget-fields/comparison/type';
import type { CustomTableColumnWidthValue } from '@/common/modules/widgets/_widget-fields/custom-table-column-width/type';
import type { DataFieldHeatmapColorValue } from '@/common/modules/widgets/_widget-fields/data-field-heatmap-color/type';
import type { _DateFormatValue as DateFormatValue } from '@/common/modules/widgets/_widget-fields/date-format/type';
import type { _MissingValueValue as MissingValueValue } from '@/common/modules/widgets/_widget-fields/missing-value/type';
import type { DateFormatValue } from '@/common/modules/widgets/_widget-fields/date-format/type';
import type { MissingValueValue } from '@/common/modules/widgets/_widget-fields/missing-value/type';
import type { NumberFormatValue } from '@/common/modules/widgets/_widget-fields/number-format/type';
import type { TableColumnWidthValue } from '@/common/modules/widgets/_widget-fields/table-column-width/type';
import type { TextWrapValue } from '@/common/modules/widgets/_widget-fields/text-wrap/type';
Expand Down

0 comments on commit 1b807cf

Please sign in to comment.