2017-11-20 23:36:21 +03:00
|
|
|
import { ComponentWithOptions } from '../OptionsProvider';
|
2017-10-12 00:01:37 +03:00
|
|
|
import * as React from 'react';
|
|
|
|
import { OperationModel } from '../../services';
|
|
|
|
import { ShelfIcon } from '../../common-elements';
|
|
|
|
import { SelectOnClick } from '../SelectOnClick/SelectOnClick';
|
|
|
|
|
|
|
|
import {
|
|
|
|
OperationEndpointWrap,
|
|
|
|
EndpointInfo,
|
|
|
|
HttpVerb,
|
|
|
|
ServerRelativeURL,
|
|
|
|
ServersOverlay,
|
|
|
|
ServerItem,
|
|
|
|
ServerUrl,
|
|
|
|
} from './styled.elements';
|
|
|
|
|
|
|
|
export interface EndpointProps {
|
|
|
|
operation: OperationModel;
|
2017-11-20 23:36:21 +03:00
|
|
|
|
|
|
|
hideHostname?: boolean;
|
2017-10-12 00:01:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface EndpointState {
|
|
|
|
expanded: boolean;
|
|
|
|
}
|
|
|
|
|
2017-11-20 23:36:21 +03:00
|
|
|
export class Endpoint extends ComponentWithOptions<EndpointProps, EndpointState> {
|
2017-10-12 00:01:37 +03:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
expanded: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
toggle = () => {
|
|
|
|
this.setState({ expanded: !this.state.expanded });
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { operation } = this.props;
|
|
|
|
const { expanded } = this.state;
|
2017-11-15 00:41:20 +03:00
|
|
|
|
2017-11-20 23:36:21 +03:00
|
|
|
const hideHostname = this.props.hideHostname || this.options.hideHostname;
|
|
|
|
|
2017-11-15 00:41:20 +03:00
|
|
|
// TODO: highlight server variables, e.g. https://{user}.test.com
|
2017-10-12 00:01:37 +03:00
|
|
|
return (
|
|
|
|
<OperationEndpointWrap>
|
|
|
|
<EndpointInfo onClick={this.toggle} expanded={expanded}>
|
|
|
|
<HttpVerb type={operation.httpVerb}> {operation.httpVerb}</HttpVerb>{' '}
|
|
|
|
<ServerRelativeURL>{operation.path}</ServerRelativeURL>
|
|
|
|
<ShelfIcon
|
|
|
|
float={'right'}
|
|
|
|
color={'white'}
|
|
|
|
size={'20px'}
|
|
|
|
direction={expanded ? 'up' : 'down'}
|
|
|
|
style={{ marginRight: '-25px' }}
|
|
|
|
/>
|
|
|
|
</EndpointInfo>
|
|
|
|
<ServersOverlay expanded={expanded}>
|
|
|
|
{operation.servers.map(server => (
|
|
|
|
<ServerItem key={server.url}>
|
|
|
|
<div>{server.description}</div>
|
|
|
|
<SelectOnClick>
|
|
|
|
<ServerUrl>
|
2017-11-20 23:36:21 +03:00
|
|
|
{!hideHostname && <span>{server.url}</span>}
|
2017-10-12 00:01:37 +03:00
|
|
|
{operation.path}
|
|
|
|
</ServerUrl>
|
|
|
|
</SelectOnClick>
|
|
|
|
</ServerItem>
|
|
|
|
))}
|
|
|
|
</ServersOverlay>
|
|
|
|
</OperationEndpointWrap>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|