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

feat(widget-config): refactor widget-config & refactor date-range composable #5231

Merged
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 @@ -6,17 +6,19 @@ import dayjs from 'dayjs';
import { getDateFormat } from '@/common/modules/widgets/_helpers/widget-date-helper';
import { DATE_RANGE_ADVANCED_OPERATOR_MAP } from '@/common/modules/widgets/_widget-fields/date-range/constant';
import type { DateRangeValue, DateRangeValueType } from '@/common/modules/widgets/_widget-fields/date-range/type';
import type { GranularityValue } from '@/common/modules/widgets/_widget-fields/granularity/type';
import type { DateRange } from '@/common/modules/widgets/types/widget-data-type';


interface UseWidgetDateRangeOptions {
dateRangeFieldValue: ComputedRef<DateRangeValue>;
baseOnDate: ComputedRef<string|undefined>;
granularity: ComputedRef<string>;
granularity: ComputedRef<GranularityValue>;
usePreviewFormat?: boolean;
}

interface UseWidgetDateRangeState {
granularity: ComputedRef<GranularityValue['granularity']>;
isInherit: ComputedRef<boolean>;
dateRangeOptions: ComputedRef<DateRangeValue['options']>;
dateRange: ComputedRef<DateRange>;
Expand All @@ -30,11 +32,12 @@ interface UseWidgetDateRangeReturnType {
export const useWidgetDateRange = (options: UseWidgetDateRangeOptions): UseWidgetDateRangeReturnType => {
const {
baseOnDate: _baseOnDate,
granularity: _granularity,
granularity: _granularityInfo,
usePreviewFormat: _usePreviewFormat,
} = options;

const state = reactive<UseWidgetDateRangeState>({
granularity: computed<GranularityValue['granularity']>(() => _granularityInfo.value?.granularity ?? 'MONTHLY'),
isInherit: computed<boolean>(() => !!options.dateRangeFieldValue.value?.inherit),
dateRangeOptions: computed<DateRangeValue['options']>(() => options.dateRangeFieldValue.value?.options || 'auto'),
baseOnDate: computed<string|undefined>(() => (state.isInherit ? _baseOnDate.value : undefined)),
Expand All @@ -43,17 +46,17 @@ export const useWidgetDateRange = (options: UseWidgetDateRangeOptions): UseWidge
const { start: _start, end: _end } = state.dateRangeOptions || {};

if (dateRangePresetKey === 'custom') {
return state.isInherit ? getWidgetDateRangeByCustomRelativeNumberUnit(_granularity.value, state.baseOnDate, _start, _end)
: getWidgetDateRangeByCustomFixedDateRange(_granularity.value, _start, _end);
return state.isInherit ? getWidgetDateRangeByCustomRelativeNumberUnit(state.granularity, state.baseOnDate, _start, _end)
: getWidgetDateRangeByCustomFixedDateRange(state.granularity, _start, _end);
} if (dateRangePresetKey === 'advanced') {
const { start_operator: _startOperator, end_operator: _endOperator } = state.dateRangeOptions || {};
const startValue: number = _startOperator === DATE_RANGE_ADVANCED_OPERATOR_MAP.ADD ? _start || 0 : (_start || 0) * -1;
const endValue: number = _endOperator === DATE_RANGE_ADVANCED_OPERATOR_MAP.ADD ? _end || 0 : (_end || 0) * -1;

return getWidgetDateRangeByAdvancedDiffValue(_granularity.value, state.baseOnDate, startValue, endValue, _usePreviewFormat);
return getWidgetDateRangeByAdvancedDiffValue(state.granularity, state.baseOnDate, startValue, endValue, _usePreviewFormat);
}

return getWidgetDateRangeByPresetKey(_granularity.value, state.baseOnDate, dateRangePresetKey, _usePreviewFormat);
return getWidgetDateRangeByPresetKey(state.granularity, state.baseOnDate, dateRangePresetKey, _usePreviewFormat);
}),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
import type { DateFormatValue } from '@/common/modules/widgets/_widget-fields/date-format/type';
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 { LegendValue } from '@/common/modules/widgets/_widget-fields/legend/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';
Expand Down Expand Up @@ -73,9 +74,9 @@ const props = defineProps<WidgetProps>();
const emit = defineEmits<WidgetEmit>();

const { dateRange } = useWidgetDateRange({
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange as DateRangeValue)),
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange?.value as DateRangeValue)),
baseOnDate: computed(() => props.dashboardOptions?.date_range?.end),
granularity: computed<string>(() => props.widgetOptions?.granularity as string),
granularity: computed<GranularityValue>(() => props.widgetOptions?.granularity?.value as GranularityValue),
});
const chartContext = ref<HTMLElement|null>(null);
const state = reactive({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const clusteredColumnChart: WidgetConfig = {
max: 31,
},
},
tableDataField: {},
dataField: {},
},
optionalFieldsSchema: {
legend: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from '@/common/modules/widgets/_helpers/widget-date-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 { GroupByValue } from '@/common/modules/widgets/_widget-fields/group-by/type';
import type { WidgetEmit, WidgetExpose, WidgetProps } from '@/common/modules/widgets/types/widget-display-type';
import type { WidgetLegend } from '@/common/modules/widgets/types/widget-legend-typs';
Expand All @@ -44,9 +45,9 @@ const props = defineProps<WidgetProps>();
const emit = defineEmits<WidgetEmit>();

const { dateRange } = useWidgetDateRange({
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange as DateRangeValue)),
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange?.value as DateRangeValue)),
baseOnDate: computed(() => props.dashboardOptions?.date_range?.end),
granularity: computed<string>(() => props.widgetOptions?.granularity as string),
granularity: computed<GranularityValue>(() => props.widgetOptions?.granularity?.value as GranularityValue),
});
const state = reactive({
loading: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ADVANCED_FORMAT_RULE_TYPE } from '@/common/modules/widgets/_constants/widget-field-constant';
import { _FORMAT_RULE_TYPE } from '@/common/modules/widgets/_constants/widget-field-constant';
import type { WidgetConfig } from '@/common/modules/widgets/types/widget-config-type';


Expand All @@ -23,9 +23,10 @@ const colorCodedHeatmap: WidgetConfig = {
excludeDateField: true,
},
},
advancedFormatRules: {
formatRules: {
options: {
formatRulesType: ADVANCED_FORMAT_RULE_TYPE.field,
useField: true,
formatRulesType: _FORMAT_RULE_TYPE.textThreshold,
description: 'COMMON.WIDGETS.ADVANCED_FORMAT_RULES.COLOR_CODED_HEATMAP_DESC',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
} 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';
Expand All @@ -58,9 +59,9 @@ const props = defineProps<WidgetProps>();
const emit = defineEmits<WidgetEmit>();

const { dateRange } = useWidgetDateRange({
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange as DateRangeValue)),
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange?.value as DateRangeValue)),
baseOnDate: computed(() => props.dashboardOptions?.date_range?.end),
granularity: computed<string>(() => props.widgetOptions?.granularity as string),
granularity: computed<GranularityValue>(() => props.widgetOptions?.granularity?.value as GranularityValue),
});
const state = reactive({
loading: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ADVANCED_FORMAT_RULE_TYPE } from '@/common/modules/widgets/_constants/widget-field-constant';
import { _FORMAT_RULE_TYPE } from '@/common/modules/widgets/_constants/widget-field-constant';
import type { WidgetConfig } from '@/common/modules/widgets/types/widget-config-type';


Expand All @@ -21,10 +21,10 @@ const colorCodedTableHeatmap: WidgetConfig = {
max: 31,
},
},
tableDataField: {},
advancedFormatRules: {
dataField: {},
formatRules: {
options: {
formatRulesType: ADVANCED_FORMAT_RULE_TYPE.textThreshold,
formatRulesType: _FORMAT_RULE_TYPE.textNumberTreshold,
description: 'COMMON.WIDGETS.ADVANCED_FORMAT_RULES.COLOR_CODED_TABLE_HEATMAP_DESC',
},
},
Expand Down
5 changes: 3 additions & 2 deletions apps/web/src/common/modules/widgets/_widgets/gauge/Gauge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { useWidgetInitAndRefresh } from '@/common/modules/widgets/_composables/u
import { getFormattedNumber } from '@/common/modules/widgets/_helpers/widget-helper';
import type { DateRangeValue } from '@/common/modules/widgets/_widget-fields/date-range/type';
import type { FormatRulesValue } from '@/common/modules/widgets/_widget-fields/format-rules/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 {
WidgetProps, WidgetEmit,
Expand All @@ -44,9 +45,9 @@ const emit = defineEmits<WidgetEmit>();

const chartContext = ref<HTMLElement|null>(null);
const { dateRange } = useWidgetDateRange({
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange as DateRangeValue)),
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange?.value as DateRangeValue)),
baseOnDate: computed(() => props.dashboardOptions?.date_range?.end),
granularity: computed<string>(() => props.widgetOptions?.granularity as string),
granularity: computed<GranularityValue>(() => props.widgetOptions?.granularity?.value as GranularityValue),
});
const state = reactive({
loading: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { useWidgetDateRange } from '@/common/modules/widgets/_composables/use-wi
import { useWidgetFrame } from '@/common/modules/widgets/_composables/use-widget-frame';
import { useWidgetInitAndRefresh } from '@/common/modules/widgets/_composables/use-widget-init-and-refresh';
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 { LegendValue } from '@/common/modules/widgets/_widget-fields/legend/type';
import type { WidgetLoadData } from '@/common/modules/widgets/types/widget-data-type';
import type {
Expand All @@ -44,9 +45,9 @@ const emit = defineEmits<WidgetEmit>();
const REGION_FIELD = 'Region';

const { dateRange } = useWidgetDateRange({
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange as DateRangeValue)),
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange?.value as DateRangeValue)),
baseOnDate: computed(() => props.dashboardOptions?.date_range?.end),
granularity: computed<string>(() => props.widgetOptions?.granularity as string),
granularity: computed<GranularityValue>(() => props.widgetOptions?.granularity?.value as GranularityValue),
});
const chartContext = ref<HTMLElement|null>(null);
const allReferenceStore = useAllReferenceStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
import type { ColorSchemaValue, ColorValue } from '@/common/modules/widgets/_widget-fields/color-schema/type';
import type { DateFormatValue } from '@/common/modules/widgets/_widget-fields/date-format/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 { LegendValue } from '@/common/modules/widgets/_widget-fields/legend/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';
Expand All @@ -57,9 +58,9 @@ const props = defineProps<WidgetProps>();
const emit = defineEmits<WidgetEmit>();

