docusaurus-theme-openapi-docs 0.0.0-beta.646 → 0.0.0-beta.651
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/Content/_Content.scss +1 -0
- package/lib/theme/ApiDemoPanel/Body/index.d.ts +3 -1
- package/lib/theme/ApiDemoPanel/Body/index.js +30 -32
- package/lib/theme/ApiDemoPanel/CodeTabs/_CodeTabs.scss +95 -39
- package/lib/theme/ApiDemoPanel/CodeTabs/index.js +24 -6
- package/lib/theme/ApiDemoPanel/Curl/index.d.ts +5 -4
- package/lib/theme/ApiDemoPanel/Curl/index.js +79 -11
- package/lib/theme/ApiDemoPanel/FormItem/_FormItem.scss +11 -2
- package/lib/theme/ApiDemoPanel/FormItem/index.d.ts +2 -1
- package/lib/theme/ApiDemoPanel/FormItem/index.js +9 -3
- package/lib/theme/ApiDemoPanel/FormMultiSelect/_FormMultiSelect.scss +8 -4
- package/lib/theme/ApiDemoPanel/FormMultiSelect/index.d.ts +2 -1
- package/lib/theme/ApiDemoPanel/FormMultiSelect/index.js +5 -2
- package/lib/theme/ApiDemoPanel/FormSelect/_FormSelect.scss +3 -3
- package/lib/theme/ApiDemoPanel/FormTextInput/_FormTextInput.scss +24 -5
- package/lib/theme/ApiDemoPanel/FormTextInput/index.d.ts +1 -1
- package/lib/theme/ApiDemoPanel/FormTextInput/index.js +56 -10
- package/lib/theme/ApiDemoPanel/LiveEditor/index.d.ts +5 -2
- package/lib/theme/ApiDemoPanel/LiveEditor/index.js +59 -14
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamArrayFormItem.d.ts +6 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamArrayFormItem.js +194 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamBooleanFormItem.d.ts +6 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamBooleanFormItem.js +63 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.d.ts +6 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.js +89 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamSelectFormItem.d.ts +6 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamSelectFormItem.js +63 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamTextFormItem.d.ts +6 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamTextFormItem.js +38 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/_ParamOptions.scss +9 -28
- package/lib/theme/ApiDemoPanel/ParamOptions/index.js +24 -176
- package/lib/theme/ApiDemoPanel/Request/_Request.scss +93 -20
- package/lib/theme/ApiDemoPanel/Request/index.d.ts +1 -1
- package/lib/theme/ApiDemoPanel/Request/index.js +316 -37
- package/lib/theme/ApiDemoPanel/Response/_Response.scss +54 -0
- package/lib/theme/ApiDemoPanel/Response/index.d.ts +4 -1
- package/lib/theme/ApiDemoPanel/Response/index.js +56 -31
- package/lib/theme/ApiDemoPanel/Server/_Server.scss +10 -0
- package/lib/theme/ApiDemoPanel/Server/index.js +10 -11
- package/lib/theme/ApiDemoPanel/index.js +1 -1
- package/lib/theme/SchemaTabs/_SchemaTabs.scss +0 -1
- package/lib/theme/styles.scss +27 -0
- package/package.json +7 -4
- package/src/theme/ApiDemoPanel/ApiCodeBlock/Content/_Content.scss +1 -0
- package/src/theme/ApiDemoPanel/Body/index.tsx +38 -29
- package/src/theme/ApiDemoPanel/CodeTabs/_CodeTabs.scss +95 -39
- package/src/theme/ApiDemoPanel/CodeTabs/index.js +24 -6
- package/src/theme/ApiDemoPanel/Curl/index.tsx +85 -22
- package/src/theme/ApiDemoPanel/FormItem/_FormItem.scss +11 -2
- package/src/theme/ApiDemoPanel/FormItem/index.tsx +8 -3
- package/src/theme/ApiDemoPanel/FormMultiSelect/_FormMultiSelect.scss +8 -4
- package/src/theme/ApiDemoPanel/FormMultiSelect/index.tsx +7 -2
- package/src/theme/ApiDemoPanel/FormSelect/_FormSelect.scss +3 -3
- package/src/theme/ApiDemoPanel/FormTextInput/_FormTextInput.scss +24 -5
- package/src/theme/ApiDemoPanel/FormTextInput/index.tsx +58 -10
- package/src/theme/ApiDemoPanel/LiveEditor/index.tsx +53 -14
- package/src/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx +153 -0
- package/src/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx +64 -0
- package/src/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx +86 -0
- package/src/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx +65 -0
- package/src/theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamTextFormItem.tsx +38 -0
- package/src/theme/ApiDemoPanel/ParamOptions/_ParamOptions.scss +9 -28
- package/src/theme/ApiDemoPanel/ParamOptions/index.tsx +8 -196
- package/src/theme/ApiDemoPanel/Request/_Request.scss +93 -20
- package/src/theme/ApiDemoPanel/Request/index.tsx +250 -28
- package/src/theme/ApiDemoPanel/Response/_Response.scss +54 -0
- package/src/theme/ApiDemoPanel/Response/index.tsx +44 -26
- package/src/theme/ApiDemoPanel/Server/_Server.scss +10 -0
- package/src/theme/ApiDemoPanel/Server/index.tsx +8 -11
- package/src/theme/ApiDemoPanel/index.tsx +1 -1
- package/src/theme/SchemaTabs/_SchemaTabs.scss +0 -1
- package/src/theme/styles.scss +27 -0
- package/src/theme-openapi.d.ts +40 -1
- package/lib/theme/ApiDemoPanel/Execute/index.d.ts +0 -8
- package/lib/theme/ApiDemoPanel/Execute/index.js +0 -213
- package/src/theme/ApiDemoPanel/Execute/index.tsx +0 -200
- /package/lib/theme/ApiDemoPanel/{Execute → Request}/makeRequest.d.ts +0 -0
- /package/lib/theme/ApiDemoPanel/{Execute → Request}/makeRequest.js +0 -0
- /package/src/theme/ApiDemoPanel/{Execute → Request}/makeRequest.ts +0 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React, { useEffect, useState } from "react";
|
|
9
|
+
|
|
10
|
+
import { ErrorMessage } from "@hookform/error-message";
|
|
11
|
+
import { nanoid } from "@reduxjs/toolkit";
|
|
12
|
+
import FormSelect from "@theme/ApiDemoPanel/FormSelect";
|
|
13
|
+
import FormTextInput from "@theme/ApiDemoPanel/FormTextInput";
|
|
14
|
+
import { Param, setParam } from "@theme/ApiDemoPanel/ParamOptions/slice";
|
|
15
|
+
import { useTypedDispatch } from "@theme/ApiItem/hooks";
|
|
16
|
+
import { Controller, useFormContext } from "react-hook-form";
|
|
17
|
+
|
|
18
|
+
export interface ParamProps {
|
|
19
|
+
param: Param;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function ArrayItem({
|
|
23
|
+
param,
|
|
24
|
+
onChange,
|
|
25
|
+
}: ParamProps & { onChange(value?: string): any }) {
|
|
26
|
+
if (param.schema?.items?.type === "boolean") {
|
|
27
|
+
return (
|
|
28
|
+
<FormSelect
|
|
29
|
+
options={["---", "true", "false"]}
|
|
30
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
31
|
+
const val = e.target.value;
|
|
32
|
+
onChange(val === "---" ? undefined : val);
|
|
33
|
+
}}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<FormTextInput
|
|
40
|
+
placeholder={param.description || param.name}
|
|
41
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
42
|
+
onChange(e.target.value);
|
|
43
|
+
}}
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default function ParamArrayFormItem({ param }: ParamProps) {
|
|
49
|
+
const [items, setItems] = useState<{ id: string; value?: string }[]>([]);
|
|
50
|
+
const dispatch = useTypedDispatch();
|
|
51
|
+
|
|
52
|
+
const {
|
|
53
|
+
control,
|
|
54
|
+
formState: { errors },
|
|
55
|
+
} = useFormContext();
|
|
56
|
+
|
|
57
|
+
const showErrorMessage = errors?.paramArray?.message;
|
|
58
|
+
|
|
59
|
+
function handleAddItem() {
|
|
60
|
+
setItems((i) => [
|
|
61
|
+
...i,
|
|
62
|
+
{
|
|
63
|
+
id: nanoid(),
|
|
64
|
+
},
|
|
65
|
+
]);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
const values = items
|
|
70
|
+
.map((item) => item.value)
|
|
71
|
+
.filter((item): item is string => !!item);
|
|
72
|
+
|
|
73
|
+
dispatch(
|
|
74
|
+
setParam({
|
|
75
|
+
...param,
|
|
76
|
+
value: values.length > 0 ? values : undefined,
|
|
77
|
+
})
|
|
78
|
+
);
|
|
79
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
80
|
+
}, [items]);
|
|
81
|
+
|
|
82
|
+
function handleDeleteItem(itemToDelete: { id: string }) {
|
|
83
|
+
return () => {
|
|
84
|
+
const newItems = items.filter((i) => i.id !== itemToDelete.id);
|
|
85
|
+
setItems(newItems);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function handleChangeItem(itemToUpdate: { id: string }, onChange: any) {
|
|
90
|
+
return (value: string) => {
|
|
91
|
+
const newItems = items.map((i) => {
|
|
92
|
+
if (i.id === itemToUpdate.id) {
|
|
93
|
+
return { ...i, value: value };
|
|
94
|
+
}
|
|
95
|
+
return i;
|
|
96
|
+
});
|
|
97
|
+
setItems(newItems);
|
|
98
|
+
onChange(newItems);
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<>
|
|
104
|
+
<Controller
|
|
105
|
+
control={control}
|
|
106
|
+
rules={{ required: param.required ? "This field is required" : false }}
|
|
107
|
+
name="paramArray"
|
|
108
|
+
render={({ field: { onChange, name } }) => (
|
|
109
|
+
<>
|
|
110
|
+
{items.map((item) => (
|
|
111
|
+
<div key={item.id} style={{ display: "flex" }}>
|
|
112
|
+
<ArrayItem
|
|
113
|
+
param={param}
|
|
114
|
+
onChange={handleChangeItem(item, onChange)}
|
|
115
|
+
/>
|
|
116
|
+
<button
|
|
117
|
+
className="openapi-demo__delete-btn"
|
|
118
|
+
onClick={handleDeleteItem(item)}
|
|
119
|
+
>
|
|
120
|
+
<svg
|
|
121
|
+
focusable="false"
|
|
122
|
+
preserveAspectRatio="xMidYMid meet"
|
|
123
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
124
|
+
fill="currentColor"
|
|
125
|
+
width="16"
|
|
126
|
+
height="16"
|
|
127
|
+
viewBox="0 0 32 32"
|
|
128
|
+
aria-hidden="true"
|
|
129
|
+
>
|
|
130
|
+
<path d="M24 9.4L22.6 8 16 14.6 9.4 8 8 9.4 14.6 16 8 22.6 9.4 24 16 17.4 22.6 24 24 22.6 17.4 16 24 9.4z"></path>
|
|
131
|
+
<title>Delete</title>
|
|
132
|
+
</svg>
|
|
133
|
+
</button>
|
|
134
|
+
</div>
|
|
135
|
+
))}
|
|
136
|
+
<button className="openapi-demo__thin-btn" onClick={handleAddItem}>
|
|
137
|
+
Add item
|
|
138
|
+
</button>
|
|
139
|
+
</>
|
|
140
|
+
)}
|
|
141
|
+
/>
|
|
142
|
+
{showErrorMessage && (
|
|
143
|
+
<ErrorMessage
|
|
144
|
+
errors={errors}
|
|
145
|
+
name="paramArray"
|
|
146
|
+
render={({ message }) => (
|
|
147
|
+
<div className="openapi-demo__input-error">{message}</div>
|
|
148
|
+
)}
|
|
149
|
+
/>
|
|
150
|
+
)}
|
|
151
|
+
</>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React from "react";
|
|
9
|
+
|
|
10
|
+
import { ErrorMessage } from "@hookform/error-message";
|
|
11
|
+
import FormSelect from "@theme/ApiDemoPanel/FormSelect";
|
|
12
|
+
import { Param, setParam } from "@theme/ApiDemoPanel/ParamOptions/slice";
|
|
13
|
+
import { useTypedDispatch } from "@theme/ApiItem/hooks";
|
|
14
|
+
import { Controller, useFormContext } from "react-hook-form";
|
|
15
|
+
|
|
16
|
+
export interface ParamProps {
|
|
17
|
+
param: Param;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default function ParamBooleanFormItem({ param }: ParamProps) {
|
|
21
|
+
const dispatch = useTypedDispatch();
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
control,
|
|
25
|
+
formState: { errors },
|
|
26
|
+
} = useFormContext();
|
|
27
|
+
|
|
28
|
+
const showErrorMessage = errors?.paramBoolean;
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<>
|
|
32
|
+
<Controller
|
|
33
|
+
control={control}
|
|
34
|
+
rules={{ required: param.required ? "This field is required" : false }}
|
|
35
|
+
name="paramBoolean"
|
|
36
|
+
render={({ field: { onChange, name } }) => (
|
|
37
|
+
<FormSelect
|
|
38
|
+
name={name}
|
|
39
|
+
options={["---", "true", "false"]}
|
|
40
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
41
|
+
const val = e.target.value;
|
|
42
|
+
dispatch(
|
|
43
|
+
setParam({
|
|
44
|
+
...param,
|
|
45
|
+
value: val === "---" ? undefined : val,
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
onChange(val);
|
|
49
|
+
}}
|
|
50
|
+
/>
|
|
51
|
+
)}
|
|
52
|
+
/>
|
|
53
|
+
{showErrorMessage && (
|
|
54
|
+
<ErrorMessage
|
|
55
|
+
errors={errors}
|
|
56
|
+
name="paramBoolean"
|
|
57
|
+
render={({ message }) => (
|
|
58
|
+
<div className="openapi-demo__input-error">{message}</div>
|
|
59
|
+
)}
|
|
60
|
+
/>
|
|
61
|
+
)}
|
|
62
|
+
</>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React from "react";
|
|
9
|
+
|
|
10
|
+
import { ErrorMessage } from "@hookform/error-message";
|
|
11
|
+
import FormMultiSelect from "@theme/ApiDemoPanel/FormMultiSelect";
|
|
12
|
+
import { Param, setParam } from "@theme/ApiDemoPanel/ParamOptions/slice";
|
|
13
|
+
import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
|
|
14
|
+
import { Controller, useFormContext } from "react-hook-form";
|
|
15
|
+
|
|
16
|
+
export interface ParamProps {
|
|
17
|
+
param: Param;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default function ParamMultiSelectFormItem({ param }: ParamProps) {
|
|
21
|
+
const {
|
|
22
|
+
control,
|
|
23
|
+
formState: { errors },
|
|
24
|
+
} = useFormContext();
|
|
25
|
+
|
|
26
|
+
const showErrorMessage = errors?.paramMultiSelect;
|
|
27
|
+
|
|
28
|
+
const dispatch = useTypedDispatch();
|
|
29
|
+
|
|
30
|
+
const options = param.schema?.items?.enum ?? [];
|
|
31
|
+
|
|
32
|
+
const pathParams = useTypedSelector((state: any) => state.params.path);
|
|
33
|
+
const queryParams = useTypedSelector((state: any) => state.params.query);
|
|
34
|
+
const cookieParams = useTypedSelector((state: any) => state.params.cookie);
|
|
35
|
+
const headerParams = useTypedSelector((state: any) => state.params.header);
|
|
36
|
+
|
|
37
|
+
const paramTypeToWatch = pathParams.length
|
|
38
|
+
? pathParams
|
|
39
|
+
: queryParams.length
|
|
40
|
+
? queryParams
|
|
41
|
+
: cookieParams.length
|
|
42
|
+
? cookieParams
|
|
43
|
+
: headerParams;
|
|
44
|
+
|
|
45
|
+
const handleChange = (e: any, onChange: any) => {
|
|
46
|
+
const values = Array.prototype.filter
|
|
47
|
+
.call(e.target.options, (o) => o.selected)
|
|
48
|
+
.map((o) => o.value);
|
|
49
|
+
|
|
50
|
+
dispatch(
|
|
51
|
+
setParam({
|
|
52
|
+
...param,
|
|
53
|
+
value: values.length > 0 ? values : undefined,
|
|
54
|
+
})
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
onChange(paramTypeToWatch);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<>
|
|
62
|
+
<Controller
|
|
63
|
+
control={control}
|
|
64
|
+
rules={{ required: param.required ? "This field is required" : false }}
|
|
65
|
+
name="paramMultiSelect"
|
|
66
|
+
render={({ field: { onChange, name } }) => (
|
|
67
|
+
<FormMultiSelect
|
|
68
|
+
options={options as string[]}
|
|
69
|
+
name={name}
|
|
70
|
+
onChange={(e: any) => handleChange(e, onChange)}
|
|
71
|
+
showErrors={showErrorMessage}
|
|
72
|
+
/>
|
|
73
|
+
)}
|
|
74
|
+
/>
|
|
75
|
+
{showErrorMessage && (
|
|
76
|
+
<ErrorMessage
|
|
77
|
+
errors={errors}
|
|
78
|
+
name="paramMultiSelect"
|
|
79
|
+
render={({ message }) => (
|
|
80
|
+
<div className="openapi-demo__input-error">{message}</div>
|
|
81
|
+
)}
|
|
82
|
+
/>
|
|
83
|
+
)}
|
|
84
|
+
</>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React from "react";
|
|
9
|
+
|
|
10
|
+
import { ErrorMessage } from "@hookform/error-message";
|
|
11
|
+
import FormSelect from "@theme/ApiDemoPanel/FormSelect";
|
|
12
|
+
import { Param, setParam } from "@theme/ApiDemoPanel/ParamOptions/slice";
|
|
13
|
+
import { useTypedDispatch } from "@theme/ApiItem/hooks";
|
|
14
|
+
import { Controller, useFormContext } from "react-hook-form";
|
|
15
|
+
|
|
16
|
+
export interface ParamProps {
|
|
17
|
+
param: Param;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default function ParamSelectFormItem({ param }: ParamProps) {
|
|
21
|
+
const {
|
|
22
|
+
control,
|
|
23
|
+
formState: { errors },
|
|
24
|
+
} = useFormContext();
|
|
25
|
+
|
|
26
|
+
const showErrorMessage = errors?.paramSelect;
|
|
27
|
+
|
|
28
|
+
const dispatch = useTypedDispatch();
|
|
29
|
+
|
|
30
|
+
const options = param.schema?.enum ?? [];
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<>
|
|
34
|
+
<Controller
|
|
35
|
+
control={control}
|
|
36
|
+
rules={{ required: param.required ? "This field is required" : false }}
|
|
37
|
+
name="paramSelect"
|
|
38
|
+
render={({ field: { onChange, name } }) => (
|
|
39
|
+
<FormSelect
|
|
40
|
+
options={["---", ...(options as string[])]}
|
|
41
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
42
|
+
const val = e.target.value;
|
|
43
|
+
dispatch(
|
|
44
|
+
setParam({
|
|
45
|
+
...param,
|
|
46
|
+
value: val === "---" ? undefined : val,
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
onChange(val);
|
|
50
|
+
}}
|
|
51
|
+
/>
|
|
52
|
+
)}
|
|
53
|
+
/>
|
|
54
|
+
{showErrorMessage && (
|
|
55
|
+
<ErrorMessage
|
|
56
|
+
errors={errors}
|
|
57
|
+
name="paramSelect"
|
|
58
|
+
render={({ message }) => (
|
|
59
|
+
<div className="openapi-demo__input-error">{message}</div>
|
|
60
|
+
)}
|
|
61
|
+
/>
|
|
62
|
+
)}
|
|
63
|
+
</>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React from "react";
|
|
9
|
+
|
|
10
|
+
import FormTextInput from "@theme/ApiDemoPanel/FormTextInput";
|
|
11
|
+
import { Param, setParam } from "@theme/ApiDemoPanel/ParamOptions/slice";
|
|
12
|
+
import { useTypedDispatch } from "@theme/ApiItem/hooks";
|
|
13
|
+
|
|
14
|
+
export interface ParamProps {
|
|
15
|
+
param: Param;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default function ParamTextFormItem({ param }: ParamProps) {
|
|
19
|
+
const dispatch = useTypedDispatch();
|
|
20
|
+
return (
|
|
21
|
+
<FormTextInput
|
|
22
|
+
isRequired={param.required}
|
|
23
|
+
paramName={param.name}
|
|
24
|
+
placeholder={param.description || param.name}
|
|
25
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
|
|
26
|
+
dispatch(
|
|
27
|
+
setParam({
|
|
28
|
+
...param,
|
|
29
|
+
value:
|
|
30
|
+
param.in === "path" || param.in === "query"
|
|
31
|
+
? e.target.value.replace(/\s/g, "%20")
|
|
32
|
+
: e.target.value,
|
|
33
|
+
})
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -8,29 +8,21 @@
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
.openapi-demo__show-more-btn {
|
|
11
|
+
width: 100%;
|
|
11
12
|
-webkit-appearance: none;
|
|
12
13
|
-moz-appearance: none;
|
|
13
14
|
appearance: none;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
font-size: var(--ifm-code-font-size);
|
|
17
|
-
|
|
15
|
+
margin-left: 0.25rem;
|
|
16
|
+
margin-bottom: 0.5rem;
|
|
18
17
|
padding: 0;
|
|
19
|
-
|
|
18
|
+
cursor: pointer;
|
|
19
|
+
font-size: var(--openapi-demo-font-size-input);
|
|
20
20
|
user-select: none;
|
|
21
21
|
white-space: nowrap;
|
|
22
|
-
|
|
23
22
|
border: 0px solid transparent;
|
|
24
|
-
|
|
25
23
|
display: block;
|
|
26
|
-
width: 100%;
|
|
27
|
-
|
|
28
24
|
background-color: transparent;
|
|
29
|
-
|
|
30
25
|
color: var(--ifm-color-primary);
|
|
31
|
-
cursor: pointer;
|
|
32
|
-
margin-top: var(--ifm-pre-padding);
|
|
33
|
-
margin-bottom: 0;
|
|
34
26
|
text-align: left;
|
|
35
27
|
|
|
36
28
|
&:hover {
|
|
@@ -88,32 +80,22 @@
|
|
|
88
80
|
.openapi-demo__thin-btn {
|
|
89
81
|
-webkit-appearance: none;
|
|
90
82
|
-moz-appearance: none;
|
|
91
|
-
appearance: none;
|
|
92
|
-
|
|
93
83
|
cursor: pointer;
|
|
94
|
-
font-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
84
|
+
font-weight: bold;
|
|
85
|
+
padding: 0.5rem 1rem;
|
|
86
|
+
font-size: 12px;
|
|
98
87
|
transition-property: color, background, border-color, box-shadow;
|
|
99
88
|
transition-duration: 100ms, 100ms, 100ms,
|
|
100
89
|
var(--ifm-button-transition-duration);
|
|
101
90
|
transition-timing-function: cubic-bezier(0.08, 0.52, 0.52, 1);
|
|
102
|
-
|
|
103
|
-
-webkit-user-select: none;
|
|
104
91
|
user-select: none;
|
|
105
92
|
white-space: nowrap;
|
|
106
|
-
|
|
107
93
|
background-color: transparent;
|
|
108
94
|
color: var(--openapi-input-border);
|
|
109
95
|
border: 1px solid var(--openapi-input-border);
|
|
110
96
|
border-radius: var(--ifm-pre-border-radius);
|
|
111
|
-
/* height: 48px; */
|
|
112
|
-
padding: 3px 60px 3px 12px;
|
|
113
97
|
margin-top: calc(var(--ifm-pre-padding) / 2);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
display: block;
|
|
98
|
+
text-transform: uppercase;
|
|
117
99
|
|
|
118
100
|
&:hover {
|
|
119
101
|
color: var(--openapi-inverse-color);
|
|
@@ -132,7 +114,6 @@
|
|
|
132
114
|
|
|
133
115
|
.openapi-demo__show-options {
|
|
134
116
|
visibility: visible;
|
|
135
|
-
margin-top: var(--ifm-pre-padding);
|
|
136
117
|
}
|
|
137
118
|
|
|
138
119
|
.openapi-demo__hide-options {
|
|
@@ -5,16 +5,17 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import React, { useState
|
|
8
|
+
import React, { useState } from "react";
|
|
9
9
|
|
|
10
|
-
import { nanoid } from "@reduxjs/toolkit";
|
|
11
10
|
import FormItem from "@theme/ApiDemoPanel/FormItem";
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
11
|
+
import ParamArrayFormItem from "@theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamArrayFormItem";
|
|
12
|
+
import ParamBooleanFormItem from "@theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamBooleanFormItem";
|
|
13
|
+
import ParamMultiSelectFormItem from "@theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamMultiSelectFormItem";
|
|
14
|
+
import ParamSelectFormItem from "@theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamSelectFormItem";
|
|
15
|
+
import ParamTextFormItem from "@theme/ApiDemoPanel/ParamOptions/ParamFormItems/ParamTextFormItem";
|
|
16
|
+
import { useTypedSelector } from "@theme/ApiItem/hooks";
|
|
16
17
|
|
|
17
|
-
import { Param
|
|
18
|
+
import { Param } from "./slice";
|
|
18
19
|
|
|
19
20
|
export interface ParamProps {
|
|
20
21
|
param: Param;
|
|
@@ -141,193 +142,4 @@ function ParamOptions() {
|
|
|
141
142
|
);
|
|
142
143
|
}
|
|
143
144
|
|
|
144
|
-
function ArrayItem({
|
|
145
|
-
param,
|
|
146
|
-
onChange,
|
|
147
|
-
}: ParamProps & { onChange(value?: string): any }) {
|
|
148
|
-
if (param.schema?.items?.type === "boolean") {
|
|
149
|
-
return (
|
|
150
|
-
<FormSelect
|
|
151
|
-
options={["---", "true", "false"]}
|
|
152
|
-
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
153
|
-
const val = e.target.value;
|
|
154
|
-
onChange(val === "---" ? undefined : val);
|
|
155
|
-
}}
|
|
156
|
-
/>
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return (
|
|
161
|
-
<FormTextInput
|
|
162
|
-
placeholder={param.description || param.name}
|
|
163
|
-
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
164
|
-
onChange(e.target.value);
|
|
165
|
-
}}
|
|
166
|
-
/>
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function ParamArrayFormItem({ param }: ParamProps) {
|
|
171
|
-
const [items, setItems] = useState<{ id: string; value?: string }[]>([]);
|
|
172
|
-
const dispatch = useTypedDispatch();
|
|
173
|
-
|
|
174
|
-
function handleAddItem() {
|
|
175
|
-
setItems((i) => [
|
|
176
|
-
...i,
|
|
177
|
-
{
|
|
178
|
-
id: nanoid(),
|
|
179
|
-
},
|
|
180
|
-
]);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
useEffect(() => {
|
|
184
|
-
const values = items
|
|
185
|
-
.map((item) => item.value)
|
|
186
|
-
.filter((item): item is string => !!item);
|
|
187
|
-
|
|
188
|
-
dispatch(
|
|
189
|
-
setParam({
|
|
190
|
-
...param,
|
|
191
|
-
value: values.length > 0 ? values : undefined,
|
|
192
|
-
})
|
|
193
|
-
);
|
|
194
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
195
|
-
}, [items]);
|
|
196
|
-
|
|
197
|
-
function handleDeleteItem(itemToDelete: { id: string }) {
|
|
198
|
-
return () => {
|
|
199
|
-
const newItems = items.filter((i) => i.id !== itemToDelete.id);
|
|
200
|
-
setItems(newItems);
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function handleChangeItem(itemToUpdate: { id: string }) {
|
|
205
|
-
return (value: string) => {
|
|
206
|
-
const newItems = items.map((i) => {
|
|
207
|
-
if (i.id === itemToUpdate.id) {
|
|
208
|
-
return { ...i, value: value };
|
|
209
|
-
}
|
|
210
|
-
return i;
|
|
211
|
-
});
|
|
212
|
-
setItems(newItems);
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return (
|
|
217
|
-
<>
|
|
218
|
-
{items.map((item) => (
|
|
219
|
-
<div key={item.id} style={{ display: "flex" }}>
|
|
220
|
-
<ArrayItem param={param} onChange={handleChangeItem(item)} />
|
|
221
|
-
<button
|
|
222
|
-
className="openapi-demo__delete-btn"
|
|
223
|
-
onClick={handleDeleteItem(item)}
|
|
224
|
-
>
|
|
225
|
-
<svg
|
|
226
|
-
focusable="false"
|
|
227
|
-
preserveAspectRatio="xMidYMid meet"
|
|
228
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
229
|
-
fill="currentColor"
|
|
230
|
-
width="16"
|
|
231
|
-
height="16"
|
|
232
|
-
viewBox="0 0 32 32"
|
|
233
|
-
aria-hidden="true"
|
|
234
|
-
>
|
|
235
|
-
<path d="M24 9.4L22.6 8 16 14.6 9.4 8 8 9.4 14.6 16 8 22.6 9.4 24 16 17.4 22.6 24 24 22.6 17.4 16 24 9.4z"></path>
|
|
236
|
-
<title>Delete</title>
|
|
237
|
-
</svg>
|
|
238
|
-
</button>
|
|
239
|
-
</div>
|
|
240
|
-
))}
|
|
241
|
-
<button className="openapi-demo__thin-btn" onClick={handleAddItem}>
|
|
242
|
-
Add item
|
|
243
|
-
</button>
|
|
244
|
-
</>
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function ParamSelectFormItem({ param }: ParamProps) {
|
|
249
|
-
const dispatch = useTypedDispatch();
|
|
250
|
-
|
|
251
|
-
const options = param.schema?.enum ?? [];
|
|
252
|
-
|
|
253
|
-
return (
|
|
254
|
-
<FormSelect
|
|
255
|
-
options={["---", ...(options as string[])]}
|
|
256
|
-
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
257
|
-
const val = e.target.value;
|
|
258
|
-
dispatch(
|
|
259
|
-
setParam({
|
|
260
|
-
...param,
|
|
261
|
-
value: val === "---" ? undefined : val,
|
|
262
|
-
})
|
|
263
|
-
);
|
|
264
|
-
}}
|
|
265
|
-
/>
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
function ParamBooleanFormItem({ param }: ParamProps) {
|
|
270
|
-
const dispatch = useTypedDispatch();
|
|
271
|
-
|
|
272
|
-
return (
|
|
273
|
-
<FormSelect
|
|
274
|
-
options={["---", "true", "false"]}
|
|
275
|
-
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
276
|
-
const val = e.target.value;
|
|
277
|
-
dispatch(
|
|
278
|
-
setParam({
|
|
279
|
-
...param,
|
|
280
|
-
value: val === "---" ? undefined : val,
|
|
281
|
-
})
|
|
282
|
-
);
|
|
283
|
-
}}
|
|
284
|
-
/>
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
function ParamMultiSelectFormItem({ param }: ParamProps) {
|
|
289
|
-
const dispatch = useTypedDispatch();
|
|
290
|
-
|
|
291
|
-
const options = param.schema?.items?.enum ?? [];
|
|
292
|
-
|
|
293
|
-
return (
|
|
294
|
-
<FormMultiSelect
|
|
295
|
-
options={options as string[]}
|
|
296
|
-
onChange={(e: any) => {
|
|
297
|
-
const values = Array.prototype.filter
|
|
298
|
-
.call(e.target.options, (o) => o.selected)
|
|
299
|
-
.map((o) => o.value);
|
|
300
|
-
|
|
301
|
-
dispatch(
|
|
302
|
-
setParam({
|
|
303
|
-
...param,
|
|
304
|
-
value: values.length > 0 ? values : undefined,
|
|
305
|
-
})
|
|
306
|
-
);
|
|
307
|
-
}}
|
|
308
|
-
/>
|
|
309
|
-
);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
function ParamTextFormItem({ param }: ParamProps) {
|
|
313
|
-
const dispatch = useTypedDispatch();
|
|
314
|
-
|
|
315
|
-
return (
|
|
316
|
-
<FormTextInput
|
|
317
|
-
placeholder={param.description || param.name}
|
|
318
|
-
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
|
|
319
|
-
dispatch(
|
|
320
|
-
setParam({
|
|
321
|
-
...param,
|
|
322
|
-
value:
|
|
323
|
-
param.in === "path" || param.in === "query"
|
|
324
|
-
? e.target.value.replace(/\s/g, "%20")
|
|
325
|
-
: e.target.value,
|
|
326
|
-
})
|
|
327
|
-
)
|
|
328
|
-
}
|
|
329
|
-
/>
|
|
330
|
-
);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
145
|
export default ParamOptions;
|