@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.
Files changed (220) hide show
  1. package/CHANGELOG.md +80 -1
  2. package/e2e/e2e.spec.ts +1 -1
  3. package/lib/ApiExplorer.d.ts +2 -6
  4. package/lib/ApiExplorer.js +53 -74
  5. package/lib/ApiExplorer.js.map +1 -1
  6. package/lib/StandaloneApiExplorer.js +35 -47
  7. package/lib/StandaloneApiExplorer.js.map +1 -1
  8. package/lib/components/Banner/Banner.d.ts +8 -0
  9. package/lib/components/Banner/Banner.js +70 -0
  10. package/lib/components/Banner/Banner.js.map +1 -0
  11. package/lib/components/Banner/index.d.ts +1 -0
  12. package/lib/components/Banner/index.js +14 -0
  13. package/lib/components/Banner/index.js.map +1 -0
  14. package/lib/components/DocPseudo/DocParam.js +3 -1
  15. package/lib/components/DocPseudo/DocParam.js.map +1 -1
  16. package/lib/components/DocSDKs/DocSDKs.js +3 -3
  17. package/lib/components/DocSDKs/DocSDKs.js.map +1 -1
  18. package/lib/components/ExploreType/ExploreType.js +3 -5
  19. package/lib/components/ExploreType/ExploreType.js.map +1 -1
  20. package/lib/components/Header/Header.d.ts +2 -5
  21. package/lib/components/Header/Header.js +1 -5
  22. package/lib/components/Header/Header.js.map +1 -1
  23. package/lib/components/SelectorContainer/ApiSpecSelector.d.ts +2 -5
  24. package/lib/components/SelectorContainer/ApiSpecSelector.js +5 -5
  25. package/lib/components/SelectorContainer/ApiSpecSelector.js.map +1 -1
  26. package/lib/components/SelectorContainer/SelectorContainer.d.ts +2 -5
  27. package/lib/components/SelectorContainer/SelectorContainer.js +3 -7
  28. package/lib/components/SelectorContainer/SelectorContainer.js.map +1 -1
  29. package/lib/components/SideNav/SideNav.d.ts +2 -5
  30. package/lib/components/SideNav/SideNav.js.map +1 -1
  31. package/lib/components/index.d.ts +1 -0
  32. package/lib/components/index.js +8 -0
  33. package/lib/components/index.js.map +1 -1
  34. package/lib/esm/ApiExplorer.js +54 -74
  35. package/lib/esm/ApiExplorer.js.map +1 -1
  36. package/lib/esm/StandaloneApiExplorer.js +34 -48
  37. package/lib/esm/StandaloneApiExplorer.js.map +1 -1
  38. package/lib/esm/components/Banner/Banner.js +54 -0
  39. package/lib/esm/components/Banner/Banner.js.map +1 -0
  40. package/lib/esm/components/Banner/index.js +2 -0
  41. package/lib/esm/components/Banner/index.js.map +1 -0
  42. package/lib/esm/components/DocPseudo/DocParam.js +2 -1
  43. package/lib/esm/components/DocPseudo/DocParam.js.map +1 -1
  44. package/lib/esm/components/DocSDKs/DocSDKs.js +2 -2
  45. package/lib/esm/components/DocSDKs/DocSDKs.js.map +1 -1
  46. package/lib/esm/components/ExploreType/ExploreType.js +3 -4
  47. package/lib/esm/components/ExploreType/ExploreType.js.map +1 -1
  48. package/lib/esm/components/Header/Header.js +1 -5
  49. package/lib/esm/components/Header/Header.js.map +1 -1
  50. package/lib/esm/components/SelectorContainer/ApiSpecSelector.js +4 -5
  51. package/lib/esm/components/SelectorContainer/ApiSpecSelector.js.map +1 -1
  52. package/lib/esm/components/SelectorContainer/SelectorContainer.js +3 -7
  53. package/lib/esm/components/SelectorContainer/SelectorContainer.js.map +1 -1
  54. package/lib/esm/components/SideNav/SideNav.js.map +1 -1
  55. package/lib/esm/components/index.js +1 -0
  56. package/lib/esm/components/index.js.map +1 -1
  57. package/lib/esm/index.js +1 -0
  58. package/lib/esm/index.js.map +1 -1
  59. package/lib/esm/routes/AppRouter.js +3 -7
  60. package/lib/esm/routes/AppRouter.js.map +1 -1
  61. package/lib/esm/scenes/DiffScene/DiffScene.js +43 -99
  62. package/lib/esm/scenes/DiffScene/DiffScene.js.map +1 -1
  63. package/lib/esm/scenes/DiffScene/DocDiff/DiffItem.js +9 -13
  64. package/lib/esm/scenes/DiffScene/DocDiff/DiffItem.js.map +1 -1
  65. package/lib/esm/scenes/DiffScene/DocDiff/DocDiff.js +2 -2
  66. package/lib/esm/scenes/DiffScene/DocDiff/DocDiff.js.map +1 -1
  67. package/lib/esm/scenes/MethodScene/MethodScene.js +4 -5
  68. package/lib/esm/scenes/MethodScene/MethodScene.js.map +1 -1
  69. package/lib/esm/state/index.js +1 -0
  70. package/lib/esm/state/index.js.map +1 -1
  71. package/lib/esm/state/specs/index.js +3 -0
  72. package/lib/esm/state/specs/index.js.map +1 -0
  73. package/lib/esm/state/specs/sagas.js +58 -0
  74. package/lib/esm/state/specs/sagas.js.map +1 -0
  75. package/lib/esm/state/specs/selectors.js +8 -0
  76. package/lib/esm/state/specs/selectors.js.map +1 -0
  77. package/lib/esm/state/specs/slice.js +55 -0
  78. package/lib/esm/state/specs/slice.js.map +1 -0
  79. package/lib/esm/state/store.js +53 -2
  80. package/lib/esm/state/store.js.map +1 -1
  81. package/lib/esm/test-utils/redux.js +9 -5
  82. package/lib/esm/test-utils/redux.js.map +1 -1
  83. package/lib/esm/utils/adaptorUtils.js +101 -0
  84. package/lib/esm/utils/adaptorUtils.js.map +1 -0
  85. package/lib/esm/utils/apixAdaptor.js +48 -0
  86. package/lib/esm/utils/apixAdaptor.js.map +1 -0
  87. package/lib/esm/utils/index.js +3 -1
  88. package/lib/esm/utils/index.js.map +1 -1
  89. package/lib/esm/utils/path.js +27 -2
  90. package/lib/esm/utils/path.js.map +1 -1
  91. package/lib/index.d.ts +1 -0
  92. package/lib/index.js +13 -0
  93. package/lib/index.js.map +1 -1
  94. package/lib/routes/AppRouter.d.ts +1 -5
  95. package/lib/routes/AppRouter.js +3 -7
  96. package/lib/routes/AppRouter.js.map +1 -1
  97. package/lib/scenes/DiffScene/DiffScene.js +45 -100
  98. package/lib/scenes/DiffScene/DiffScene.js.map +1 -1
  99. package/lib/scenes/DiffScene/DocDiff/DiffItem.js +9 -13
  100. package/lib/scenes/DiffScene/DocDiff/DiffItem.js.map +1 -1
  101. package/lib/scenes/DiffScene/DocDiff/DocDiff.js +2 -2
  102. package/lib/scenes/DiffScene/DocDiff/DocDiff.js.map +1 -1
  103. package/lib/scenes/MethodScene/MethodScene.d.ts +0 -4
  104. package/lib/scenes/MethodScene/MethodScene.js +5 -5
  105. package/lib/scenes/MethodScene/MethodScene.js.map +1 -1
  106. package/lib/state/index.d.ts +1 -0
  107. package/lib/state/index.js +13 -0
  108. package/lib/state/index.js.map +1 -1
  109. package/lib/state/settings/selectors.d.ts +1 -1
  110. package/lib/state/settings/slice.d.ts +1 -1
  111. package/lib/state/specs/index.d.ts +2 -0
  112. package/lib/state/specs/index.js +32 -0
  113. package/lib/state/specs/index.js.map +1 -0
  114. package/lib/state/specs/sagas.d.ts +1 -0
  115. package/lib/state/specs/sagas.js +67 -0
  116. package/lib/state/specs/sagas.js.map +1 -0
  117. package/lib/state/specs/selectors.d.ts +4 -0
  118. package/lib/state/specs/selectors.js +20 -0
  119. package/lib/state/specs/selectors.js.map +1 -0
  120. package/lib/state/specs/slice.d.ts +49 -0
  121. package/lib/state/specs/slice.js +70 -0
  122. package/lib/state/specs/slice.js.map +1 -0
  123. package/lib/state/store.d.ts +3 -0
  124. package/lib/state/store.js +56 -2
  125. package/lib/state/store.js.map +1 -1
  126. package/lib/test-data/declarations.d.ts +2 -0
  127. package/lib/test-data/examples.d.ts +2 -0
  128. package/lib/test-data/index.d.ts +3 -0
  129. package/lib/test-data/index.js +12 -42
  130. package/lib/test-data/index.js.map +1 -1
  131. package/lib/test-data/specs.d.ts +10 -0
  132. package/lib/test-data/specs.js +6 -6
  133. package/lib/test-data/specs.js.map +1 -1
  134. package/lib/test-utils/redux.d.ts +2 -1
  135. package/lib/test-utils/redux.js +9 -4
  136. package/lib/test-utils/redux.js.map +1 -1
  137. package/lib/utils/adaptorUtils.d.ts +30 -0
  138. package/lib/utils/adaptorUtils.js +124 -0
  139. package/lib/utils/adaptorUtils.js.map +1 -0
  140. package/lib/utils/apixAdaptor.d.ts +15 -0
  141. package/lib/utils/apixAdaptor.js +67 -0
  142. package/lib/utils/apixAdaptor.js.map +1 -0
  143. package/lib/utils/index.d.ts +3 -1
  144. package/lib/utils/index.js +45 -30
  145. package/lib/utils/index.js.map +1 -1
  146. package/lib/utils/path.d.ts +3 -0
  147. package/lib/utils/path.js +32 -2
  148. package/lib/utils/path.js.map +1 -1
  149. package/package.json +10 -10
  150. package/src/ApiExplorer.tsx +47 -74
  151. package/src/StandaloneApiExplorer.tsx +37 -52
  152. package/src/components/Banner/Banner.spec.tsx +99 -0
  153. package/src/components/Banner/Banner.tsx +87 -0
  154. package/src/{reducers → components/Banner}/index.ts +1 -1
  155. package/src/components/DocPseudo/DocParam.spec.tsx +2 -1
  156. package/src/components/DocPseudo/DocParam.tsx +2 -1
  157. package/src/components/DocSDKs/DocSDKs.tsx +4 -5
  158. package/src/components/ExploreType/ExploreType.spec.tsx +0 -23
  159. package/src/components/ExploreType/ExploreType.tsx +5 -6
  160. package/src/components/ExploreType/exploreUtils.spec.tsx +1 -1
  161. package/src/components/Header/Header.spec.tsx +9 -30
  162. package/src/components/Header/Header.tsx +3 -10
  163. package/src/components/SelectorContainer/ApiSpecSelector.spec.tsx +31 -44
  164. package/src/components/SelectorContainer/ApiSpecSelector.tsx +6 -12
  165. package/src/components/SelectorContainer/SelectorContainer.spec.tsx +7 -26
  166. package/src/components/SelectorContainer/SelectorContainer.tsx +4 -10
  167. package/src/components/SideNav/SideNav.spec.tsx +12 -45
  168. package/src/components/SideNav/SideNav.tsx +1 -7
  169. package/src/components/index.ts +1 -0
  170. package/src/index.ts +1 -0
  171. package/src/routes/AppRouter.tsx +25 -37
  172. package/src/scenes/DiffScene/DiffScene.tsx +47 -84
  173. package/src/scenes/DiffScene/DocDiff/DiffItem.spec.tsx +9 -16
  174. package/src/scenes/DiffScene/DocDiff/DiffItem.tsx +11 -12
  175. package/src/scenes/DiffScene/DocDiff/DocDiff.tsx +2 -2
  176. package/src/scenes/MethodScene/MethodScene.tsx +4 -10
  177. package/src/state/index.ts +1 -0
  178. package/src/{reducers/spec → state/specs}/index.ts +2 -3
  179. package/src/state/specs/sagas.spec.ts +135 -0
  180. package/src/state/specs/sagas.ts +81 -0
  181. package/src/{reducers/spec/actions.spec.ts → state/specs/selectors.ts} +12 -11
  182. package/src/state/specs/slice.ts +109 -0
  183. package/src/state/store.ts +58 -0
  184. package/src/test-data/index.ts +1 -8
  185. package/src/test-data/specs.ts +6 -6
  186. package/src/test-utils/redux.tsx +15 -4
  187. package/src/utils/adaptorUtils.ts +181 -0
  188. package/src/utils/apixAdaptor.ts +72 -0
  189. package/src/utils/index.ts +3 -7
  190. package/src/utils/path.ts +25 -2
  191. package/lib/esm/reducers/index.js +0 -2
  192. package/lib/esm/reducers/index.js.map +0 -1
  193. package/lib/esm/reducers/spec/actions.js +0 -19
  194. package/lib/esm/reducers/spec/actions.js.map +0 -1
  195. package/lib/esm/reducers/spec/index.js +0 -4
  196. package/lib/esm/reducers/spec/index.js.map +0 -1
  197. package/lib/esm/reducers/spec/reducer.js +0 -62
  198. package/lib/esm/reducers/spec/reducer.js.map +0 -1
  199. package/lib/esm/reducers/spec/utils.js +0 -74
  200. package/lib/esm/reducers/spec/utils.js.map +0 -1
  201. package/lib/reducers/index.d.ts +0 -1
  202. package/lib/reducers/index.js +0 -19
  203. package/lib/reducers/index.js.map +0 -1
  204. package/lib/reducers/spec/actions.d.ts +0 -20
  205. package/lib/reducers/spec/actions.js +0 -31
  206. package/lib/reducers/spec/actions.js.map +0 -1
  207. package/lib/reducers/spec/index.d.ts +0 -3
  208. package/lib/reducers/spec/index.js +0 -45
  209. package/lib/reducers/spec/index.js.map +0 -1
  210. package/lib/reducers/spec/reducer.d.ts +0 -7
  211. package/lib/reducers/spec/reducer.js +0 -73
  212. package/lib/reducers/spec/reducer.js.map +0 -1
  213. package/lib/reducers/spec/utils.d.ts +0 -7
  214. package/lib/reducers/spec/utils.js +0 -91
  215. package/lib/reducers/spec/utils.js.map +0 -1
  216. package/src/reducers/spec/actions.ts +0 -62
  217. package/src/reducers/spec/reducer.spec.ts +0 -44
  218. package/src/reducers/spec/reducer.ts +0 -69
  219. package/src/reducers/spec/utils.spec.ts +0 -138
  220. 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, SpecItem } from '@looker/sdk-codegen'
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 { fallbackFetch, funFetch } from '@looker/run-it'
42
- import { getDefaultSpecKey } from '../../reducers/spec/utils'
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>(pickLeft(specs, l))
118
- const [rightKey, setRightKey] = useState<string>(pickRight(specs, r, leftKey))
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
- toggleNavigation(false)
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
- return []
134
- }
135
- const [delta, setDelta] = useState<DiffRow[]>(
136
- computeDelta(leftKey, rightKey, toggles)
137
- )
111
+ }, [r, rightKey])
138
112
 
