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

Addon-docs: Move summary & detail equality check to createSummaryValue #12588

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -47,10 +47,7 @@ function generateElement(
inferedType as InspectionIdentifiableInferedType
);

return createSummaryValue(
prettyIdentifier,
prettyIdentifier !== defaultValue ? defaultValue : undefined
);
return createSummaryValue(prettyIdentifier, defaultValue);
}
}

Expand Down
Expand Up @@ -50,7 +50,7 @@ function generateReactObject(rawDefaultProp: any) {
if (displayName != null) {
const prettyIdentifier = getPrettyElementIdentifier(displayName);

return createSummaryValue(prettyIdentifier, prettyIdentifier !== jsx ? jsx : undefined);
return createSummaryValue(prettyIdentifier, jsx);
}

if (isString(type)) {
Expand Down
2 changes: 1 addition & 1 deletion addons/docs/src/frameworks/react/propTypes/createType.ts
Expand Up @@ -381,7 +381,7 @@ export function createType(extractedProp: ExtractedProp): PropType {
}
}

return createSummaryValue(short, short !== full ? full : undefined);
return createSummaryValue(short, full);
}
case PropTypesType.FUNC: {
const { short, full } = generateType(type, extractedProp);
Expand Down
20 changes: 20 additions & 0 deletions addons/docs/src/lib/utils.test.ts
@@ -0,0 +1,20 @@
import { createSummaryValue } from './utils';

describe('createSummaryValue', () => {
it('creates an object with just summary if detail is not passed', () => {
const summary = 'boolean';
expect(createSummaryValue(summary)).toEqual({ summary });
});

it('creates an object with summary & detail if passed', () => {
const summary = 'MyType';
const detail = 'boolean | string';
expect(createSummaryValue(summary, detail)).toEqual({ summary, detail });
});

it('creates an object with just summary if details are equal', () => {
const summary = 'boolean';
const detail = 'boolean';
expect(createSummaryValue(summary, detail)).toEqual({ summary });
});
});
3 changes: 3 additions & 0 deletions addons/docs/src/lib/utils.ts
Expand Up @@ -12,6 +12,9 @@ export function isTooLongForDefaultValueSummary(value: string): boolean {
}

export function createSummaryValue(summary: string, detail?: string): PropSummaryValue {
if (summary === detail) {
return { summary };
}
return { summary, detail };
}

Expand Down