From 0a0d4cea7def227f9864e1f21862468255508876 Mon Sep 17 00:00:00 2001 From: John Kaster Date: Mon, 17 May 2021 19:38:51 +0000 Subject: [PATCH 1/3] feat: added original spec in APIX --- .../components/Collapser/CollapserCard.tsx | 6 ++- .../DocReferences/DocReferences.tsx | 53 +++++++++--------- .../components/DocResponses/DocResponses.tsx | 43 ++++++--------- .../src/components/DocSDKs/DocSDKs.tsx | 23 ++++---- .../src/components/DocSchema/DocSchema.tsx | 54 +++++++++++++++++++ .../src/components/DocSchema/index.ts | 27 ++++++++++ packages/api-explorer/src/components/index.ts | 1 + .../src/scenes/DiffScene/DiffScene.tsx | 2 +- .../src/scenes/MethodScene/MethodScene.tsx | 4 +- .../MethodScene/components/DocOperation.tsx | 2 +- .../src/scenes/TypeScene/TypeScene.tsx | 2 + .../src/components/DocSdkCalls/callUtils.ts | 4 +- 12 files changed, 149 insertions(+), 72 deletions(-) create mode 100644 packages/api-explorer/src/components/DocSchema/DocSchema.tsx create mode 100644 packages/api-explorer/src/components/DocSchema/index.ts diff --git a/packages/api-explorer/src/components/Collapser/CollapserCard.tsx b/packages/api-explorer/src/components/Collapser/CollapserCard.tsx index a297ca68a..b0299a217 100644 --- a/packages/api-explorer/src/components/Collapser/CollapserCard.tsx +++ b/packages/api-explorer/src/components/Collapser/CollapserCard.tsx @@ -36,6 +36,7 @@ interface CollapserCardProps { id?: string heading: string children: ReactElement + defaultOpen?: boolean } /** @@ -45,8 +46,9 @@ export const CollapserCard: FC = ({ id, heading, children, + defaultOpen = true, }) => { - const { value, toggle } = useToggle(true) + const { value, toggle } = useToggle(defaultOpen) return ( = ({ indicatorPosition="left" isOpen={value} toggleOpen={toggle} + mb="small" + mt="small" > {heading} diff --git a/packages/api-explorer/src/components/DocReferences/DocReferences.tsx b/packages/api-explorer/src/components/DocReferences/DocReferences.tsx index edd18d659..4d11f16d2 100644 --- a/packages/api-explorer/src/components/DocReferences/DocReferences.tsx +++ b/packages/api-explorer/src/components/DocReferences/DocReferences.tsx @@ -25,7 +25,6 @@ */ import React, { FC, useContext } from 'react' -import { Box } from '@looker/components' import { ApiModel, IMethod, IType } from '@looker/sdk-codegen' import { SearchContext } from '../../context' @@ -62,32 +61,30 @@ export const DocReferences: FC = ({ return <> return ( - - - <> - {DocReferenceItems( - 'Referenced Types:', - typesUsed, - api, - specKey, - pattern - )} - {DocReferenceItems( - 'Used by types:', - typesUsedBy, - api, - specKey, - pattern - )} - {DocReferenceItems( - 'Used by methods:', - methodsUsedBy, - api, - specKey, - pattern - )} - - - + + <> + {DocReferenceItems( + 'Referenced Types:', + typesUsed, + api, + specKey, + pattern + )} + {DocReferenceItems( + 'Used by types:', + typesUsedBy, + api, + specKey, + pattern + )} + {DocReferenceItems( + 'Used by methods:', + methodsUsedBy, + api, + specKey, + pattern + )} + + ) } diff --git a/packages/api-explorer/src/components/DocResponses/DocResponses.tsx b/packages/api-explorer/src/components/DocResponses/DocResponses.tsx index d39e0910c..810d32a70 100644 --- a/packages/api-explorer/src/components/DocResponses/DocResponses.tsx +++ b/packages/api-explorer/src/components/DocResponses/DocResponses.tsx @@ -25,14 +25,7 @@ */ import React, { FC } from 'react' -import { - Box, - Tab, - TabList, - TabPanel, - TabPanels, - useTabs, -} from '@looker/components' +import { Tab, TabList, TabPanel, TabPanels, useTabs } from '@looker/components' import { IMethodResponse } from '@looker/sdk-codegen' import { CollapserCard } from '../Collapser' @@ -54,23 +47,21 @@ export const DocResponses: FC = ({ responses }) => { const responseTree = buildResponseTree(responses) return ( - - - <> - - {Object.keys(responseTree).map((statusCode, index) => ( - {statusCode} - ))} - - - {Object.values(responseTree).map((responses, index) => ( - - - - ))} - - - - + + <> + + {Object.keys(responseTree).map((statusCode, index) => ( + {statusCode} + ))} + + + {Object.values(responseTree).map((responses, index) => ( + + + + ))} + + + ) } diff --git a/packages/api-explorer/src/components/DocSDKs/DocSDKs.tsx b/packages/api-explorer/src/components/DocSDKs/DocSDKs.tsx index 9cbe932b8..e34f02210 100644 --- a/packages/api-explorer/src/components/DocSDKs/DocSDKs.tsx +++ b/packages/api-explorer/src/components/DocSDKs/DocSDKs.tsx @@ -35,7 +35,6 @@ import { Method, } from '@looker/sdk-codegen' import { getGenerators } from '@looker/run-it' -import { Box } from '@looker/components' import { DocCode } from '../DocCode' import { getSelectedSdkLanguage } from '../../state' @@ -98,17 +97,15 @@ export const DocSDKs: FC = ({ api, method, type }) => { }, [sdkLanguage, item]) return ( - - - {Object.keys(declarations).length > 1 ? ( - - ) : ( - - )} - - + + {Object.keys(declarations).length > 1 ? ( + + ) : ( + + )} + ) } diff --git a/packages/api-explorer/src/components/DocSchema/DocSchema.tsx b/packages/api-explorer/src/components/DocSchema/DocSchema.tsx new file mode 100644 index 000000000..5b85723eb --- /dev/null +++ b/packages/api-explorer/src/components/DocSchema/DocSchema.tsx @@ -0,0 +1,54 @@ +/* + + MIT License + + Copyright (c) 2021 Looker Data Sciences, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + + */ + +import React, { FC } from 'react' + +import { CodeDisplay } from '@looker/code-editor' +import { CollapserCard } from '../Collapser' + +interface DocSchemaProps { + object: any +} + +/** + * It renders links to the given types and/or methods references + */ +export const DocSchema: FC = ({ object }) => { + if (!object) return <> + const json = JSON.stringify(object, null, 2) + + return ( + + <> + + + + ) +} diff --git a/packages/api-explorer/src/components/DocSchema/index.ts b/packages/api-explorer/src/components/DocSchema/index.ts new file mode 100644 index 000000000..da951ab76 --- /dev/null +++ b/packages/api-explorer/src/components/DocSchema/index.ts @@ -0,0 +1,27 @@ +/* + + MIT License + + Copyright (c) 2021 Looker Data Sciences, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + + */ + +export { DocSchema } from './DocSchema' diff --git a/packages/api-explorer/src/components/index.ts b/packages/api-explorer/src/components/index.ts index 3ac54b2f6..f318d73a1 100644 --- a/packages/api-explorer/src/components/index.ts +++ b/packages/api-explorer/src/components/index.ts @@ -41,3 +41,4 @@ export { Header } from './Header' export { SideNav } from './SideNav' export { ExploreType, ExploreProperty } from './ExploreType' export { CollapserCard } from './Collapser' +export { DocSchema } from './DocSchema' diff --git a/packages/api-explorer/src/scenes/DiffScene/DiffScene.tsx b/packages/api-explorer/src/scenes/DiffScene/DiffScene.tsx index 8dbcb7a58..4eb2108d0 100644 --- a/packages/api-explorer/src/scenes/DiffScene/DiffScene.tsx +++ b/packages/api-explorer/src/scenes/DiffScene/DiffScene.tsx @@ -165,7 +165,7 @@ export const DiffScene: FC = ({ specs, toggleNavigation }) => { return ( - +