-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Match rendering of callbacks to style of operation responses
- Loading branch information
1 parent
06440a5
commit 60fa093
Showing
9 changed files
with
156 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { observer } from 'mobx-react'; | ||
import * as React from 'react'; | ||
import { isPayloadSample, 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'; | ||
import { CallbackModel } from '../../services/models'; | ||
import { Endpoint } from '../Endpoint/Endpoint'; | ||
|
||
export interface CallbackSamplesProps { | ||
callbacks: CallbackModel[]; | ||
} | ||
|
||
@observer | ||
export class CallbackSamples extends React.Component<CallbackSamplesProps> { | ||
static contextType = OptionsContext; | ||
context: RedocNormalizedOptions; | ||
|
||
render() { | ||
const { callbacks } = this.props; | ||
|
||
// Sums number of code samples per operation per callback | ||
const numSamples = callbacks.reduce( | ||
(callbackSum, callback) => | ||
callbackSum + | ||
callback.operations.reduce( | ||
(sampleSum, operation) => sampleSum + operation.codeSamples.length, | ||
0, | ||
), | ||
0, | ||
); | ||
|
||
const hasSamples = numSamples > 0; | ||
const hideTabList = numSamples === 1 ? this.context.hideSingleRequestSampleTab : false; | ||
|
||
const renderTabs = () => { | ||
return callbacks.map(callback => { | ||
return callback.operations.map(operation => { | ||
return operation.codeSamples.map(sample => { | ||
return ( | ||
<Tab key={operation.id + '_' + operation.name}> | ||
{operation.name} {sample.label !== undefined ? sample.label : sample.lang} | ||
</Tab> | ||
); | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
const renderTabPanels = () => { | ||
return callbacks.map(callback => { | ||
return callback.operations.map(operation => { | ||
return operation.codeSamples.map(sample => { | ||
return ( | ||
<TabPanel key={sample.lang + '_' + (sample.label || '')}> | ||
{isPayloadSample(sample) ? ( | ||
<div> | ||
<Endpoint operation={operation} inverted={false} /> | ||
<PayloadSamples content={sample.requestBodyContent} /> | ||
</div> | ||
) : ( | ||
<SourceCodeWithCopy lang={sample.lang} source={sample.source} /> | ||
)} | ||
</TabPanel> | ||
); | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
return ( | ||
(hasSamples && ( | ||
<div> | ||
<RightPanelHeader> Callback samples </RightPanelHeader> | ||
|
||
<Tabs defaultIndex={0}> | ||
<TabList hidden={hideTabList}>{renderTabs()}</TabList> | ||
{renderTabPanels()} | ||
</Tabs> | ||
</div> | ||
)) || | ||
null | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as React from 'react'; | ||
import { OperationModel } from '../../services/models'; | ||
import { OperationItem } from '../ContentItems/ContentItems'; | ||
|
||
export class CallbackDetails extends React.PureComponent<{ callbackOperation: OperationModel }> { | ||
render() { | ||
return <OperationItem item={this.props.callbackOperation} />; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters