-
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): store [YTFRONT-4612]
- Loading branch information
1 parent
ced7ff9
commit 533f16c
Showing
6 changed files
with
85 additions
and
40 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
28 changes: 28 additions & 0 deletions
28
packages/ui/src/ui/pages/query-tracker/module/neuralNetwork/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,28 @@ | ||
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 './neuralNetworkSlice'; | ||
|
||
export const createContextId = | ||
(queryId: string): ThunkAction<void, RootState, unknown, any> => | ||
async (dispatch) => { | ||
const newContextId = crypto.randomUUID(); | ||
|
||
await wrapApiPromiseByToaster( | ||
ytApiV4Id.alterQuery(YTApiId.alterQuery, { | ||
parameters: { | ||
query_id: queryId, | ||
annotations: { | ||
contextId: newContextId, | ||
}, | ||
}, | ||
}), | ||
{ | ||
toasterName: `context_id`, | ||
skipSuccessToast: true, | ||
errorTitle: `Failed to set query contect id`, | ||
}, | ||
); | ||
dispatch(setContextId(newContextId)); | ||
}; |
33 changes: 33 additions & 0 deletions
33
packages/ui/src/ui/pages/query-tracker/module/neuralNetwork/neuralNetworkSlice.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,33 @@ | ||
import {PayloadAction, createSlice} from '@reduxjs/toolkit'; | ||
|
||
type NeuralNetworkState = { | ||
suggestions: string[]; | ||
requestId: string; | ||
contextId: string; | ||
}; | ||
|
||
const initialState: NeuralNetworkState = { | ||
suggestions: [], | ||
requestId: '', | ||
contextId: '', | ||
}; | ||
|
||
const neuralNetworkSlice = createSlice({ | ||
initialState, | ||
name: 'neuralNetwork', | ||
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; | ||
}, | ||
}, | ||
}); | ||
|
||
export const {setSuggestions, setRequestId, setContextId} = neuralNetworkSlice.actions; | ||
|
||
export const neuralNetworkReducer = neuralNetworkSlice.reducer; |
10 changes: 10 additions & 0 deletions
10
packages/ui/src/ui/pages/query-tracker/module/neuralNetwork/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,10 @@ | ||
import {RootState} from '../../../../store/reducers'; | ||
|
||
export const selectNeuralNetworkContextId = (state: RootState) => | ||
state.queryTracker.neuralNetwork.contextId; | ||
|
||
export const selectNeuralNetworkRequestId = (state: RootState) => | ||
state.queryTracker.neuralNetwork.requestId; | ||
|
||
export const selectNeuralNetworkSuggestions = (state: RootState) => | ||
state.queryTracker.neuralNetwork.suggestions; |
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