Skip to content

Commit 04bde50

Browse files
committed
fix: should always ask confirmation is user input is truthy
1 parent d1997fb commit 04bde50

File tree

4 files changed

+9
-36
lines changed

4 files changed

+9
-36
lines changed

src/containers/Tenant/ObjectSummary/SchemaTree/SchemaTree.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import React from 'react';
66
import {NavigationTree} from 'ydb-ui-components';
77

88
import {useCreateDirectoryFeatureAvailable} from '../../../../store/reducers/capabilities/hooks';
9-
import {selectIsQuerySaved} from '../../../../store/reducers/executeQuery';
9+
import {selectUserInput} from '../../../../store/reducers/executeQuery';
1010
import {schemaApi} from '../../../../store/reducers/schema/schema';
1111
import {tableSchemaDataApi} from '../../../../store/reducers/tableSchemaData';
1212
import type {GetTableSchemaDataParams} from '../../../../store/reducers/tableSchemaData';
@@ -39,7 +39,7 @@ export function SchemaTree(props: SchemaTreeProps) {
3939
const createDirectoryFeatureAvailable = useCreateDirectoryFeatureAvailable();
4040
const {rootPath, rootName, rootType, currentPath, onActivePathUpdate} = props;
4141
const dispatch = useTypedDispatch();
42-
const isQuerySaved = useTypedSelector(selectIsQuerySaved);
42+
const input = useTypedSelector(selectUserInput);
4343
const [getTableSchemaDataMutation] = tableSchemaDataApi.useGetTableSchemaDataMutation();
4444

4545
const getTableSchemaDataPromise = React.useCallback(
@@ -151,7 +151,7 @@ export function SchemaTree(props: SchemaTreeProps) {
151151
? handleOpenCreateDirectoryDialog
152152
: undefined,
153153
getTableSchemaDataPromise,
154-
getConfirmation: isQuerySaved ? undefined : getConfirmation,
154+
getConfirmation: input ? getConfirmation : undefined,
155155
},
156156
rootPath,
157157
)}

src/store/reducers/executeQuery.ts

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
1-
import {createSelector, createSlice} from '@reduxjs/toolkit';
1+
import {createSlice} from '@reduxjs/toolkit';
22
import type {PayloadAction} from '@reduxjs/toolkit';
33

44
import {settingsManager} from '../../services/settings';
55
import {TracingLevelNumber} from '../../types/api/query';
66
import type {ExecuteActions} from '../../types/api/query';
77
import {ResultType} from '../../types/store/executeQuery';
88
import type {ExecuteQueryState, QueryInHistory, QueryResult} from '../../types/store/executeQuery';
9-
import type {
10-
QueryRequestParams,
11-
QuerySettings,
12-
QuerySyntax,
13-
SavedQuery,
14-
} from '../../types/store/query';
15-
import {QUERIES_HISTORY_KEY, SAVED_QUERIES_KEY} from '../../utils/constants';
9+
import type {QueryRequestParams, QuerySettings, QuerySyntax} from '../../types/store/query';
10+
import {QUERIES_HISTORY_KEY} from '../../utils/constants';
1611
import {QUERY_SYNTAX, isQueryErrorResponse, parseQueryAPIExecuteResponse} from '../../utils/query';
1712
import {isNumeric} from '../../utils/utils';
18-
import type {RootState} from '../defaultStore';
1913

2014
import {api} from './api';
21-
import {getSettingValue} from './settings/settings';
2215

2316
const MAXIMUM_QUERIES_IN_HISTORY = 20;
2417

@@ -31,7 +24,6 @@ const sliceLimit = queriesHistoryInitial.length - MAXIMUM_QUERIES_IN_HISTORY;
3124

3225
const initialState: ExecuteQueryState = {
3326
input: '',
34-
changed: false,
3527
history: {
3628
queries: queriesHistoryInitial
3729
.slice(sliceLimit < 0 ? 0 : sliceLimit)
@@ -50,11 +42,6 @@ const slice = createSlice({
5042
reducers: {
5143
changeUserInput: (state, action: PayloadAction<{input: string}>) => {
5244
state.input = action.payload.input;
53-
state.changed = state.input !== action.payload.input;
54-
},
55-
56-
setQueryChanged: (state, action: PayloadAction<boolean>) => {
57-
state.changed = action.payload;
5845
},
5946
setQueryTraceReady: (state) => {
6047
if (state.result) {
@@ -156,7 +143,6 @@ const slice = createSlice({
156143
export default slice.reducer;
157144
export const {
158145
changeUserInput,
159-
setQueryChanged,
160146
setQueryTraceReady,
161147
setQueryResult,
162148
saveQueryToHistory,
@@ -175,18 +161,6 @@ export const {
175161
selectUserInput,
176162
} = slice.selectors;
177163

178-
export const selectIsQuerySaved = createSelector(
179-
(state: RootState) => state,
180-
(state: RootState) => {
181-
const savedQueries = (getSettingValue(state, SAVED_QUERIES_KEY) as SavedQuery[]) ?? [];
182-
return (
183-
savedQueries.some((query) => query.body === state.executeQuery.input) ||
184-
state.executeQuery.history.queries[state.executeQuery.history.queries.length - 1]
185-
?.queryText === state.executeQuery.input
186-
);
187-
},
188-
);
189-
190164
interface SendQueryParams extends QueryRequestParams {
191165
queryId: string;
192166
querySettings?: Partial<QuerySettings>;

src/types/store/executeQuery.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export type QueryResult = ExecuteQueryResult | ExplainQueryResult;
3838
export interface ExecuteQueryState {
3939
input: string;
4040
result?: QueryResult & {isTraceReady?: boolean};
41-
changed?: boolean;
4241
history: {
4342
// String type for backward compatibility
4443
queries: QueryInHistory[];

src/utils/hooks/withConfirmation/useChangeInputWithConfirmation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import NiceModal from '@ebay/nice-modal-react';
44

55
import {useTypedSelector} from '..';
66
import {CONFIRMATION_DIALOG} from '../../../components/ConfirmationDialog/ConfirmationDialog';
7-
import {selectIsQuerySaved} from '../../../store/reducers/executeQuery';
7+
import {selectUserInput} from '../../../store/reducers/executeQuery';
88

99
import i18n from './i18n';
1010

@@ -27,12 +27,12 @@ export function changeInputWithConfirmation<T>(callback: (args: T) => void) {
2727
}
2828

2929
export function useChangeInputWithConfirmation<T>(callback: (args: T) => void) {
30-
const isQuerySaved = useTypedSelector(selectIsQuerySaved);
30+
const userInput = useTypedSelector(selectUserInput);
3131
const callbackWithConfirmation = React.useMemo(
3232
() => changeInputWithConfirmation<T>(callback),
3333
[callback],
3434
);
35-
if (isQuerySaved) {
35+
if (!userInput) {
3636
return callback;
3737
}
3838
return callbackWithConfirmation;

0 commit comments

Comments
 (0)