Skip to content

Commit

Permalink
[Pre-Codemod] docgen should generate tsType instead of flowType
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhsu978 committed May 15, 2024
1 parent 2ecc62c commit fc5f045
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 30 deletions.
12 changes: 6 additions & 6 deletions docs/docs-components/GeneratedPropTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ export default function GeneratedPropTable({
// Using Object.keys because of https://github.com/facebook/flow/issues/2174
const props = Object.keys(generatedDocGen.props)
.map((key: string) => {
const { flowType, description, required, defaultValue } = generatedDocGen.props[key];
const { tsType, description, required, defaultValue } = generatedDocGen.props[key];

// Filter out "_fooInternalProp" internal props that we don't want to document
if (key.startsWith('_')) {
return null;
}

// Filter out PropType only types & excluded props
if (!flowType || excludeProps.includes(key)) {
if (!tsType || excludeProps.includes(key)) {
return null;
}

Expand All @@ -100,9 +100,9 @@ export default function GeneratedPropTable({

// Trim leading `|`
const transformedType = (
flowType.raw?.replace(/^\|/, '').trim() ??
flowType?.value ??
flowType.name ??
tsType.raw?.replace(/^\|/, '').trim() ??
tsType?.value ??
tsType.name ??
''
)
// Replace "Node" with "React.Node" to match docs convention
Expand All @@ -122,7 +122,7 @@ export default function GeneratedPropTable({
description: descriptionWithoutOverrides?.trim(),
required,
defaultValue: defaultValue?.value?.replace(/'/g, ''),
nullable: flowType?.nullable || false,
nullable: tsType?.nullable || false,
...overrides,
};
})
Expand Down
4 changes: 2 additions & 2 deletions docs/docs-components/docgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type DocGen = {
},
required: boolean,
description: string,
flowType: {
tsType: {
raw?: string,
nullable?: boolean,
name: string,
Expand Down Expand Up @@ -47,7 +47,7 @@ export function overrideTypes(docGenArg: DocGen, typeOverrides: { [string]: stri
Object.keys(typeOverrides).forEach((key) => {
if (docGenArg?.props?.[key]) {
// eslint-disable-next-line no-param-reassign
docGenArg.props[key].flowType = {
docGenArg.props[key].tsType = {
name: 'union',
raw: typeOverrides[key],
};
Expand Down
2 changes: 1 addition & 1 deletion docs/docs-components/metadata.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ declare module 'metadata' {
},
required: boolean,
description: string,
flowType: {
tsType: {
raw?: string,
nullable?: boolean,
name: string,
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/web/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export async function getServerSideProps(): Promise<{

docGen.Accordion.props.icon = {
...docGen.Accordion.props.icon,
flowType: {
tsType: {
name: 'string',
raw: 'Icon[icon]',
},
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/web/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ export async function getServerSideProps(): Promise<{
'DropdownSection',
]);

docGen.Dropdown.props.children.flowType.raw =
docGen.Dropdown.props.children.tsType.raw =
'React.ChildrenArray<React.Element<typeof DropdownItem | typeof DropdownSection>>';
docGen.DropdownSection.props.children.flowType.raw =
docGen.DropdownSection.props.children.tsType.raw =
'React.ChildrenArray<React.Element<typeof DropdownItem | typeof DropdownSection>>';

return {
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/web/iconbuttonfloating.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export async function getServerSideProps(): Promise<{

generatedDocGen.props.icon = {
...generatedDocGen.props.icon,
flowType: {
tsType: {
name: 'string',
raw: 'Icon[icon]',
},
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/web/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ export async function getServerSideProps(): Promise<{
}> {
const docGen = await multipleDocGen(['List', 'ListItem']);

docGen.List.props.children.flowType.raw = '<Element<typeof List.Item>>';
docGen.ListItem.props.children.flowType.raw = '<Element<typeof List | typeof List.Item>>';
docGen.List.props.children.tsType.raw = '<Element<typeof List.Item>>';
docGen.ListItem.props.children.tsType.raw = '<Element<typeof List | typeof List.Item>>';

return {
props: {
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/web/masonry.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export async function getServerSideProps(): Promise<{

generatedDocGen.props.measurementStore = {
...generatedDocGen.props.measurementStore,
flowType: {
tsType: {
name: 'string',
raw: 'typeof MeasurementStore',
},
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/web/pog.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export async function getServerSideProps(): Promise<{

generatedDocGen.props.icon = {
...generatedDocGen.props.icon,
flowType: {
tsType: {
name: 'string',
raw: 'Icon[icon]',
},
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/web/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export async function getServerSideProps(): Promise<{
props: { generatedDocGen: DocGen },
}> {
const generatedDocGen = await docGen('Popover');
generatedDocGen.props.color.flowType.raw = '"white" | "darkGray"';
generatedDocGen.props.color.tsType.raw = '"white" | "darkGray"';

return {
props: {
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/web/sticky.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function getServerSideProps(): Promise<{
generatedDocGen.props[prop] = {
defaultValue: null,
required: false,
flowType: {
tsType: {
name: 'number | string',
raw: `number | string`,
},
Expand Down
14 changes: 7 additions & 7 deletions docs/pages/web/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,18 +590,18 @@ export async function getServerSideProps(): Promise<{
'TableRowDrawer',
]);

docGen.Table.props.children.flowType.raw =
docGen.Table.props.children.tsType.raw =
'React.ChildrenArray<React.Element<typeof Table.Body | typeof Table.Footer | typeof Table.Header>>';
docGen.TableHeader.props.children.flowType.raw = 'React.Element<typeof Table.Row>';
docGen.TableBody.props.children.flowType.raw =
docGen.TableHeader.props.children.tsType.raw = 'React.Element<typeof Table.Row>';
docGen.TableBody.props.children.tsType.raw =
'React.ChildrenArray<React.Element<typeof Table.Row | typeof Table.RowExpandable>>';
docGen.TableFooter.props.children.flowType.raw =
docGen.TableFooter.props.children.tsType.raw =
'React.ChildrenArray<React.Element<typeof Table.Row | typeof Table.RowExpandable>>';
docGen.TableRow.props.children.flowType.raw =
docGen.TableRow.props.children.tsType.raw =
'React.ChildrenArray<React.Element<typeof Table.Cell | typeof Table.HeaderCell | typeof Table.SortableHeaderCell>>';
docGen.TableRowExpandable.props.children.flowType.raw =
docGen.TableRowExpandable.props.children.tsType.raw =
'React.ChildrenArray<React.Element<typeof Table.Cell>>';
docGen.TableRowDrawer.props.children.flowType.raw =
docGen.TableRowDrawer.props.children.tsType.raw =
'React.ChildrenArray<React.Element<typeof Table.Cell>>';

return {
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/web/tableofcontents.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ export async function getServerSideProps(): Promise<{
}> {
const docGen = await multipleDocGen(['TableOfContents', 'TableOfContentsItem']);

docGen.TableOfContents.props.children.flowType.raw = '<Element<typeof TableOfContents.Item>>';
docGen.TableOfContentsItem.props.children.flowType.raw = '<Element<typeof TableOfContents.Item>>';
docGen.TableOfContents.props.children.tsType.raw = '<Element<typeof TableOfContents.Item>>';
docGen.TableOfContentsItem.props.children.tsType.raw = '<Element<typeof TableOfContents.Item>>';

return {
props: {
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/web/textfield.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ export async function getServerSideProps(): Promise<{
}> {
const generatedDocGen = await docGen('TextField');

generatedDocGen.props.autoComplete.flowType.raw = `'bday' | 'current-password' | 'email' | 'new-password' | 'on' | 'off' | 'username' | 52 more ...`;
generatedDocGen.props.autoComplete.tsType.raw = `'bday' | 'current-password' | 'email' | 'new-password' | 'on' | 'off' | 'username' | 52 more ...`;

return {
props: { generatedDocGen: await docGen('TextField') },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/web/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export async function getServerSideProps(): Promise<{ props: { generatedDocGen:
generatedDocGen.props.ref = {
required: false,
defaultValue: null,
flowType: {
tsType: {
name: 'Ref',
raw: 'Ref<typeof Video>',
},
Expand Down

0 comments on commit fc5f045

Please sign in to comment.