@looker/api-explorer 0.9.26 → 0.9.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -1
- package/e2e/e2e.spec.ts +1 -1
- package/lib/ApiExplorer.d.ts +2 -6
- package/lib/ApiExplorer.js +53 -74
- package/lib/ApiExplorer.js.map +1 -1
- package/lib/StandaloneApiExplorer.js +35 -47
- package/lib/StandaloneApiExplorer.js.map +1 -1
- package/lib/components/Banner/Banner.d.ts +8 -0
- package/lib/components/Banner/Banner.js +70 -0
- package/lib/components/Banner/Banner.js.map +1 -0
- package/lib/components/Banner/index.d.ts +1 -0
- package/lib/components/Banner/index.js +14 -0
- package/lib/components/Banner/index.js.map +1 -0
- package/lib/components/DocSDKs/DocSDKs.js +3 -3
- package/lib/components/DocSDKs/DocSDKs.js.map +1 -1
- package/lib/components/ExploreType/ExploreType.js +3 -5
- package/lib/components/ExploreType/ExploreType.js.map +1 -1
- package/lib/components/Header/Header.d.ts +2 -5
- package/lib/components/Header/Header.js +1 -5
- package/lib/components/Header/Header.js.map +1 -1
- package/lib/components/SelectorContainer/ApiSpecSelector.d.ts +2 -5
- package/lib/components/SelectorContainer/ApiSpecSelector.js +5 -5
- package/lib/components/SelectorContainer/ApiSpecSelector.js.map +1 -1
- package/lib/components/SelectorContainer/SelectorContainer.d.ts +2 -5
- package/lib/components/SelectorContainer/SelectorContainer.js +3 -7
- package/lib/components/SelectorContainer/SelectorContainer.js.map +1 -1
- package/lib/components/SideNav/SideNav.d.ts +2 -5
- package/lib/components/SideNav/SideNav.js.map +1 -1
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +8 -0
- package/lib/components/index.js.map +1 -1
- package/lib/esm/ApiExplorer.js +54 -74
- package/lib/esm/ApiExplorer.js.map +1 -1
- package/lib/esm/StandaloneApiExplorer.js +34 -48
- package/lib/esm/StandaloneApiExplorer.js.map +1 -1
- package/lib/esm/components/Banner/Banner.js +54 -0
- package/lib/esm/components/Banner/Banner.js.map +1 -0
- package/lib/esm/components/Banner/index.js +2 -0
- package/lib/esm/components/Banner/index.js.map +1 -0
- package/lib/esm/components/DocSDKs/DocSDKs.js +2 -2
- package/lib/esm/components/DocSDKs/DocSDKs.js.map +1 -1
- package/lib/esm/components/ExploreType/ExploreType.js +3 -4
- package/lib/esm/components/ExploreType/ExploreType.js.map +1 -1
- package/lib/esm/components/Header/Header.js +1 -5
- package/lib/esm/components/Header/Header.js.map +1 -1
- package/lib/esm/components/SelectorContainer/ApiSpecSelector.js +4 -5
- package/lib/esm/components/SelectorContainer/ApiSpecSelector.js.map +1 -1
- package/lib/esm/components/SelectorContainer/SelectorContainer.js +3 -7
- package/lib/esm/components/SelectorContainer/SelectorContainer.js.map +1 -1
- package/lib/esm/components/SideNav/SideNav.js.map +1 -1
- package/lib/esm/components/index.js +1 -0
- package/lib/esm/components/index.js.map +1 -1
- package/lib/esm/index.js +1 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/routes/AppRouter.js +3 -7
- package/lib/esm/routes/AppRouter.js.map +1 -1
- package/lib/esm/scenes/DiffScene/DiffScene.js +43 -99
- package/lib/esm/scenes/DiffScene/DiffScene.js.map +1 -1
- package/lib/esm/scenes/DiffScene/DocDiff/DiffItem.js +9 -13
- package/lib/esm/scenes/DiffScene/DocDiff/DiffItem.js.map +1 -1
- package/lib/esm/scenes/DiffScene/DocDiff/DocDiff.js +2 -2
- package/lib/esm/scenes/DiffScene/DocDiff/DocDiff.js.map +1 -1
- package/lib/esm/scenes/MethodScene/MethodScene.js +4 -5
- package/lib/esm/scenes/MethodScene/MethodScene.js.map +1 -1
- package/lib/esm/state/index.js +1 -0
- package/lib/esm/state/index.js.map +1 -1
- package/lib/esm/state/specs/index.js +3 -0
- package/lib/esm/state/specs/index.js.map +1 -0
- package/lib/esm/state/specs/sagas.js +58 -0
- package/lib/esm/state/specs/sagas.js.map +1 -0
- package/lib/esm/state/specs/selectors.js +8 -0
- package/lib/esm/state/specs/selectors.js.map +1 -0
- package/lib/esm/state/specs/slice.js +55 -0
- package/lib/esm/state/specs/slice.js.map +1 -0
- package/lib/esm/state/store.js +53 -2
- package/lib/esm/state/store.js.map +1 -1
- package/lib/esm/test-utils/redux.js +9 -5
- package/lib/esm/test-utils/redux.js.map +1 -1
- package/lib/esm/utils/adaptorUtils.js +101 -0
- package/lib/esm/utils/adaptorUtils.js.map +1 -0
- package/lib/esm/utils/apixAdaptor.js +48 -0
- package/lib/esm/utils/apixAdaptor.js.map +1 -0
- package/lib/esm/utils/index.js +3 -1
- package/lib/esm/utils/index.js.map +1 -1
- package/lib/esm/utils/path.js +27 -2
- package/lib/esm/utils/path.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +13 -0
- package/lib/index.js.map +1 -1
- package/lib/routes/AppRouter.d.ts +1 -5
- package/lib/routes/AppRouter.js +3 -7
- package/lib/routes/AppRouter.js.map +1 -1
- package/lib/scenes/DiffScene/DiffScene.js +45 -100
- package/lib/scenes/DiffScene/DiffScene.js.map +1 -1
- package/lib/scenes/DiffScene/DocDiff/DiffItem.js +9 -13
- package/lib/scenes/DiffScene/DocDiff/DiffItem.js.map +1 -1
- package/lib/scenes/DiffScene/DocDiff/DocDiff.js +2 -2
- package/lib/scenes/DiffScene/DocDiff/DocDiff.js.map +1 -1
- package/lib/scenes/MethodScene/MethodScene.d.ts +0 -4
- package/lib/scenes/MethodScene/MethodScene.js +5 -5
- package/lib/scenes/MethodScene/MethodScene.js.map +1 -1
- package/lib/state/index.d.ts +1 -0
- package/lib/state/index.js +13 -0
- package/lib/state/index.js.map +1 -1
- package/lib/state/settings/selectors.d.ts +1 -1
- package/lib/state/settings/slice.d.ts +1 -1
- package/lib/state/specs/index.d.ts +2 -0
- package/lib/state/specs/index.js +32 -0
- package/lib/state/specs/index.js.map +1 -0
- package/lib/state/specs/sagas.d.ts +1 -0
- package/lib/state/specs/sagas.js +67 -0
- package/lib/state/specs/sagas.js.map +1 -0
- package/lib/state/specs/selectors.d.ts +4 -0
- package/lib/state/specs/selectors.js +20 -0
- package/lib/state/specs/selectors.js.map +1 -0
- package/lib/state/specs/slice.d.ts +49 -0
- package/lib/state/specs/slice.js +70 -0
- package/lib/state/specs/slice.js.map +1 -0
- package/lib/state/store.d.ts +3 -0
- package/lib/state/store.js +56 -2
- package/lib/state/store.js.map +1 -1
- package/lib/test-data/declarations.d.ts +2 -0
- package/lib/test-data/examples.d.ts +2 -0
- package/lib/test-data/index.d.ts +3 -0
- package/lib/test-data/index.js +12 -42
- package/lib/test-data/index.js.map +1 -1
- package/lib/test-data/specs.d.ts +10 -0
- package/lib/test-data/specs.js +6 -6
- package/lib/test-data/specs.js.map +1 -1
- package/lib/test-utils/redux.d.ts +2 -1
- package/lib/test-utils/redux.js +9 -4
- package/lib/test-utils/redux.js.map +1 -1
- package/lib/utils/adaptorUtils.d.ts +30 -0
- package/lib/utils/adaptorUtils.js +124 -0
- package/lib/utils/adaptorUtils.js.map +1 -0
- package/lib/utils/apixAdaptor.d.ts +15 -0
- package/lib/utils/apixAdaptor.js +67 -0
- package/lib/utils/apixAdaptor.js.map +1 -0
- package/lib/utils/index.d.ts +3 -1
- package/lib/utils/index.js +45 -30
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/path.d.ts +3 -0
- package/lib/utils/path.js +32 -2
- package/lib/utils/path.js.map +1 -1
- package/package.json +10 -10
- package/src/ApiExplorer.tsx +47 -74
- package/src/StandaloneApiExplorer.tsx +37 -52
- package/src/components/Banner/Banner.spec.tsx +99 -0
- package/src/components/Banner/Banner.tsx +87 -0
- package/src/{reducers → components/Banner}/index.ts +1 -1
- package/src/components/DocSDKs/DocSDKs.tsx +4 -5
- package/src/components/ExploreType/ExploreType.spec.tsx +0 -23
- package/src/components/ExploreType/ExploreType.tsx +5 -6
- package/src/components/ExploreType/exploreUtils.spec.tsx +1 -1
- package/src/components/Header/Header.spec.tsx +9 -30
- package/src/components/Header/Header.tsx +3 -10
- package/src/components/SelectorContainer/ApiSpecSelector.spec.tsx +31 -44
- package/src/components/SelectorContainer/ApiSpecSelector.tsx +6 -12
- package/src/components/SelectorContainer/SelectorContainer.spec.tsx +7 -26
- package/src/components/SelectorContainer/SelectorContainer.tsx +4 -10
- package/src/components/SideNav/SideNav.spec.tsx +12 -45
- package/src/components/SideNav/SideNav.tsx +1 -7
- package/src/components/index.ts +1 -0
- package/src/index.ts +1 -0
- package/src/routes/AppRouter.tsx +25 -37
- package/src/scenes/DiffScene/DiffScene.tsx +47 -84
- package/src/scenes/DiffScene/DocDiff/DiffItem.spec.tsx +9 -16
- package/src/scenes/DiffScene/DocDiff/DiffItem.tsx +11 -12
- package/src/scenes/DiffScene/DocDiff/DocDiff.tsx +2 -2
- package/src/scenes/MethodScene/MethodScene.tsx +4 -10
- package/src/state/index.ts +1 -0
- package/src/{reducers/spec → state/specs}/index.ts +2 -3
- package/src/state/specs/sagas.spec.ts +135 -0
- package/src/state/specs/sagas.ts +81 -0
- package/src/{reducers/spec/actions.spec.ts → state/specs/selectors.ts} +12 -11
- package/src/state/specs/slice.ts +109 -0
- package/src/state/store.ts +58 -0
- package/src/test-data/index.ts +1 -8
- package/src/test-data/specs.ts +6 -6
- package/src/test-utils/redux.tsx +15 -4
- package/src/utils/adaptorUtils.ts +181 -0
- package/src/utils/apixAdaptor.ts +72 -0
- package/src/utils/index.ts +3 -7
- package/src/utils/path.ts +25 -2
- package/lib/esm/reducers/index.js +0 -2
- package/lib/esm/reducers/index.js.map +0 -1
- package/lib/esm/reducers/spec/actions.js +0 -19
- package/lib/esm/reducers/spec/actions.js.map +0 -1
- package/lib/esm/reducers/spec/index.js +0 -4
- package/lib/esm/reducers/spec/index.js.map +0 -1
- package/lib/esm/reducers/spec/reducer.js +0 -62
- package/lib/esm/reducers/spec/reducer.js.map +0 -1
- package/lib/esm/reducers/spec/utils.js +0 -74
- package/lib/esm/reducers/spec/utils.js.map +0 -1
- package/lib/reducers/index.d.ts +0 -1
- package/lib/reducers/index.js +0 -19
- package/lib/reducers/index.js.map +0 -1
- package/lib/reducers/spec/actions.d.ts +0 -20
- package/lib/reducers/spec/actions.js +0 -31
- package/lib/reducers/spec/actions.js.map +0 -1
- package/lib/reducers/spec/index.d.ts +0 -3
- package/lib/reducers/spec/index.js +0 -45
- package/lib/reducers/spec/index.js.map +0 -1
- package/lib/reducers/spec/reducer.d.ts +0 -7
- package/lib/reducers/spec/reducer.js +0 -73
- package/lib/reducers/spec/reducer.js.map +0 -1
- package/lib/reducers/spec/utils.d.ts +0 -7
- package/lib/reducers/spec/utils.js +0 -91
- package/lib/reducers/spec/utils.js.map +0 -1
- package/src/reducers/spec/actions.ts +0 -62
- package/src/reducers/spec/reducer.spec.ts +0 -44
- package/src/reducers/spec/reducer.ts +0 -69
- package/src/reducers/spec/utils.spec.ts +0 -138
- package/src/reducers/spec/utils.ts +0 -123
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
SOFTWARE.
|
|
24
24
|
|
|
25
25
|
*/
|
|
26
|
-
import type { FC
|
|
26
|
+
import type { FC } from 'react'
|
|
27
27
|
import React, { useState, useEffect } from 'react'
|
|
28
|
-
import ReactDiffViewer, { DiffMethod } from 'react-diff-viewer'
|
|
29
28
|
import { useHistory } from 'react-router'
|
|
29
|
+
import ReactDiffViewer, { DiffMethod } from 'react-diff-viewer'
|
|
30
30
|
import styled from 'styled-components'
|
|
31
|
-
import { Accordion2, Box, Card, Grid, Heading } from '@looker/components'
|
|
31
|
+
import { Accordion2, Box, Card, Grid, Heading, Link } from '@looker/components'
|
|
32
32
|
import type { DiffRow } from '@looker/sdk-codegen/src'
|
|
33
33
|
import type { ApiModel, IMethod } from '@looker/sdk-codegen'
|
|
34
34
|
import { useSelector } from 'react-redux'
|
|
@@ -42,7 +42,7 @@ interface DiffMethodLinkProps {
|
|
|
42
42
|
specKey: string
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
const DiffLink = styled(
|
|
45
|
+
const DiffLink = styled(Link)`
|
|
46
46
|
color: ${({ theme }) => theme.colors.ui5};
|
|
47
47
|
cursor: pointer;
|
|
48
48
|
display: block;
|
|
@@ -61,19 +61,18 @@ export const DiffMethodLink: FC<DiffMethodLinkProps> = ({
|
|
|
61
61
|
specKey,
|
|
62
62
|
}) => {
|
|
63
63
|
const history = useHistory()
|
|
64
|
+
|
|
64
65
|
if (!method) return <Heading as="h4">{`Missing in ${specKey}`}</Heading>
|
|
65
66
|
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
const tag = method.schema.tags[0]
|
|
69
|
-
const path = `${buildMethodPath(specKey, tag, method.name)}`
|
|
70
|
-
history.push(path)
|
|
71
|
-
}
|
|
67
|
+
const tag = method.schema.tags[0]
|
|
68
|
+
const path = `${buildMethodPath(specKey, tag, method.name)}`
|
|
72
69
|
|
|
73
70
|
return (
|
|
74
71
|
<DiffLink
|
|
75
|
-
|
|
76
|
-
onClick={
|
|
72
|
+
role="link"
|
|
73
|
+
onClick={() => {
|
|
74
|
+
history.push(path)
|
|
75
|
+
}}
|
|
77
76
|
>{`${method.name} for ${specKey}`}</DiffLink>
|
|
78
77
|
)
|
|
79
78
|
}
|
|
@@ -80,9 +80,9 @@ export const DocDiff: FC<DocDiffProps> = ({
|
|
|
80
80
|
<Heading as="h2">{`${delta.length} differences between ${leftKey} and ${rightKey}`}</Heading>
|
|
81
81
|
</Space>
|
|
82
82
|
<SpaceVertical mt="large" gap="xxsmall">
|
|
83
|
-
{pageItemData.map((item) => (
|
|
83
|
+
{pageItemData.map((item, index) => (
|
|
84
84
|
<DiffItem
|
|
85
|
-
key={
|
|
85
|
+
key={index}
|
|
86
86
|
item={item}
|
|
87
87
|
leftKey={leftKey}
|
|
88
88
|
leftSpec={leftSpec}
|
|
@@ -36,13 +36,13 @@ import {
|
|
|
36
36
|
} from '@looker/components'
|
|
37
37
|
import { Beaker } from '@looker/icons'
|
|
38
38
|
import { useHistory, useParams } from 'react-router-dom'
|
|
39
|
-
import type { RunItSetter } from '@looker/run-it'
|
|
40
39
|
import { RunIt, RunItFormKey } from '@looker/run-it'
|
|
41
40
|
import type { ApiModel } from '@looker/sdk-codegen'
|
|
42
41
|
import { typeRefs } from '@looker/sdk-codegen'
|
|
43
42
|
import { useSelector } from 'react-redux'
|
|
44
|
-
|
|
45
43
|
import type { IEnvironmentAdaptor } from '@looker/extension-utils'
|
|
44
|
+
|
|
45
|
+
import { getApixAdaptor } from '../../utils'
|
|
46
46
|
import {
|
|
47
47
|
ApixSection,
|
|
48
48
|
DocActivityType,
|
|
@@ -62,8 +62,6 @@ import { DocOperation, DocRequestBody } from './components'
|
|
|
62
62
|
|
|
63
63
|
interface MethodSceneProps {
|
|
64
64
|
api: ApiModel
|
|
65
|
-
adaptor: IEnvironmentAdaptor
|
|
66
|
-
setVersionsUrl: RunItSetter
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
interface MethodSceneParams {
|
|
@@ -77,11 +75,8 @@ const showRunIt = async (adaptor: IEnvironmentAdaptor) => {
|
|
|
77
75
|
return !!data
|
|
78
76
|
}
|
|
79
77
|
|
|
80
|
-
export const MethodScene: FC<MethodSceneProps> = ({
|
|
81
|
-
|
|
82
|
-
adaptor,
|
|
83
|
-
setVersionsUrl,
|
|
84
|
-
}) => {
|
|
78
|
+
export const MethodScene: FC<MethodSceneProps> = ({ api }) => {
|
|
79
|
+
const adaptor = getApixAdaptor()
|
|
85
80
|
const history = useHistory()
|
|
86
81
|
const sdkLanguage = useSelector(selectSdkLanguage)
|
|
87
82
|
const { specKey, methodTag, methodName } = useParams<MethodSceneParams>()
|
|
@@ -175,7 +170,6 @@ export const MethodScene: FC<MethodSceneProps> = ({
|
|
|
175
170
|
sdkLanguage={sdkLanguage}
|
|
176
171
|
api={api}
|
|
177
172
|
method={method}
|
|
178
|
-
setVersionsUrl={setVersionsUrl}
|
|
179
173
|
/>
|
|
180
174
|
</ExtendComponentsThemeProvider>
|
|
181
175
|
</Aside>
|
package/src/state/index.ts
CHANGED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2021 Looker Data Sciences, Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
24
|
+
|
|
25
|
+
*/
|
|
26
|
+
import ReduxSagaTester from 'redux-saga-tester'
|
|
27
|
+
import { registerTestEnvAdaptor } from '@looker/extension-utils'
|
|
28
|
+
import { initRunItSdk } from '@looker/run-it'
|
|
29
|
+
import cloneDeep from 'lodash/cloneDeep'
|
|
30
|
+
import { ApixAdaptor } from '../../utils'
|
|
31
|
+
|
|
32
|
+
import { getLoadedSpecs } from '../../test-data'
|
|
33
|
+
import { specActions, specsSlice } from './slice'
|
|
34
|
+
import * as sagas from './sagas'
|
|
35
|
+
|
|
36
|
+
describe('Specs Sagas', () => {
|
|
37
|
+
let sagaTester: ReduxSagaTester<any>
|
|
38
|
+
const adaptor = new ApixAdaptor(initRunItSdk(), '')
|
|
39
|
+
registerTestEnvAdaptor(adaptor)
|
|
40
|
+
const specState = getLoadedSpecs()
|
|
41
|
+
const mockError = new Error('boom')
|
|
42
|
+
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
jest.resetAllMocks()
|
|
45
|
+
sagaTester = new ReduxSagaTester({
|
|
46
|
+
initialState: { specs: { specs: specState } },
|
|
47
|
+
reducers: {
|
|
48
|
+
specs: specsSlice.reducer,
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
sagaTester.start(sagas.saga)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
describe('initSaga', () => {
|
|
55
|
+
const { initSpecsAction, initSpecsFailureAction, initSpecsSuccessAction } =
|
|
56
|
+
specActions
|
|
57
|
+
|
|
58
|
+
it('sends initSpecsFailureAction on error', async () => {
|
|
59
|
+
jest.spyOn(adaptor, 'fetchSpecList').mockRejectedValueOnce(mockError)
|
|
60
|
+
|
|
61
|
+
sagaTester.dispatch(initSpecsAction({ specKey: null }))
|
|
62
|
+
await sagaTester.waitFor('specs/initSpecsFailureAction')
|
|
63
|
+
const calledActions = sagaTester.getCalledActions()
|
|
64
|
+
expect(calledActions).toHaveLength(2)
|
|
65
|
+
expect(calledActions[0]).toEqual(initSpecsAction({ specKey: null }))
|
|
66
|
+
expect(calledActions[1]).toEqual(initSpecsFailureAction(mockError))
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('sends initSpecsSuccessAction on success', async () => {
|
|
70
|
+
// fetchSpecList returns the test specs
|
|
71
|
+
jest
|
|
72
|
+
.spyOn(adaptor, 'fetchSpecList')
|
|
73
|
+
.mockResolvedValueOnce(cloneDeep(specState))
|
|
74
|
+
|
|
75
|
+
const currentSpec = specState['3.1']
|
|
76
|
+
jest.spyOn(adaptor, 'fetchSpec').mockResolvedValueOnce(currentSpec!)
|
|
77
|
+
|
|
78
|
+
// expected state is all the specs with the current spec containing the ApiModel
|
|
79
|
+
const expected = cloneDeep(specState)
|
|
80
|
+
expected[currentSpec.key] = currentSpec
|
|
81
|
+
|
|
82
|
+
sagaTester.dispatch(initSpecsAction({ specKey: null }))
|
|
83
|
+
await sagaTester.waitFor('specs/initSpecsSuccessAction')
|
|
84
|
+
const calledActions = sagaTester.getCalledActions()
|
|
85
|
+
expect(calledActions).toHaveLength(2)
|
|
86
|
+
expect(calledActions[0]).toEqual(initSpecsAction({ specKey: null }))
|
|
87
|
+
expect(calledActions[1]).toEqual(
|
|
88
|
+
initSpecsSuccessAction({
|
|
89
|
+
specs: expected,
|
|
90
|
+
currentSpecKey: currentSpec.key,
|
|
91
|
+
})
|
|
92
|
+
)
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
describe('setCurrentSpecSaga', () => {
|
|
97
|
+
const {
|
|
98
|
+
setCurrentSpecAction,
|
|
99
|
+
setCurrentSpecSuccessAction,
|
|
100
|
+
setCurrentSpecFailureAction,
|
|
101
|
+
} = specActions
|
|
102
|
+
const spec = specState['4.0']
|
|
103
|
+
|
|
104
|
+
it('sends setCurrentSpecSuccessAction on success', async () => {
|
|
105
|
+
jest.spyOn(adaptor, 'fetchSpec').mockResolvedValueOnce(spec)
|
|
106
|
+
|
|
107
|
+
sagaTester.dispatch(setCurrentSpecAction({ currentSpecKey: spec.key }))
|
|
108
|
+
await sagaTester.waitFor('specs/setCurrentSpecAction')
|
|
109
|
+
const calledActions = sagaTester.getCalledActions()
|
|
110
|
+
expect(calledActions).toHaveLength(2)
|
|
111
|
+
expect(calledActions[0]).toEqual(
|
|
112
|
+
setCurrentSpecAction({ currentSpecKey: spec.key })
|
|
113
|
+
)
|
|
114
|
+
expect(calledActions[1]).toEqual(
|
|
115
|
+
setCurrentSpecSuccessAction({
|
|
116
|
+
api: spec.api!,
|
|
117
|
+
currentSpecKey: spec.key,
|
|
118
|
+
})
|
|
119
|
+
)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('sends setCurrentSpecFailureAction on failure', async () => {
|
|
123
|
+
jest.spyOn(adaptor, 'fetchSpec').mockRejectedValueOnce(mockError)
|
|
124
|
+
|
|
125
|
+
sagaTester.dispatch(setCurrentSpecAction({ currentSpecKey: spec.key }))
|
|
126
|
+
await sagaTester.waitFor('specs/setCurrentSpecAction')
|
|
127
|
+
const calledActions = sagaTester.getCalledActions()
|
|
128
|
+
expect(calledActions).toHaveLength(2)
|
|
129
|
+
expect(calledActions[0]).toEqual(
|
|
130
|
+
setCurrentSpecAction({ currentSpecKey: spec.key })
|
|
131
|
+
)
|
|
132
|
+
expect(calledActions[1]).toEqual(setCurrentSpecFailureAction(mockError))
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
})
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2021 Looker Data Sciences, Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
24
|
+
|
|
25
|
+
*/
|
|
26
|
+
import type { SpecItem, SpecList } from '@looker/sdk-codegen'
|
|
27
|
+
import { call, put, takeEvery, select } from 'typed-redux-saga'
|
|
28
|
+
import type { PayloadAction } from '@reduxjs/toolkit'
|
|
29
|
+
|
|
30
|
+
import { getApixAdaptor } from '../../utils'
|
|
31
|
+
import type { RootState } from '../store'
|
|
32
|
+
import type { InitSpecsAction, SetCurrentSpecAction } from './slice'
|
|
33
|
+
import { specActions } from './slice'
|
|
34
|
+
|
|
35
|
+
function* initSaga(action: PayloadAction<InitSpecsAction>) {
|
|
36
|
+
const { initSpecsSuccessAction, initSpecsFailureAction } = specActions
|
|
37
|
+
const adaptor = getApixAdaptor()
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const specs: SpecList = yield* call([adaptor, 'fetchSpecList'])
|
|
41
|
+
let currentSpecKey = action.payload.specKey
|
|
42
|
+
if (!currentSpecKey) {
|
|
43
|
+
currentSpecKey = Object.values(specs).find(
|
|
44
|
+
(spec) => spec.status === 'current'
|
|
45
|
+
)!.key
|
|
46
|
+
}
|
|
47
|
+
const spec = yield* call([adaptor, 'fetchSpec'], specs[currentSpecKey])
|
|
48
|
+
specs[currentSpecKey] = spec
|
|
49
|
+
yield* put(initSpecsSuccessAction({ specs, currentSpecKey }))
|
|
50
|
+
} catch (error: any) {
|
|
51
|
+
yield* put(initSpecsFailureAction(new Error(error.message)))
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function* setCurrentSpecSaga(action: PayloadAction<SetCurrentSpecAction>) {
|
|
56
|
+
const { setCurrentSpecSuccessAction, setCurrentSpecFailureAction } =
|
|
57
|
+
specActions
|
|
58
|
+
const adaptor = getApixAdaptor()
|
|
59
|
+
const spec: SpecItem = yield* select(
|
|
60
|
+
(state: RootState) => state.specs.specs[action.payload.currentSpecKey]
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const newSpec = yield* call([adaptor, 'fetchSpec'], spec)
|
|
65
|
+
yield* put(
|
|
66
|
+
setCurrentSpecSuccessAction({
|
|
67
|
+
api: newSpec.api!,
|
|
68
|
+
currentSpecKey: action.payload.currentSpecKey,
|
|
69
|
+
})
|
|
70
|
+
)
|
|
71
|
+
} catch (error: any) {
|
|
72
|
+
yield put(setCurrentSpecFailureAction(new Error(error.message)))
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function* saga() {
|
|
77
|
+
const { initSpecsAction, setCurrentSpecAction } = specActions
|
|
78
|
+
|
|
79
|
+
yield* takeEvery(initSpecsAction, initSaga)
|
|
80
|
+
yield* takeEvery(setCurrentSpecAction, setCurrentSpecSaga)
|
|
81
|
+
}
|
|
@@ -23,14 +23,15 @@
|
|
|
23
23
|
SOFTWARE.
|
|
24
24
|
|
|
25
25
|
*/
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
import type { SpecItem } from '@looker/sdk-codegen'
|
|
27
|
+
|
|
28
|
+
import type { RootState } from '../store'
|
|
29
|
+
|
|
30
|
+
const selectSpecsState = (state: RootState) => state.specs
|
|
31
|
+
|
|
32
|
+
export const selectSpecs = (state: RootState) => selectSpecsState(state).specs
|
|
33
|
+
|
|
34
|
+
export const selectCurrentSpec = (state: RootState): SpecItem => {
|
|
35
|
+
const specState = selectSpecsState(state)
|
|
36
|
+
return specState.specs[specState.currentSpecKey]
|
|
37
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2021 Looker Data Sciences, Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
24
|
+
|
|
25
|
+
*/
|
|
26
|
+
import type { PayloadAction } from '@reduxjs/toolkit'
|
|
27
|
+
import { createSlice } from '@reduxjs/toolkit'
|
|
28
|
+
import type { ApiModel, SpecList } from '@looker/sdk-codegen'
|
|
29
|
+
import { createSliceHooks } from '@looker/redux'
|
|
30
|
+
|
|
31
|
+
import { saga } from './sagas'
|
|
32
|
+
|
|
33
|
+
export interface SpecState {
|
|
34
|
+
specs: SpecList
|
|
35
|
+
currentSpecKey: string
|
|
36
|
+
error?: Error
|
|
37
|
+
working: boolean
|
|
38
|
+
description?: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const defaultSpecsState: SpecState = {
|
|
42
|
+
specs: {},
|
|
43
|
+
currentSpecKey: '',
|
|
44
|
+
working: true,
|
|
45
|
+
description: undefined,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface InitSpecsAction {
|
|
49
|
+
specKey: string | null
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface InitSpecsSuccessPayload {
|
|
53
|
+
specs: SpecList
|
|
54
|
+
currentSpecKey: string
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface SetCurrentSpecAction {
|
|
58
|
+
currentSpecKey: string
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface SetCurrentSpecSuccessAction {
|
|
62
|
+
api: ApiModel
|
|
63
|
+
currentSpecKey: string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const specsSlice = createSlice({
|
|
67
|
+
name: 'specs',
|
|
68
|
+
initialState: defaultSpecsState,
|
|
69
|
+
reducers: {
|
|
70
|
+
initSpecsAction(state, _action: PayloadAction<InitSpecsAction>) {
|
|
71
|
+
state.working = true
|
|
72
|
+
state.description = 'Fetching specifications...'
|
|
73
|
+
},
|
|
74
|
+
initSpecsSuccessAction(
|
|
75
|
+
state,
|
|
76
|
+
action: PayloadAction<InitSpecsSuccessPayload>
|
|
77
|
+
) {
|
|
78
|
+
state.specs = action.payload.specs
|
|
79
|
+
state.currentSpecKey = action.payload.currentSpecKey
|
|
80
|
+
state.working = false
|
|
81
|
+
state.description = undefined
|
|
82
|
+
},
|
|
83
|
+
initSpecsFailureAction(state, action: PayloadAction<Error>) {
|
|
84
|
+
state.working = false
|
|
85
|
+
state.error = action.payload
|
|
86
|
+
},
|
|
87
|
+
setCurrentSpecAction(state, action: PayloadAction<SetCurrentSpecAction>) {
|
|
88
|
+
state.working = true
|
|
89
|
+
state.description = `Fetching API ${action.payload.currentSpecKey} spec`
|
|
90
|
+
},
|
|
91
|
+
setCurrentSpecSuccessAction(
|
|
92
|
+
state,
|
|
93
|
+
action: PayloadAction<SetCurrentSpecSuccessAction>
|
|
94
|
+
) {
|
|
95
|
+
state.currentSpecKey = action.payload.currentSpecKey
|
|
96
|
+
state.specs[state.currentSpecKey].api = action.payload.api
|
|
97
|
+
state.description = undefined
|
|
98
|
+
state.working = false
|
|
99
|
+
},
|
|
100
|
+
setCurrentSpecFailureAction(state, action: PayloadAction<Error>) {
|
|
101
|
+
state.working = false
|
|
102
|
+
state.error = action.payload
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
export const specActions = specsSlice.actions
|
|
108
|
+
export const { useActions: useSpecActions, useStoreState: useSpecStoreState } =
|
|
109
|
+
createSliceHooks(specsSlice, saga)
|
package/src/state/store.ts
CHANGED
|
@@ -24,24 +24,82 @@
|
|
|
24
24
|
|
|
25
25
|
*/
|
|
26
26
|
import { createStore } from '@looker/redux'
|
|
27
|
+
import type { PayloadAction } from '@reduxjs/toolkit'
|
|
28
|
+
import type { Action } from 'redux'
|
|
29
|
+
import map from 'lodash/map'
|
|
30
|
+
import type { SpecList } from '@looker/sdk-codegen'
|
|
27
31
|
|
|
28
32
|
import type { SettingState } from './settings'
|
|
29
33
|
import { defaultSettingsState, settingsSlice } from './settings'
|
|
30
34
|
import type { LodesState } from './lodes'
|
|
31
35
|
import { lodesSlice, defaultLodesState } from './lodes'
|
|
36
|
+
import type { SpecState, InitSpecsSuccessPayload } from './specs'
|
|
37
|
+
import { defaultSpecsState, specsSlice } from './specs'
|
|
38
|
+
|
|
39
|
+
const isInitSuccessAction = (
|
|
40
|
+
action: any
|
|
41
|
+
): action is PayloadAction<InitSpecsSuccessPayload> => !!action.payload?.specs
|
|
42
|
+
|
|
43
|
+
const actionSanitizer = <A extends Partial<Action>>(
|
|
44
|
+
action: A,
|
|
45
|
+
_id: number
|
|
46
|
+
): A => {
|
|
47
|
+
if (isInitSuccessAction(action)) {
|
|
48
|
+
action = {
|
|
49
|
+
...action,
|
|
50
|
+
payload: {
|
|
51
|
+
...action.payload,
|
|
52
|
+
specs: sanitizeSpecs(action.payload.specs),
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return action
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const stateSanitizer = <S extends Partial<RootState>>(
|
|
60
|
+
state: S,
|
|
61
|
+
_index: number
|
|
62
|
+
): S => {
|
|
63
|
+
if (state.specs) {
|
|
64
|
+
return {
|
|
65
|
+
...state,
|
|
66
|
+
specs: {
|
|
67
|
+
...state.specs,
|
|
68
|
+
specs: sanitizeSpecs(state.specs.specs),
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return state
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const sanitizeSpecs = (specList: SpecList) =>
|
|
76
|
+
map(specList, (spec) => ({
|
|
77
|
+
...spec,
|
|
78
|
+
api: spec.api ? '<api>' : undefined,
|
|
79
|
+
specContent: spec.specContent ? '<specContent>' : undefined,
|
|
80
|
+
})) as unknown as SpecList
|
|
81
|
+
|
|
82
|
+
const devTools =
|
|
83
|
+
process.env.NODE_ENV !== 'production'
|
|
84
|
+
? { actionSanitizer, stateSanitizer }
|
|
85
|
+
: false
|
|
32
86
|
|
|
33
87
|
export const store = createStore({
|
|
88
|
+
devTools,
|
|
34
89
|
preloadedState: {
|
|
35
90
|
settings: defaultSettingsState,
|
|
36
91
|
lodes: defaultLodesState,
|
|
92
|
+
specs: defaultSpecsState,
|
|
37
93
|
},
|
|
38
94
|
reducer: {
|
|
39
95
|
settings: settingsSlice.reducer,
|
|
40
96
|
lodes: lodesSlice.reducer,
|
|
97
|
+
specs: specsSlice.reducer,
|
|
41
98
|
},
|
|
42
99
|
})
|
|
43
100
|
|
|
44
101
|
export interface RootState {
|
|
45
102
|
settings: SettingState
|
|
46
103
|
lodes: LodesState
|
|
104
|
+
specs: SpecState
|
|
47
105
|
}
|
package/src/test-data/index.ts
CHANGED
package/src/test-data/specs.ts
CHANGED
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
*/
|
|
26
26
|
import type { SpecList } from '@looker/sdk-codegen'
|
|
27
27
|
import { ApiModel } from '@looker/sdk-codegen'
|
|
28
|
-
|
|
29
|
-
import {
|
|
28
|
+
import type { SpecState } from '../state'
|
|
29
|
+
import { defaultSpecsState } from '../state'
|
|
30
30
|
|
|
31
31
|
export const specs: SpecList = {
|
|
32
32
|
'3.1': {
|
|
@@ -47,8 +47,6 @@ export const specs: SpecList = {
|
|
|
47
47
|
},
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
export const specState = initDefaultSpecState(specs, window.location)
|
|
51
|
-
|
|
52
50
|
export const api = ApiModel.fromJson(specs['3.1'].specContent)
|
|
53
51
|
export const api40 = ApiModel.fromJson(specs['4.0'].specContent)
|
|
54
52
|
|
|
@@ -59,5 +57,7 @@ export const getLoadedSpecs = () => {
|
|
|
59
57
|
return loadedSpecs
|
|
60
58
|
}
|
|
61
59
|
|
|
62
|
-
export const
|
|
63
|
-
|
|
60
|
+
export const specState: SpecState = {
|
|
61
|
+
...defaultSpecsState,
|
|
62
|
+
specs: getLoadedSpecs(),
|
|
63
|
+
}
|
package/src/test-utils/redux.tsx
CHANGED
|
@@ -34,19 +34,21 @@ import { createStore } from '@looker/redux'
|
|
|
34
34
|
import { BrowserAdaptor, registerEnvAdaptor } from '@looker/extension-utils'
|
|
35
35
|
import { initRunItSdk } from '@looker/run-it'
|
|
36
36
|
|
|
37
|
-
import type { LodesState, RootState, SettingState } from '../state'
|
|
37
|
+
import type { LodesState, RootState, SettingState, SpecState } from '../state'
|
|
38
38
|
import {
|
|
39
39
|
settingsSlice,
|
|
40
40
|
defaultLodesState,
|
|
41
41
|
defaultSettingsState,
|
|
42
|
-
store as defaultStore,
|
|
43
42
|
lodesSlice,
|
|
43
|
+
defaultSpecsState,
|
|
44
|
+
specsSlice,
|
|
44
45
|
} from '../state'
|
|
46
|
+
import { specState } from '../test-data'
|
|
45
47
|
import { renderWithRouter } from './router'
|
|
46
48
|
|
|
47
49
|
export const withReduxProvider = (
|
|
48
50
|
consumers: ReactElement<any>,
|
|
49
|
-
store: Store<RootState> =
|
|
51
|
+
store: Store<RootState> = createTestStore()
|
|
50
52
|
) => {
|
|
51
53
|
registerEnvAdaptor(new BrowserAdaptor(initRunItSdk()))
|
|
52
54
|
return <Provider store={store}>{consumers}</Provider>
|
|
@@ -69,6 +71,7 @@ export const renderWithRouterAndReduxProvider = (
|
|
|
69
71
|
export const preloadedState: RootState = {
|
|
70
72
|
settings: defaultSettingsState,
|
|
71
73
|
lodes: defaultLodesState,
|
|
74
|
+
specs: defaultSpecsState,
|
|
72
75
|
}
|
|
73
76
|
|
|
74
77
|
type DeepPartial<T> = {
|
|
@@ -86,6 +89,14 @@ export const createTestStore = (overrides?: DeepPartial<RootState>) =>
|
|
|
86
89
|
...defaultLodesState,
|
|
87
90
|
...overrides?.lodes,
|
|
88
91
|
} as LodesState,
|
|
92
|
+
specs: {
|
|
93
|
+
...specState,
|
|
94
|
+
...overrides?.specs,
|
|
95
|
+
} as SpecState,
|
|
96
|
+
},
|
|
97
|
+
reducer: {
|
|
98
|
+
settings: settingsSlice.reducer,
|
|
99
|
+
lodes: lodesSlice.reducer,
|
|
100
|
+
specs: specsSlice.reducer,
|
|
89
101
|
},
|
|
90
|
-
reducer: { settings: settingsSlice.reducer, lodes: lodesSlice.reducer },
|
|
91
102
|
})
|