Skip to content

Enum and readonly component settings#6001

Merged
tramuntanal merged 17 commits intodevelopfrom
feat/enum-settings
May 6, 2020
Merged

Enum and readonly component settings#6001
tramuntanal merged 17 commits intodevelopfrom
feat/enum-settings

Conversation

@leio10
Copy link
Copy Markdown
Contributor

@leio10 leio10 commented Apr 20, 2020

🎩 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

  • Add CHANGELOG entry
  • Add tests
  • Add documentation regarding the feature

📷 Screenshots (optional)

Description

@leio10 leio10 added the project: PAM2020 Barcelona City Council contract label Apr 20, 2020
mrcasals
mrcasals previously approved these changes Apr 21, 2020
Copy link
Copy Markdown
Contributor

@mrcasals mrcasals left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wohooo good job here! 😍

agustibr
agustibr previously approved these changes Apr 21, 2020
Copy link
Copy Markdown
Contributor

@agustibr agustibr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 😃 Great!

@leio10
Copy link
Copy Markdown
Contributor Author

leio10 commented Apr 21, 2020

@decidim/core this is ready to be reviewed. I added the PAM2020 because I need this for #5993.
Also, coverage % is not accurate (comments part has failed during upload), and probably #5991 should fix it. (edit: coverage is now ok, as it was executed again)

Copy link
Copy Markdown
Contributor

@tramuntanal tramuntanal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please complete the documentation and rename the step method?

Suggested change
def restore_disabled_settings(step, settings)
# Loads persisted settings from `ComponentManifest`.
# To be used ...
def restore_disabled_settings(settings_name, settings)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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? }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 😄

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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? 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@leio10 leio10 force-pushed the feat/enum-settings branch 3 times, most recently from 67933ef to 2c68391 Compare April 22, 2020 17:18
Copy link
Copy Markdown
Contributor

@tramuntanal tramuntanal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I just started a review when I was simply commenting the previous one

Comment on lines +80 to +81
@component.manifest.settings(settings_name).attributes
.select { |_attribute, obj| obj.disabled?(component: @component) }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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? }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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? 😅

@leio10 leio10 force-pushed the feat/enum-settings branch 3 times, most recently from 45ce735 to c653161 Compare April 23, 2020 17:05
@leio10 leio10 changed the title Enum and disabled component settings Enum and readonly component settings Apr 23, 2020
@leio10 leio10 force-pushed the feat/enum-settings branch 3 times, most recently from 7212e84 to 864b387 Compare April 29, 2020 07:56
leio10 added 9 commits April 30, 2020 10:09
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
@leio10 leio10 force-pushed the feat/enum-settings branch from 864b387 to 4c84d78 Compare April 30, 2020 08:12
@leio10
Copy link
Copy Markdown
Contributor Author

leio10 commented Apr 30, 2020

@decidim/core finally everything is green! 🎉 🎉 Can we merge it?

Copy link
Copy Markdown
Contributor

@tramuntanal tramuntanal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!!

@tramuntanal tramuntanal merged commit efa9aae into develop May 6, 2020
@tramuntanal tramuntanal deleted the feat/enum-settings branch May 6, 2020 10:47
@tramuntanal
Copy link
Copy Markdown
Contributor

🎉 🎉 🎉

ace pushed a commit to aspgems/decidim that referenced this pull request May 12, 2020
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in-review project: PAM2020 Barcelona City Council contract

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants