@looker/api-explorer 0.9.35 → 0.9.36

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 (89) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/dist/bundle.js +1 -1
  3. package/dist/bundle.js.map +1 -1
  4. package/lib/ApiExplorer.js +9 -1
  5. package/lib/ApiExplorer.js.map +1 -1
  6. package/lib/components/DocMarkdown/DocMarkdown.js +7 -7
  7. package/lib/components/DocMarkdown/DocMarkdown.js.map +1 -1
  8. package/lib/components/SelectorContainer/ApiSpecSelector.js +4 -2
  9. package/lib/components/SelectorContainer/ApiSpecSelector.js.map +1 -1
  10. package/lib/components/SideNav/SideNav.js +23 -13
  11. package/lib/components/SideNav/SideNav.js.map +1 -1
  12. package/lib/components/SideNav/SideNavMethods.js +8 -6
  13. package/lib/components/SideNav/SideNavMethods.js.map +1 -1
  14. package/lib/components/SideNav/SideNavTypes.js +6 -4
  15. package/lib/components/SideNav/SideNavTypes.js.map +1 -1
  16. package/lib/esm/ApiExplorer.js +9 -1
  17. package/lib/esm/ApiExplorer.js.map +1 -1
  18. package/lib/esm/components/DocMarkdown/DocMarkdown.js +4 -4
  19. package/lib/esm/components/DocMarkdown/DocMarkdown.js.map +1 -1
  20. package/lib/esm/components/SelectorContainer/ApiSpecSelector.js +4 -3
  21. package/lib/esm/components/SelectorContainer/ApiSpecSelector.js.map +1 -1
  22. package/lib/esm/components/SideNav/SideNav.js +26 -16
  23. package/lib/esm/components/SideNav/SideNav.js.map +1 -1
  24. package/lib/esm/components/SideNav/SideNavMethods.js +8 -6
  25. package/lib/esm/components/SideNav/SideNavMethods.js.map +1 -1
  26. package/lib/esm/components/SideNav/SideNavTypes.js +8 -6
  27. package/lib/esm/components/SideNav/SideNavTypes.js.map +1 -1
  28. package/lib/esm/scenes/DiffScene/DiffScene.js +6 -6
  29. package/lib/esm/scenes/DiffScene/DiffScene.js.map +1 -1
  30. package/lib/esm/scenes/DiffScene/DocDiff/DiffItem.js +3 -4
  31. package/lib/esm/scenes/DiffScene/DocDiff/DiffItem.js.map +1 -1
  32. package/lib/esm/scenes/MethodScene/MethodScene.js +4 -3
  33. package/lib/esm/scenes/MethodScene/MethodScene.js.map +1 -1
  34. package/lib/esm/scenes/MethodTagScene/MethodTagScene.js +3 -2
  35. package/lib/esm/scenes/MethodTagScene/MethodTagScene.js.map +1 -1
  36. package/lib/esm/scenes/TypeScene/TypeScene.js +5 -1
  37. package/lib/esm/scenes/TypeScene/TypeScene.js.map +1 -1
  38. package/lib/esm/scenes/TypeTagScene/TypeTagScene.js +5 -5
  39. package/lib/esm/scenes/TypeTagScene/TypeTagScene.js.map +1 -1
  40. package/lib/esm/utils/hooks.js +26 -0
  41. package/lib/esm/utils/hooks.js.map +1 -0
  42. package/lib/esm/utils/index.js +1 -0
  43. package/lib/esm/utils/index.js.map +1 -1
  44. package/lib/esm/utils/path.js +2 -2
  45. package/lib/esm/utils/path.js.map +1 -1
  46. package/lib/scenes/DiffScene/DiffScene.js +4 -4
  47. package/lib/scenes/DiffScene/DiffScene.js.map +1 -1
  48. package/lib/scenes/DiffScene/DocDiff/DiffItem.js +2 -4
  49. package/lib/scenes/DiffScene/DocDiff/DiffItem.js.map +1 -1
  50. package/lib/scenes/MethodScene/MethodScene.js +3 -2
  51. package/lib/scenes/MethodScene/MethodScene.js.map +1 -1
  52. package/lib/scenes/MethodTagScene/MethodTagScene.js +2 -1
  53. package/lib/scenes/MethodTagScene/MethodTagScene.js.map +1 -1
  54. package/lib/scenes/TypeScene/TypeScene.js +6 -1
  55. package/lib/scenes/TypeScene/TypeScene.js.map +1 -1
  56. package/lib/scenes/TypeTagScene/TypeTagScene.js +3 -3
  57. package/lib/scenes/TypeTagScene/TypeTagScene.js.map +1 -1
  58. package/lib/utils/hooks.d.ts +3 -0
  59. package/lib/utils/hooks.js +36 -0
  60. package/lib/utils/hooks.js.map +1 -0
  61. package/lib/utils/index.d.ts +1 -0
  62. package/lib/utils/index.js +10 -1
  63. package/lib/utils/index.js.map +1 -1
  64. package/lib/utils/path.d.ts +2 -2
  65. package/lib/utils/path.js +2 -2
  66. package/lib/utils/path.js.map +1 -1
  67. package/package.json +9 -9
  68. package/src/ApiExplorer.tsx +7 -1
  69. package/src/components/DocMarkdown/DocMarkdown.tsx +4 -4
  70. package/src/components/SelectorContainer/ApiSpecSelector.spec.tsx +5 -2
  71. package/src/components/SelectorContainer/ApiSpecSelector.tsx +4 -3
  72. package/src/components/SideNav/SideNav.spec.tsx +39 -5
  73. package/src/components/SideNav/SideNav.tsx +22 -21
  74. package/src/components/SideNav/SideNavMethods.spec.tsx +9 -2
  75. package/src/components/SideNav/SideNavMethods.tsx +15 -8
  76. package/src/components/SideNav/SideNavTypes.spec.tsx +9 -2
  77. package/src/components/SideNav/SideNavTypes.tsx +15 -8
  78. package/src/scenes/DiffScene/DiffScene.tsx +6 -6
  79. package/src/scenes/DiffScene/DocDiff/DiffItem.spec.tsx +4 -3
  80. package/src/scenes/DiffScene/DocDiff/DiffItem.tsx +3 -4
  81. package/src/scenes/MethodScene/MethodScene.tsx +4 -3
  82. package/src/scenes/MethodTagScene/MethodTagScene.tsx +3 -2
  83. package/src/scenes/TypeScene/TypeScene.tsx +8 -2
  84. package/src/scenes/TypeTagScene/TypeTagScene.tsx +5 -5
  85. package/src/utils/hooks.spec.ts +78 -0
  86. package/src/utils/hooks.ts +53 -0
  87. package/src/utils/index.ts +1 -0
  88. package/src/utils/path.spec.ts +25 -2
  89. package/src/utils/path.ts +11 -4
@@ -0,0 +1,78 @@
1
+ /*
2
+
3
+ MIT License
4
+
5
+ Copyright (c) 2022 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 { useHistory } from 'react-router-dom'
27
+ import { useNavigation } from './hooks'
28
+
29
+ const mockHistoryPush = jest.fn()
30
+ jest.mock('react-router-dom', () => {
31
+ const ReactRouterDOM = jest.requireActual('react-router-dom')
32
+ return {
33
+ ...ReactRouterDOM,
34
+ useHistory: () => ({
35
+ push: mockHistoryPush,
36
+ location: { pathname: '/3.1/methods', search: 's=test' },
37
+ }),
38
+ }
39
+ })
40
+
41
+ describe('Navigate', () => {
42
+ const history = useHistory()
43
+ const navigate = useNavigation()
44
+ const curParams = new URLSearchParams(history.location.search) // 's=test'
45
+ const route = `/3.1`
46
+
47
+ test('preserves existing query params when given params are undefined', () => {
48
+ navigate(route)
49
+ expect(curParams.get('s')).toBe('test')
50
+ expect(mockHistoryPush).lastCalledWith({
51
+ pathname: route,
52
+ search: curParams.toString(),
53
+ })
54
+ })
55
+
56
+ test('clears existing params when given params are null', () => {
57
+ navigate(route, null)
58
+ expect(mockHistoryPush).lastCalledWith({
59
+ pathname: route,
60
+ })
61
+ })
62
+
63
+ test('clears existing params when given params are an empty object', () => {
64
+ navigate(route, {})
65
+ expect(mockHistoryPush).lastCalledWith({
66
+ pathname: route,
67
+ })
68
+ })
69
+
70
+ test('sets query parameters when given a populated query params object', () => {
71
+ const newParams = 's=embedsso'
72
+ navigate(route, { search: newParams })
73
+ expect(mockHistoryPush).lastCalledWith({
74
+ pathname: route,
75
+ search: newParams,
76
+ })
77
+ })
78
+ })
@@ -0,0 +1,53 @@
1
+ /*
2
+
3
+ MIT License
4
+
5
+ Copyright (c) 2022 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 { useHistory } from 'react-router-dom'
27
+
28
+ /**
29
+ * Hook for navigating to given route with specified query params
30
+ *
31
+ * @param path Pathname to navigate to
32
+ * @param queryParams Hash of query param name/value pairs to include in the destination url
33
+ */
34
+
35
+ export const useNavigation = () => {
36
+ const history = useHistory()
37
+
38
+ const navigate = (path: string, queryParams?: { search?: string } | null) => {
39
+ if (queryParams === undefined) {
40
+ // if params passed in is undefined, maintain existing parameters in the URL
41
+ const curParams = new URLSearchParams(history.location.search)
42
+ history.push({ pathname: path, search: curParams.toString() })
43
+ } else if (queryParams === null || Object.keys(queryParams).length === 0) {
44
+ // if params passed in is null or empty, remove all parameters from the URL
45
+ history.push({ pathname: path })
46
+ } else {
47
+ // if we have new parameters passed in, push them to the URL
48
+ history.push({ pathname: path, search: queryParams.search })
49
+ }
50
+ }
51
+
52
+ return navigate
53
+ }
@@ -29,3 +29,4 @@ export { getLoded } from './lodeUtils'
29
29
  export { useWindowSize } from './useWindowSize'
