Skip to content

Commit

Permalink
fix(unified-cost-full-link): apply unified-cost full-data link (#5666)
Browse files Browse the repository at this point in the history
* fix(unified-cost-full-link): apply unified-cost full-data link

Signed-off-by: samuel.park <samuel.park@megazone.com>

* refactor(data-table): refactor selection data-table

Signed-off-by: samuel.park <samuel.park@megazone.com>

* chore: small fix

Signed-off-by: samuel.park <samuel.park@megazone.com>

---------

Signed-off-by: samuel.park <samuel.park@megazone.com>
  • Loading branch information
piggggggggy authored Feb 25, 2025
1 parent a1fa280 commit d245a63
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,6 @@ const { mutateAsync: updateWidget } = useMutation({
? keys.privateWidgetQueryKey
: keys.publicWidgetQueryKey;
queryClient.setQueryData(widgetQueryKey.value, () => data);
showSuccessMessage(i18n.t('COMMON.WIDGETS.DATA_TABLE.FORM.UPDATE_DATA_TALBE_INVALID_SUCCESS'), '');
widgetGenerateStore.setSelectedDataTableId(state.dataTableId);
},
onError: (e) => {
showErrorMessage(e.message, e);
Expand Down Expand Up @@ -454,6 +451,8 @@ const handleUpdateDataTable = async () => {
state: 'INACTIVE',
options: sanitizedOptions,
});
showSuccessMessage(i18n.t('COMMON.WIDGETS.DATA_TABLE.FORM.UPDATE_DATA_TALBE_INVALID_SUCCESS'), '');
widgetGenerateStore.setSelectedDataTableId(state.dataTableId);
await cascadeUpdateDataTable(result.data_table_id);
}
setTimeout(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { computed, reactive } from 'vue';
import { useMutation } from '@tanstack/vue-query';
import { cloneDeep } from 'lodash';
import {
PIconButton, PI, PTextInput, PTooltip,
Expand All @@ -20,6 +21,7 @@ import { useWidgetFormQuery } from '@/common/modules/widgets/_composables/use-wi
import {
DATA_TABLE_TYPE,
} from '@/common/modules/widgets/_constants/data-table-constant';
import { sanitizeWidgetOptions } from '@/common/modules/widgets/_helpers/widget-helper';
import { useWidgetGenerateStore } from '@/common/modules/widgets/_store/widget-generate-store';
import type { DataTableModel } from '@/common/modules/widgets/types/widget-data-table-type';
import type { DataTableDataType } from '@/common/modules/widgets/types/widget-model';
Expand All @@ -44,6 +46,7 @@ const widgetGenerateState = widgetGenerateStore.state;
/* Query */
const {
widget,
dataTableList,
fetcher,
keys,
Expand Down Expand Up @@ -71,6 +74,15 @@ const handleSelectDataTable = async (dataTableId: string) => {
showErrorMessage(i18n.t('COMMON.WIDGETS.DATA_TABLE.FORM.SELECT_DATA_TABLE_WARNING'), '');
return;
}
if (widgetGenerateState.selectedDataTableId === dataTableId) return;
const _widgetOptions = cloneDeep(widget.value?.options);
const sanitizedOptions = sanitizeWidgetOptions(_widgetOptions, widget.value?.widget_type, storeState.currentDataTable);
await updateWidget({
widget_id: widgetGenerateState.widgetId,
state: 'INACTIVE',
options: sanitizedOptions,
});
widgetGenerateStore.setSelectedDataTableId(dataTableId);
};
const handleUpdateDataTableName = (value: string) => {
Expand Down Expand Up @@ -108,6 +120,19 @@ const handleClickNameConfirm = async () => {
};
/* Api */
const { mutateAsync: updateWidget } = useMutation({
mutationFn: fetcher.updateWidgetFn,
onSuccess: (data) => {
const widgetQueryKey = widgetGenerateState.widgetId?.startsWith('private')
? keys.privateWidgetQueryKey
: keys.publicWidgetQueryKey;
queryClient.setQueryData(widgetQueryKey.value, () => data);
},
onError: (e) => {
showErrorMessage(e.message, e);
ErrorHandler.handleError(e);
},
});
const { mutate: updateDataTable } = useMutation({
mutationFn: fetcher.updateDataTableFn,
onSuccess: async (data) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ const { mutateAsync: updateWidget } = useMutation({
? keys.privateWidgetQueryKey
: keys.publicWidgetQueryKey;
queryClient.setQueryData(widgetQueryKey.value, () => data);
showSuccessMessage(i18n.t('COMMON.WIDGETS.DATA_TABLE.FORM.UPDATE_DATA_TALBE_INVALID_SUCCESS'), '');
},
onError: (e) => {
showErrorMessage(e.message, e);
Expand Down Expand Up @@ -432,6 +431,7 @@ const handleUpdateDataTable = async () => {
state: 'INACTIVE',
options: sanitizedOptions,
});
showSuccessMessage(i18n.t('COMMON.WIDGETS.DATA_TABLE.FORM.UPDATE_DATA_TALBE_INVALID_SUCCESS'), '');
widgetGenerateStore.setSelectedDataTableId(result.data_table_id);
await cascadeUpdateDataTable(result.data_table_id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type { FullDataLink, WidgetFrameProps } from '@/common/modules/widgets/ty

import { ASSET_INVENTORY_ROUTE_V1 } from '@/services/asset-inventory-v1/routes/route-constant';
import type { MetricFilter } from '@/services/asset-inventory-v1/types/asset-analysis-type';
import { UNIFIED_COST_KEY } from '@/services/cost-explorer/constants/cost-explorer-constant';
import { DYNAMIC_COST_QUERY_SET_PARAMS } from '@/services/cost-explorer/constants/managed-cost-analysis-query-sets';
import { COST_EXPLORER_ROUTE } from '@/services/cost-explorer/routes/route-constant';

Expand Down Expand Up @@ -85,7 +86,7 @@ const getFullDataLocation = (dataTable: DataTableModel, widgetOptions?: WidgetPr
...convertConsoleFiltersToMetricFilter(dataTable?.options?.filter ?? []),
...dashboardVars,
};
const _filter = dataTable?.source_type === DATA_SOURCE_DOMAIN.COST ? _costFilters : _assetFilters;
const _filter = (dataTable?.source_type === DATA_SOURCE_DOMAIN.COST || dataTable?.source_type === DATA_SOURCE_DOMAIN.UNIFIED_COST) ? _costFilters : _assetFilters;

const _dateRange: DateRange = cloneDeep(dateRange);
if (!_dateRange?.start) _dateRange.start = dateRange?.end;
Expand All @@ -105,7 +106,18 @@ const getFullDataLocation = (dataTable: DataTableModel, widgetOptions?: WidgetPr
},
query: _query,
});
} if (dataTable?.source_type === DATA_SOURCE_DOMAIN.ASSET) {
}
if (dataTable?.source_type === DATA_SOURCE_DOMAIN.UNIFIED_COST) {
return getProperRouteLocation({
name: COST_EXPLORER_ROUTE.COST_ANALYSIS.QUERY_SET._NAME,
params: {
dataSourceId: UNIFIED_COST_KEY,
costQuerySetId: DYNAMIC_COST_QUERY_SET_PARAMS,
},
query: _query,
});
}
if (dataTable?.source_type === DATA_SOURCE_DOMAIN.ASSET) {
const _metricId = dataTable?.options?.[DATA_SOURCE_DOMAIN.ASSET]?.metric_id;
if (_metricId) {
return getProperRouteLocation({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ const handleSelectUnifiedCostToggle = (value: boolean) => {
};
(() => {
costQuerySetStore.setUnifiedCostOn(storeState.isAdminMode);
const isUnifiedCostRoute = route.params.dataSourceId === UNIFIED_COST_KEY;
costQuerySetStore.setUnifiedCostOn(isUnifiedCostRoute || storeState.isAdminMode);
})();
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const useDashboardDetailInfoStore = defineStore('dashboard-detail-info',
console.error('setDashboardInfo failed', dashboardInfo);
return;
}
if (!!dashboardInfo.project_id && dashboardInfo.project_id !== '*') {
if (!!dashboardInfo.project_id && dashboardInfo.project_id !== '*' && dashboardInfo.project_id !== '-') {
state.projectId = dashboardInfo.project_id;
}
state.vars = dashboardInfo.vars ?? {};
Expand Down

0 comments on commit d245a63

Please sign in to comment.