const { dateRange } = useWidgetDateRange({
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange as DateRangeValue)),
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange?.value as DateRangeValue)),
baseOnDate: computed(() => props.dashboardOptions?.date_range?.end),
granularity: computed<string>(() => props.widgetOptions?.granularity as string),
granularity: computed<GranularityValue>(() => props.widgetOptions?.granularity?.value as GranularityValue),
});
const chartContext = ref<HTMLElement|null>(null);
const state = reactive({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const heatmap: WidgetConfig = {
defaultIndex: 0,
},
},
tableDataField: {},
dataField: {},
colorSchema: {},
},
optionalFieldsSchema: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { getWidgetLoadApiQueryDateRange, getWidgetLoadApiQuery } from '@/common/
import type { DateFormatValue } from '@/common/modules/widgets/_widget-fields/date-format/type';
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 { LegendValue } from '@/common/modules/widgets/_widget-fields/legend/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';
Expand All @@ -60,9 +61,9 @@ const props = defineProps<WidgetProps>();
const emit = defineEmits<WidgetEmit>();

const { dateRange } = useWidgetDateRange({
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange as DateRangeValue)),
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange?.value as DateRangeValue)),
baseOnDate: computed(() => props.dashboardOptions?.date_range?.end),
granularity: computed<string>(() => props.widgetOptions?.granularity as string),
granularity: computed<GranularityValue>(() => props.widgetOptions?.granularity?.value as GranularityValue),
});
const chartContext = ref<HTMLElement|null>(null);
const state = reactive({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const lineChart: WidgetConfig = {
max: 31,
},
},
tableDataField: {},
dataField: {},
},
optionalFieldsSchema: {
legend: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
import { getFormattedNumber } from '@/common/modules/widgets/_helpers/widget-helper';
import type { ComparisonValue } from '@/common/modules/widgets/_widget-fields/comparison/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 { IconValue } from '@/common/modules/widgets/_widget-fields/icon/type';
import type { NumberFormatValue } from '@/common/modules/widgets/_widget-fields/number-format/type';
import type {
Expand All @@ -50,9 +51,9 @@ const topPartRef = ref<null | HTMLElement>(null);
const valueTextRef = ref<null | HTMLElement>(null);

const { dateRange } = useWidgetDateRange({
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange as DateRangeValue)),
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange?.value as DateRangeValue)),
baseOnDate: computed(() => props.dashboardOptions?.date_range?.end),
granularity: computed<string>(() => props.widgetOptions?.granularity as string),
granularity: computed<GranularityValue>(() => props.widgetOptions?.granularity?.value as GranularityValue),
});
const state = reactive({
loading: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { getFormattedNumber } from '@/common/modules/widgets/_helpers/widget-hel
import type { DateFormatValue } from '@/common/modules/widgets/_widget-fields/date-format/type';
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 { LegendValue } from '@/common/modules/widgets/_widget-fields/legend/type';
import type { NumberFormatValue } from '@/common/modules/widgets/_widget-fields/number-format/type';
Expand All @@ -58,9 +59,9 @@ type Data = ListResponse<{
const props = defineProps<WidgetProps>();
const emit = defineEmits<WidgetEmit>();
const { dateRange } = useWidgetDateRange({
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange as DateRangeValue)),
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange?.value as DateRangeValue)),
baseOnDate: computed(() => props.dashboardOptions?.date_range?.end),
granularity: computed<string>(() => props.widgetOptions?.granularity as string),
granularity: computed<GranularityValue>(() => props.widgetOptions?.granularity?.value as GranularityValue),
});
const chartContext = ref<HTMLElement|null>(null);
const state = reactive({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const stackedAreaChart: WidgetConfig = {
max: 31,
},
},
tableDataField: {},
dataField: {},
},
optionalFieldsSchema: {
legend: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { getWidgetLoadApiQueryDateRange, getWidgetLoadApiQuery } from '@/common/
import type { DateFormatValue } from '@/common/modules/widgets/_widget-fields/date-format/type';
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 { LegendValue } from '@/common/modules/widgets/_widget-fields/legend/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';
Expand All @@ -61,9 +62,9 @@ const props = defineProps<WidgetProps>();
const emit = defineEmits<WidgetEmit>();

const { dateRange } = useWidgetDateRange({
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange as DateRangeValue)),
dateRangeFieldValue: computed(() => (props.widgetOptions?.dateRange?.value as DateRangeValue)),
baseOnDate: computed(() => props.dashboardOptions?.date_range?.end),
granularity: computed<string>(() => props.widgetOptions?.granularity as string),
granularity: computed<GranularityValue>(() => props.widgetOptions?.granularity?.value as GranularityValue),
});
const chartContext = ref<HTMLElement|null>(null);
const state = reactive({
Expand Down
Loading
Loading