Skip to content

Conversation

@khushal87
Copy link
Member

@khushal87 khushal87 commented Jul 16, 2021

This PR fixes existing issues and covers the document generation tasks which include the following:

Issues:

  • Fixing the typescript compilation issue which was due to the presence of scripts in the root directory and having a different target to which it was compiled into.
  • Fixing the issues related to preview of markdown on the docusaurus pages.
  • Improving the performance of the script by improving the file input strategy to the docgen parser.
  • Adding relevant Comments and Descriptions wherever needed.
  • Made SpeedDial structured to parse it as a Compound Component.

Features

  • Adding relevant scripts in package.json to run the docgen scripts.
  • Upgrading the version of the docusaurus package and related presets and plugins to 2.0.0-beta.4.
  • Improve the Generate Markdown script to accommodate the markdown generation for Compound Components.
  • For compound components, the children's would be stored within the parent of the Component within the childrens array.
    Eg: ListItem.Accordion
    The JSON for the Accordion will be inside the ListItem childrens key.
  • Fixing the broken links within the markdown which were not working the Docusaurus preview.
  • Added relevant Prop Filters in the docgenParser.ts to fix issues with the broken markdown. These issues were due to the presence of improper JSX in markdown, irrelevant props which would be difficult to understand for users.
  • Added pre-push hook to automate the process.
  • Added Google Summer of Code - khushal87 blog to the documentation website.

Tags
#gsoc #docs-autogen #khushal87

@khushal87 khushal87 marked this pull request as draft July 16, 2021 17:14
@khushal87 khushal87 marked this pull request as ready for review July 16, 2021 17:15
@codecov
Copy link

codecov bot commented Jul 16, 2021

Codecov Report

Merging #3145 (34e97a2) into next (1edab6e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             next    #3145   +/-   ##
=======================================
  Coverage   83.91%   83.92%           
=======================================
  Files          80       80           
  Lines        1654     1655    +1     
  Branches      693      693           
=======================================
+ Hits         1388     1389    +1     
  Misses        262      262           
  Partials        4        4           
Impacted Files Coverage Δ
src/Avatar/Avatar.Accessory.tsx 100.00% <ø> (ø)
src/Card/Card.Divider.tsx 100.00% <ø> (ø)
src/Card/Card.FeaturedSubtitle.tsx 100.00% <ø> (ø)
src/Card/Card.FeaturedTitle.tsx 100.00% <ø> (ø)
src/Card/Card.Image.tsx 100.00% <ø> (ø)
src/Card/Card.Title.tsx 100.00% <ø> (ø)
src/CheckBox/components/CheckBoxIcon.tsx 100.00% <ø> (ø)
src/Dialog/Dialog.Button.tsx 100.00% <ø> (ø)
src/Dialog/Dialog.tsx 100.00% <ø> (ø)
src/Image/Image.tsx 77.77% <ø> (ø)
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1edab6e...34e97a2. Read the comment docs.

Copy link
Member

@arpitBhalla arpitBhalla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@khushal87 khushal87 marked this pull request as draft July 17, 2021 10:27
@khushal87 khushal87 marked this pull request as ready for review August 5, 2021 05:31
@khushal87 khushal87 marked this pull request as draft August 5, 2021 07:10
@netlify
Copy link

netlify bot commented Aug 6, 2021

✔️ Deploy Preview for react-native-elements ready!

🔨 Explore the source changes: 34e97a2

🔍 Inspect the deploy log: https://app.netlify.com/sites/react-native-elements/deploys/611d3e6eac75f80008ba1478

😎 Browse the preview: https://deploy-preview-3145--react-native-elements.netlify.app

Comment on lines 37 to 180
const parserOptions = {
savePropValueAsString: true,
propFilter: (prop, component) => {
// This removes the theme props(theme, updateTheme, replaceTheme) from the documentation as they are common to all
if (themeProps.includes(prop.name)) {
return false;
}

// To replace all the '|' in props with 'or'
// Input - TouchableOpacity | View
// Output - TouchableOpacity or View
if (prop.type && prop.type.name && prop.type.name.includes('|')) {
prop.type.name = prop.type.name.replace(/\|/g, 'or');
}

// To replace all the '&' in props with 'and'
// Input - TouchableOpacity & View
// Output - TouchableOpacity and View
if (prop.type && prop.type.name && prop.type.name.includes('&')) {
prop.type.name = prop.type.name.replace(/&/g, 'and');
}

// To deal with the props of type StyleProp<ViewStyle> and StyleProp<TextStyle> which breaks the markdown
// Input - StyleProp<ViewStyle>
// Output - View style(Object)
if (prop.type && prop.type.name && prop.type.name.includes('StyleProp')) {
if (prop.type.name.includes('TextStyle')) {
prop.type.name = 'Text Style(Object)';
} else {
prop.type.name = 'View style(Object)';
}
}

// To deal with the props of type Partial<> which breaks the markdown
// Input - Partial<ImageProps>
// Output - ImageProps(Object)
if (prop.type && prop.type.name && prop.type.name.includes('Partial')) {
const propName = prop.type.name;
prop.type.name =
propName.substring(
propName.lastIndexOf('<') + 1,
propName.lastIndexOf('>')
) + '(Object)';
}

// Replace the occurances of type Component/ViewComponent to React Component
// Input - Component/ViewComponent
// Output - React Component
if (prop.name === 'Component' || prop.name === 'ViewComponent') {
prop.type.name = 'React Component';
}

// To replace the containerStyle props with 'typeof styles'(Object) to Style Object
// Input - typeof styles
// Output - Style Object
if (component.name === 'Slider' && prop.name === 'containerStyle') {
prop.type.name = 'Style Object';
}

// To replace the animation prop to a valid type of ListItem.Accordion
// Input - {
// type?: 'timing' | 'spring';
// duration?: number;
// }
// | boolean;
// Output - Boolean or Object
if (component.name === 'ListItem.Accordion' && prop.name == 'animation') {
prop.type.name = 'Boolean or Object';
}

// To deal with the platform specific props default value in ButtonGroup
// Input - Platform.select<typeof React.Component>({
// android: TouchableNativeFeedback,
// default: TouchableOpacity,
// })
// Output - TouchableOpacity(ios),TouchableNativeFeedback(android),TouchableOpacity(web)
if (component.name === 'ButtonGroup' && prop.name === 'Component') {
prop.defaultValue.value = platformMappingHandler(prop.defaultValue.value);
}

// To replace '\r\n' which breaks the markdown for certain props to ''
if (
prop.defaultValue &&
prop.defaultValue.value &&
prop.defaultValue.value.includes('\r\n')
) {
prop.defaultValue.value = prop.defaultValue.value.replace(/\r\n/g, '');
}

// To deal with the platform specific props default value in Icon
// Image - onPress ? Platform.select<typeof React.Component>({
// android: TouchableNativeFeedback,
// default: TouchableHighlight,
// }) | View
// Output - TouchableHighlight(ios),TouchableNativeFeedback(android),TouchableHighlight(web) | View
if (component.name === 'Icon' && prop.name === 'Component') {
prop.defaultValue.value =
platformMappingHandler(prop.defaultValue.value) + ' | View';
}

// To deal with the ViewComponent prop default value in Header
// linearGradientProps || !backgroundImage
// ? View
// : ImageBackground
// Output - ImageBackground or View Component
if (component.name === 'Header' && prop.name === 'ViewComponent') {
prop.defaultValue.value = 'ImageBackground or View Component';
}

// Replace all the props with default value theme?.colors?.primary to Color(Primary)
// Input - theme?.colors?.primary
// Output - Color(Primary)
if (
prop.defaultValue &&
prop.defaultValue.value === 'theme?.colors?.primary'
) {
prop.defaultValue.value = 'Color(Primary)';
}

// To deal with the prop of default value onPress || onLongPress ? TouchableOpacity : View in Avatar
// Input - onPress || onLongPress ? TouchableOpacity : View
// Output - TouchableOpacity or View
if (
prop.defaultValue &&
prop.defaultValue.value ===
'onPress || onLongPress ? TouchableOpacity : View'
) {
prop.defaultValue.value = 'TouchableOpacity or View';
}

// Filter to show the props of the components only related to the src and ignore the props of the noe modules
if (
prop.declarations !== undefined &&
prop.declarations.length > 0 &&
!componentsWithParentsTypeToBeParsed.includes(component.name)
) {
return Boolean(
prop.declarations.find((declaration) => {
return declaration.fileName.includes(component.name);
})
);
}
return true;
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure whether this is maintainable in the long run.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but if we don't do this, the markdown is not parsed well with docusaurus. If we want to improve this we will have to change the code base of Typescript files such that they are parsed will with the scripts. Do you have any other solution in mind? @pranshuchittora

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not informed regarding this change the code base of Typescript files such that they are parsed will with the scripts 😞

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much effort is required to make the following changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will take time, as we have to directly change the typescript logic such that code also works and auto generation of docs also works.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pranshuchittora We've already evaluated looking at how we can minimize adding custom props filter. @khushal87 has fixed certain things in the source code to minimize these but for some of these props, it's difficult / not possible to fix in the source code.

Anyway, let's relook into this separately & not block this PR. @khushal87

We've made sure to document these things well so it's easier for maintenance.

Copy link
Member

@pranshuchittora pranshuchittora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

@pranshuchittora
Copy link
Member

Can you pls document the process of

  • How to add a new component to this pipeline.
  • Also the internals of the implementation

Create a blog inside the website.

Update Documentation

[update] khushal87 test workflow

[fix] khushal87 build-workflow

[fix] khushal87 build-workflow

[add] khushal87 docs autogen test
@pranshuchittora
Copy link
Member

Ready to merge. Pls resolve the conflicts

@khushal87
Copy link
Member Author

@pranshuchittora done.

@pranshuchittora pranshuchittora merged commit ef4176d into react-native-elements:next Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants