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

Fix TabbedForm and TabbedShowLayout do not support parenthesis in id #4028

Merged
merged 1 commit into from
Nov 22, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/ra-core/src/util/escapePath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Escape special characters in path so that react-router Route does not do any special treatment
*
* @see https://github.com/ReactTraining/react-router/blob/v3/docs/guides/RouteMatching.md#path-syntax
*
* @example
*
* escapePath('/foo(bar)') => 'foo\(bar\)'
*/
export default url => url.replace(/(\(|\))/g, '\\$1');
2 changes: 2 additions & 0 deletions packages/ra-core/src/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import downloadCSV from './downloadCSV';
import escapePath from './escapePath';
import FieldTitle from './FieldTitle';
import getFetchedAt from './getFetchedAt';
import getFieldLabelTranslationArgs from './getFieldLabelTranslationArgs';
Expand All @@ -16,6 +17,7 @@ import { useSafeSetState, useTimeout } from './hooks';

export {
downloadCSV,
escapePath,
FieldTitle,
getFetchedAt,
getFieldLabelTranslationArgs,
Expand Down
7 changes: 5 additions & 2 deletions packages/ra-ui-materialui/src/detail/TabbedShowLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import PropTypes from 'prop-types';
import Divider from '@material-ui/core/Divider';
import { Route } from 'react-router-dom';
import { makeStyles } from '@material-ui/core/styles';
import { useRouteMatch } from 'react-router-dom';
import { escapePath } from 'ra-core';

import TabbedShowLayoutTabs, { getTabFullPath } from './TabbedShowLayoutTabs';
import { useRouteMatch } from 'react-router-dom';

const sanitizeRestProps = ({
children,
Expand Down Expand Up @@ -93,7 +94,9 @@ const TabbedShowLayout = ({
tab && isValidElement(tab) ? (
<Route
exact
path={getTabFullPath(tab, index, match.url)}
path={escapePath(
getTabFullPath(tab, index, match.url)
)}
render={() =>
cloneElement(tab, {
context: 'content',
Expand Down
8 changes: 7 additions & 1 deletion packages/ra-ui-materialui/src/form/TabbedForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Route } from 'react-router-dom';
import Divider from '@material-ui/core/Divider';
import { makeStyles } from '@material-ui/core/styles';
import {
escapePath,
useTranslate,
useInitializeFormWithRecord,
sanitizeEmptyValues,
Expand Down Expand Up @@ -153,7 +154,12 @@ export const TabbedFormView = ({
children,
(tab, index) =>
tab && (
<Route exact path={getTabFullPath(tab, index, url)}>
<Route
exact
path={escapePath(
getTabFullPath(tab, index, url)
)}
>
{routeProps =>
isValidElement(tab)
? React.cloneElement(tab, {
Expand Down