redoc/src/components/Operation/Operation.tsx

73 lines
2.3 KiB
TypeScript
Raw Normal View History

2017-10-12 00:01:37 +03:00
import * as React from 'react';
import { SecurityRequirements } from '../SecurityRequirement/SecurityRequirement';
2017-10-12 00:01:37 +03:00
import { observer } from 'mobx-react';
import { Badge, DarkRightPanel, H2, MiddlePanel, Row } from '../../common-elements';
2017-10-12 00:01:37 +03:00
2018-03-17 23:04:37 +03:00
import { OptionsContext } from '../OptionsProvider';
2017-11-22 11:57:51 +03:00
2018-01-22 21:30:53 +03:00
import { ShareLink } from '../../common-elements/linkify';
import { Endpoint } from '../Endpoint/Endpoint';
2017-10-12 00:01:37 +03:00
import { Markdown } from '../Markdown/Markdown';
import { Parameters } from '../Parameters/Parameters';
import { RequestSamples } from '../RequestSamples/RequestSamples';
2018-01-22 21:30:53 +03:00
import { ResponsesList } from '../Responses/ResponsesList';
2017-10-12 00:01:37 +03:00
import { ResponseSamples } from '../ResponseSamples/ResponseSamples';
import { OperationModel as OperationType } from '../../services/models';
const OperationRow = Row.extend`
backface-visibility: hidden;
contain: content;
2017-10-12 00:01:37 +03:00
overflow: hidden;
2018-01-30 16:35:18 +03:00
position: relative;
&:after {
position: absolute;
bottom: 0;
width: 100%;
display: block;
content: '';
border-bottom: 1px solid rgba(0, 0, 0, 0.2);
}
2017-10-12 00:01:37 +03:00
`;
2018-05-16 12:44:36 +03:00
export interface OperationProps {
2017-10-12 00:01:37 +03:00
operation: OperationType;
}
@observer
2018-03-17 23:04:37 +03:00
export class Operation extends React.Component<OperationProps> {
2017-10-12 00:01:37 +03:00
render() {
const { operation } = this.props;
const { name: summary, description, deprecated } = operation;
return (
2018-03-17 23:04:37 +03:00
<OptionsContext.Consumer>
{options => (
<OperationRow>
<MiddlePanel>
<H2>
<ShareLink href={'#' + operation.id} />
2018-03-17 23:04:37 +03:00
{summary} {deprecated && <Badge type="warning"> Deprecated </Badge>}
</H2>
{options.pathInMiddlePanel && <Endpoint operation={operation} inverted={true} />}
{description !== undefined && <Markdown source={description} />}
<SecurityRequirements securities={operation.security} />
<Parameters parameters={operation.parameters} body={operation.requestBody} />
<ResponsesList responses={operation.responses} />
</MiddlePanel>
<DarkRightPanel>
{!options.pathInMiddlePanel && <Endpoint operation={operation} />}
<RequestSamples operation={operation} />
<ResponseSamples operation={operation} />
</DarkRightPanel>
</OperationRow>
)}
</OptionsContext.Consumer>
2017-10-12 00:01:37 +03:00
);
}
}