@looker/api-explorer 0.9.26 → 0.9.29
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 +80 -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/DocPseudo/DocParam.js +3 -1
- package/lib/components/DocPseudo/DocParam.js.map +1 -1
- 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/DocPseudo/DocParam.js +2 -1
- package/lib/esm/components/DocPseudo/DocParam.js.map +1 -1
- 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/DocPseudo/DocParam.spec.tsx +2 -1
- package/src/components/DocPseudo/DocParam.tsx +2 -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
|
@@ -1,69 +0,0 @@
|
|
|
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
|
-
|
|
27
|
-
import type { SpecItem, SpecList } from '@looker/sdk-codegen'
|
|
28
|
-
import { ApiModel } from '@looker/sdk-codegen'
|
|
29
|
-
import type { ApiUpdatePayload } from './actions'
|
|
30
|
-
import type { SpecAction } from '.'
|
|
31
|
-
import { Actions } from '.'
|
|
32
|
-
|
|
33
|
-
export interface SpecState {
|
|
34
|
-
specList: SpecList
|
|
35
|
-
spec: SpecItem
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const specReducer = (
|
|
39
|
-
state: SpecState,
|
|
40
|
-
action: SpecAction
|
|
41
|
-
): SpecState => {
|
|
42
|
-
const { type, payload } = action
|
|
43
|
-
switch (type) {
|
|
44
|
-
case Actions.UPDATE_SPEC_API: {
|
|
45
|
-
const specList = { ...state.specList }
|
|
46
|
-
const { specKey, api } = payload as ApiUpdatePayload
|
|
47
|
-
let spec = specList[specKey]
|
|
48
|
-
if (spec) {
|
|
49
|
-
spec = { ...spec, api }
|
|
50
|
-
specList[specKey] = spec
|
|
51
|
-
}
|
|
52
|
-
return { specList, spec }
|
|
53
|
-
}
|
|
54
|
-
case 'SELECT_SPEC': {
|
|
55
|
-
const newState = { ...state }
|
|
56
|
-
const spec = newState.specList[payload as string]
|
|
57
|
-
// Does extension API Explorer needs this?
|
|
58
|
-
if (spec) {
|
|
59
|
-
if (!spec.api && spec.specContent) {
|
|
60
|
-
spec.api = ApiModel.fromJson(spec.specContent)
|
|
61
|
-
}
|
|
62
|
-
return { ...state, spec }
|
|
63
|
-
}
|
|
64
|
-
return state
|
|
65
|
-
}
|
|
66
|
-
default:
|
|
67
|
-
return state
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
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 { SpecList } from '@looker/sdk-codegen'
|
|
27
|
-
import omit from 'lodash/omit'
|
|
28
|
-
|
|
29
|
-
import { specs } from '../../test-data'
|
|
30
|
-
import { getDefaultSpecKey, initDefaultSpecState, getSpecKey } from './utils'
|
|
31
|
-
|
|
32
|
-
describe('Spec reducer utils', () => {
|
|
33
|
-
const specList: SpecList = {
|
|
34
|
-
defaultKey: {
|
|
35
|
-
key: 'defaultKey',
|
|
36
|
-
version: '4.0',
|
|
37
|
-
status: 'experimental',
|
|
38
|
-
isDefault: true,
|
|
39
|
-
},
|
|
40
|
-
deprecatedKey: {
|
|
41
|
-
key: 'deprecatedKey',
|
|
42
|
-
version: '3.0',
|
|
43
|
-
status: 'deprecated',
|
|
44
|
-
isDefault: false,
|
|
45
|
-
},
|
|
46
|
-
currentKey: {
|
|
47
|
-
key: 'currentKey',
|
|
48
|
-
version: '3.1',
|
|
49
|
-
status: 'current',
|
|
50
|
-
isDefault: false,
|
|
51
|
-
},
|
|
52
|
-
stableKey: {
|
|
53
|
-
key: 'stableKey',
|
|
54
|
-
version: '3.1',
|
|
55
|
-
status: 'stable',
|
|
56
|
-
isDefault: false,
|
|
57
|
-
},
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
describe('getSpecKey', () => {
|
|
61
|
-
const saveLocation = window.location
|
|
62
|
-
|
|
63
|
-
afterAll(() => {
|
|
64
|
-
window.location = saveLocation
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
test('recognizes spec version in url', () => {
|
|
68
|
-
window.history.pushState({}, '', '/4.0/')
|
|
69
|
-
const specKey = getSpecKey(window.location)
|
|
70
|
-
expect(specKey).toBeDefined()
|
|
71
|
-
expect(specKey).toEqual('4.0')
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
test('ignores oauth as a spec key', () => {
|
|
75
|
-
window.history.pushState({}, '', '/oauth/')
|
|
76
|
-
const specKey = getSpecKey(window.location)
|
|
77
|
-
expect(specKey).toEqual('')
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
test('gets default spec key when specs are provided and url has no path', () => {
|
|
81
|
-
window.history.pushState({}, '', '')
|
|
82
|
-
const specKey = getSpecKey(window.location, specList)
|
|
83
|
-
expect(specKey).toBeDefined()
|
|
84
|
-
expect(specKey).toEqual('defaultKey')
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
test('gets default spec key when specs are provided and url has oauth path', () => {
|
|
88
|
-
window.history.pushState({}, '', '/oauth/')
|
|
89
|
-
const specKey = getSpecKey(window.location, specList)
|
|
90
|
-
expect(specKey).toBeDefined()
|
|
91
|
-
expect(specKey).toEqual('defaultKey')
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
describe('getDefaultSpecKey', () => {
|
|
96
|
-
test('it throws if no specs are provided', () => {
|
|
97
|
-
expect(() => {
|
|
98
|
-
getDefaultSpecKey({} as SpecList)
|
|
99
|
-
}).toThrow('No specs found.')
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
test('it returns specKey for default spec if found', () => {
|
|
103
|
-
expect(getDefaultSpecKey(specList)).toEqual('defaultKey')
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
test('it returns specKey for spec marked as current if none are marked as default', () => {
|
|
107
|
-
const specItems = omit(specList, 'defaultKey')
|
|
108
|
-
expect(getDefaultSpecKey(specItems)).toEqual('currentKey')
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
test('it returns first spec if no spec is marked as default or current', () => {
|
|
112
|
-
const specItems = omit(specList, ['defaultKey', 'currentKey'])
|
|
113
|
-
expect(getDefaultSpecKey(specItems)).toEqual('deprecatedKey')
|
|
114
|
-
})
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
describe('initDefaultSpecState', () => {
|
|
118
|
-
const saveLocation = window.location
|
|
119
|
-
|
|
120
|
-
afterAll(() => {
|
|
121
|
-
window.location = saveLocation
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
test('it fetches spec using key defined in url', () => {
|
|
125
|
-
window.history.pushState({}, '', '/4.0/')
|
|
126
|
-
const specState = initDefaultSpecState(specs, window.location)
|
|
127
|
-
expect(specState).toBeDefined()
|
|
128
|
-
expect(specState.spec.key).toEqual('4.0')
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
test('it gets default spec if url does not specify a key', () => {
|
|
132
|
-
window.history.pushState({}, '', '/')
|
|
133
|
-
const specState = initDefaultSpecState(specs, window.location)
|
|
134
|
-
expect(specState).toBeDefined()
|
|
135
|
-
expect(specState.spec.key).toEqual('4.0')
|
|
136
|
-
})
|
|
137
|
-
})
|
|
138
|
-
})
|
|
@@ -1,123 +0,0 @@
|
|
|
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
|
-
|
|
27
|
-
import type { SpecList } from '@looker/sdk-codegen'
|
|
28
|
-
import type { Location as HLocation } from 'history'
|
|
29
|
-
import { OAuthSession } from '@looker/sdk-rtl'
|
|
30
|
-
import { diffPath, oAuthPath } from '../../utils'
|
|
31
|
-
import type { SpecState } from './reducer'
|
|
32
|
-
|
|
33
|
-
export type AbstractLocation = HLocation | Location
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Given a collection of specs, it returns the spec marked as default, the one
|
|
37
|
-
* marked as current or the first one, in that order.
|
|
38
|
-
* @param specs A collection of specs
|
|
39
|
-
* @returns A spec
|
|
40
|
-
*/
|
|
41
|
-
export const getDefaultSpecKey = (specs: SpecList): string => {
|
|
42
|
-
const items = Object.entries(specs)
|
|
43
|
-
|
|
44
|
-
if (items.length === 0) {
|
|
45
|
-
throw Error('No specs found.')
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
let specKey = ''
|
|
49
|
-
items.forEach(([key, item]) => {
|
|
50
|
-
if (item.isDefault) {
|
|
51
|
-
specKey = key
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
if (!specKey) {
|
|
56
|
-
items.forEach(([key, item]) => {
|
|
57
|
-
if (item.status === 'current') {
|
|
58
|
-
specKey = key
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (!specKey) {
|
|
64
|
-
specKey = Object.keys(specs)[0]
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (!specKey) {
|
|
68
|
-
throw Error('No specs found.')
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return specKey
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Determine the API specification key from URL pattern or default spec
|
|
76
|
-
* @param location service to examine
|
|
77
|
-
* @param specs to use to find the default spec key
|
|
78
|
-
*/
|
|
79
|
-
export const getSpecKey = (location: AbstractLocation, specs?: SpecList) => {
|
|
80
|
-
let pathName = location.pathname
|
|
81
|
-
if (pathName === `/${oAuthPath}`) {
|
|
82
|
-
const returnUrl = sessionStorage.getItem(OAuthSession.returnUrlKey)
|
|
83
|
-
if (returnUrl) {
|
|
84
|
-
pathName = returnUrl
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
const pathNodes = pathName.split('/')
|
|
88
|
-
let specKey = ''
|
|
89
|
-
if (
|
|
90
|
-
pathNodes.length > 1 &&
|
|
91
|
-
pathNodes[1] &&
|
|
92
|
-
pathNodes[1] !== oAuthPath &&
|
|
93
|
-
pathNodes[1] !== diffPath
|
|
94
|
-
) {
|
|
95
|
-
specKey = pathNodes[1]
|
|
96
|
-
} else if (specs) {
|
|
97
|
-
specKey = getDefaultSpecKey(specs)
|
|
98
|
-
}
|
|
99
|
-
return specKey
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Creates a default state object with the spec matching the specKey defined
|
|
104
|
-
* in the url or the default criteria in getDefaultSpecKey
|
|
105
|
-
* @param specList A collection of specs
|
|
106
|
-
* @param location Standalone or extension location
|
|
107
|
-
* @returns An object to be used as default state
|
|
108
|
-
*/
|
|
109
|
-
export const initDefaultSpecState = (
|
|
110
|
-
specList: SpecList,
|
|
111
|
-
location: AbstractLocation
|
|
112
|
-
): SpecState => {
|
|
113
|
-
const specKey = getSpecKey(location, specList)
|
|
114
|
-
// Handle bad spec in the URL. Fall back to 4.0
|
|
115
|
-
let spec = specList[specKey]
|
|
116
|
-
if (!spec) {
|
|
117
|
-
spec = specList['4.0']
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
specList,
|
|
121
|
-
spec,
|
|
122
|
-
}
|
|
123
|
-
}
|