From 0ac08e94075c6df634dc5afbeb86618ebb55fe71 Mon Sep 17 00:00:00 2001 From: Oleksiy Kachynskyy Date: Thu, 2 Apr 2020 15:08:28 +0300 Subject: [PATCH] Update CallbackDetails --- demo/openapi.yaml | 3 ++ .../CallbackSamples/CallbackSamples.tsx | 4 ++ src/components/Callbacks/CallbackDetails.tsx | 49 +++++++++++------ .../Callbacks/CallbackOperation.tsx | 8 +-- src/components/Callbacks/CallbackTitle.tsx | 4 +- src/components/Callbacks/CallbacksList.tsx | 16 +++--- src/components/Operation/Operation.tsx | 54 +++++++------------ src/services/models/Operation.ts | 1 - 8 files changed, 70 insertions(+), 69 deletions(-) diff --git a/demo/openapi.yaml b/demo/openapi.yaml index bc7d797d..6a097a66 100644 --- a/demo/openapi.yaml +++ b/demo/openapi.yaml @@ -539,6 +539,9 @@ paths: post: summary: Order in Progress (Summary) description: A callback triggered every time an Order is updated status to "inProgress" (Description) + externalDocs: + description: Find out more + url: 'https://more-details.com/demo' requestBody: content: application/json: diff --git a/src/components/CallbackSamples/CallbackSamples.tsx b/src/components/CallbackSamples/CallbackSamples.tsx index 611e8ea2..ae0a9f57 100644 --- a/src/components/CallbackSamples/CallbackSamples.tsx +++ b/src/components/CallbackSamples/CallbackSamples.tsx @@ -27,6 +27,10 @@ export class CallbackSamples extends React.Component { render() { const { callbacks } = this.props; + if (!callbacks || callbacks.length === 0) { + return null; + } + const operations = callbacks .map(callback => callback.operations.map(operation => operation)) .reduce((a, b) => a.concat(b), []); diff --git a/src/components/Callbacks/CallbackDetails.tsx b/src/components/Callbacks/CallbackDetails.tsx index e955ab3d..3730aa9f 100644 --- a/src/components/Callbacks/CallbackDetails.tsx +++ b/src/components/Callbacks/CallbackDetails.tsx @@ -1,30 +1,47 @@ +import { observer } from 'mobx-react'; import * as React from 'react'; import { OperationModel } from '../../services/models'; -import { OperationItem } from '../ContentItems/ContentItems'; -import { Endpoint } from '../Endpoint/Endpoint'; -import { Markdown } from '../Markdown/Markdown'; import styled from '../../styled-components'; +import { Endpoint } from '../Endpoint/Endpoint'; +import { ExternalDocumentation } from '../ExternalDocumentation/ExternalDocumentation'; +import { Extensions } from '../Fields/Extensions'; +import { Markdown } from '../Markdown/Markdown'; +import { Parameters } from '../Parameters/Parameters'; +import { ResponsesList } from '../Responses/ResponsesList'; +import { SecurityRequirements } from '../SecurityRequirement/SecurityRequirement'; +import { CallbackDetailsWrap } from './styled.elements'; -export class CallbackDetails extends React.PureComponent<{ callbackOperation: OperationModel }> { +export interface CallbackDetailsProps { + operation: OperationModel; +} + +@observer +export class CallbackDetails extends React.Component { render() { - const description = this.props.callbackOperation.description; + const { operation } = this.props; + const { description, externalDocs } = operation; + const hasDescription = !!(description || externalDocs); return ( -
- {description && ( - - - + + {hasDescription && ( + + {description !== undefined && } + {externalDocs && } + )} - - -
+ + {/* Do we need Extensions in callback details? */} + + + + + ); } } -const CallbackDescription = styled.div` - margin-top: 10px; - margin-bottom: 20px; +const Description = styled.div` + margin-bottom: ${({ theme }) => theme.spacing.unit * 3}px; `; diff --git a/src/components/Callbacks/CallbackOperation.tsx b/src/components/Callbacks/CallbackOperation.tsx index 04c89041..7b9792a6 100644 --- a/src/components/Callbacks/CallbackOperation.tsx +++ b/src/components/Callbacks/CallbackOperation.tsx @@ -2,7 +2,7 @@ import { observer } from 'mobx-react'; import * as React from 'react'; import { OperationModel } from '../../services/models'; -import { CallbackDetailsWrap, StyledCallbackTitle } from './styled.elements'; +import { StyledCallbackTitle } from './styled.elements'; import { CallbackDetails } from './CallbackDetails'; @observer @@ -20,11 +20,7 @@ export class CallbackOperation extends React.Component<{ callbackOperation: Oper onClick={this.toggle} callbackOperation={this.props.callbackOperation} /> - {expanded && ( - - - - )} + {expanded && } ); } diff --git a/src/components/Callbacks/CallbackTitle.tsx b/src/components/Callbacks/CallbackTitle.tsx index f438619f..5dcbcbe6 100644 --- a/src/components/Callbacks/CallbackTitle.tsx +++ b/src/components/Callbacks/CallbackTitle.tsx @@ -23,7 +23,7 @@ export class CallbackTitle extends React.PureComponent { {shortenHTTPVerb(httpVerb)} - {name} + {name} {deprecated ? {l('deprecated')} : null} ); @@ -36,7 +36,7 @@ const CallbackTitleWrapper = styled.div` } `; -const CallbackNameStyled = styled.span<{ deprecated?: boolean }>` +const CallbackName = styled.span<{ deprecated?: boolean }>` text-decoration: ${props => (props.deprecated ? 'line-through' : 'none')}; margin-right: 8px; `; diff --git a/src/components/Callbacks/CallbacksList.tsx b/src/components/Callbacks/CallbacksList.tsx index 37e21644..0ea2b40b 100644 --- a/src/components/Callbacks/CallbacksList.tsx +++ b/src/components/Callbacks/CallbacksList.tsx @@ -4,14 +4,6 @@ import { CallbackModel } from '../../services/models'; import styled from '../../styled-components'; import { CallbackOperation } from './CallbackOperation'; -const CallbacksHeader = styled.h3` - font-size: 18px; - padding: 0.2em 0; - margin: 3em 0 1.1em; - color: #253137; - font-weight: normal; -`; - export interface CallbacksListProps { callbacks: CallbackModel[]; } @@ -38,3 +30,11 @@ export class CallbacksList extends React.PureComponent { ); } } + +const CallbacksHeader = styled.h3` + font-size: 18px; + padding: 0.2em 0; + margin: 3em 0 1.1em; + color: #253137; + font-weight: normal; +`; diff --git a/src/components/Operation/Operation.tsx b/src/components/Operation/Operation.tsx index 89ec56da..3f5aa2a0 100644 --- a/src/components/Operation/Operation.tsx +++ b/src/components/Operation/Operation.tsx @@ -3,8 +3,8 @@ import * as React from 'react'; import { Badge, DarkRightPanel, H2, MiddlePanel, Row } from '../../common-elements'; import { ShareLink } from '../../common-elements/linkify'; -import { OperationModel as OperationType } from '../../services/models'; -import styled, { media } from '../../styled-components'; +import { OperationModel } from '../../services/models'; +import styled from '../../styled-components'; import { CallbacksList } from '../Callbacks'; import { CallbackSamples } from '../CallbackSamples/CallbackSamples'; import { Endpoint } from '../Endpoint/Endpoint'; @@ -19,7 +19,7 @@ import { ResponseSamples } from '../ResponseSamples/ResponseSamples'; import { SecurityRequirements } from '../SecurityRequirement/SecurityRequirement'; export interface OperationProps { - operation: OperationType; + operation: OperationModel; } @observer @@ -29,23 +29,18 @@ export class Operation extends React.Component { const { name: summary, description, deprecated, externalDocs } = operation; const hasDescription = !!(description || externalDocs); - const AdaptiveMiddlePanel = operation.isCallback ? CallbackMiddlePanel : MiddlePanel; return ( {options => ( - - {!operation.isCallback && ( -

- - {summary} {deprecated && Deprecated } -

- )} - {!operation.isCallback && options.pathInMiddlePanel && ( - - )} - {!operation.isCallback && hasDescription && ( + +

+ + {summary} {deprecated && Deprecated } +

+ {options.pathInMiddlePanel && } + {hasDescription && ( {description !== undefined && } {externalDocs && } @@ -54,19 +49,15 @@ export class Operation extends React.Component { - + -
- {!operation.isCallback && ( - - {!options.pathInMiddlePanel && } - - - {operation.callbacks.length > 0 && ( - - )} - - )} + + + {!options.pathInMiddlePanel && } + + + +
)}
@@ -74,18 +65,9 @@ export class Operation extends React.Component { } } -const CallbackMiddlePanel = styled(MiddlePanel)` - width: 100%; - padding: 0; - ${() => media.lessThan('medium', true)` - padding: 0 - `}; -`; - const OperationRow = styled(Row)` backface-visibility: hidden; contain: content; - overflow: hidden; `; diff --git a/src/services/models/Operation.ts b/src/services/models/Operation.ts index 9b468d70..e35a1c58 100644 --- a/src/services/models/Operation.ts +++ b/src/services/models/Operation.ts @@ -254,7 +254,6 @@ export class OperationModel implements IMenuItem { @memoize get callbacks() { - console.log('this.operationSpec.callbacks', this.operationSpec.callbacks); return Object.keys(this.operationSpec.callbacks || []).map(callbackEventName => { return new CallbackModel( this.parser,