Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: deprecated badge on one of any of buttons #1930

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@
"modulePathIgnorePatterns": [
"/benchmark/"
],
"snapshotSerializers": [
"enzyme-to-json/serializer"
],
"moduleNameMapper": {
"\\.(css|less)$": "<rootDir>/src/empty.js"
}
Expand Down
5 changes: 4 additions & 1 deletion src/common-elements/schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled from '../styled-components';
import { darken } from 'polished';
import { deprecatedCss } from './mixins';

export const OneOfList = styled.div`
margin: 0 0 3px 0;
Expand All @@ -14,7 +15,7 @@ export const OneOfLabel = styled.span`
}
`;

export const OneOfButton = styled.button<{ active: boolean }>`
export const OneOfButton = styled.button<{ active: boolean; deprecated: boolean }>`
display: inline-block;
margin-right: 10px;
margin-bottom: 5px;
Expand All @@ -28,6 +29,8 @@ export const OneOfButton = styled.button<{ active: boolean }>`
box-shadow: 0 0 0 1px ${props => props.theme.colors.primary.main};
}

${({ deprecated }) => (deprecated && deprecatedCss) || ''};

${props => {
if (props.active) {
return `
Expand Down
10 changes: 9 additions & 1 deletion src/components/Schema/OneOfSchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
OneOfLabel,
OneOfList,
} from '../../common-elements/schema';
import { Badge } from '../../common-elements/shelfs';
import { SchemaModel } from '../../services/models';
import { Schema, SchemaProps } from './Schema';

Expand All @@ -20,7 +21,11 @@ export class OneOfButton extends React.Component<OneOfButtonProps> {
render() {
const { idx, schema, subSchema } = this.props;
return (
<StyledOneOfButton active={idx === schema.activeOneOf} onClick={this.activateOneOf}>
<StyledOneOfButton
deprecated={subSchema.deprecated}
active={idx === schema.activeOneOf}
onClick={this.activateOneOf}
>
{subSchema.title || subSchema.typePrefix + subSchema.displayType}
</StyledOneOfButton>
);
Expand Down Expand Up @@ -50,6 +55,9 @@ export class OneOfSchema extends React.Component<SchemaProps> {
<OneOfButton key={subSchema.pointer} schema={schema} subSchema={subSchema} idx={idx} />
))}
</OneOfList>
<div>
{oneOf[schema.activeOneOf].deprecated && <Badge type="warning">Deprecated</Badge>}
</div>
<Schema {...this.props} schema={oneOf[schema.activeOneOf]} />
</div>
);
Expand Down
27 changes: 21 additions & 6 deletions src/components/__tests__/OneOfSchema.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import * as React from 'react';
import { OneOfSchema, Schema } from '../';
import { OpenAPIParser, SchemaModel } from '../../services';
import { RedocNormalizedOptions } from '../../services/RedocNormalizedOptions';
import { withTheme } from '../testProviders';

const options = new RedocNormalizedOptions({});
describe('Components', () => {
describe('SchemaView', () => {
const parser = new OpenAPIParser(
{ openapi: '3.0', info: { title: 'test', version: '0' }, paths: {} },
undefined,
options,
);

describe('OneOf', () => {
it('should pass down skipReadOnly/skipReadWrite to nested oneOf', () => {
const parser = new OpenAPIParser(
{ openapi: '3.0', info: { title: 'test', version: '0' }, paths: {} },
undefined,
options,
);

const schema = new SchemaModel(
parser,
{ oneOf: [{ type: 'string' }, { type: 'integer' }] },
Expand All @@ -38,5 +39,19 @@ describe('Components', () => {
expect(schemaViewElement.props.skipReadOnly).toBeTruthy();
});
});

describe('OneOf deprecated', () => {
const schema = new SchemaModel(
parser,
{ oneOf: [{ type: 'string', deprecated: true }, { type: 'integer' }] },
'',
options,
);

it('should match snapshot', () => {
const component = shallow(withTheme(<Schema schema={schema} />));
expect(component.render()).toMatchSnapshot();
});
});
});
});
53 changes: 53 additions & 0 deletions src/components/__tests__/__snapshots__/OneOfSchema.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Components SchemaView OneOf deprecated should match snapshot 1`] = `
<div>
<span
class="sc-kfYoZR juYXUf"
>
One of
</span>
<div
class="sc-dlMDgC EoFth"
>
<button
class="sc-fKgJPI iEPbLk"
>
string
</button>
<button
class="sc-fKgJPI bpjiHN"
>
integer
</button>
</div>
<div>
<span
class="sc-bqGGPW eSYQnm"
type="warning"
>
Deprecated
</span>
</div>
<div>
<div>
<div>
<span
class="sc-fbIWvP sc-FRrlG CMpTe bBFKjV"
/>
<span
class="sc-fbIWvP sc-fXazdy CMpTe gJKPGC"
>
string
</span>
</div>

<div>
<div
class="sc-iBzEeX sc-cOifOu dFWqin hjSJYo"
/>
</div>
</div>
</div>
</div>
`;
4 changes: 2 additions & 2 deletions src/components/testProviders.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as React from 'react';
import { ThemeProvider } from 'styled-components';
import defaultTheme from '../theme';
import defaultTheme, { resolveTheme } from '../theme';

export default class TestThemeProvider extends React.Component {
render() {
return (
<ThemeProvider theme={defaultTheme}>
<ThemeProvider theme={resolveTheme(defaultTheme)}>
{React.Children.only(this.props.children as any)}
</ThemeProvider>
);
Expand Down