@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
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
import type { FC } from 'react'
|
|
28
28
|
import React, { useState, useEffect } from 'react'
|
|
29
|
-
import type { ApiModel, DiffRow, SpecList
|
|
29
|
+
import type { ApiModel, DiffRow, SpecList } from '@looker/sdk-codegen'
|
|
30
30
|
import { useHistory, useRouteMatch } from 'react-router-dom'
|
|
31
31
|
import {
|
|
32
32
|
Box,
|
|
@@ -38,35 +38,14 @@ import {
|
|
|
38
38
|
SelectMulti,
|
|
39
39
|
} from '@looker/components'
|
|
40
40
|
import { SyncAlt } from '@styled-icons/material/SyncAlt'
|
|
41
|
-
import {
|
|
42
|
-
|
|
43
|
-
import { diffPath } from '../../utils'
|
|
41
|
+
import { useSelector } from 'react-redux'
|
|
42
|
+
|
|
44
43
|
import { ApixSection } from '../../components'
|
|
44
|
+
import { selectCurrentSpec } from '../../state'
|
|
45
|
+
import { diffPath, getApixAdaptor } from '../../utils'
|
|
45
46
|
import { diffSpecs, standardDiffToggles } from './diffUtils'
|
|
46
47
|
import { DocDiff } from './DocDiff'
|
|
47
48
|
|
|
48
|
-
/**
|
|
49
|
-
* Pick the left key, or default spec
|
|
50
|
-
* @param specs to pick from
|
|
51
|
-
* @param leftKey spec key that may or may not have a value
|
|
52
|
-
*/
|
|
53
|
-
const pickLeft = (specs: SpecList, leftKey: string) => {
|
|
54
|
-
if (leftKey) return leftKey
|
|
55
|
-
return getDefaultSpecKey(specs)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Pick the right key, or "other" spec
|
|
60
|
-
* @param specs to pick from
|
|
61
|
-
* @param rightKey spec key from url path
|
|
62
|
-
* @param leftKey spec key from url path
|
|
63
|
-
*/
|
|
64
|
-
const pickRight = (specs: SpecList, rightKey: string, leftKey: string) => {
|
|
65
|
-
if (rightKey) return rightKey
|
|
66
|
-
if (!leftKey) leftKey = getDefaultSpecKey(specs)
|
|
67
|
-
return Object.keys(specs).find((k) => k !== leftKey) || ''
|
|
68
|
-
}
|
|
69
|
-
|
|
70
49
|
const diffToggles = [
|
|
71
50
|
{
|
|
72
51
|
label: 'Missing',
|
|
@@ -104,7 +83,10 @@ const validateParam = (specs: SpecList, specKey = '') => {
|
|
|
104
83
|
}
|
|
105
84
|
|
|
106
85
|
export const DiffScene: FC<DiffSceneProps> = ({ specs, toggleNavigation }) => {
|
|
86
|
+
const adaptor = getApixAdaptor()
|
|
107
87
|
const history = useHistory()
|
|
88
|
+
const spec = useSelector(selectCurrentSpec)
|
|
89
|
+
const currentSpecKey = spec.key
|
|
108
90
|
const match = useRouteMatch<{ l: string; r: string }>(`/${diffPath}/:l?/:r?`)
|
|
109
91
|
const l = validateParam(specs, match?.params.l)
|
|
110
92
|
const r = validateParam(specs, match?.params.r)
|
|
@@ -114,83 +96,62 @@ export const DiffScene: FC<DiffSceneProps> = ({ specs, toggleNavigation }) => {
|
|
|
114
96
|
label: `${key} (${spec.status})`,
|
|
115
97
|
}))
|
|
116
98
|
|
|
117
|
-
const [leftKey, setLeftKey] = useState<string>(
|
|
118
|
-
const [rightKey, setRightKey] = useState<string>(
|
|
99
|
+
const [leftKey, setLeftKey] = useState<string>(l || currentSpecKey)
|
|
100
|
+
const [rightKey, setRightKey] = useState<string>(r || '')
|
|
119
101
|
const [leftApi, setLeftApi] = useState<ApiModel>(specs[leftKey].api!)
|
|
120
|
-
const [rightApi, setRightApi] = useState<ApiModel>(
|
|
102
|
+
const [rightApi, setRightApi] = useState<ApiModel>(() =>
|
|
121
103
|
rightKey ? specs[rightKey].api! : specs[leftKey].api!
|
|
122
104
|
)
|
|
123
105
|
const [toggles, setToggles] = useState<string[]>(standardDiffToggles)
|
|
124
106
|
|
|
125
107
|
useEffect(() => {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const computeDelta = (left: string, right: string, toggles: string[]) => {
|
|
130
|
-
if (left && right && specs[left].api && specs[right].api) {
|
|
131
|
-
return diffSpecs(specs[left].api!, specs[right].api!, toggles)
|
|
108
|
+
if (r !== rightKey) {
|
|
109
|
+
setRightKey(r)
|
|
132
110
|
}
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
const [delta, setDelta] = useState<DiffRow[]>(
|
|
136
|
-
computeDelta(leftKey, rightKey, toggles)
|
|
137
|
-
)
|
|
111
|
+
}, [r, rightKey])
|
|
138
112
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
setter: (spec: SpecItem) => void
|
|
143
|
-
) => {
|
|
144
|
-
const spec = specs[key]
|
|
145
|
-
if (!spec.api) {
|
|
146
|
-
try {
|
|
147
|
-
const newSpec = { ...spec }
|
|
148
|
-
const api = await fallbackFetch(newSpec, funFetch)
|
|
149
|
-
if (api) {
|
|
150
|
-
spec.api = api
|
|
151
|
-
setter(spec)
|
|
152
|
-
}
|
|
153
|
-
} catch (error) {
|
|
154
|
-
console.error(error)
|
|
155
|
-
}
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (l !== leftKey) {
|
|
115
|
+
setLeftKey(l)
|
|
156
116
|
}
|
|
157
|
-
}
|
|
117
|
+
}, [l, leftKey])
|
|
158
118
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
await loadSpec(specs, leftKey, (spec) => setLeftApi(spec.api!))
|
|
165
|
-
}
|
|
166
|
-
if (!specs[right].api) {
|
|
167
|
-
await loadSpec(specs, rightKey, (spec) => setRightApi(spec.api!))
|
|
168
|
-
}
|
|
169
|
-
setDelta([...computeDelta(left, right, toggles)])
|
|
170
|
-
}
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
toggleNavigation(false)
|
|
121
|
+
}, [])
|
|
122
|
+
|
|
123
|
+
const [delta, setDelta] = useState<DiffRow[]>([])
|
|
171
124
|
|
|
172
125
|
const handleLeftChange = (newLeft: string) => {
|
|
173
|
-
|
|
126
|
+
history.push(`/${diffPath}/${newLeft}/${rightKey}`)
|
|
127
|
+
}
|
|
128
|
+
const handleRightChange = (newRight: string) => {
|
|
129
|
+
history.push(`/${diffPath}/${leftKey}/${newRight}`)
|
|
174
130
|
}
|
|
175
131
|
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
setToggles(newToggles)
|
|
179
|
-
setDelta([...computeDelta(leftKey, rightKey, newToggles)])
|
|
132
|
+
const handleSwitch = () => {
|
|
133
|
+
history.push(`/${diffPath}/${rightKey}/${leftKey}`)
|
|
180
134
|
}
|
|
181
135
|
|
|
182
136
|
useEffect(() => {
|
|
183
|
-
|
|
184
|
-
}, [leftKey
|
|
137
|
+
adaptor.fetchSpec(specs[leftKey]).then((spec) => setLeftApi(spec.api!))
|
|
138
|
+
}, [leftKey])
|
|
185
139
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (rightKey in specs) {
|
|
142
|
+
adaptor.fetchSpec(specs[rightKey]).then((spec) => setRightApi(spec.api!))
|
|
143
|
+
}
|
|
144
|
+
}, [rightKey])
|
|
189
145
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
if (leftApi && rightApi) {
|
|
148
|
+
setDelta([...diffSpecs(leftApi, rightApi, toggles)])
|
|
149
|
+
}
|
|
150
|
+
}, [leftApi, rightApi, toggles])
|
|
151
|
+
|
|
152
|
+
const handleTogglesChange = (values?: string[]) => {
|
|
153
|
+
const newToggles = values || []
|
|
154
|
+
setToggles(newToggles)
|
|
194
155
|
}
|
|
195
156
|
|
|
196
157
|
return (
|
|
@@ -211,6 +172,7 @@ export const DiffScene: FC<DiffSceneProps> = ({ specs, toggleNavigation }) => {
|
|
|
211
172
|
<IconButton
|
|
212
173
|
label="switch"
|
|
213
174
|
size="small"
|
|
175
|
+
disabled={!leftKey || !rightKey}
|
|
214
176
|
icon={<SyncAlt />}
|
|
215
177
|
mt="medium"
|
|
216
178
|
onClick={handleSwitch}
|
|
@@ -221,6 +183,7 @@ export const DiffScene: FC<DiffSceneProps> = ({ specs, toggleNavigation }) => {
|
|
|
221
183
|
mt="xxsmall"
|
|
222
184
|
id="compare"
|
|
223
185
|
name="Right Version"
|
|
186
|
+
placeholder="Select a comparison..."
|
|
224
187
|
value={rightKey}
|
|
225
188
|
options={options}
|
|
226
189
|
onChange={handleRightChange}
|
|
@@ -28,8 +28,7 @@ import { Router } from 'react-router'
|
|
|
28
28
|
import type { MemoryHistory } from 'history'
|
|
29
29
|
import { createMemoryHistory } from 'history'
|
|
30
30
|
import { renderWithTheme } from '@looker/components-test-utils'
|
|
31
|
-
import
|
|
32
|
-
import { act, screen } from '@testing-library/react'
|
|
31
|
+
import { screen, fireEvent } from '@testing-library/react'
|
|
33
32
|
import { api } from '../../../test-data'
|
|
34
33
|
import { DiffMethodLink } from './DiffItem'
|
|
35
34
|
|
|
@@ -37,27 +36,24 @@ describe('DiffMethodLink', () => {
|
|
|
37
36
|
const method = api.methods.create_dashboard
|
|
38
37
|
const specKey = '4.0'
|
|
39
38
|
let history: MemoryHistory
|
|
40
|
-
let pushSpy: jasmine.Spy
|
|
41
39
|
|
|
42
40
|
beforeEach(() => {
|
|
43
41
|
history = createMemoryHistory()
|
|
44
|
-
pushSpy = spyOn(history, 'push')
|
|
45
42
|
})
|
|
46
43
|
|
|
47
44
|
test('it renders method and navigates on click', () => {
|
|
45
|
+
const pushSpy = jest.spyOn(history, 'push')
|
|
48
46
|
renderWithTheme(
|
|
49
47
|
<Router history={history}>
|
|
50
48
|
<DiffMethodLink method={method} specKey={specKey} />
|
|
51
49
|
</Router>
|
|
52
50
|
)
|
|
53
|
-
const
|
|
54
|
-
expect(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
)
|
|
60
|
-
})
|
|
51
|
+
const link = screen.getByRole('link')
|
|
52
|
+
expect(link).toHaveTextContent(`${method.name} for ${specKey}`)
|
|
53
|
+
fireEvent.click(link)
|
|
54
|
+
expect(pushSpy).toHaveBeenCalledWith(
|
|
55
|
+
`/${specKey}/methods/${method.schema.tags[0]}/${method.name}`
|
|
56
|
+
)
|
|
61
57
|
})
|
|
62
58
|
|
|
63
59
|
test('it renders missing method and does not navigate on click', () => {
|
|
@@ -68,9 +64,6 @@ describe('DiffMethodLink', () => {
|
|
|
68
64
|
)
|
|
69
65
|
const s = `Missing in ${specKey}`
|
|
70
66
|
expect(screen.getByText(s)).toBeInTheDocument()
|
|
71
|
-
|
|
72
|
-
act(() => {
|
|
73
|
-
expect(pushSpy).not.toHaveBeenCalled()
|
|
74
|
-
})
|
|
67
|
+
expect(screen.queryByRole('link')).not.toBeInTheDocument()
|
|
75
68
|
})
|
|
76
69
|
})
|
|
@@ -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
|
+
}
|