Skip to content

Commit a6a47ca

Browse files
authored
Merge branch 'main' into patnir41/preconfig-difs-8-15
2 parents 91917f5 + 180cf20 commit a6a47ca

File tree

9 files changed

+76
-163
lines changed

9 files changed

+76
-163
lines changed

packages/api-explorer/e2e/diffScene.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ describe('Diff Scene', () => {
4444
await jestPuppeteer.resetBrowser()
4545
await page.setDefaultNavigationTimeout(120000)
4646
})
47-
it('loads the default scene (/diff/3.1)', async () => {
48-
await goToPage(`${BASE_URL}/diff/3.1`)
47+
48+
it('loads the default scene (/3.1/diff)', async () => {
49+
await goToPage(`${BASE_URL}/3.1/diff`)
4950
const body = await page.$('body')
5051

5152
// "Base" input element
@@ -106,9 +107,8 @@ describe('Diff Scene', () => {
106107
}
107108
})
108109

109-
it('loads a comparison scene (/diff/3.1/4.0) and navigates from it', async () => {
110-
await goToPage(`${BASE_URL}/diff/3.1/4.0`)
111-
110+
it('loads a comparison scene (/3.1/diff/4.0) and navigates from it', async () => {
111+
await goToPage(`${BASE_URL}/3.1/diff/4.0`)
112112
// "Base" input element
113113
{
114114
const baseInputElement = await page.$(baseInputSelector)
@@ -189,7 +189,7 @@ describe('Diff Scene', () => {
189189
})
190190

191191
it('updates when a comparison is chosen or switched', async () => {
192-
await goToPage(`${BASE_URL}/diff/3.1`)
192+
await goToPage(`${BASE_URL}/3.1/diff`)
193193

194194
// "Base" input element
195195
const baseInputElement = await page.$(baseInputSelector)
@@ -219,7 +219,7 @@ describe('Diff Scene', () => {
219219
// Check the URL
220220
// Would like to do this earlier, but not sure what to wait on
221221
const compUrl = page.url()
222-
expect(compUrl).toEqual(`${BASE_URL}/diff/3.1/4.0?sdk=py`)
222+
expect(compUrl).toEqual(`${BASE_URL}/3.1/diff/4.0?sdk=py`)
223223

224224
// Check the results
225225
const diffResultCards = await page.$$(resultCardsSelector)
@@ -247,7 +247,7 @@ describe('Diff Scene', () => {
247247
await page.waitForTimeout(150)
248248

249249
const switchUrl = page.url()
250-
expect(switchUrl).toEqual(`${BASE_URL}/diff/4.0/3.1?sdk=py`)
250+
expect(switchUrl).toEqual(`${BASE_URL}/4.0/diff/3.1?sdk=py`)
251251

252252
// Check the results again, even though they should be the same
253253
const diff40to31Page1Methods = await Promise.all(

packages/api-explorer/e2e/e2e.spec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,16 @@ describe('API Explorer', () => {
4040
await page.setDefaultNavigationTimeout(120000)
4141
})
4242

43+
afterEach(async () => {
44+
await page.evaluate(() => {
45+
localStorage.clear()
46+
})
47+
})
4348
describe('general', () => {
4449
beforeEach(async () => {
4550
await goToPage(v40)
4651
})
4752

48-
afterEach(async () => {
49-
await page.evaluate(() => {
50-
localStorage.clear()
51-
})
52-
})
53-
5453
it('renders a method page', async () => {
5554
await Promise.all([
5655
page.waitForNavigation(),

packages/api-explorer/src/ApiExplorer.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import {
6868
selectCurrentSpec,
6969
useSettingStoreState,
7070
} from './state'
71-
import { getSpecKey, diffPath, findSdk, useGlobalStoreSync } from './utils'
71+
import { getSpecKey, findSdk, useGlobalStoreSync } from './utils'
7272

7373
export interface ApiExplorerProps {
7474
adaptor: IApixAdaptor
@@ -120,7 +120,7 @@ export const ApiExplorer: FC<ApiExplorerProps> = ({
120120

121121
useEffect(() => {
122122
const maybeSpec = location.pathname?.split('/')[1]
123-
if (spec && maybeSpec && maybeSpec !== diffPath && maybeSpec !== spec.key) {
123+
if (spec && maybeSpec && maybeSpec !== spec.key) {
124124
setCurrentSpecAction({ currentSpecKey: maybeSpec })
125125
}
126126
}, [location.pathname, spec])
@@ -149,7 +149,7 @@ export const ApiExplorer: FC<ApiExplorerProps> = ({
149149
const themeOverrides = adaptor.themeOverrides()
150150

151151
let neededSpec = location.pathname?.split('/')[1]
152-
if (!neededSpec || neededSpec === diffPath) {
152+
if (!neededSpec) {
153153
neededSpec = spec?.key
154154
}
155155

@@ -219,7 +219,6 @@ export const ApiExplorer: FC<ApiExplorerProps> = ({
219219
<AppRouter
220220
specKey={spec.key}
221221
api={spec.api!}
222-
specs={specs}
223222
toggleNavigation={toggleNavigation}
224223
/>
225224
</Layout>

packages/api-explorer/src/components/Header/Header.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ describe('Header', () => {
9393
name: 'Compare Specifications',
9494
})
9595
.closest('a')
96-
).toHaveAttribute('href', `/diff/${spec.key}/`)
96+
).toHaveAttribute('href', `/${spec.key}/diff`)
9797
})
9898
})

packages/api-explorer/src/components/SelectorContainer/SelectorContainer.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ describe('SelectorContainer', () => {
7575
name: 'Compare Specifications',
7676
})
7777
.closest('a')
78-
).toHaveAttribute('href', `/diff/${spec.key}/`)
78+
).toHaveAttribute('href', `/${spec.key}/diff`)
7979
})
8080
})

packages/api-explorer/src/components/SelectorContainer/SelectorContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const SelectorContainer: FC<SelectorContainerProps> = ({
5555
<Space width="auto" {...spaceProps}>
5656
<SdkLanguageSelector />
5757
<ApiSpecSelector spec={spec} />
58-
<Link to={buildPathWithGlobalParams(`/${diffPath}/${spec.key}/`)}>
58+
<Link to={buildPathWithGlobalParams(`/${spec.key}/${diffPath}`)}>
5959
<IconButton
6060
toggle
6161
label="Compare Specifications"

packages/api-explorer/src/routes/AppRouter.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import type { FC } from 'react'
2828
import React from 'react'
2929
import { Redirect, Route, Switch } from 'react-router-dom'
30-
import type { ApiModel, SpecList } from '@looker/sdk-codegen'
30+
import type { ApiModel } from '@looker/sdk-codegen'
3131

3232
import {
3333
HomeScene,
@@ -41,21 +41,19 @@ import { diffPath } from '../utils'
4141

4242
interface AppRouterProps {
4343
specKey: string
44-
specs: SpecList
4544
api: ApiModel
4645
toggleNavigation: (target?: boolean) => void
4746
}
4847

4948
export const AppRouter: FC<AppRouterProps> = ({
5049
api,
5150
specKey,
52-
specs,
5351
toggleNavigation,
5452
}) => (
5553
<Switch>
5654
<Redirect from="/" to={`/${specKey}/`} exact />
57-
<Route path={`/${diffPath}/:l?/:r?`}>
58-
<DiffScene specs={specs} toggleNavigation={toggleNavigation} />
55+
<Route path={`/:specKey/${diffPath}/:compareSpecKey?`}>
56+
<DiffScene toggleNavigation={toggleNavigation} />
5957
</Route>
6058
<Route path="/:specKey/(methods|types)?" exact>
6159
<HomeScene api={api} />

packages/api-explorer/src/scenes/DiffScene/DiffScene.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { useSelector } from 'react-redux'
4343
import { ApixSection } from '../../components'
4444
import {
4545
selectCurrentSpec,
46+
selectSpecs,
4647
selectDiffOptions,
4748
useSettingActions,
4849
} from '../../state'
@@ -79,22 +80,22 @@ const diffToggles = [
7980
]
8081

8182
export interface DiffSceneProps {
82-
specs: SpecList
8383
toggleNavigation: (target?: boolean) => void
8484
}
8585

8686
const validateParam = (specs: SpecList, specKey = '') => {
8787
return specs[specKey] ? specKey : ''
8888
}
8989

90-
export const DiffScene: FC<DiffSceneProps> = ({ specs, toggleNavigation }) => {
90+
export const DiffScene: FC<DiffSceneProps> = ({ toggleNavigation }) => {
9191
const adaptor = getApixAdaptor()
9292
const { navigate } = useNavigation()
9393
const selectedDiffOptions = useSelector(selectDiffOptions)
9494
const { setDiffOptionsAction } = useSettingActions()
9595
const spec = useSelector(selectCurrentSpec)
96+
const specs = useSelector(selectSpecs)
9697
const currentSpecKey = spec.key
97-
const match = useRouteMatch<{ l: string; r: string }>(`/${diffPath}/:l?/:r?`)
98+
const match = useRouteMatch<{ l: string; r: string }>(`/:l/${diffPath}/:r?`)
9899
const l = validateParam(specs, match?.params.l)
99100
const r = validateParam(specs, match?.params.r)
100101

@@ -131,14 +132,14 @@ export const DiffScene: FC<DiffSceneProps> = ({ specs, toggleNavigation }) => {
131132
const [delta, setDelta] = useState<DiffRow[]>([])
132133

133134
const handleLeftChange = (newLeft: string) => {
134-
navigate(`/${diffPath}/${newLeft}/${rightKey}`)
135+
navigate(`/${newLeft}/${diffPath}/${rightKey}`)
135136
}
136137
const handleRightChange = (newRight: string) => {
137-
navigate(`/${diffPath}/${leftKey}/${newRight}`)
138+
navigate(`/${leftKey}/${diffPath}/${newRight}`)
138139
}
139140

140141
const handleSwitch = () => {
141-
navigate(`/${diffPath}/${rightKey}/${leftKey}`)
142+
navigate(`/${rightKey}/${diffPath}/${leftKey}`)
142143
}
143144

144145
useEffect(() => {

0 commit comments

Comments
 (0)