From 8d022aaac3c65e8c9d8b60457de95498b71b7cc4 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 19 Oct 2023 08:29:17 -0300 Subject: [PATCH] swap from useLocationParams to useLocation --- src/shared/RawFileviewer/RawFileviewer.jsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/shared/RawFileviewer/RawFileviewer.jsx b/src/shared/RawFileviewer/RawFileviewer.jsx index 36d03457f6..781267ece6 100644 --- a/src/shared/RawFileviewer/RawFileviewer.jsx +++ b/src/shared/RawFileviewer/RawFileviewer.jsx @@ -1,9 +1,9 @@ import PropTypes from 'prop-types' -import { useParams } from 'react-router-dom' +import qs from 'qs' +import { useLocation, useParams } from 'react-router-dom' import NotFound from 'pages/NotFound' import { useCommitBasedCoverageForFileViewer } from 'services/file' -import { useLocationParams } from 'services/navigation' import { useOwner } from 'services/user' import { CODE_RENDERER_TYPE } from 'shared/utils/fileviewer' import { unsupportedExtensionsMapper } from 'shared/utils/unsupportedExtensionsMapper' @@ -101,10 +101,6 @@ CodeRendererContent.propTypes = { stickyPadding: PropTypes.number, } -const defaultQueryParams = { - flags: [], -} - // Note: This component is both used in the standalone file viewer page and in the overview page. Changing this // component will affect both places function RawFileViewer({ @@ -116,10 +112,16 @@ function RawFileViewer({ showFlagsSelect, }) { const { owner, repo, provider, path: urlPath } = useParams() - const { params } = useLocationParams(defaultQueryParams) + const location = useLocation() const path = decodeURIComponent(urlPath) const { data: ownerData } = useOwner({ username: owner }) + const params = qs.parse(location.search, { + ignoreQueryPrefix: true, + depth: 1, + }) + const flags = params?.flags ?? [] + const isUnsupportedFileType = unsupportedExtensionsMapper({ path }) // TODO: This hook needs revision/enhancement @@ -134,7 +136,7 @@ function RawFileViewer({ provider, commit, path, - selectedFlags: params?.flags, + selectedFlags: flags, opts: { enabled: !isUnsupportedFileType, },