From 80ef706d24a338dfb5a9daf69ff2f5ce9ed4f2b0 Mon Sep 17 00:00:00 2001 From: Michael Crowther Date: Wed, 18 Dec 2024 15:48:09 -0700 Subject: [PATCH] Clear URL button, query params, request body --- .../components/YamlUrls/QueryParamsView.tsx | 68 ++++++++++ .../components/YamlUrls/RequestBodyView.tsx | 45 +++++++ .../YamlUrls/RequestDetailsTabs.tsx | 26 +++- .../src/components/YamlUrls/index.tsx | 125 +++++++++++++++--- .../src/util/yamlwriter.ts | 11 +- 5 files changed, 255 insertions(+), 20 deletions(-) create mode 100644 guide/results-viewer-react/src/components/YamlUrls/QueryParamsView.tsx create mode 100644 guide/results-viewer-react/src/components/YamlUrls/RequestBodyView.tsx diff --git a/guide/results-viewer-react/src/components/YamlUrls/QueryParamsView.tsx b/guide/results-viewer-react/src/components/YamlUrls/QueryParamsView.tsx new file mode 100644 index 00000000..2932b0b0 --- /dev/null +++ b/guide/results-viewer-react/src/components/YamlUrls/QueryParamsView.tsx @@ -0,0 +1,68 @@ +import { PewPewHeader, PewPewQueryParam } from "../../util/yamlwriter"; +import { PewPewQueryParamStringType } from "."; +import React from "react"; + +export interface QueryParamsViewProps { + id: string; + queryParamList: PewPewQueryParam[]; + removeParam: (param: PewPewQueryParam) => void; + changeParam: (paramIndex: number, type: PewPewQueryParamStringType, value: string) => void; + addParam: () => void; +} + +function QueryParamsView ({ id, queryParamList, removeParam, changeParam, addParam }: QueryParamsViewProps): JSX.Element { + const styles: Record = { + headersDisplay: { + marginTop: "10px", + maxHeight: "300px", + overflow: "auto" + }, + gridContainer: { + display: "grid", + gap: "10px" + }, + gridHeader: { + display: "grid", + gridTemplateColumns: "auto 1fr 2fr", + gap: "10px", + fontWeight: "bold", + height: "20px" + }, + gridRows: { + display: "grid", + gridTemplateColumns: "auto 1fr 2fr", + gap: "10px", + alignItems: "stretch" + }, + input: { + boxSizing: "border-box" + }, + button: { + boxSizing: "border-box", + whiteSpace: "nowrap" + } + }; + return ( + +
+
+
+ + Name + Value +
+ {queryParamList.length === 0 && No Query Params yet, click "+" to create one} + {queryParamList.map((param: PewPewHeader, index: number) => ( +
+ + changeParam(index, "name", event.target.value)} /> + changeParam(index, "value", event.target.value)} /> +
+ ))} +
+
+
+ ); +} + +export default QueryParamsView; \ No newline at end of file diff --git a/guide/results-viewer-react/src/components/YamlUrls/RequestBodyView.tsx b/guide/results-viewer-react/src/components/YamlUrls/RequestBodyView.tsx new file mode 100644 index 00000000..867f6742 --- /dev/null +++ b/guide/results-viewer-react/src/components/YamlUrls/RequestBodyView.tsx @@ -0,0 +1,45 @@ +import React from "react"; + +export interface RequestBodyViewProps { + requestBody: object | undefined; + updateRequestBody: (newRequestBody: object) => void; +} + +function RequestBodyView ({ requestBody, updateRequestBody }: RequestBodyViewProps): JSX.Element { + const [requestBodyInEdit, setRequestBodyInEdit] = React.useState(JSON.stringify(requestBody, null, 2).replace(/\\n/g, "\n").replace(/^"|"$/g, "")); + + const requestBodyDisplayStyle: React.CSSProperties = { + fontFamily: "monospace", + width: "100%", + height: "270px", + overflow: "auto", + border: "1px solid #ccc", + padding: "10px", + backgroundColor: "#2e3438", + resize: "none", + tabSize: 2, + boxSizing: "border-box" + }; + + const handleEditorInput = (event: React.ChangeEvent) => { + const newRequestBody = event.target.value; + setRequestBodyInEdit(newRequestBody); + try { + updateRequestBody(JSON.parse(newRequestBody)); + } catch (error) { + console.error(error); + } + }; + + return ( + +