139
- const loadSpec = async (
140
- specs: SpecList,
141
- key: string,
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
- const compareKeys = async (left: string, right: string) => {
160
- if (left !== leftKey || right !== rightKey) {
161
- history.push(`/${diffPath}/${left}/${right}`)
162
- }
163
- if (!specs[left].api) {
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
- setLeftKey(newLeft)
126
+ history.push(`/${diffPath}/${newLeft}/${rightKey}`)
127
+ }
128
+ const handleRightChange = (newRight: string) => {
129
+ history.push(`/${diffPath}/${leftKey}/${newRight}`)
174
130
  }
175
131
 
176
- const handleTogglesChange = (values?: string[]) => {
177
- const newToggles = values || []
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
- compareKeys(leftKey, rightKey)
184
- }, [leftKey, rightKey])
137
+ adaptor.fetchSpec(specs[leftKey]).then((spec) => setLeftApi(spec.api!))
138
+ }, [leftKey])
185
139
 
186
- const handleRightChange = (newRight: string) => {
187
- setRightKey(newRight)
188
- }
140
+ useEffect(() => {
141
+ if (rightKey in specs) {
142
+ adaptor.fetchSpec(specs[rightKey]).then((spec) => setRightApi(spec.api!))
143
+ }
144
+ }, [rightKey])
189
145
 
