Skip to content

Commit 5211639

Browse files
authored
Merge pull request #768 from rvsia/fixMappersComponentDemo
Fix links for components examples
2 parents b83cc6f + 8b874e5 commit 5211639

File tree

8 files changed

+25
-10
lines changed

8 files changed

+25
-10
lines changed

packages/react-renderer-demo/src/components/common/example-link.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const ExampleLink = ({ to, text = 'To example' }) => {
1515
return (
1616
<React.Fragment>
1717
<div style={{ float: 'right' }}>
18-
<RouterLink href={`/mappers/${to}`}>
19-
<a className={classes.toExampleLink} href={`/mappers/${to}`}>
18+
<RouterLink href={`/mappers/${to}?mapper=mui`}>
19+
<a className={classes.toExampleLink} href={`/mappers/${to}?mapper=mui`}>
2020
<Button color="primary">{text}</Button>
2121
</a>
2222
</RouterLink>

packages/react-renderer-demo/src/components/navigation/examples-definitions.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,7 @@ export const baseExamples = [
8181
link: componentTypes.WIZARD,
8282
linkText: 'Wizard'
8383
}
84-
];
84+
].map((component) => ({
85+
...component,
86+
link: `${component.link}?mapper=mui`
87+
}));
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const query = /\?.*/;
22

3-
const findConnectedLinks = (pathname, navSchema) => navSchema.find(({ link }) => pathname.replace(/^\//, '').replace(query, '') === link);
3+
const findConnectedLinks = (pathname, navSchema) =>
4+
navSchema.find(({ link }) => pathname.replace(/^\//, '').replace(query, '') === link.replace(query, ''));
45

56
export default findConnectedLinks;

packages/react-renderer-demo/src/components/navigation/mapper.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,22 @@ const Item = ({ href, linkText, component, divider, level }) => {
2525
const classes = useStyles();
2626
const router = useRouter();
2727
const link = useMapperLink(href.replace('/?', '?'));
28+
29+
const queryMapper = router.query.mapper ? `?mapper=${router.query.mapper}` : '';
30+
const finalHref = queryMapper && link.match(query) ? `${link.replace(query, '')}${queryMapper}` : link;
31+
2832
return (
2933
<ListItem
3034
divider={divider}
3135
button
32-
selected={href.replace('/?', '?') === router.asPath.replace(query, '')}
36+
selected={href.replace(query, '') === router.asPath.replace(query, '')}
3337
key={href || linkText}
3438
className={clsx(classes.item, {
3539
[classes.nested]: level > 0
3640
})}
3741
component={forwardRef((props, ref) => (
38-
<RouterNavLink ref={ref} key={component} href={link}>
39-
<Link style={{ color: 'rgba(0, 0, 0, 0.87)' }} {...props} href={link} />
42+
<RouterNavLink ref={ref} key={component} href={finalHref}>
43+
<Link style={{ color: 'rgba(0, 0, 0, 0.87)' }} {...props} href={finalHref} />
4044
</RouterNavLink>
4145
))}
4246
>

packages/react-renderer-demo/src/doc-components/dual-list-select.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ import PropTypes from 'prop-types';
33
import MuiDualListSelect from './examples-texts/mui/mui-dual-list-select.md';
44
import SuirDualListSelect from './examples-texts/suir/suir-dual-list-select.md';
55
import BlueprintDualListSelect from './examples-texts/blueprint/blueprint-dual-list-select.md';
6+
import PF4DualListSelect from './examples-texts/pf4/pf4-dual-list.md';
7+
68
import GenericMuiComponent from '../helpers/generic-mui-component';
79

810
const DualListSelect = ({ activeMapper }) => {
11+
if (activeMapper === 'pf4') {
12+
return <PF4DualListSelect />;
13+
}
14+
915
if (activeMapper === 'mui') {
1016
return <MuiDualListSelect />;
1117
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import useQueryParam from './use-query-param';
2+
import { query } from '../components/navigation/find-connected-links';
23

34
/**
45
* Appends current query mapper value to URL
56
* @param {string} link url string to be appended with current mapper query param
67
*/
78
const useMapperLink = (link = '') => {
89
const mapperQuery = useQueryParam('mapper');
9-
return link.includes('component-example/') ? `${link}${mapperQuery}` : link;
10+
return link.match(query) && mapperQuery ? `${link.replace(query, '')}${mapperQuery}` : link;
1011
};
1112

1213
export default useMapperLink;

packages/react-renderer-demo/src/pages/mappers/component-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ Wizard step <br/>
205205
|----|:--:|----------:|
206206
|title|node/string|Step title|
207207
|name|string, number|Uniq name of the step|
208-
|nextStep|object/name of next step|See [wizard documentation](/mappers/wizard)|
208+
|nextStep|object/name of next step|See [wizard documentation](/mappers/wizard?mapper=mui)|
209209
|fields|array|An array of form fields|
210210

211211
<ExampleLink to='wizard' />

packages/react-renderer-demo/src/pages/typescript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ React form renderer and component mappers include Typescript typings. Each expor
1414

1515
You can learn more about Renderer and its prop types [here](/components/renderer).
1616

17-
Mapper component prop types are listed in the mappers section of the documentation. You can start with [checkbox](/mappers/checkbox).
17+
Mapper component prop types are listed in the mappers section of the documentation. You can start with [checkbox](/mappers/checkbox?mapper=mui).
1818

1919
</DocPage>

0 commit comments

Comments
 (0)