diff --git a/packages/run-it/src/components/DocSdkCalls/DocMultiCall.tsx b/packages/run-it/src/components/DocSdkCalls/DocMultiCall.tsx index 26b54bf0b..e9433624e 100644 --- a/packages/run-it/src/components/DocSdkCalls/DocMultiCall.tsx +++ b/packages/run-it/src/components/DocSdkCalls/DocMultiCall.tsx @@ -25,39 +25,23 @@ */ import type { FC } from 'react' import React from 'react' -import { Tab, TabList, TabPanel, TabPanels, useTabs } from '@looker/components' - +import { Tabs2, Tab2 } from '@looker/components' import { CodeCopy } from '@looker/code-editor' -import { getGenerators } from './callUtils' -import type { DocSdkCallsProps } from './DocSdkCalls' + +interface DocMultiCallProps { + /** An object with keys representing the language and values for call syntax */ + calls: Record +} /** * Generates the SDK call syntax for all supported languages */ -export const DocMultiCall: FC> = ({ - api, - inputs, - method, -}) => { - const tabs = useTabs() - const generators = getGenerators(api) - return ( - <> - - {Object.keys(generators).map((language) => ( - {language} - ))} - - - {Object.entries(generators).map(([language, gen]) => { - const code = gen.makeTheCall(method, inputs) - return ( - - - - ) - })} - - - ) -} +export const DocMultiCall: FC = ({ calls }) => ( + + {Object.entries(calls).map(([language, callSyntax]) => ( + + + + ))} + +) diff --git a/packages/run-it/src/components/DocSdkCalls/DocSdkCalls.spec.tsx b/packages/run-it/src/components/DocSdkCalls/DocSdkCalls.spec.tsx index dceaa8050..a4d3e1614 100644 --- a/packages/run-it/src/components/DocSdkCalls/DocSdkCalls.spec.tsx +++ b/packages/run-it/src/components/DocSdkCalls/DocSdkCalls.spec.tsx @@ -40,15 +40,7 @@ describe('DocSdkCalls', () => { ) @@ -69,15 +61,7 @@ describe('DocSdkCalls', () => { ) @@ -87,4 +71,22 @@ describe('DocSdkCalls', () => { ).toBeInTheDocument() } ) + + test('shows useful message when it errors while parsing complex structures', () => { + renderWithTheme( + + ) + expect( + screen.getByText( + 'Cannot generate SDK call syntax. Ensure all complex structures in the request form are valid.' + ) + ).toBeInTheDocument() + }) }) diff --git a/packages/run-it/src/components/DocSdkCalls/DocSdkCalls.tsx b/packages/run-it/src/components/DocSdkCalls/DocSdkCalls.tsx index af712b9e2..d34cc39d6 100644 --- a/packages/run-it/src/components/DocSdkCalls/DocSdkCalls.tsx +++ b/packages/run-it/src/components/DocSdkCalls/DocSdkCalls.tsx @@ -27,12 +27,14 @@ import type { FC } from 'react' import React, { useEffect, useState } from 'react' import type { ApiModel, IMethod } from '@looker/sdk-codegen' -import { trimInputs } from '@looker/sdk-codegen' +import { getCodeGenerator, trimInputs } from '@looker/sdk-codegen' import { Heading } from '@looker/components' +import { CodeCopy } from '@looker/code-editor' import type { RunItValues } from '../../RunIt' -import { DocSingleCall } from './DocSingleCall' +import { DarkSpan } from '../common' import { DocMultiCall } from './DocMultiCall' +import { getGenerators } from './callUtils' export interface DocSdkCallsProps { /** API spec */ @@ -64,20 +66,36 @@ export const DocSdkCalls: FC = ({ : `${sdkLanguage} SDK call syntax` setHeading(text) }, [sdkLanguage]) + + const calls = {} + try { + if (sdkLanguage === 'All') { + const generators = getGenerators(api) + Object.entries(generators).forEach(([language, gen]) => { + calls[language] = gen.makeTheCall(method, trimmedInputs) + }) + } else { + const gen = getCodeGenerator(sdkLanguage, api) + calls[sdkLanguage] = gen!.makeTheCall(method, trimmedInputs) + } + } catch { + return ( + + Cannot generate SDK call syntax. Ensure all complex structures in the + request form are valid. + + ) + } + return ( <> {heading} {sdkLanguage === 'All' ? ( - + ) : ( - + )} ) diff --git a/packages/run-it/src/components/DocSdkCalls/DocSingleCall.tsx b/packages/run-it/src/components/DocSdkCalls/DocSingleCall.tsx deleted file mode 100644 index ac81feb24..000000000 --- a/packages/run-it/src/components/DocSdkCalls/DocSingleCall.tsx +++ /dev/null @@ -1,46 +0,0 @@ -/* - - 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 type { FC } from 'react' -import React from 'react' -import { getCodeGenerator } from '@looker/sdk-codegen' - -import { CodeCopy } from '@looker/code-editor' -import type { DocSdkCallsProps } from './DocSdkCalls' - -/** - * Generates the SDK call syntax for a given language - */ -export const DocSingleCall: FC = ({ - api, - method, - inputs, - sdkLanguage, -}) => { - const generator = getCodeGenerator(sdkLanguage, api) - const code = generator!.makeTheCall(method, inputs) - - return -}