2017-10-12 00:01:37 +03:00
|
|
|
import * as React from 'react';
|
|
|
|
import { ShelfIcon } from '../../common-elements';
|
2018-01-22 21:30:53 +03:00
|
|
|
import { OperationModel } from '../../services';
|
2018-11-27 12:43:31 +03:00
|
|
|
import { Markdown } from '../Markdown/Markdown';
|
2018-03-17 23:04:37 +03:00
|
|
|
import { OptionsContext } from '../OptionsProvider';
|
2017-10-12 00:01:37 +03:00
|
|
|
import { SelectOnClick } from '../SelectOnClick/SelectOnClick';
|
|
|
|
|
2019-09-30 10:39:19 +03:00
|
|
|
import { expandDefaultServerVariables, getBasePath } from '../../utils';
|
2017-10-12 00:01:37 +03:00
|
|
|
import {
|
|
|
|
EndpointInfo,
|
|
|
|
HttpVerb,
|
2018-01-22 21:30:53 +03:00
|
|
|
OperationEndpointWrap,
|
|
|
|
ServerItem,
|
2017-10-12 00:01:37 +03:00
|
|
|
ServerRelativeURL,
|
|
|
|
ServersOverlay,
|
|
|
|
ServerUrl,
|
|
|
|
} from './styled.elements';
|
|
|
|
|
|
|
|
export interface EndpointProps {
|
|
|
|
operation: OperationModel;
|
2017-11-20 23:36:21 +03:00
|
|
|
|
|
|
|
hideHostname?: boolean;
|
2017-11-22 11:57:51 +03:00
|
|
|
inverted?: boolean;
|
2020-04-08 14:04:58 +03:00
|
|
|
compact?: boolean;
|
2017-10-12 00:01:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface EndpointState {
|
|
|
|
expanded: boolean;
|
|
|
|
}
|
|
|
|
|
2018-03-17 23:04:37 +03:00
|
|
|
export class Endpoint extends React.Component<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() {
|
2018-03-17 23:04:37 +03:00
|
|
|
const { operation, inverted, hideHostname } = this.props;
|
2017-10-12 00:01:37 +03:00
|
|
|
const { expanded } = this.state;
|
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 (
|
2018-03-17 23:04:37 +03:00
|
|
|
<OptionsContext.Consumer>
|
|
|
|
{options => (
|
|
|
|
<OperationEndpointWrap>
|
|
|
|
<EndpointInfo onClick={this.toggle} expanded={expanded} inverted={inverted}>
|
2020-04-08 14:04:58 +03:00
|
|
|
<HttpVerb type={operation.httpVerb} compact={this.props.compact}>
|
|
|
|
{operation.httpVerb}
|
|
|
|
</HttpVerb>
|
2018-03-17 23:04:37 +03:00
|
|
|
<ServerRelativeURL>{operation.path}</ServerRelativeURL>
|
|
|
|
<ShelfIcon
|
|
|
|
float={'right'}
|
|
|
|
color={inverted ? 'black' : 'white'}
|
|
|
|
size={'20px'}
|
|
|
|
direction={expanded ? 'up' : 'down'}
|
|
|
|
style={{ marginRight: '-25px' }}
|
|
|
|
/>
|
|
|
|
</EndpointInfo>
|
2020-07-06 15:53:31 +03:00
|
|
|
<ServersOverlay expanded={expanded} aria-hidden={!expanded}>
|
2019-07-29 13:08:17 +03:00
|
|
|
{operation.servers.map(server => {
|
2019-09-30 10:39:19 +03:00
|
|
|
const normalizedUrl = options.expandDefaultServerVariables
|
|
|
|
? expandDefaultServerVariables(server.url, server.variables)
|
|
|
|
: server.url;
|
2020-11-03 15:47:23 +03:00
|
|
|
const basePath = getBasePath(normalizedUrl);
|
2019-07-29 13:08:17 +03:00
|
|
|
return (
|
2019-09-30 10:39:19 +03:00
|
|
|
<ServerItem key={normalizedUrl}>
|
2019-07-29 13:08:17 +03:00
|
|
|
<Markdown source={server.description || ''} compact={true} />
|
|
|
|
<SelectOnClick>
|
|
|
|
<ServerUrl>
|
2022-07-22 17:15:34 +03:00
|
|
|
<span>
|
|
|
|
{hideHostname || options.hideHostname
|
|
|
|
? basePath === '/'
|
|
|
|
? ''
|
|
|
|
: basePath
|
|
|
|
: normalizedUrl}
|
|
|
|
</span>
|
2019-07-29 13:08:17 +03:00
|
|
|
{operation.path}
|
|
|
|
</ServerUrl>
|
|
|
|
</SelectOnClick>
|
|
|
|
</ServerItem>
|
|
|
|
);
|
|
|
|
})}
|
2018-03-17 23:04:37 +03:00
|
|
|
</ServersOverlay>
|
|
|
|
</OperationEndpointWrap>
|
|
|
|
)}
|
|
|
|
</OptionsContext.Consumer>
|
2017-10-12 00:01:37 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|