Enum and readonly component settings#6001
Conversation
mrcasals
left a comment
There was a problem hiding this comment.
Wohooo good job here! 😍
21f1e2b to
8c494de
Compare
tramuntanal
left a comment
There was a problem hiding this comment.
Hi @leio10 good refactoring!
I only have doubts about how the disabled setting attribute is used in the proposals component.
| @component.attributes["settings"] | ||
| end | ||
|
|
||
| def restore_disabled_settings(step, settings) |
There was a problem hiding this comment.
Can you please complete the documentation and rename the step method?
| def restore_disabled_settings(step, settings) | |
| # Loads persisted settings from `ComponentManifest`. | |
| # To be used ... | |
| def restore_disabled_settings(settings_name, settings) |
There was a problem hiding this comment.
done, thanks for the feedback! I've refactored that part, that it was confusing and with a bug, I hope that it is much clear now, without the need of extra comments to be understood :)
| settings.attribute :participatory_texts_enabled, type: :boolean, default: false | ||
| settings.attribute :participatory_texts_enabled, | ||
| type: :boolean, default: false, | ||
| disabled: ->(context) { Decidim::Proposals::Proposal.where(component: context[:component]).any? } |
There was a problem hiding this comment.
Does this mean that the admin will only be able to enable participatory texts if there are some proposals for the current component?
We must take into account that participatory texts should be enabled for the admins to upload the text that will be converted into proposals.
Am I correct?
There was a problem hiding this comment.
Mmm, it's just the other way around: this setting will only be allowed to be changed when there are no proposals in the component. 😄
There was a problem hiding this comment.
if disabled is true then the attribute is disabled no? Then, if the lambda returns true (the component has proposals) it will be disabled. Am I missing something? 😅
There was a problem hiding this comment.
Oh, I think that now I understand your concern.
Maybe is a naming issue, if I rename from disabled to readonly it would be clearer for you?
I mean, the idea is that admins can change the value for this setting until the component has any proposal. After that, the setting's value just keeps the same, doesn't change to false.
67933ef to
2c68391
Compare
tramuntanal
left a comment
There was a problem hiding this comment.
sorry I just started a review when I was simply commenting the previous one
| @component.manifest.settings(settings_name).attributes | ||
| .select { |_attribute, obj| obj.disabled?(component: @component) } |
There was a problem hiding this comment.
It would be great to have a enabled_attributes in SettingsManifest. Or event better, make the getter filter by only enalbed and have another all_attributes. What do you think?
There was a problem hiding this comment.
Ok, I think that is definitely a bad idea to have a disabled option when a lot of settings are called ...._enabled. It seems that it could affect the value, while it only affects the ability of admins to modify it. If you are ok with the readonly name I'll change it that way.
| settings.attribute :participatory_texts_enabled, type: :boolean, default: false | ||
| settings.attribute :participatory_texts_enabled, | ||
| type: :boolean, default: false, | ||
| disabled: ->(context) { Decidim::Proposals::Proposal.where(component: context[:component]).any? } |
There was a problem hiding this comment.
if disabled is true then the attribute is disabled no? Then, if the lambda returns true (the component has proposals) it will be disabled. Am I missing something? 😅
45ce735 to
c653161
Compare
7212e84 to
864b387
Compare
Also refactors labels and help texts generation. With the new features is possible to remove all references to proposals in the helper.
* Participatory texts enabled attribute is disabled when there are proposals created on the component. * Amendments visibility attribute is converted to the enum type, using `Decidim.config.amendments_visibility_options` as the choices list
864b387 to
4c84d78
Compare
|
@decidim/core finally everything is green! 🎉 🎉 Can we merge it? |
|
🎉 🎉 🎉 |
* feature/initiatives_search_fo_new_design: Updates changelog Harmonizes the design of initiatives search in FO New question type "Matrix" in questionnaires (decidim#5948) Add filter options to Timeline and Activity tabs (decidim#5845) Remove relations between user and spaces on destroy account command (decidim#6041) Explain how to initialize a custom oauth2 client provider (decidim#6055) Reenable main tests on Crowdin PRs (decidim#6076) Enum and readonly component settings (decidim#6001) New Crowdin translations (decidim#6066) Add missing notifications (decidim#5906)
🎩 What? Why?
This PR adds the enum type of attribute for component settings. This settings are rendered as a collection checkboxes, and allow admins to choose between a set of options. I'm going to use this in #5993, but I created as a separated PR to simplify reviewing it.
During this work, I've found that this logic was already implemented for a proposals setting (amendment visibility), so I decided to reuse that logic as a generic feature.
Also, I've refactored the texts generation for the settings helpers and added the ability to make some settings read-only in specific conditions, to remove proposals logic from that file and thus reduce coupling between modules.
📌 Related Issues
📋 Subtasks
CHANGELOGentry📷 Screenshots (optional)