-
Notifications
You must be signed in to change notification settings - Fork 310
Expand file tree
/
Copy pathslice.ts
More file actions
37 lines (30 loc) · 1.09 KB
/
Copy pathslice.ts
File metadata and controls
37 lines (30 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* ============================================================================
* Copyright (c) Palo Alto Networks
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* ========================================================================== */
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import type { ParameterObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
export type Param = ParameterObject & { value?: string[] | string };
export interface State {
path: Param[];
query: Param[];
header: Param[];
cookie: Param[];
}
const initialState: State = {} as any;
const slice = createSlice({
name: "params",
initialState,
reducers: {
setParam: (state, action: PayloadAction<Param>) => {
const newParam = action.payload;
const paramGroup = state[action.payload.in];
const index = paramGroup.findIndex((p) => p.name === newParam.name);
paramGroup[index] = newParam;
},
},
});
export const { setParam } = slice.actions;
export default slice.reducer;