190
- const handleSwitch = () => {
191
- const currLeftKey = leftKey
192
- setLeftKey(rightKey)
193
- setRightKey(currLeftKey)
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 userEvent from '@testing-library/user-event'
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 s = `${method.name} for ${specKey}`
54
- expect(screen.getByText(s)).toBeInTheDocument()
55
- userEvent.click(screen.getByText(s))
56
- act(() => {
57
- expect(pushSpy).toHaveBeenCalledWith(
58
- `/${specKey}/methods/${method.schema.tags[0]}/${method.name}`
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
- userEvent.click(screen.getByText(s))
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, BaseSyntheticEvent } from 'react'
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(Heading)`
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 handleClick = (e: BaseSyntheticEvent) => {
67
- e.stopPropagation()
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
- as="h4"
76
- onClick={handleClick}
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={item.id}
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
- api,
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>
@@ -26,3 +26,4 @@
26
26
  export * from './store'
27
27
  export * from './settings'
28
28
  export * from './lodes'
29
+ export * from './specs'
@@ -23,6 +23,5 @@
23
23
  SOFTWARE.
24
24
 
25
25
  */
26
- export * from './utils'
27
- export * from './actions'
28
- export * from './reducer'
26
+ export * from './selectors'
27
+ export * from './slice'
@@ -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 { selectSpec } from './actions'
27
-
28
- describe('Spec reducer actions', () => {
29
- test('returns a SELECT_SPEC action object with provided values', () => {
30
- const action = selectSpec('3.1')
31
- expect(action).toEqual({
32
- type: 'SELECT_SPEC',
33
- payload: '3.1',
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
+ }