From a9ee70ae50e84374d36d5918f2ffc43f49755390 Mon Sep 17 00:00:00 2001 From: Christian Michael Kang Date: Thu, 26 Sep 2024 10:23:00 -0600 Subject: [PATCH] Tried to fix all differences between master and my branch, added more comments on more of my personal sections of code --- guide/results-viewer-react/src/YamlWriter.tsx | 4 +- .../src/components/Modal/story.tsx | 78 +++++++++++++++++++ .../src/components/YamlWriterUpload/index.tsx | 49 +++--------- 3 files changed, 91 insertions(+), 40 deletions(-) diff --git a/guide/results-viewer-react/src/YamlWriter.tsx b/guide/results-viewer-react/src/YamlWriter.tsx index 8f1dd87b..aa990e5c 100644 --- a/guide/results-viewer-react/src/YamlWriter.tsx +++ b/guide/results-viewer-react/src/YamlWriter.tsx @@ -96,9 +96,7 @@ export const YamlWriter = () => {

Create a PewPew Test

- + diff --git a/guide/results-viewer-react/src/components/Modal/story.tsx b/guide/results-viewer-react/src/components/Modal/story.tsx index e68e2da5..a0f8f7a8 100644 --- a/guide/results-viewer-react/src/components/Modal/story.tsx +++ b/guide/results-viewer-react/src/components/Modal/story.tsx @@ -187,6 +187,76 @@ const ModalCreateYamlDemo = () => { ); }; +// const ModalSwaggerUrlDemo = () => { +// const modalRef = useRef(null); +// useEffectModal(modalRef, LogLevel.INFO); + +// const [swaggerUrl, setSwaggerUrl] = useState(''); + +// const submitEvent = () => { +// log ("Swagger URL submitted: " + swaggerUrl, LogLevel.INFO); +// return Promise.resolve(); +// }; + +// return ( +//
+// +// +// 0} +// > +// setSwaggerUrl(e.target.value)} +// placeholder="Enter Swagger URL" +// style={{ width: "100%", padding: "8px", marginTop: "10px" }} +// /> +// +//
+// ); +// }; + +// const ModalServerUrlDemo = () => { +// const modalRef = useRef(null); +// useEffectModal(modalRef, LogLevel.INFO); + +// const [serverUrl, setServerUrl] = useState(''); + +// const submitEvent = () => { +// log ("Server URL submitted: " + serverUrl, LogLevel.INFO); +// return Promise.resolve(); +// }; + +// return ( +//
+// +// +// 0} +// > +// setServerUrl(e.target.value)} +// placeholder="Enter Server URL" +// style={{ width: "100%", padding: "8px", marginTop: "10px" }} +// /> +// +//
+// ); +// } + export default { title: "Modal" } as Meta; @@ -206,3 +276,11 @@ export const _LoggerModal: StoryFn = () => ( export const CreateYamlModal: StoryFn = () => ( ); + +// export const SwaggerUrlModal: StoryFn = () => ( +// +// ); + +// export const ServerUrlModal: StoryFn = () => ( +// +// ); \ No newline at end of file diff --git a/guide/results-viewer-react/src/components/YamlWriterUpload/index.tsx b/guide/results-viewer-react/src/components/YamlWriterUpload/index.tsx index 111a1109..b4f94b60 100644 --- a/guide/results-viewer-react/src/components/YamlWriterUpload/index.tsx +++ b/guide/results-viewer-react/src/components/YamlWriterUpload/index.tsx @@ -175,33 +175,6 @@ interface IndexType { id: string } -// Modal wrapper props to make reusing modal component easier -interface ModalWrapperProps { - modalRef: React.RefObject; - title: string; - submitText: string; - closeText: string; - isReady: boolean; - onSubmit: () => void; - onClose: () => void; - children: React.ReactNode; -} - -// A resusable modal wrapper that accepts props and provides a consistent structure for modals -const ModalWrapper = ({ modalRef, title, submitText, closeText, isReady, onSubmit, onClose, children }: ModalWrapperProps) => ( - Promise.resolve(onSubmit())} - closeText={closeText} - onClose={onClose} - isReady={isReady} - > - {children} - -); - export const YamlWriterUpload = (props: YamlWriterUploadProps) => { const defaultState: YamlWriterUploadState = { file: undefined, // To track the Har file @@ -419,11 +392,9 @@ export const YamlWriterUpload = (props: YamlWriterUploadProps) => { let hasValidVersion: boolean = false; let hasValidHost: boolean = false; if ("openapi" in swaggerData) { - // const swaggerData = unknownData as SwaggerDoc3; hasValidServers = Array.isArray(swaggerData.servers) && swaggerData.servers.length > 0; hasValidVersion = typeof swaggerData.openapi === "string" && versionRegex.test(swaggerData.openapi); } else if ("swagger" in swaggerData) { - // const swaggerData = unknownData as SwaggerDoc2; hasValidHost = typeof swaggerData.host === "string"; hasValidVersion = typeof swaggerData.swagger === "string" && versionRegex.test(swaggerData.swagger); } else { @@ -647,7 +618,9 @@ export const YamlWriterUpload = (props: YamlWriterUploadProps) => { const fullPath = baseUrl.endsWith("/") || url.startsWith("/") ? `${baseUrl}${url}` : `${baseUrl}/${url}`; const hostUrl = new URL(baseUrl).hostname; - // Create URL object + // Create URL-like object without URL encoding the `{}` on the endpoints, + // because using the `new URL()` would encode `{}` into `%7B` and `%7D`. + // This ensures the curly braces remain intact for the endpoints. const parsedUrl = { href: fullPath, toString: () => fullPath @@ -745,7 +718,9 @@ export const YamlWriterUpload = (props: YamlWriterUploadProps) => { } } - // Create URL object + // Create URL-like object without URL encoding the `{}` on the endpoints, + // because using the `new URL()` would encode `{}` into `%7B` and `%7D`. + // This ensures the curly braces remain intact for the endpoints. const parsedUrl = { href: fullPath, toString: () => fullPath @@ -902,8 +877,8 @@ export const YamlWriterUpload = (props: YamlWriterUploadProps) => { {/* This is the upload file modal */} - { )} - + {/* Modal for Swagger URL input */} - {
setState({ ...state, swaggerUrl: e.target.value })} />
-
+ {/* This is the modal that opens when a server is missing in a swagger upload */}