chore(#197): ran prettier on packages/bruno-graphql-docs

This commit is contained in:
Anoop M D
2023-09-22 00:37:51 +05:30
parent 67fe264494
commit a53dd76854
14 changed files with 96 additions and 248 deletions

View File

@@ -17,11 +17,7 @@ type ArgumentProps = {
showDefaultValue?: boolean;
};
export default function Argument({
arg,
onClickType,
showDefaultValue,
}: ArgumentProps) {
export default function Argument({ arg, onClickType, showDefaultValue }: ArgumentProps) {
return (
<span className="arg">
<span className="arg-name">{arg.name}</span>

View File

@@ -26,9 +26,7 @@ export default function DefaultValue({ field }: DefaultValueProps) {
return (
<span>
{' = '}
<span className="arg-default-value">
{printDefault(astFromValue(field.defaultValue, field.type))}
</span>
<span className="arg-default-value">{printDefault(astFromValue(field.defaultValue, field.type))}</span>
</span>
);
}

View File

@@ -27,37 +27,27 @@ export default function FieldDoc({ field, onClickType }: FieldDocProps) {
<div id="doc-args" className="doc-category">
<div className="doc-category-title">{'arguments'}</div>
{field.args
.filter(arg => !arg.deprecationReason)
.filter((arg) => !arg.deprecationReason)
.map((arg: GraphQLArgument) => (
<div key={arg.name} className="doc-category-item">
<div>
<Argument arg={arg} onClickType={onClickType} />
</div>
<MarkdownContent
className="doc-value-description"
markdown={arg.description}
/>
<MarkdownContent className="doc-value-description" markdown={arg.description} />
{arg && 'deprecationReason' in arg && (
<MarkdownContent
className="doc-deprecation"
markdown={arg?.deprecationReason}
/>
<MarkdownContent className="doc-deprecation" markdown={arg?.deprecationReason} />
)}
</div>
))}
</div>
);
const deprecatedArgs = field.args.filter(arg =>
Boolean(arg.deprecationReason),
);
const deprecatedArgs = field.args.filter((arg) => Boolean(arg.deprecationReason));
if (deprecatedArgs.length > 0) {
deprecatedArgsDef = (
<div id="doc-deprecated-args" className="doc-category">
<div className="doc-category-title">{'deprecated arguments'}</div>
{!showDeprecated ? (
<button
className="show-btn"
onClick={() => handleShowDeprecated(!showDeprecated)}>
<button className="show-btn" onClick={() => handleShowDeprecated(!showDeprecated)}>
{'Show deprecated arguments...'}
</button>
) : (
@@ -66,15 +56,9 @@ export default function FieldDoc({ field, onClickType }: FieldDocProps) {
<div>
<Argument arg={arg} onClickType={onClickType} />
</div>
<MarkdownContent
className="doc-value-description"
markdown={arg.description}
/>
<MarkdownContent className="doc-value-description" markdown={arg.description} />
{arg && 'deprecationReason' in arg && (
<MarkdownContent
className="doc-deprecation"
markdown={arg?.deprecationReason}
/>
<MarkdownContent className="doc-deprecation" markdown={arg?.deprecationReason} />
)}
</div>
))
@@ -85,12 +69,7 @@ export default function FieldDoc({ field, onClickType }: FieldDocProps) {
}
let directivesDef;
if (
field &&
field.astNode &&
field.astNode.directives &&
field.astNode.directives.length > 0
) {
if (field && field.astNode && field.astNode.directives && field.astNode.directives.length > 0) {
directivesDef = (
<div id="doc-directives" className="doc-category">
<div className="doc-category-title">{'directives'}</div>
@@ -107,15 +86,9 @@ export default function FieldDoc({ field, onClickType }: FieldDocProps) {
return (
<div>
<MarkdownContent
className="doc-type-description"
markdown={field?.description || 'No Description'}
/>
<MarkdownContent className="doc-type-description" markdown={field?.description || 'No Description'} />
{field && 'deprecationReason' in field && (
<MarkdownContent
className="doc-deprecation"
markdown={field?.deprecationReason}
/>
<MarkdownContent className="doc-deprecation" markdown={field?.deprecationReason} />
)}
<div className="doc-category">
<div className="doc-category-title">{'type'}</div>

View File

@@ -12,7 +12,7 @@ type Maybe<T> = T | null | undefined;
const md = new MD({
// render urls as links, à la github-flavored markdown
linkify: true,
linkify: true
});
type MarkdownContentProps = {
@@ -20,18 +20,10 @@ type MarkdownContentProps = {
className?: string;
};
export default function MarkdownContent({
markdown,
className,
}: MarkdownContentProps) {
export default function MarkdownContent({ markdown, className }: MarkdownContentProps) {
if (!markdown) {
return <div />;
}
return (
<div
className={className}
dangerouslySetInnerHTML={{ __html: md.render(markdown) }}
/>
);
return <div className={className} dangerouslySetInnerHTML={{ __html: md.render(markdown) }} />;
}

View File

@@ -20,17 +20,13 @@ type SchemaDocProps = {
export default function SchemaDoc({ schema, onClickType }: SchemaDocProps) {
const queryType = schema.getQueryType();
const mutationType = schema.getMutationType && schema.getMutationType();
const subscriptionType =
schema.getSubscriptionType && schema.getSubscriptionType();
const subscriptionType = schema.getSubscriptionType && schema.getSubscriptionType();
return (
<div>
<MarkdownContent
className="doc-type-description"
markdown={
schema.description ||
'A GraphQL schema provides a root type for each kind of operation.'
}
markdown={schema.description || 'A GraphQL schema provides a root type for each kind of operation.'}
/>
<div className="doc-category">
<div className="doc-category-title">{'root types'}</div>

View File

@@ -21,10 +21,7 @@ type SearchBoxState = {
value: string;
};
export default class SearchBox extends React.Component<
SearchBoxProps,
SearchBoxState
> {
export default class SearchBox extends React.Component<SearchBoxProps, SearchBoxState> {
debouncedOnSearch: OnSearchFn;
constructor(props: SearchBoxProps) {
@@ -47,10 +44,7 @@ export default class SearchBox extends React.Component<
aria-label={this.props.placeholder}
/>
{this.state.value && (
<button
className="search-box-clear"
onClick={this.handleClear}
aria-label="Clear search input">
<button className="search-box-clear" onClick={this.handleClear} aria-label="Clear search input">
{'\u2715'}
</button>
)}
@@ -58,7 +52,7 @@ export default class SearchBox extends React.Component<
);
}
handleChange: ChangeEventHandler<HTMLInputElement> = event => {
handleChange: ChangeEventHandler<HTMLInputElement> = (event) => {
const value = event.currentTarget.value;
this.setState({ value });
this.debouncedOnSearch(value);

View File

@@ -20,15 +20,9 @@ type SearchResultsProps = {
onClickField: OnClickFieldFunction;
};
export default class SearchResults extends React.Component<
SearchResultsProps,
{}
> {
export default class SearchResults extends React.Component<SearchResultsProps, {}> {
shouldComponentUpdate(nextProps: SearchResultsProps) {
return (
this.props.schema !== nextProps.schema ||
this.props.searchValue !== nextProps.searchValue
);
return this.props.schema !== nextProps.schema || this.props.searchValue !== nextProps.searchValue;
}
render() {
@@ -47,15 +41,12 @@ export default class SearchResults extends React.Component<
// Move the within type name to be the first searched.
if (withinType) {
typeNames = typeNames.filter(n => n !== withinType.name);
typeNames = typeNames.filter((n) => n !== withinType.name);
typeNames.unshift(withinType.name);
}
for (const typeName of typeNames) {
if (
matchedWithin.length + matchedTypes.length + matchedFields.length >=
100
) {
if (matchedWithin.length + matchedTypes.length + matchedFields.length >= 100) {
break;
}
@@ -64,21 +55,19 @@ export default class SearchResults extends React.Component<
matchedTypes.push(
<div className="doc-category-item" key={typeName}>
<TypeLink type={type} onClick={onClickType} />
</div>,
</div>
);
}
if (type && 'getFields' in type) {
const fields = type.getFields();
Object.keys(fields).forEach(fieldName => {
Object.keys(fields).forEach((fieldName) => {
const field = fields[fieldName];
let matchingArgs;
if (!isMatch(fieldName, searchValue)) {
if ('args' in field && field.args.length) {
matchingArgs = field.args.filter(arg =>
isMatch(arg.name, searchValue),
);
matchingArgs = field.args.filter((arg) => isMatch(arg.name, searchValue));
if (matchingArgs.length === 0) {
return;
}
@@ -89,28 +78,18 @@ export default class SearchResults extends React.Component<
const match = (
<div className="doc-category-item" key={typeName + '.' + fieldName}>
{withinType !== type && [
<TypeLink key="type" type={type} onClick={onClickType} />,
'.',
]}
<a
className="field-name"
onClick={event => onClickField(field, type, event)}>
{withinType !== type && [<TypeLink key="type" type={type} onClick={onClickType} />, '.']}
<a className="field-name" onClick={(event) => onClickField(field, type, event)}>
{field.name}
</a>
{matchingArgs && [
'(',
<span key="args">
{matchingArgs.map(arg => (
<Argument
key={arg.name}
arg={arg}
onClickType={onClickType}
showDefaultValue={false}
/>
{matchingArgs.map((arg) => (
<Argument key={arg.name} arg={arg} onClickType={onClickType} showDefaultValue={false} />
))}
</span>,
')',
')'
]}
</div>
);
@@ -124,10 +103,7 @@ export default class SearchResults extends React.Component<
}
}
if (
matchedWithin.length + matchedTypes.length + matchedFields.length ===
0
) {
if (matchedWithin.length + matchedTypes.length + matchedFields.length === 0) {
return <span className="doc-alert-text">{'No results found.'}</span>;
}
@@ -156,7 +132,7 @@ export default class SearchResults extends React.Component<
function isMatch(sourceText: string, searchValue: string) {
try {
const escaped = searchValue.replace(/[^_0-9A-Za-z]/g, ch => '\\' + ch);
const escaped = searchValue.replace(/[^_0-9A-Za-z]/g, (ch) => '\\' + ch);
return sourceText.search(new RegExp(escaped, 'i')) !== -1;
} catch (e) {
return sourceText.toLowerCase().indexOf(searchValue.toLowerCase()) !== -1;

View File

@@ -13,7 +13,7 @@ import {
GraphQLUnionType,
GraphQLEnumType,
GraphQLType,
GraphQLEnumValue,
GraphQLEnumValue
} from 'graphql';
import Argument from './Argument';
@@ -33,10 +33,7 @@ type TypeDocState = {
showDeprecated: boolean;
};
export default class TypeDoc extends React.Component<
TypeDocProps,
TypeDocState
> {
export default class TypeDoc extends React.Component<TypeDocProps, TypeDocState> {
constructor(props: TypeDocProps) {
super(props);
this.state = { showDeprecated: false };
@@ -74,7 +71,7 @@ export default class TypeDoc extends React.Component<
typesDef = (
<div id="doc-types" className="doc-category">
<div className="doc-category-title">{typesTitle}</div>
{types.map(subtype => (
{types.map((subtype) => (
<div key={subtype.name} className="doc-category-item">
<TypeLink type={subtype} onClick={onClickType} />
</div>
@@ -88,27 +85,19 @@ export default class TypeDoc extends React.Component<
let deprecatedFieldsDef;
if (type && 'getFields' in type) {
const fieldMap = type.getFields();
const fields = Object.keys(fieldMap).map(name => fieldMap[name]);
const fields = Object.keys(fieldMap).map((name) => fieldMap[name]);
fieldsDef = (
<div id="doc-fields" className="doc-category">
<div className="doc-category-title">{'fields'}</div>
{fields
.filter(field => !field.deprecationReason)
.map(field => (
<Field
key={field.name}
type={type}
field={field}
onClickType={onClickType}
onClickField={onClickField}
/>
.filter((field) => !field.deprecationReason)
.map((field) => (
<Field key={field.name} type={type} field={field} onClickType={onClickType} onClickField={onClickField} />
))}
</div>
);
const deprecatedFields = fields.filter(field =>
Boolean(field.deprecationReason),
);
const deprecatedFields = fields.filter((field) => Boolean(field.deprecationReason));
if (deprecatedFields.length > 0) {
deprecatedFieldsDef = (
<div id="doc-deprecated-fields" className="doc-category">
@@ -118,7 +107,7 @@ export default class TypeDoc extends React.Component<
{'Show deprecated fields...'}
</button>
) : (
deprecatedFields.map(field => (
deprecatedFields.map((field) => (
<Field
key={field.name}
type={type}
@@ -141,16 +130,14 @@ export default class TypeDoc extends React.Component<
<div className="doc-category">
<div className="doc-category-title">{'values'}</div>
{values
.filter(value => Boolean(!value.deprecationReason))
.map(value => (
.filter((value) => Boolean(!value.deprecationReason))
.map((value) => (
<EnumValue key={value.name} value={value} />
))}
</div>
);
const deprecatedValues = values.filter(value =>
Boolean(value.deprecationReason),
);
const deprecatedValues = values.filter((value) => Boolean(value.deprecationReason));
if (deprecatedValues.length > 0) {
deprecatedValuesDef = (
<div className="doc-category">
@@ -160,9 +147,7 @@ export default class TypeDoc extends React.Component<
{'Show deprecated values...'}
</button>
) : (
deprecatedValues.map(value => (
<EnumValue key={value.name} value={value} />
))
deprecatedValues.map((value) => <EnumValue key={value.name} value={value} />)
)}
</div>
);
@@ -173,9 +158,7 @@ export default class TypeDoc extends React.Component<
<div>
<MarkdownContent
className="doc-type-description"
markdown={
('description' in type && type.description) || 'No Description'
}
markdown={('description' in type && type.description) || 'No Description'}
/>
{type instanceof GraphQLObjectType && typesDef}
{fieldsDef}
@@ -200,9 +183,7 @@ type FieldProps = {
function Field({ type, field, onClickType, onClickField }: FieldProps) {
return (
<div className="doc-category-item">
<a
className="field-name"
onClick={event => onClickField(field, type, event)}>
<a className="field-name" onClick={(event) => onClickField(field, type, event)}>
{field.name}
</a>
{'args' in field &&
@@ -211,27 +192,19 @@ function Field({ type, field, onClickType, onClickField }: FieldProps) {
'(',
<span key="args">
{field.args
.filter(arg => !arg.deprecationReason)
.map(arg => (
.filter((arg) => !arg.deprecationReason)
.map((arg) => (
<Argument key={arg.name} arg={arg} onClickType={onClickType} />
))}
</span>,
')',
')'
]}
{': '}
<TypeLink type={field.type} onClick={onClickType} />
<DefaultValue field={field} />
{field.description && (
<MarkdownContent
className="field-short-description"
markdown={field.description}
/>
)}
{field.description && <MarkdownContent className="field-short-description" markdown={field.description} />}
{'deprecationReason' in field && field.deprecationReason && (
<MarkdownContent
className="doc-deprecation"
markdown={field.deprecationReason}
/>
<MarkdownContent className="doc-deprecation" markdown={field.deprecationReason} />
)}
</div>
);
@@ -245,16 +218,8 @@ function EnumValue({ value }: EnumValue) {
return (
<div className="doc-category-item">
<div className="enum-value">{value.name}</div>
<MarkdownContent
className="doc-value-description"
markdown={value.description}
/>
{value.deprecationReason && (
<MarkdownContent
className="doc-deprecation"
markdown={value.deprecationReason}
/>
)}
<MarkdownContent className="doc-value-description" markdown={value.description} />
{value.deprecationReason && <MarkdownContent className="doc-deprecation" markdown={value.deprecationReason} />}
</div>
);
}

View File

@@ -6,12 +6,7 @@
*/
import React from 'react';
import {
GraphQLList,
GraphQLNonNull,
GraphQLType,
GraphQLNamedType,
} from 'graphql';
import { GraphQLList, GraphQLNonNull, GraphQLType, GraphQLNamedType } from 'graphql';
import { OnClickTypeFunction } from './types';
type Maybe<T> = T | null | undefined;
@@ -47,11 +42,12 @@ function renderType(type: Maybe<GraphQLType>, onClick: OnClickTypeFunction) {
return (
<a
className="type-name"
onClick={event => {
onClick={(event) => {
event.preventDefault();
onClick(type as GraphQLNamedType, event);
}}
href="#">
href="#"
>
{type?.name}
</a>
);

View File

@@ -7,29 +7,17 @@ import {
GraphQLInterfaceType,
GraphQLInputObjectType,
GraphQLType,
GraphQLNamedType,
GraphQLNamedType
} from 'graphql';
export type FieldType =
| GraphQLField<{}, {}, {}>
| GraphQLInputField
| GraphQLArgument;
export type FieldType = GraphQLField<{}, {}, {}> | GraphQLInputField | GraphQLArgument;
export type OnClickFieldFunction = (
field: FieldType,
type?:
| GraphQLObjectType
| GraphQLInterfaceType
| GraphQLInputObjectType
| GraphQLType,
event?: MouseEvent,
type?: GraphQLObjectType | GraphQLInterfaceType | GraphQLInputObjectType | GraphQLType,
event?: MouseEvent
) => void;
export type OnClickTypeFunction = (
type: GraphQLNamedType,
event?: MouseEvent<HTMLAnchorElement>,
) => void;
export type OnClickTypeFunction = (type: GraphQLNamedType, event?: MouseEvent<HTMLAnchorElement>) => void;
export type OnClickFieldOrTypeFunction =
| OnClickFieldFunction
| OnClickTypeFunction;
export type OnClickFieldOrTypeFunction = OnClickFieldFunction | OnClickTypeFunction;