From 9f0252e12eb00354ac464aab7492d4eb423210cf Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Sat, 14 Jul 2018 17:11:29 +0300 Subject: [PATCH] chore: update security-requirement ui --- src/components/Markdown/styled.elements.ts | 28 +++++++++++-------- .../SecuirityRequirement.tsx | 26 +++++++++++++++-- src/services/models/SecurityRequirement.ts | 7 ++--- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/components/Markdown/styled.elements.ts b/src/components/Markdown/styled.elements.ts index ff743c2b..dd5054ad 100644 --- a/src/components/Markdown/styled.elements.ts +++ b/src/components/Markdown/styled.elements.ts @@ -10,6 +10,21 @@ import styled, { withProps, } from '../../styled-components'; +export const linksCss = css` + a { + text-decoration: none; + color: ${props => props.theme.links.color}; + + &:visited { + color: ${props => props.theme.links.visited}; + } + + &:hover { + color: ${props => props.theme.links.hover}; + } + } +`; + export const StyledMarkdownBlock = withProps<{ dense?: boolean; inline?: boolean }>(styled.div)` font-family: ${props => props.theme.baseFont.family}; @@ -136,16 +151,5 @@ export const StyledMarkdownBlock = withProps<{ dense?: boolean; inline?: boolean ${extensionsHook('Markdown')}; - a { - text-decoration: none; - color: ${props => props.theme.links.color}; - - &:visited { - color: ${props => props.theme.links.visited}; - } - - &:hover { - color: ${props => props.theme.links.hover}; - } - } + ${linksCss} `; diff --git a/src/components/SecurityRequirement/SecuirityRequirement.tsx b/src/components/SecurityRequirement/SecuirityRequirement.tsx index 194e6856..94c74f85 100644 --- a/src/components/SecurityRequirement/SecuirityRequirement.tsx +++ b/src/components/SecurityRequirement/SecuirityRequirement.tsx @@ -5,6 +5,7 @@ import styled from '../../styled-components'; import { UnderlinedHeader } from '../../common-elements/headers'; import { SecurityRequirementModel } from '../../services/models/SecurityRequirement'; +import { linksCss } from '../Markdown/styled.elements'; const ScopeName = styled.code` font-size: ${props => props.theme.code.fontSize}; @@ -14,6 +15,25 @@ const ScopeName = styled.code` padding: 0.2em; display: inline-block; line-height: 1; + + &:after { + content: ','; + } + &:last-child:after { + content: none; + } +`; + +const SecurityRequirementWrap = styled.span` + &:after { + content: ' OR '; + font-weight: bold; + } + &:last-child:after { + content: none; + } + + ${linksCss}; `; export interface SecurityRequirementProps { @@ -25,13 +45,13 @@ export class SecurityRequirement extends React.PureComponent { return ( -
+ {scheme.id} {scheme.scopes.length > 0 && ' ('} {scheme.scopes.map(scope => {scope})} {scheme.scopes.length > 0 && ') '} - {idx < security.schemes.length - 1 && ' and '} -
+ {idx < security.schemes.length - 1 && ' & '} + ); }); } diff --git a/src/services/models/SecurityRequirement.ts b/src/services/models/SecurityRequirement.ts index 62fe2ca4..e7c57663 100644 --- a/src/services/models/SecurityRequirement.ts +++ b/src/services/models/SecurityRequirement.ts @@ -1,11 +1,10 @@ -import { OpenAPISecurityRequirement } from '../../types'; +import { OpenAPISecurityRequirement, OpenAPISecurityScheme } from '../../types'; import { SECURITY_SCHEMES_SECTION } from '../../utils/openapi'; import { OpenAPIParser } from '../OpenAPIParser'; -export interface SecurityScheme { +export interface SecurityScheme extends OpenAPISecurityScheme { id: string; sectionId: string; - type: string; scopes: string[]; } @@ -26,9 +25,9 @@ export class SecurityRequirementModel { } return { + ...scheme, id, sectionId: SECURITY_SCHEMES_SECTION + id, - type: scheme.type, scopes, }; })