From 4a41aa8da21ecfbe271174f0b2fd209163857c4f Mon Sep 17 00:00:00 2001 From: asvarcas Date: Wed, 29 Apr 2020 10:50:25 -0300 Subject: [PATCH 1/2] Updated documentation and propType for SimpleList linkType. --- docs/List.md | 6 ++++-- packages/ra-ui-materialui/src/list/SimpleList.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/List.md b/docs/List.md index 72caab65168..c8e381cccc4 100644 --- a/docs/List.md +++ b/docs/List.md @@ -1607,12 +1607,13 @@ export const PostList = (props) => ( primaryText={record => record.title} secondaryText={record => `${record.views} views`} tertiaryText={record => new Date(record.published_at).toLocaleDateString()} + linkType={record => record.canEdit ? "edit" : "show"} /> ); ``` -`` iterates over the list data. For each record, it executes the `primaryText`, `secondaryText`, `leftAvatar`, `leftIcon`, `rightAvatar`, and `rightIcon` props function, and passes the result as the corresponding `` prop. +`` iterates over the list data. For each record, it executes the `primaryText`, `secondaryText`, `linkType`, `leftAvatar`, `leftIcon`, `rightAvatar`, and `rightIcon` props function, and passes the result as the corresponding `` prop. **Tip**: To use a `` on small screens and a `` on larger screens, use material-ui's `useMediaQuery` hook: @@ -1631,6 +1632,7 @@ export const PostList = (props) => { primaryText={record => record.title} secondaryText={record => `${record.views} views`} tertiaryText={record => new Date(record.published_at).toLocaleDateString()} + linkType={record => record.canEdit ? "edit" : "show"} /> ) : ( @@ -1642,7 +1644,7 @@ export const PostList = (props) => { } ``` -**Tip**: The `` items link to the edition page by default. You can set the `linkType` prop to `show` to link to the `` page instead. +**Tip**: The `` items link to the edition page by default. You can also set the `linkType` prop to `show` directly to link to the `` page instead. ```jsx // in src/posts.js diff --git a/packages/ra-ui-materialui/src/list/SimpleList.js b/packages/ra-ui-materialui/src/list/SimpleList.js index a7aabd5db93..accdbeedc8f 100644 --- a/packages/ra-ui-materialui/src/list/SimpleList.js +++ b/packages/ra-ui-materialui/src/list/SimpleList.js @@ -163,7 +163,7 @@ SimpleList.propTypes = { ids: PropTypes.array, leftAvatar: PropTypes.func, leftIcon: PropTypes.func, - linkType: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]) + linkType: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.func]) .isRequired, onToggleItem: PropTypes.func, primaryText: PropTypes.func, From 9f5683f8ad2e3a3109e1cb73e0d0db97620df256 Mon Sep 17 00:00:00 2001 From: asvarcas Date: Wed, 29 Apr 2020 11:03:02 -0300 Subject: [PATCH 2/2] Prettier changes. --- packages/ra-ui-materialui/src/list/SimpleList.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/ra-ui-materialui/src/list/SimpleList.js b/packages/ra-ui-materialui/src/list/SimpleList.js index accdbeedc8f..d370a53ce28 100644 --- a/packages/ra-ui-materialui/src/list/SimpleList.js +++ b/packages/ra-ui-materialui/src/list/SimpleList.js @@ -163,8 +163,11 @@ SimpleList.propTypes = { ids: PropTypes.array, leftAvatar: PropTypes.func, leftIcon: PropTypes.func, - linkType: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.func]) - .isRequired, + linkType: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.bool, + PropTypes.func, + ]).isRequired, onToggleItem: PropTypes.func, primaryText: PropTypes.func, rightAvatar: PropTypes.func,