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

emptyText prop on ArrayField has no effect. #6179

Closed
martdavidson opened this issue Apr 16, 2021 · 9 comments · Fixed by #6525
Closed

emptyText prop on ArrayField has no effect. #6179

martdavidson opened this issue Apr 16, 2021 · 9 comments · Fixed by #6525
Assignees

Comments

@martdavidson
Copy link

martdavidson commented Apr 16, 2021

What you were expecting:
Expected emptyText to be output from an ArrayField when there are no items in that array.

What happened instead:
Instead, we get an empty <DataGrid> (or I assume whatever child) with the table headers, and no data.

Steps to reproduce:
Can do something like:

<ArrayField
      label={'YouTube Videos'}
      source={'source'}
      emptyText={'None'}
    >
      <Datagrid>
        <TextField source={'videoId'} />
        <NumberField source={'weight'} />
      </Datagrid>
    </ArrayField>

And the result is:

image

Instead of the empty text.

Environment

  • React-admin version: 3.14.3
  • React version: 17.0.1
  • Browser: Chrome 89.0.4389.128 on Mac.
@djhi
Copy link
Contributor

djhi commented Apr 19, 2021

Indeed, it hasn't been implemented for ArrayField. Thanks for the report!

@djhi djhi added the bug label Apr 19, 2021
@fzaninotto
Copy link
Member

I think <ArrayField> shouldn't implement emptyText, just like <ReferenceManyField> and <ReferenceArrayField>. It's the child's responsibility (e.g. <Datagrid>, <SimpleList>) to display an alternative empty component when empty.

So I'm transforming this into a documentation issue: in the list of common field props, it should be mentioned that emptyText doesn't concern ArrayField and the likes.

@martdavidson
Copy link
Author

martdavidson commented Jun 10, 2021

Thanks for bringing that prop to my attention, I upgraded my version and see it now.

It doesn't solve this issue though, consider this code:

<ArrayField
      label={'Twitch Streams'}
      source={'mediaContentDetails.twitchStreams'}
      sortable={false}
    >
      <Datagrid empty={<p>Empty</p>}>
        <TextField source={'username'} />
        <NumberField source={'weight'} />
      </Datagrid>
</ArrayField>

So in our case mediaContentDetails can be null, so twitchStreams doesn't exist and results in:

image

Which is why I would argue having an empty prop for ArrayField makes sense (to me). I don't care what child is rendering in an ArrayField (DataGrid, SimpleList, etc), I would expect the ArrayField to short circuit if source value is either null / undefined / an empty list.

Let me know what you think.

Edit: Or maybe this is a bug and DataGrid should be checking for null / undefined?

@martdavidson
Copy link
Author

@fzaninotto Any thoughts on the above?

@fzaninotto
Copy link
Member

ArrayField should always put an array of ids in the ListContext. If Datagrid receives a null value for ids, then it may be a bug. Can you build a CodeSandbox to reproduce the issue?

@martdavidson
Copy link
Author

I probably won't get to that for a while, so if you have an easily accessible API that you can test against that's probably going to be faster.

@martdavidson
Copy link
Author

martdavidson commented Aug 11, 2021

@fzaninotto (Sorry to tag, just in case you only get notifications when tagged)

I got to this sooner than I thought, here's a recreation:

https://github.com/martdavidson/6179-recreation

Check that out, run yarn install then yarn start, view the only post, and you'll see that even though the Datagrid in the PostShow component has an empty prop, it's still showing an empty table.

@fzaninotto
Copy link
Member

@martdavidson Thanks, I managed to reproduce the issue with ArrayField, I'll open a PR to fix it.

@fzaninotto
Copy link
Member

The documentation problem remains: we should explicitly say that emptyText doesn't work on array fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants