Skip to content

Commit

Permalink
spec selection now tries to match current path
Browse files Browse the repository at this point in the history
  • Loading branch information
jkaster committed Sep 3, 2021
1 parent 1a46454 commit 67e81e5
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import React, { FC, Dispatch } from 'react'
import { Select } from '@looker/components'
import { useHistory } from 'react-router-dom'
import { useHistory, useLocation } from 'react-router-dom'

import { SpecList, SpecItem } from '@looker/sdk-codegen'
import { SpecAction, selectSpec } from '../../reducers'
Expand All @@ -43,6 +43,7 @@ export const ApiSpecSelector: FC<ApiSpecSelectorProps> = ({
specDispatch,
}) => {
const history = useHistory()
const location = useLocation()
const options = Object.entries(specs).map(([key, spec]) => ({
value: key,
label: key,
Expand All @@ -51,7 +52,8 @@ export const ApiSpecSelector: FC<ApiSpecSelectorProps> = ({

const handleChange = (specKey: string) => {
specDispatch(selectSpec(specKey))
history.push(`/${specKey}`)
const matchPath = location.pathname.replace(`/${spec.key}`, `/${specKey}`)
history.push(matchPath)
}

return (
Expand Down

0 comments on commit 67e81e5

Please sign in to comment.