Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Swap from useLocationParams to useLocation in RawFileviewer #2325

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/shared/RawFileviewer/RawFileviewer.jsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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({
Expand All @@ -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
Expand All @@ -134,7 +136,7 @@ function RawFileViewer({
provider,
commit,
path,
selectedFlags: params?.flags,
selectedFlags: flags,
opts: {
enabled: !isUnsupportedFileType,
},
Expand Down
Loading