mirror of
				https://github.com/Redocly/redoc.git
				synced 2025-10-30 23:37:28 +03:00 
			
		
		
		
	feat: add hideSingleRequestSampleTab option
This commit is contained in:
		
							parent
							
								
									de2aed21e7
								
							
						
					
					
						commit
						4550e4d61f
					
				|  | @ -1,10 +1,11 @@ | ||||||
| import { observer } from 'mobx-react'; | import { observer } from 'mobx-react'; | ||||||
| import * as React from 'react'; | import * as React from 'react'; | ||||||
| import { OperationModel } from '../../services/models'; | import { OperationModel, RedocNormalizedOptions } from '../../services'; | ||||||
| import { PayloadSamples } from '../PayloadSamples/PayloadSamples'; | import { PayloadSamples } from '../PayloadSamples/PayloadSamples'; | ||||||
| import { SourceCodeWithCopy } from '../SourceCode/SourceCode'; | import { SourceCodeWithCopy } from '../SourceCode/SourceCode'; | ||||||
| 
 | 
 | ||||||
| import { RightPanelHeader, Tab, TabList, TabPanel, Tabs } from '../../common-elements'; | import { RightPanelHeader, Tab, TabList, TabPanel, Tabs } from '../../common-elements'; | ||||||
|  | import { OptionsContext } from '../OptionsProvider'; | ||||||
| 
 | 
 | ||||||
| export interface RequestSamplesProps { | export interface RequestSamplesProps { | ||||||
|   operation: OperationModel; |   operation: OperationModel; | ||||||
|  | @ -12,6 +13,8 @@ export interface RequestSamplesProps { | ||||||
| 
 | 
 | ||||||
| @observer | @observer | ||||||
| export class RequestSamples extends React.Component<RequestSamplesProps> { | export class RequestSamples extends React.Component<RequestSamplesProps> { | ||||||
|  |   static contextType = OptionsContext; | ||||||
|  |   context: RedocNormalizedOptions; | ||||||
|   operation: OperationModel; |   operation: OperationModel; | ||||||
| 
 | 
 | ||||||
|   render() { |   render() { | ||||||
|  | @ -21,13 +24,17 @@ export class RequestSamples extends React.Component<RequestSamplesProps> { | ||||||
|     const samples = operation.codeSamples; |     const samples = operation.codeSamples; | ||||||
| 
 | 
 | ||||||
|     const hasSamples = hasBodySample || samples.length > 0; |     const hasSamples = hasBodySample || samples.length > 0; | ||||||
|  |     const hideTabList = | ||||||
|  |       samples.length + (hasBodySample ? 1 : 0) === 1 | ||||||
|  |         ? this.context.hideSingleRequestSampleTab | ||||||
|  |         : false; | ||||||
|     return ( |     return ( | ||||||
|       (hasSamples && ( |       (hasSamples && ( | ||||||
|         <div> |         <div> | ||||||
|           <RightPanelHeader> Request samples </RightPanelHeader> |           <RightPanelHeader> Request samples </RightPanelHeader> | ||||||
| 
 | 
 | ||||||
|           <Tabs defaultIndex={0}> |           <Tabs defaultIndex={0}> | ||||||
|             <TabList> |             <TabList hidden={hideTabList}> | ||||||
|               {hasBodySample && <Tab key="payload"> Payload </Tab>} |               {hasBodySample && <Tab key="payload"> Payload </Tab>} | ||||||
|               {samples.map(sample => ( |               {samples.map(sample => ( | ||||||
|                 <Tab key={sample.lang + '_' + (sample.label || '')}> |                 <Tab key={sample.lang + '_' + (sample.label || '')}> | ||||||
|  |  | ||||||
|  | @ -20,6 +20,7 @@ export interface RedocRawOptions { | ||||||
|   disableSearch?: boolean | string; |   disableSearch?: boolean | string; | ||||||
|   onlyRequiredInSamples?: boolean | string; |   onlyRequiredInSamples?: boolean | string; | ||||||
|   showExtensions?: boolean | string | string[]; |   showExtensions?: boolean | string | string[]; | ||||||
|  |   hideSingleRequestSampleTab?: boolean | string; | ||||||
| 
 | 
 | ||||||
|   unstable_ignoreMimeParameters?: boolean; |   unstable_ignoreMimeParameters?: boolean; | ||||||
| 
 | 
 | ||||||
|  | @ -120,6 +121,7 @@ export class RedocNormalizedOptions { | ||||||
|   disableSearch: boolean; |   disableSearch: boolean; | ||||||
|   onlyRequiredInSamples: boolean; |   onlyRequiredInSamples: boolean; | ||||||
|   showExtensions: boolean | string[]; |   showExtensions: boolean | string[]; | ||||||
|  |   hideSingleRequestSampleTab: boolean; | ||||||
| 
 | 
 | ||||||
|   /* tslint:disable-next-line */ |   /* tslint:disable-next-line */ | ||||||
|   unstable_ignoreMimeParameters: boolean; |   unstable_ignoreMimeParameters: boolean; | ||||||
|  | @ -147,6 +149,7 @@ export class RedocNormalizedOptions { | ||||||
|     this.disableSearch = argValueToBoolean(raw.disableSearch); |     this.disableSearch = argValueToBoolean(raw.disableSearch); | ||||||
|     this.onlyRequiredInSamples = argValueToBoolean(raw.onlyRequiredInSamples); |     this.onlyRequiredInSamples = argValueToBoolean(raw.onlyRequiredInSamples); | ||||||
|     this.showExtensions = RedocNormalizedOptions.normalizeShowExtensions(raw.showExtensions); |     this.showExtensions = RedocNormalizedOptions.normalizeShowExtensions(raw.showExtensions); | ||||||
|  |     this.hideSingleRequestSampleTab = argValueToBoolean(raw.hideSingleRequestSampleTab); | ||||||
| 
 | 
 | ||||||
|     this.unstable_ignoreMimeParameters = argValueToBoolean(raw.unstable_ignoreMimeParameters); |     this.unstable_ignoreMimeParameters = argValueToBoolean(raw.unstable_ignoreMimeParameters); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user