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

Read-only field #61

Closed
luizhop opened this issue Nov 10, 2023 · 7 comments
Closed

Read-only field #61

luizhop opened this issue Nov 10, 2023 · 7 comments

Comments

@luizhop
Copy link
Contributor

luizhop commented Nov 10, 2023

Hello 👋

First of all, thanks for this great plugin!

I am trying to disable the iconPicker field for certain user roles, but not being able to do that.

Tried to use readOnly property on iconPicker field schema, like on other primitive fields, but apparently is not working.
Just to be sure I've tested adding it to other primitive fields like string and it worked.

{
   name: 'icon',
   title: 'Icon',
   type: 'iconPicker',
   readOnly: ({currentUser}) => {
      return !(currentUser.roles.find(({name}) => name === 'administrator'))
   }
}

The HTML output I was expecting is something like this:

<button data-ui="MenuButton" id="menu-button-example" aria-haspopup="true" aria-expanded="false" disabled aria-disabled="true" data-disabled="true" type="button" class="sc-brSaZW gFytae">...</button>

And the expected behaviour is the button to select the icon to be grey out and not clickable:
image

Is there another way to achieve that, or this is something not supported currently?

Thank you!

@christopherafbjur
Copy link
Owner

christopherafbjur commented Nov 11, 2023

Hi @luizhop I'm glad you like it. This is currently not supported but is something we should definitely add support for. Will implement this feature within the upcoming 2 weeks. Feel free to contribute with this feature :)

@luizhop
Copy link
Contributor Author

luizhop commented Nov 20, 2023

That's great @christopherafbjur.
Sure I would be happy to work on this, let me try find some time over the next weeks.
Thanks!

@luizhop
Copy link
Contributor Author

luizhop commented Dec 22, 2023

Hi @christopherafbjur finally I found some time to work on this.

I am just starting with Sanity, React, Typescript and all this stuff, also this is my first contribution to a repository, so apologies for any bad or misplaced changes, specially the ones below I could notice.

Skipped verification for committing and pushing to repo

I was having issues on SearchResults (type check on the component and props import on the tests) and couldn't figure what was the best way to sort them. As I didn't do any changes on these files, I thought it could be something with my node version (20.9.0) and probably won't give you any issues when reviewing and building.

Formatting changes on src/components/IconPicker.tsx

When trying to sort those issues, I thought running yarn format would help with that, in the end it didn't help and I missed reverting it before committing.

Please feel free to make or suggest any changes, I would happy to work on them or to take any advice.

Thanks again!

@christopherafbjur
Copy link
Owner

Thank you for your contribution @luizhop and the well described challenges you faced. I will have a look at this and come back with an answer in the upcoming days. Merry X-Mas 🎅🏻

@luizhop
Copy link
Contributor Author

luizhop commented Jan 3, 2024

@christopherafbjur merry Xmas (a bit delayed 🐢) and happy new year 🌟
That's perfect, will be great to have your feedback, whenever suits you best. Thank you!

@christopherafbjur
Copy link
Owner

christopherafbjur commented Jan 17, 2024

Merged this #63 just now. Thank you for your contribution @luizhop very nice feature 👍

Will create a patch update and publish to npm so it should be available when you read this :)

@luizhop
Copy link
Contributor Author

luizhop commented Jan 29, 2024

Many thanks for that @christopherafbjur, my pleasure being able to help 🙂

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

No branches or pull requests

2 participants