mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-08 14:14:56 +03:00
Rename CallbackView to CallbackOperation,
Refactor params
This commit is contained in:
parent
b88ecad51a
commit
dd1e0dcec4
|
@ -2,27 +2,23 @@ import { observer } from 'mobx-react';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
import { OperationModel } from '../../services/models';
|
import { OperationModel } from '../../services/models';
|
||||||
import { CallbackDetailsWrap, StyledCallbackTitle } from '../Callbacks/styled.elements';
|
import { CallbackDetailsWrap, StyledCallbackTitle } from './styled.elements';
|
||||||
import { CallbackDetails } from './CallbackDetails';
|
import { CallbackDetails } from './CallbackDetails';
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
// TODO: rename to Callback
|
export class CallbackOperation extends React.Component<{ callbackOperation: OperationModel }> {
|
||||||
export class CallbackView extends React.Component<{ callbackOperation: OperationModel }> {
|
|
||||||
toggle = () => {
|
toggle = () => {
|
||||||
this.props.callbackOperation.toggle();
|
this.props.callbackOperation.toggle();
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { name, expanded, httpVerb, deprecated } = this.props.callbackOperation;
|
const { expanded } = this.props.callbackOperation;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<StyledCallbackTitle
|
<StyledCallbackTitle
|
||||||
onClick={this.toggle}
|
onClick={this.toggle}
|
||||||
name={name}
|
callbackOperation={this.props.callbackOperation}
|
||||||
opened={expanded}
|
|
||||||
httpVerb={httpVerb}
|
|
||||||
deprecated={deprecated}
|
|
||||||
/>
|
/>
|
||||||
{expanded && (
|
{expanded && (
|
||||||
<CallbackDetailsWrap>
|
<CallbackDetailsWrap>
|
|
@ -6,23 +6,23 @@ import { shortenHTTPVerb } from '../../utils/openapi';
|
||||||
import styled from '../../styled-components';
|
import styled from '../../styled-components';
|
||||||
import { Badge } from '../../common-elements/';
|
import { Badge } from '../../common-elements/';
|
||||||
import { l } from '../../services/Labels';
|
import { l } from '../../services/Labels';
|
||||||
|
import { OperationModel } from '../../services/models';
|
||||||
|
|
||||||
export interface CallbackTitleProps {
|
export interface CallbackTitleProps {
|
||||||
name: string;
|
|
||||||
opened?: boolean;
|
|
||||||
className?: string;
|
className?: string;
|
||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
httpVerb: string;
|
callbackOperation: OperationModel;
|
||||||
deprecated?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CallbackTitle extends React.PureComponent<CallbackTitleProps> {
|
export class CallbackTitle extends React.PureComponent<CallbackTitleProps> {
|
||||||
render() {
|
render() {
|
||||||
const { name, opened, className, onClick, httpVerb, deprecated } = this.props;
|
const { className, onClick, callbackOperation } = this.props;
|
||||||
|
const { name, httpVerb, deprecated, expanded } = callbackOperation;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CallbackTitleWrapper className={className} onClick={onClick || undefined}>
|
<CallbackTitleWrapper className={className} onClick={onClick || undefined}>
|
||||||
<OperationBadgeStyled type={httpVerb}>{shortenHTTPVerb(httpVerb)}</OperationBadgeStyled>
|
<OperationBadgeStyled type={httpVerb}>{shortenHTTPVerb(httpVerb)}</OperationBadgeStyled>
|
||||||
<ShelfIcon size={'1.5em'} direction={opened ? 'down' : 'right'} float={'left'} />
|
<ShelfIcon size={'1.5em'} direction={expanded ? 'down' : 'right'} float={'left'} />
|
||||||
<CallbackNameStyled deprecated={deprecated}>{name}</CallbackNameStyled>
|
<CallbackNameStyled deprecated={deprecated}>{name}</CallbackNameStyled>
|
||||||
{deprecated ? <Badge type="warning"> {l('deprecated')} </Badge> : null}
|
{deprecated ? <Badge type="warning"> {l('deprecated')} </Badge> : null}
|
||||||
</CallbackTitleWrapper>
|
</CallbackTitleWrapper>
|
||||||
|
|
|
@ -2,7 +2,7 @@ import * as React from 'react';
|
||||||
|
|
||||||
import { CallbackModel } from '../../services/models';
|
import { CallbackModel } from '../../services/models';
|
||||||
import styled from '../../styled-components';
|
import styled from '../../styled-components';
|
||||||
import { CallbackView } from './Callback';
|
import { CallbackOperation } from './CallbackOperation';
|
||||||
|
|
||||||
const CallbacksHeader = styled.h3`
|
const CallbacksHeader = styled.h3`
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
|
@ -29,7 +29,9 @@ export class CallbacksList extends React.PureComponent<CallbacksListProps> {
|
||||||
<CallbacksHeader> Callbacks </CallbacksHeader>
|
<CallbacksHeader> Callbacks </CallbacksHeader>
|
||||||
{callbacks.map(callback => {
|
{callbacks.map(callback => {
|
||||||
return callback.operations.map((operation, index) => {
|
return callback.operations.map((operation, index) => {
|
||||||
return <CallbackView key={callback.name + index} callbackOperation={operation} />;
|
return (
|
||||||
|
<CallbackOperation key={`${callback.name}_${index}`} callbackOperation={operation} />
|
||||||
|
);
|
||||||
});
|
});
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
export * from './Callback';
|
export * from './CallbackOperation';
|
||||||
export * from './CallbackTitle';
|
export * from './CallbackTitle';
|
||||||
export * from './CallbacksList';
|
export * from './CallbacksList';
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import styled from '../../styled-components';
|
import styled from '../../styled-components';
|
||||||
import { CallbackTitle } from './CallbackTitle';
|
import { CallbackTitle } from './CallbackTitle';
|
||||||
|
|
||||||
|
// TODO: get 'background-color' from theme
|
||||||
|
// e.g. "theme.colors.secondary.main" or "theme.colors.callbacks.background.main"
|
||||||
export const StyledCallbackTitle = styled(CallbackTitle)`
|
export const StyledCallbackTitle = styled(CallbackTitle)`
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
|
@ -10,6 +12,8 @@ export const StyledCallbackTitle = styled(CallbackTitle)`
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
// TODO: get 'background-color' from theme
|
||||||
|
// e.g. "theme.colors.secondary.light" or "theme.colors.callbacks.background.light"
|
||||||
export const CallbackDetailsWrap = styled.div`
|
export const CallbackDetailsWrap = styled.div`
|
||||||
padding: 10px 25px;
|
padding: 10px 25px;
|
||||||
background-color: #fafafa;
|
background-color: #fafafa;
|
||||||
|
|
|
@ -6,8 +6,9 @@ import * as React from 'react';
|
||||||
import { OpenAPIParser } from '../../services';
|
import { OpenAPIParser } from '../../services';
|
||||||
import { CallbackModel } from '../../services/models/Callback';
|
import { CallbackModel } from '../../services/models/Callback';
|
||||||
import { RedocNormalizedOptions } from '../../services/RedocNormalizedOptions';
|
import { RedocNormalizedOptions } from '../../services/RedocNormalizedOptions';
|
||||||
import { CallbacksList, CallbackTitle, CallbackView } from '../Callbacks';
|
import { CallbacksList, CallbackTitle, CallbackOperation } from '../Callbacks';
|
||||||
import * as simpleCallbackFixture from './fixtures/simple-callback.json';
|
import * as simpleCallbackFixture from './fixtures/simple-callback.json';
|
||||||
|
import { OperationModel } from '../../services/models';
|
||||||
|
|
||||||
const options = new RedocNormalizedOptions({});
|
const options = new RedocNormalizedOptions({});
|
||||||
describe('Components', () => {
|
describe('Components', () => {
|
||||||
|
@ -22,7 +23,7 @@ describe('Components', () => {
|
||||||
);
|
);
|
||||||
// There should be 1 operation defined in simple-callback.json, just get it manually for readability.
|
// There should be 1 operation defined in simple-callback.json, just get it manually for readability.
|
||||||
const callbackViewElement = shallow(
|
const callbackViewElement = shallow(
|
||||||
<CallbackView key={callback.name} callbackOperation={callback.operations[0]} />,
|
<CallbackOperation key={callback.name} callbackOperation={callback.operations[0]} />,
|
||||||
).getElement();
|
).getElement();
|
||||||
expect(callbackViewElement.props).toBeDefined();
|
expect(callbackViewElement.props).toBeDefined();
|
||||||
expect(callbackViewElement.props.children).toBeDefined();
|
expect(callbackViewElement.props.children).toBeDefined();
|
||||||
|
@ -30,8 +31,16 @@ describe('Components', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should correctly render CallbackTitle', () => {
|
it('should correctly render CallbackTitle', () => {
|
||||||
|
const callbackOperation = {
|
||||||
|
name: 'Test',
|
||||||
|
httpVerb: 'get',
|
||||||
|
} as OperationModel;
|
||||||
const callbackTitleViewElement = shallow(
|
const callbackTitleViewElement = shallow(
|
||||||
<CallbackTitle name={'Test'} className={'.test'} onClick={undefined} httpVerb={'get'} />,
|
<CallbackTitle
|
||||||
|
className={'.test'}
|
||||||
|
onClick={undefined}
|
||||||
|
callbackOperation={callbackOperation}
|
||||||
|
/>,
|
||||||
).getElement();
|
).getElement();
|
||||||
expect(callbackTitleViewElement.props).toBeDefined();
|
expect(callbackTitleViewElement.props).toBeDefined();
|
||||||
expect(callbackTitleViewElement.props.className).toEqual('.test');
|
expect(callbackTitleViewElement.props.className).toEqual('.test');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user