feat: add hideSingleRequestSampleTab option

This commit is contained in:
Roman Hotsiy 2019-05-10 16:21:14 +03:00
parent de2aed21e7
commit 4550e4d61f
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
2 changed files with 12 additions and 2 deletions

View File

@ -1,10 +1,11 @@
import { observer } from 'mobx-react';
import * as React from 'react';
import { OperationModel } from '../../services/models';
import { OperationModel, RedocNormalizedOptions } from '../../services';
import { PayloadSamples } from '../PayloadSamples/PayloadSamples';
import { SourceCodeWithCopy } from '../SourceCode/SourceCode';
import { RightPanelHeader, Tab, TabList, TabPanel, Tabs } from '../../common-elements';
import { OptionsContext } from '../OptionsProvider';
export interface RequestSamplesProps {
operation: OperationModel;
@ -12,6 +13,8 @@ export interface RequestSamplesProps {
@observer
export class RequestSamples extends React.Component<RequestSamplesProps> {
static contextType = OptionsContext;
context: RedocNormalizedOptions;
operation: OperationModel;
render() {
@ -21,13 +24,17 @@ export class RequestSamples extends React.Component<RequestSamplesProps> {
const samples = operation.codeSamples;
const hasSamples = hasBodySample || samples.length > 0;
const hideTabList =
samples.length + (hasBodySample ? 1 : 0) === 1
? this.context.hideSingleRequestSampleTab
: false;
return (
(hasSamples && (
<div>
<RightPanelHeader> Request samples </RightPanelHeader>
<Tabs defaultIndex={0}>
<TabList>
<TabList hidden={hideTabList}>
{hasBodySample && <Tab key="payload"> Payload </Tab>}
{samples.map(sample => (
<Tab key={sample.lang + '_' + (sample.label || '')}>

View File

@ -20,6 +20,7 @@ export interface RedocRawOptions {
disableSearch?: boolean | string;
onlyRequiredInSamples?: boolean | string;
showExtensions?: boolean | string | string[];
hideSingleRequestSampleTab?: boolean | string;
unstable_ignoreMimeParameters?: boolean;
@ -120,6 +121,7 @@ export class RedocNormalizedOptions {
disableSearch: boolean;
onlyRequiredInSamples: boolean;
showExtensions: boolean | string[];
hideSingleRequestSampleTab: boolean;
/* tslint:disable-next-line */
unstable_ignoreMimeParameters: boolean;
@ -147,6 +149,7 @@ export class RedocNormalizedOptions {
this.disableSearch = argValueToBoolean(raw.disableSearch);
this.onlyRequiredInSamples = argValueToBoolean(raw.onlyRequiredInSamples);
this.showExtensions = RedocNormalizedOptions.normalizeShowExtensions(raw.showExtensions);
this.hideSingleRequestSampleTab = argValueToBoolean(raw.hideSingleRequestSampleTab);
this.unstable_ignoreMimeParameters = argValueToBoolean(raw.unstable_ignoreMimeParameters);