Skip to content

Commit eb54851

Browse files
fix(QueryEditor): pass base64 from settings (#3093)
1 parent d85e8d3 commit eb54851

File tree

6 files changed

+23
-22
lines changed

6 files changed

+23
-22
lines changed

src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ export default function QueryEditor(props: QueryEditorProps) {
9595
const [lastExecutedQueryText, setLastExecutedQueryText] = React.useState<string>('');
9696
const [isQueryStreamingEnabled] = useQueryStreamingSetting();
9797

98+
const [binaryDataInPlainTextDisplay] = useSetting<boolean>(
99+
SETTING_KEYS.BINARY_DATA_IN_PLAIN_TEXT_DISPLAY,
100+
);
101+
102+
const encodeTextWithBase64 = !binaryDataInPlainTextDisplay;
103+
98104
const isStreamingEnabled =
99105
useStreamingAvailable() &&
100106
isQueryStreamingEnabled &&
@@ -160,6 +166,7 @@ export default function QueryEditor(props: QueryEditorProps) {
160166
database,
161167
querySettings,
162168
enableTracingLevel,
169+
base64: encodeTextWithBase64,
163170
});
164171

165172
queryManagerInstance.registerQuery(query);
@@ -172,6 +179,7 @@ export default function QueryEditor(props: QueryEditorProps) {
172179
querySettings,
173180
enableTracingLevel,
174181
queryId,
182+
base64: encodeTextWithBase64,
175183
});
176184

177185
queryManagerInstance.registerQuery(query);
@@ -212,6 +220,7 @@ export default function QueryEditor(props: QueryEditorProps) {
212220
querySettings,
213221
enableTracingLevel,
214222
queryId,
223+
base64: encodeTextWithBase64,
215224
});
216225

217226
queryManagerInstance.registerQuery(query);

src/services/api/base.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import type {AxiosWrapperOptions} from '@gravity-ui/axios-wrapper';
33
import axiosRetry from 'axios-retry';
44

55
import {backend as BACKEND, clusterName} from '../../store';
6+
import {readSettingValueFromLS} from '../../store/reducers/settings/utils';
67
import type {SchemaPathParam} from '../../types/api/common';
78
import {DEV_ENABLE_TRACING_FOR_ALL_REQUESTS} from '../../utils/constants';
89
import {prepareBackendWithMetaProxy} from '../../utils/parseBalancer';
910
import {isRedirectToAuth} from '../../utils/response';
10-
import {settingsManager} from '../settings';
1111

