1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-08-07 03:35:18 +02:00

Add and update custom queries

This commit is contained in:
unknown 2021-10-11 13:55:53 +02:00
parent a885440fef
commit 38ffdf1bff
8 changed files with 159 additions and 25 deletions

View file

@ -32,6 +32,7 @@ import {
AddQueryAction,
DeleteQueryAction,
FetchQueriesAction,
UpdateQueryAction,
} from './config';
export enum ActionTypes {
@ -71,6 +72,7 @@ export enum ActionTypes {
fetchQueries = 'FETCH_QUERIES',
addQuery = 'ADD_QUERY',
deleteQuery = 'DELETE_QUERY',
updateQuery = 'UPDATE_QUERY',
}
export type Action =
@ -104,4 +106,5 @@ export type Action =
| UpdateConfigAction
| FetchQueriesAction
| AddQueryAction
| DeleteQueryAction;
| DeleteQueryAction
| UpdateQueryAction;

View file

@ -110,3 +110,26 @@ export const deleteQuery =
console.log(err);
}
};
export interface UpdateQueryAction {
type: ActionTypes.updateQuery;
payload: Query[];
}
export const updateQuery =
(query: Query, oldPrefix: string) =>
async (dispatch: Dispatch<UpdateQueryAction>) => {
try {
const res = await axios.put<ApiResponse<Query[]>>(
`/api/queries/${oldPrefix}`,
query
);
dispatch<UpdateQueryAction>({
type: ActionTypes.updateQuery,
payload: res.data.data,
});
} catch (err) {
console.log(err);
}
};

View file

@ -48,6 +48,13 @@ const deleteQuery = (state: State, action: Action): State => {
};
};
const updateQuery = (state: State, action: Action): State => {
return {
...state,
customQueries: action.payload,
};
};
const configReducer = (state: State = initialState, action: Action) => {
switch (action.type) {
case ActionTypes.getConfig:
@ -60,6 +67,8 @@ const configReducer = (state: State = initialState, action: Action) => {
return addQuery(state, action);
case ActionTypes.deleteQuery:
return deleteQuery(state, action);
case ActionTypes.updateQuery:
return updateQuery(state, action);
default:
return state;
}