30
30
  export * from './apixAdaptor'
31
31
  export * from './adaptorUtils'
32
+ export { useNavigation } from './hooks'
@@ -28,16 +28,39 @@ import { api } from '../test-data'
28
28
  import { buildMethodPath, buildPath, buildTypePath } from './path'
29
29
 
30
30
  describe('path utils', () => {
31
+ const testParam = 's=test'
31
32
  describe('buildMethodPath', () => {
32
33
  test('it builds a method path', () => {
33
34
  const path = buildMethodPath('3.1', 'Dashboard', 'create_dashboard')
34
35
  expect(path).toEqual('/3.1/methods/Dashboard/create_dashboard')
35
36
  })
37
+ test('it builds a method path with params', () => {
38
+ const path = buildMethodPath(
39
+ '3.1',
40
+ 'Dashboard',
41
+ 'create_dashboard',
42
+ testParam
43
+ )
44
+ expect(path).toEqual(
45
+ `/3.1/methods/Dashboard/create_dashboard?${testParam}`
46
+ )
47
+ })
36
48
  })
37
49
 
38
50
  describe('buildTypePath', () => {
39
- const path = buildTypePath('3.1', 'Dashboard', 'WriteDashboard')
40
- expect(path).toEqual('/3.1/types/Dashboard/WriteDashboard')
51
+ test('it builds a type path', () => {
52
+ const path = buildTypePath('3.1', 'Dashboard', 'WriteDashboard')
53
+ expect(path).toEqual('/3.1/types/Dashboard/WriteDashboard')
54
+ })
55
+ test('it builds a type path with params', () => {
56
+ const path = buildTypePath(
57
+ '3.1',
58
+ 'Dashboard',
59
+ 'create_dashboard',
60
+ testParam
61
+ )
62
+ expect(path).toEqual(`/3.1/types/Dashboard/create_dashboard?${testParam}`)
63
+ })
41
64
  })
42
65
 
43
66
  describe('buildPath', () => {
package/src/utils/path.ts CHANGED
@@ -33,23 +33,30 @@ import type { Location as HLocation } from 'history'
33
33
  * @param specKey A string to identify the spec in the URL
34
34
  * @param tag Corresponding method tag
35
35
  * @param methodName A method name
36
+ * @param params Hash of query param name/value pairs to include in the destination url
36
37
  * @returns a Method path
37
38
  */
38
39
  export const buildMethodPath = (
39
40
  specKey: string,
40
41
  tag: string,
41
- methodName: string
42
- ) => `/${specKey}/methods/${tag}/${methodName}`
42
+ methodName: string,
43
+ params?: string
44
+ ) => `/${specKey}/methods/${tag}/${methodName}${params ? `?${params}` : ''}`
43
45
 
44
46
  /**
45
47
  * Builds a path matching the route used by TypeScene
46
48
  * @param specKey A string to identify the spec in the URL
47
49
  * @param tag Corresponding type tag
48
50
  * @param typeName A type name
51
+ * @param params Hash of query param name/value pairs to include in the destination url
49
52
  * @returns a Type path
50
53
  */
51
- export const buildTypePath = (specKey: string, tag: string, typeName: string) =>
52
- `/${specKey}/types/${tag}/${typeName}`
54
+ export const buildTypePath = (
55
+ specKey: string,
56
+ tag: string,
57
+ typeName: string,
58
+ params?: string
59
+ ) => `/${specKey}/types/${tag}/${typeName}${params ? `?${params}` : ''}`
53
60
 
54
61
  export const diffPath = 'diff'
55
62
  export const oAuthPath = 'oauth'