-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(Queries): add query suggestions store [YTFRONT-4612]
- Loading branch information
1 parent
4639d41
commit 066de49
Showing
7 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/ui/src/ui/pages/query-tracker/module/querySuggestions/actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {ThunkAction} from 'redux-thunk'; | ||
import {RootState} from '../../../../store/reducers'; | ||
import {wrapApiPromiseByToaster} from '../../../../utils/utils'; | ||
import {YTApiId, ytApiV4Id} from '../../../../rum/rum-wrap-api'; | ||
import {setContextId} from './querySuggestionsSlice'; | ||
import guid from '../../../../common/hammer/guid'; | ||
|
||
export const createContextId = | ||
(queryId: string): ThunkAction<void, RootState, unknown, any> => | ||
async (dispatch) => { | ||
const newContextId = guid(); | ||
|
||
await wrapApiPromiseByToaster( | ||
ytApiV4Id.alterQuery(YTApiId.alterQuery, { | ||
parameters: { | ||
query_id: queryId, | ||
annotations: { | ||
contextId: newContextId, | ||
}, | ||
}, | ||
}), | ||
{ | ||
toasterName: `context_id`, | ||
skipSuccessToast: true, | ||
errorTitle: `Failed to set query context id`, | ||
}, | ||
); | ||
dispatch(setContextId(newContextId)); | ||
}; |
41 changes: 41 additions & 0 deletions
41
packages/ui/src/ui/pages/query-tracker/module/querySuggestions/querySuggestionsSlice.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import {PayloadAction, createSlice} from '@reduxjs/toolkit'; | ||
|
||
export type PrevAction = 'accepted' | 'ignored' | 'discarded' | 'empty' | 'received'; | ||
|
||
type QuerySuggestionsState = { | ||
suggestions: string[]; | ||
prevAction: PrevAction; | ||
requestId: string; | ||
contextId: string; | ||
}; | ||
|
||
const initialState: QuerySuggestionsState = { | ||
suggestions: [], | ||
prevAction: 'empty', | ||
requestId: '', | ||
contextId: '', | ||
}; | ||
|
||
const querySuggestionsSlice = createSlice({ | ||
initialState, | ||
name: 'querySuggestions', | ||
reducers: { | ||
setSuggestions: (state, {payload}: PayloadAction<string[]>) => { | ||
state.suggestions = payload; | ||
}, | ||
setRequestId: (state, {payload}: PayloadAction<string>) => { | ||
state.requestId = payload; | ||
}, | ||
setContextId: (state, {payload}: PayloadAction<string>) => { | ||
state.contextId = payload; | ||
}, | ||
setPrevAction: (state, {payload}: PayloadAction<PrevAction>) => { | ||
state.prevAction = payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const {setSuggestions, setRequestId, setContextId, setPrevAction} = | ||
querySuggestionsSlice.actions; | ||
|
||
export const querySuggestionsReducer = querySuggestionsSlice.reducer; |
13 changes: 13 additions & 0 deletions
13
packages/ui/src/ui/pages/query-tracker/module/querySuggestions/selectors.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {RootState} from '../../../../store/reducers'; | ||
|
||
export const selectQuerySuggestionsContextId = (state: RootState) => | ||
state.queryTracker.querySuggestions.contextId; | ||
|
||
export const selectQuerySuggestionsRequestId = (state: RootState) => | ||
state.queryTracker.querySuggestions.requestId; | ||
|
||
export const selectQuerySuggestions = (state: RootState) => | ||
state.queryTracker.querySuggestions.suggestions; | ||
|
||
export const selectPrevAction = (state: RootState) => | ||
state.queryTracker.querySuggestions.prevAction; |