Skip to content

Commit

Permalink
fix(Queries): now change of query ACO does not reset chart state and …
Browse files Browse the repository at this point in the history
…vice versa [#1006]
  • Loading branch information
vrozaev committed Feb 24, 2025
1 parent c80f1ed commit 1a94c7f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
12 changes: 11 additions & 1 deletion packages/ui/src/ui/pages/query-tracker/module/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {generateQuerySettings, generateQueryText} from '../utils/query_generate'
import {RootState} from '../../../store/reducers';
import {makeDirectDownloadPath} from '../../../utils/navigation';
import {QueriesHistoryCursorDirection, UPDATE_QUERIES_LIST} from './query-tracker-contants';
import {getEffectiveApiStage, getQueryTrackerRequestOptions} from './query/selectors';
import {
getEffectiveApiStage,
getQueryAnnotations,
getQueryTrackerRequestOptions,
} from './query/selectors';
import {AnyAction} from 'redux';
import {QueryEngine} from './engines';
import {getLastSelectedACONamespaces, selectIsMultipleAco} from './query_aco/selectors';
Expand Down Expand Up @@ -618,6 +622,8 @@ export function updateACOQuery({
const state = getState();
const isMultipleAco = selectIsMultipleAco(state);
const {stage} = getQueryTrackerRequestOptions(state);
const annotations = getQueryAnnotations(state);
const chartConfig = state.queryTracker.queryChart.visualization;

return ytApiV4Id
.alterQuery(YTApiId.alterQuery, {
Expand All @@ -627,6 +633,10 @@ export function updateACOQuery({
...(isMultipleAco
? {access_control_objects: aco}
: {access_control_object: aco[0]}),
annotations: {
...annotations,
chartConfig,
},
},
setup: getQTApiSetup(),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const SHARED_QUERY_ACO = 'everyone-share';

export const getQuery = (state: RootState) => getState(state).queryItem;
export const getQueryId = (state: RootState) => getState(state).queryItem?.id;
export const getQueryAnnotations = (state: RootState) => getState(state).queryItem?.annotations;
export const getQueryGetParams = (state: RootState) => getState(state).params;

export const getQueryDraft = (state: RootState) => getState(state).draft;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {RootState} from '../../../../store/reducers';
import {wrapApiPromiseByToaster} from '../../../../utils/utils';
import {ThunkAction} from 'redux-thunk';
import {Action, Dispatch} from 'redux';
import {getQueryItem} from '../query/selectors';
import {getCurrentQueryACO, getQueryAnnotations, getQueryItem} from '../query/selectors';
import {
Config,
FieldKey,
Expand All @@ -23,24 +23,38 @@ import {
} from './selectors';
import {getPointValue} from '../../QueryResultsVisualization/preparers/getPointData';
import {ChartKitWidgetAxisType} from '@gravity-ui/chartkit/build/types/widget-data/axis';
import {selectIsMultipleAco} from '../query_aco/selectors';

const DELAY = 2 * 1000;

type AsyncAction = ThunkAction<void, RootState, undefined, Action>;

type SaveQueryChartConfig = {
type SaveQueryChartConfigPayload = {
state: VisualizationState;
queryId: string;
};

const saveChartConfig = (dispatch: Dispatch, chartConfig: SaveQueryChartConfig) => {
const saveChartConfig = (
dispatch: Dispatch,
getState: () => RootState,
payload: SaveQueryChartConfigPayload,
) => {
dispatch(setSaved(false));
const state = getState();
const annotations = getQueryAnnotations(state);
const isMultipleAco = selectIsMultipleAco(state);
const aco = getCurrentQueryACO(state);

wrapApiPromiseByToaster(
ytApiV4Id.alterQuery(YTApiId.alterQuery, {
parameters: {
query_id: chartConfig.queryId,
query_id: payload.queryId,
...(isMultipleAco
? {access_control_objects: aco}
: {access_control_object: aco[0]}),
annotations: {
chartConfig: chartConfig.state,
...annotations,
chartConfig: payload.state,
},
},
}),
Expand All @@ -57,9 +71,9 @@ const saveChartConfig = (dispatch: Dispatch, chartConfig: SaveQueryChartConfig)
const debouncedSaveQueryChartConfig = debounce_(saveChartConfig, DELAY);

export const saveQueryChartConfig =
(payload: SaveQueryChartConfig): AsyncAction =>
(dispatch) => {
debouncedSaveQueryChartConfig(dispatch, payload);
(payload: SaveQueryChartConfigPayload): AsyncAction =>
(dispatch, getState) => {
debouncedSaveQueryChartConfig(dispatch, getState, payload);
};

export const changeAxisType =
Expand Down

0 comments on commit 1a94c7f

Please sign in to comment.