1212
export type AxiosOptions = {
1313
concurrentId?: string;
@@ -42,9 +42,7 @@ export class BaseYdbAPI extends AxiosWrapper {
4242
// Make possible manually enable tracing for all requests
4343
// For development purposes
4444
this._axios.interceptors.request.use(function (config) {
45-
const enableTracing = settingsManager.readUserSettingsValue(
46-
DEV_ENABLE_TRACING_FOR_ALL_REQUESTS,
47-
);
45+
const enableTracing = readSettingValueFromLS(DEV_ENABLE_TRACING_FOR_ALL_REQUESTS);
4846

4947
if (enableTracing) {
5048
config.headers['X-Want-Trace'] = 1;

src/services/api/streaming.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
isSessionChunk,
99
isStreamDataChunk,
1010
} from '../../store/reducers/query/utils';
11-
import {SETTING_KEYS} from '../../store/reducers/settings/constants';
11+
import {readSettingValueFromLS} from '../../store/reducers/settings/utils';
1212
import type {Actions, StreamQueryParams} from '../../types/api/query';
1313
import type {
1414
QueryResponseChunk,
@@ -18,7 +18,6 @@ import type {
1818
} from '../../types/store/streaming';
1919
import {DEV_ENABLE_TRACING_FOR_ALL_REQUESTS} from '../../utils/constants';
2020
import {isRedirectToAuth} from '../../utils/response';
21-
import {settingsManager} from '../settings';
2221

2322
import {BaseYdbAPI} from './base';
2423

@@ -42,10 +41,7 @@ export class StreamingAPI extends BaseYdbAPI {
4241
params: StreamQueryParams<Action>,
4342
options: StreamQueryOptions,
4443
) {
45-
const base64 = !settingsManager.readUserSettingsValue(
46-
SETTING_KEYS.BINARY_DATA_IN_PLAIN_TEXT_DISPLAY,
47-
true,
48-
);
44+
const base64 = params.base64;
4945

5046
const queryParams = qs.stringify(
5147
{timeout: params.timeout, base64, schema: 'multipart'},
@@ -66,9 +62,7 @@ export class StreamingAPI extends BaseYdbAPI {
6662
headers.set('X-Trace-Verbosity', String(params.tracingLevel));
6763
}
6864

69-
const enableTracing = settingsManager.readUserSettingsValue(
70-
DEV_ENABLE_TRACING_FOR_ALL_REQUESTS,
71-
);
65+
const enableTracing = readSettingValueFromLS(DEV_ENABLE_TRACING_FOR_ALL_REQUESTS);
7266

7367
if (enableTracing) {
7468
headers.set('X-Want-Trace', '1');

src/services/api/viewer.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type {PlanToSvgQueryParams} from '../../store/reducers/planToSvg';
2-
import {SETTING_KEYS} from '../../store/reducers/settings/constants';
32
import type {VDiskBlobIndexStatParams} from '../../store/reducers/vdisk/vdisk';
43
import type {
54
AccessRightsUpdateRequest,
@@ -40,7 +39,6 @@ import type {VDiskBlobIndexResponse} from '../../types/api/vdiskBlobIndex';
4039
import type {TUserToken} from '../../types/api/whoami';
4140
import type {TabletsApiRequestParams} from '../../types/store/tablets';
4241
import type {Nullable} from '../../utils/typecheckers';
43-
import {settingsManager} from '../settings';
4442

4543
import type {AxiosOptions} from './base';
4644
import {BaseYdbAPI} from './base';
@@ -416,10 +414,7 @@ export class ViewerAPI extends BaseYdbAPI {
416414
params: SendQueryParams<Action>,
417415
{concurrentId, signal, withRetries}: AxiosOptions = {},
418416
) {
419-
const base64 = !settingsManager.readUserSettingsValue(
420-
SETTING_KEYS.BINARY_DATA_IN_PLAIN_TEXT_DISPLAY,
421-
true,
422-
);
417+
const base64 = params.base64;
423418

424419
return this.post<QueryAPIResponse<Action> | ErrorResponse | null>(
425420
this.getPath('/viewer/json/query'),

src/store/reducers/query/query.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ interface SendQueryParams extends QueryRequestParams {
222222
// flag whether to send new tracing header or not
223223
// default: not send
224224
enableTracingLevel?: boolean;
225+
base64?: boolean;
225226
}
226227

227228
// Stream query receives queryId from session chunk.
@@ -239,7 +240,7 @@ export const queryApi = api.injectEndpoints({
239240
endpoints: (build) => ({
240241
useStreamQuery: build.mutation<null, StreamQueryParams>({
241242
queryFn: async (
242-
{query, database, querySettings = {}, enableTracingLevel},
243+
{query, database, querySettings = {}, enableTracingLevel, base64},
243244
{signal, dispatch, getState},
244245
) => {
245246
const startTime = Date.now();
@@ -294,6 +295,7 @@ export const queryApi = api.injectEndpoints({
294295
: undefined,
295296
output_chunk_max_size: DEFAULT_STREAM_CHUNK_SIZE,
296297
concurrent_results: DEFAULT_CONCURRENT_RESULTS || undefined,
298+
base64,
297299
},
298300
{
299301
signal,
@@ -343,7 +345,7 @@ export const queryApi = api.injectEndpoints({
343345
}
344346
},
345347
}),
346-
useSendQuery: build.mutation<null, SendQueryParams>({
348+
useSendQuery: build.mutation({
347349
queryFn: async (
348350
{
349351
actionType = 'execute',
@@ -352,7 +354,8 @@ export const queryApi = api.injectEndpoints({
352354
querySettings = {},
353355
enableTracingLevel,
354356
queryId,
355-
},
357+
base64,
358+
}: SendQueryParams,
356359
{signal, dispatch, getState},
357360
) => {
358361
const startTime = Date.now();
@@ -396,6 +399,7 @@ export const queryApi = api.injectEndpoints({
396399
? Number(querySettings.timeout) * 1000
397400
: undefined,
398401
query_id: queryId,
402+
base64,
399403
},
400404
{signal},
401405
);

src/types/api/query.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ export interface SendQueryParams<Action extends Actions> {
327327
query_id?: string;
328328
limit_rows?: number;
329329
internal_call?: boolean;
330+
base64?: boolean;
330331
}
331332

332333
export interface StreamQueryParams<Action extends Actions> extends SendQueryParams<Action> {

0 commit comments

Comments
 (0)