You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/04/17 02:03:03 UTC
[GitHub] [apisix-dashboard] liuxiran commented on a change in pull request #1779: feat: Improve debug view
liuxiran commented on a change in pull request #1779:
URL: https://github.com/apache/apisix-dashboard/pull/1779#discussion_r615186515
##########
File path: web/src/pages/Route/components/DebugViews/DebugDrawView.tsx
##########
@@ -229,8 +233,23 @@ const DebugDrawView: React.FC<RouteModule.DebugDrawProps> = (props) => {
}, bodyFormData)
.then((req) => {
setLoading(false);
- setResponseBody(JSON.stringify(req.data.data, null, 2));
- setResponseHeader(JSON.stringify(req.data.header, null, 2));
+ const resp: RouteModule.debugResponse= req.data;
+ if (typeof (resp.data) !== 'string') {
Review comment:
It would be better to use `resp.header['Content-Type']` as judging condition, just like Line244 does
##########
File path: web/src/pages/Route/components/DebugViews/DebugDrawView.tsx
##########
@@ -50,13 +53,15 @@ const DebugDrawView: React.FC<RouteModule.DebugDrawProps> = (props) => {
const [formDataForm] = Form.useForm();
const [authForm] = Form.useForm();
const [headerForm] = Form.useForm();
- const [responseBody, setResponseBody] = useState<string>();
- const [responseHeader, setResponseHeader] = useState<string>();
+ const [response, setResponse] = useState<RouteModule.debugResponse>()
Review comment:
```suggestion
const [response, setResponse] = useState<RouteModule.debugResponse | null>()
```
##########
File path: web/src/components/RawDataEditor/RawDataEditor.tsx
##########
@@ -154,19 +154,19 @@ const RawDataEditor: React.FC<Props> = ({ visible, readonly = true, type, data =
handleModeChange(value);
}}
data-cy='code-mirror-mode'
- ></Select>,
+ />,
Review comment:
You can use the self-closing form of the `Select tag` since there are no children in it
##########
File path: web/src/pages/Route/components/DebugViews/DebugDrawView.tsx
##########
@@ -229,8 +233,23 @@ const DebugDrawView: React.FC<RouteModule.DebugDrawProps> = (props) => {
}, bodyFormData)
.then((req) => {
setLoading(false);
- setResponseBody(JSON.stringify(req.data.data, null, 2));
- setResponseHeader(JSON.stringify(req.data.header, null, 2));
+ const resp: RouteModule.debugResponse= req.data;
+ if (typeof (resp.data) !== 'string') {
+ resp.data = JSON.stringify(resp.data, null, 2);
+ }
+ setResponse(resp);
+ const contentType=resp.header["Content-Type"];
+ if (contentType == null || contentType.length !== 1) {
Review comment:
May I ask why not merge this judgment condition to the Line 250?
##########
File path: web/src/pages/Route/constants.ts
##########
@@ -180,6 +180,13 @@ export const DEBUG_BODY_CODEMIRROR_MODE_SUPPORTED = [
{ name: 'XML', mode: 'xml' },
];
+export const DEBUG_RESPONSE_BODY_CODEMIRROR_MODE_SUPPORTED = [
+ { name: 'Json', mode: 'javascript' },
Review comment:
```suggestion
{ name: 'JSON', mode: 'javascript' },
```
##########
File path: web/src/pages/Route/components/DebugViews/DebugDrawView.tsx
##########
@@ -74,8 +79,7 @@ const DebugDrawView: React.FC<RouteModule.DebugDrawProps> = (props) => {
formDataForm.setFieldsValue(DEFAULT_DEBUG_PARAM_FORM_DATA);
headerForm.setFieldsValue(DEFAULT_DEBUG_PARAM_FORM_DATA);
authForm.setFieldsValue(DEFAULT_DEBUG_AUTH_FORM_DATA);
- setResponseBody(formatMessage({ id: 'page.route.debug.showResultAfterSendRequest' }));
- setResponseHeader(formatMessage({ id: 'page.route.debug.showResultAfterSendRequest' }));
+ setResponse(undefined);
Review comment:
```suggestion
setResponse(null);
```
##########
File path: web/src/pages/Route/components/DebugViews/DebugDrawView.tsx
##########
@@ -389,15 +408,44 @@ const DebugDrawView: React.FC<RouteModule.DebugDrawProps> = (props) => {
</Tabs>
</PanelSection>
<PanelSection title={formatMessage({ id: 'page.route.PanelSection.title.responseResult' })}>
- <Tabs>
- <TabPane tab={formatMessage({ id: 'page.route.TabPane.response' })} key="response">
- <Spin tip="Loading..." spinning={loading}>
- <div id='codeMirror-response'>
+ <Spin tip="Loading..." spinning={loading}>
+ <Tabs tabBarExtraContent={
+ response ? response.message : formatMessage({ id: 'page.route.debug.showResultAfterSendRequest' })
+ }>
+ <TabPane tab={formatMessage({ id: 'page.route.TabPane.response' })} key="response">
+ <Select
+ disabled={response == null}
+ value={responseBodyCodeMirrorMode}
+ onSelect={(mode) => setResponseBodyCodeMirrorMode(mode as string)}>
+ {
+ DEBUG_RESPONSE_BODY_CODEMIRROR_MODE_SUPPORTED.map(mode => {
+ return <Option value={mode.mode}>{mode.name}</Option>
+ })
+ }
+ </Select>
+ <CopyToClipboard
+ text={response ? response.data : ""}
+ onCopy={(_: string, result: boolean) => {
+ if (!result) {
+ notification.error({
+ message: formatMessage({ id: 'component.global.copyFail' }),
+ });
+ return;
+ }
+ notification.success({
+ message: formatMessage({ id: 'component.global.copySuccess' }),
+ });
+ }}>
+ <Button type="text" disabled={response == null}>
Review comment:
```suggestion
<Button type="text" disabled={!response}>
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org