-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Introduce <TextArrayField>
and use <TextArrayInput>
/ <TextArrayField>
in guessers for scalar arrays
#10939
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
Merged
Merged
Introduce <TextArrayField>
and use <TextArrayInput>
/ <TextArrayField>
in guessers for scalar arrays
#10939
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8d1c6a8
Use TextArrayInput in EditGuesser for scalar array
slax57 1970995
introduce TextArrayField and use it in ShowGuesser
slax57 5bcfbf8
use TextArrayField in ListGuesser
slax57 98afaa4
add TextArrayField doc
slax57 c518eb1
[no ci] Apply suggestions from code review
slax57 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
--- | ||
layout: default | ||
title: "The TextArrayField Component" | ||
storybook_path: ra-ui-materialui-fields-textarrayfield--basic | ||
--- | ||
|
||
# `<TextArrayField>` | ||
|
||
`<TextArrayField>` renders an array of scalar values using Material-UI's Stack and Chips. | ||
|
||
 | ||
|
||
`<TextArrayField>` is ideal for displaying lists of simple text values, such as genres or tags, in a visually appealing way. | ||
|
||
## Usage | ||
|
||
`<TextArrayField>` can be used in a Show view to display an array of values from a record. For example: | ||
|
||
```js | ||
const book = { | ||
id: 1, | ||
title: 'War and Peace', | ||
genres: [ | ||
'Fiction', | ||
'Historical Fiction', | ||
'Classic Literature', | ||
'Russian Literature', | ||
], | ||
}; | ||
``` | ||
|
||
You can render the `TextArrayField` like this: | ||
|
||
```jsx | ||
import { Show, SimpleShowLayout, TextArrayField } from 'react-admin'; | ||
|
||
const BookShow = () => ( | ||
<Show> | ||
<SimpleShowLayout> | ||
<TextField source="title" /> | ||
<TextArrayField source="genres" /> | ||
</SimpleShowLayout> | ||
</Show> | ||
); | ||
``` | ||
|
||
## Props | ||
|
||
The following props are available for `<TextArrayField>`: | ||
|
||
| Prop | Type | Required | Description | | ||
| ----------- | ------------ | -------- | ------------------------------------------------------------- | | ||
| `source` | `string` | Yes | The name of the record field containing the array to display. | | ||
| `color` | `string` | - | The color of the Chip components. | | ||
| `emptyText` | `ReactNode` | - | Text to display when the array is empty. | | ||
| `record` | `RecordType` | - | The record containing the data to display. | | ||
| `size` | `string` | - | The size of the Chip components. | | ||
| `variant` | `string` | - | The variant of the Chip components. | | ||
|
||
Additional props are passed to the underlying [Material-UI `Stack` component](https://mui.com/material-ui/react-stack/). | ||
|
||
## `color` | ||
|
||
The color of the Chip components. Accepts any value supported by MUI's Chip (`primary`, `secondary`, etc). | ||
slax57 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
```jsx | ||
<TextArrayField source="genres" color="secondary" /> | ||
``` | ||
|
||
## `direction` | ||
|
||
The direction of the Stack layout. Accepts `row` or `column`. The default is `row`. | ||
|
||
```jsx | ||
<TextArrayField source="genres" direction="column" /> | ||
``` | ||
|
||
## `emptyText` | ||
|
||
Text to display when the array is empty. | ||
|
||
```jsx | ||
<TextArrayField source="genres" emptyText="No genres available" /> | ||
``` | ||
|
||
## `record` | ||
|
||
The record containing the data to display. Usually provided by react-admin automatically. | ||
|
||
```jsx | ||
const book = { | ||
id: 1, | ||
title: 'War and Peace', | ||
genres: [ | ||
'Fiction', | ||
'Historical Fiction', | ||
'Classic Literature', | ||
'Russian Literature', | ||
], | ||
}; | ||
|
||
<TextArrayField source="genres" record={book} /> | ||
``` | ||
|
||
## `size` | ||
|
||
The size of the Chip components. Accepts any value supported by MUI's Chip (`small`, `medium`). The default is `small`. | ||
slax57 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
```jsx | ||
<TextArrayField source="genres" size="medium" /> | ||
``` | ||
|
||
## `source` | ||
|
||
The name of the record field containing the array to display. | ||
|
||
```jsx | ||
<TextArrayField source="genres" /> | ||
``` | ||
|
||
## `sx` | ||
|
||
Custom styles for the Stack, using MUI's `sx` prop. | ||
|
||
{% raw %} | ||
```jsx | ||
<TextArrayField source="genres" sx={{ gap: 2 }} /> | ||
``` | ||
{% endraw %} | ||
|
||
## `variant` | ||
|
||
The variant of the Chip components. Accepts any value supported by MUI's Chip (`filled`, `outlined`). The default is `filled`. | ||
slax57 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
```jsx | ||
<TextArrayField source="genres" variant="outlined" /> | ||
``` | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 14 additions & 32 deletions
46
packages/ra-ui-materialui/src/detail/EditGuesser.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/ra-ui-materialui/src/detail/EditGuesser.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as React from 'react'; | ||
import { Admin } from 'react-admin'; | ||
import { Resource, TestMemoryRouter } from 'ra-core'; | ||
import fakeRestProvider from 'ra-data-fakerest'; | ||
|
||
import { EditGuesser as RAEditGuesser } from './EditGuesser'; | ||
|
||
export default { title: 'ra-ui-materialui/detail/EditGuesser' }; | ||
|
||
const data = { | ||
books: [ | ||
{ | ||
id: 123, | ||
authors: [ | ||
{ id: 1, name: 'john doe', dob: '1990-01-01' }, | ||
{ id: 2, name: 'jane doe', dob: '1992-01-01' }, | ||
], | ||
post_id: 6, | ||
score: 3, | ||
body: "Queen, tossing her head through the wood. 'If it had lost something; and she felt sure it.", | ||
description: `<p><strong>War and Peace</strong> is a novel by the Russian author <a href="https://en.wikipedia.org/wiki/Leo_Tolstoy">Leo Tolstoy</a>, | ||
published serially, then in its entirety in 1869.</p> | ||
<p>It is regarded as one of Tolstoy's finest literary achievements and remains a classic of world literature.</p>`, | ||
created_at: new Date('2012-08-02'), | ||
tags_ids: [1, 2], | ||
url: 'https://www.myshop.com/tags/top-seller', | ||
email: '[email protected]', | ||
isAlreadyPublished: true, | ||
genres: [ | ||
'Fiction', | ||
'Historical Fiction', | ||
'Classic Literature', | ||
'Russian Literature', | ||
], | ||
}, | ||
], | ||
tags: [ | ||
{ id: 1, name: 'top seller' }, | ||
{ id: 2, name: 'new' }, | ||
], | ||
posts: [ | ||
{ id: 6, title: 'War and Peace', body: 'A great novel by Leo Tolstoy' }, | ||
], | ||
}; | ||
|
||
const EditGuesserWithProdLogs = () => <RAEditGuesser enableLog />; | ||
|
||
export const EditGuesser = () => ( | ||
<TestMemoryRouter initialEntries={['/books/123']}> | ||
<Admin dataProvider={fakeRestProvider(data)}> | ||
<Resource name="books" edit={EditGuesserWithProdLogs} /> | ||
</Admin> | ||
</TestMemoryRouter> | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,12 @@ published serially, then in its entirety in 1869.</p> | |
url: 'https://www.myshop.com/tags/top-seller', | ||
email: '[email protected]', | ||
isAlreadyPublished: true, | ||
genres: [ | ||
'Fiction', | ||
'Historical Fiction', | ||
'Classic Literature', | ||
'Russian Literature', | ||
], | ||
}, | ||
], | ||
tags: [ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: the Required column is the second one in all prop tables, here it's the third. Also, we usually include a Default column.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay I'll change that on master
UPDATE: I mean on next
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done: d785636