redoc/src/components/Operation/Operation.tsx

69 lines
2.2 KiB
TypeScript
Raw Normal View History

2017-10-12 00:01:37 +03:00
import * as React from 'react';
import styled from '../../styled-components';
import { SecurityRequirements } from '../SecurityRequirement/SecuirityRequirement';
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
2017-11-22 11:57:51 +03:00
import { ComponentWithOptions } from '../OptionsProvider';
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 = styled(Row)`
2017-10-12 00:01:37 +03:00
transform: translateZ(0);
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
`;
interface OperationProps {
operation: OperationType;
}
@observer
2017-11-22 11:57:51 +03:00
export class Operation extends ComponentWithOptions<OperationProps> {
2017-10-12 00:01:37 +03:00
render() {
const { operation } = this.props;
const { name: summary, description, deprecated } = operation;
2017-11-22 11:57:51 +03:00
const pathInMiddle = this.options.pathInMiddlePanel;
2017-10-12 00:01:37 +03:00
return (
<OperationRow>
<MiddlePanel>
<H2>
<ShareLink href={'#' + operation.getHash()} />
2017-10-12 00:01:37 +03:00
{summary} {deprecated && <Badge type="warning"> Deprecated </Badge>}
</H2>
2017-11-22 11:57:51 +03:00
{pathInMiddle && <Endpoint operation={operation} inverted={true} />}
2017-10-12 00:01:37 +03:00
{description !== undefined && <Markdown source={description} />}
<SecurityRequirements securities={operation.security} />
2017-10-12 00:01:37 +03:00
<Parameters parameters={operation.parameters} body={operation.requestBody} />
<ResponsesList responses={operation.responses} />
</MiddlePanel>
<DarkRightPanel>
2017-11-22 11:57:51 +03:00
{!pathInMiddle && <Endpoint operation={operation} />}
2017-10-12 00:01:37 +03:00
<RequestSamples operation={operation} />
<ResponseSamples operation={operation} />
</DarkRightPanel>
2017-10-12 00:01:37 +03:00
</OperationRow>
);
}
}