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

Unable to omit specific fields which share the same source #9587

Open
Dreamsorcerer opened this issue Jan 15, 2024 · 15 comments
Open

Unable to omit specific fields which share the same source #9587

Dreamsorcerer opened this issue Jan 15, 2024 · 15 comments

Comments

@Dreamsorcerer
Copy link
Contributor

Is your feature request related to a problem? Please describe.
If there are multiple fields which use the same source (e.g. to render different views of the same data), then it's not possible to omit specific fields from DatagridConfigurable as the omit property works with sources only. Given that they can be individually toggled on/off in the columns selection, it seems reasonable that they should also be configurable individually in omit.

Describe the solution you'd like
Haven't thought of one yet.

@slax57
Copy link
Contributor

slax57 commented Jan 16, 2024

Thank you for your suggestion.
This seems like a very specific use-case, I'm not sure it's that common.
I suggest we wait for more feedback from the community before taking actions.

@slax57 slax57 added the RFC Request For Comments label Jan 16, 2024
@Dreamsorcerer
Copy link
Contributor Author

Just to give an example, you could have a NumberField to display the value of a foreign key, a ReferenceField linking to the foreign record, and a field that displays a link to some external resource, all using the same source attribute. Another example could be a TextField showing a file name and a custom field that displays an audio player for that file. I suspect there are many examples of these around, they probably just haven't tried to omit one individually.

I think another issue is that you can't omit columns without a source. For example, putting an Edit button in the list view, it then can't be omitted by default, even though the user can hide it with the columns button.

@slax57
Copy link
Contributor

slax57 commented Jan 16, 2024

Okay I get your point, thanks for providing additional examples.
I'll mark this as enhancement then, so anyone can open a PR implementing this feature (remember to target the next branch if your do).
Note that we probably won't work on this ourselves though, since we don't have that need on our own projects.

@Dreamsorcerer
Copy link
Contributor Author

So, the Columns button appears to use the column index. I'm not sure that's going to be a reliable way to implement this feature. Could we maybe extend omit so it matches the label or the source?

@fzaninotto
Copy link
Member

The columns preference is a mix of availableColumns (used to display the list of possible columns in SelectColumnsButtons) and columns (which stores the user's choice regarding the orer and visibility of the columns). The second setting is related to the first one.

You have to consider that the feature must still work after the developer changes the number of orer of Fields in the datagrid, given users have already saved preferences.

@Dreamsorcerer
Copy link
Contributor Author

Right, so columns is actually the index listed in availableColumns. I'm not sure how that index is kept in sync with developer changes (presumably by checking for columns with the same source or label?).

But, availableColumns contains both source and label, which suggests to me that allowing omit to match the label would be a resonable approach?

@fzaninotto
Copy link
Member

No news for some time, closing.

@Dreamsorcerer
Copy link
Contributor Author

@fzaninotto I'm still waiting for confirmation that my proposed approach would be accepted...

@fzaninotto
Copy link
Member

I can't tell you if your approach works if you don't provide an implementation ;)

I suggest you open a PR, so we can judge on the code.

@fzaninotto fzaninotto reopened this May 13, 2024
@Dreamsorcerer
Copy link
Contributor Author

Well, I don't want to spend hours creating an implementation if you're just going to say that approach is not acceptable...

It shouldn't be difficult to answer yes/no to whether it sounds reasonable that omit could match source or label. As mentioned above, I'm assuming this is what availableColumns is already doing.

@fzaninotto
Copy link
Member

Could you illustrate your suggestion with examples?

@Dreamsorcerer
Copy link
Contributor Author

A NumberField(source="foo", label="ID") and ReferenceField(source="foo", label="Apple") on the same view. omit="Apple" would then work to hide the reference field (current behaviour is that you'd only be able to use omit="foo" and it would hide both fields).

@fzaninotto
Copy link
Member

I fail to see how that would work without breaking backwards compatibility. Because developers may define two fields, one with source X and the other with label X.

@Dreamsorcerer
Copy link
Contributor Author

I wouldn't expect people to have labels named the same as a different source. Can also put it in v5, so the small break in backwards compatibility is not an issue.

@fzaninotto
Copy link
Member

I wouldn't expect people to have labels named the same as a different source.

This is the type of situation react-admin has to deal all the time. So in my opinion, your proposed solution isn't robust enough.

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

No branches or pull requests

3 participants