Skip to content

Commit 293b233

Browse files
committed
Support showing Incubator components and Support unifying Internal components with parent component
1 parent aefa112 commit 293b233

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

uilib-docs/configurations/pageCreators/createComponentPages.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const path = require('path');
2+
const _ = require('lodash');
23

34
module.exports = async ({graphql, boundActionCreators}) => {
45
const {createPage} = boundActionCreators;
@@ -39,8 +40,12 @@ module.exports = async ({graphql, boundActionCreators}) => {
3940
}
4041
});
4142

43+
const allComponents = getRelevantComponents(
44+
result.data.allComponentMetadata.edges
45+
);
46+
4247
// Create components pages
43-
result.data.allComponentMetadata.edges.map(({node}) => {
48+
allComponents.map(({node}) => {
4449
createPage({
4550
path: `/docs/${node.displayName}`,
4651
component: path.resolve('./src/templates/component.js'),
@@ -52,3 +57,31 @@ module.exports = async ({graphql, boundActionCreators}) => {
5257
});
5358
});
5459
};
60+
61+
function getRelevantComponents(edges) {
62+
const components = _.chain(edges)
63+
/* Filter all Ignored components */
64+
.filter(e => {
65+
return e.node.displayName !== 'IGNORE';
66+
})
67+
/* Group internal components with parent component */
68+
.groupBy(e => e.node.displayName)
69+
.map((groupedEdged, id) => {
70+
if (groupedEdged.length > 1) {
71+
const edge = {
72+
node: {
73+
displayName: id,
74+
docblock: _.find(groupedEdged, e => !!e.node.docblock),
75+
description: _.find(groupedEdged, e => !!e.node.description),
76+
props: _.reduce(groupedEdged, (props, e) => [...props, ...e.node.props], [])
77+
}
78+
};
79+
return edge;
80+
} else {
81+
return groupedEdged[0];
82+
}
83+
})
84+
.value();
85+
86+
return components;
87+
}

uilib-docs/configurations/plugins.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ const componentsDocgenPlugin = [
3434
}
3535
];
3636

37+
const incubatorComponentsDocgenPlugin = [
38+
'gatsby-transformer-react-docgen',
39+
{
40+
resolve: 'gatsby-source-filesystem',
41+
options: {
42+
path: `${__dirname}/../../src/incubator/`
43+
}
44+
}
45+
];
46+
3747
const nativeComponentsDocgenPlugin = [
3848
'gatsby-transformer-react-docgen',
3949
{
@@ -69,6 +79,7 @@ module.exports = {
6979
manifestPlugin,
7080
markdownPagesPlugin,
7181
componentsDocgenPlugin,
82+
incubatorComponentsDocgenPlugin,
7283
nativeComponentsDocgenPlugin,
7384
imagesPlugin,
7485
layoutPlugin

uilib-docs/gatsby-config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {manifestPlugin, markdownPagesPlugin, componentsDocgenPlugin, nativeComponentsDocgenPlugin, imagesPlugin, layoutPlugin} = require('./configurations/plugins');
1+
const {manifestPlugin, markdownPagesPlugin, componentsDocgenPlugin, incubatorComponentsDocgenPlugin, nativeComponentsDocgenPlugin, imagesPlugin, layoutPlugin} = require('./configurations/plugins');
22

33
module.exports = {
44
pathPrefix: '/react-native-ui-lib',
@@ -12,6 +12,7 @@ module.exports = {
1212
`gatsby-plugin-sass`,
1313
...markdownPagesPlugin,
1414
...componentsDocgenPlugin,
15+
...incubatorComponentsDocgenPlugin,
1516
...nativeComponentsDocgenPlugin,
1617
...imagesPlugin,
1718
...manifestPlugin,

uilib-docs/src/components/navbar/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Navbar extends Component {
4646
const components = data.allComponentMetadata.edges;
4747
const filteredComponents = _.chain(components)
4848
.filter(component => component.node.displayName !== 'IGNORE')
49+
.uniqBy('node.displayName')
4950
.sortBy('node.displayName')
5051
.value();
5152

@@ -77,7 +78,6 @@ class Navbar extends Component {
7778
const {filter} = this.state;
7879
const markdowns = this.getMarkdownPages(data);
7980
const components = this.getNavbarComponents(data);
80-
8181
const filteredComponents = _.filter(components, component =>
8282
_.includes(_.lowerCase(component.node.displayName), _.lowerCase(filter))
8383
);

uilib-docs/src/components/navbar/item.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import classnames from 'classnames';
55

66
export default ({id, link, components, currentPage}) => {
77
const hasChildren = _.size(components) > 1;
8+
89
if (!hasChildren) {
910
return <ItemEntry id={id} link={link} currentPage={currentPage} />;
1011
} else {
@@ -17,7 +18,7 @@ export default ({id, link, components, currentPage}) => {
1718
</Link>
1819

1920
<ul class="nested">
20-
{_.map(_.drop(components, 1), c => {
21+
{_.map(_.filter(components, c => c.node.displayName !== id), c => {
2122
return (
2223
<ItemEntry id={c.node.displayName} currentPage={currentPage} />
2324
);

0 commit comments

Comments
 (0)