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

KCheckbox: Remove local state management, rely on given props #744

Merged

Conversation

nucleogenesis
Copy link
Member

@nucleogenesis nucleogenesis commented Aug 21, 2024

Description

KCheckbox had local data which are initialized to the given props for indeterminate and checked and then updated in a watcher. This resulted in that clicking a checkbox would always toggle it's isCurrentlyChecked value and setting isCurrentlyIndeterminate to false.

The changes here instead have KCheckbox simply use the given prop values and does nothing to manage any internal state around whether it shows indeterminate and/or checked.

This results in users of KCheckbox needing to be mindful of how they manage the values they pass into KCheckbox's props as the component will now reflect their values at all time.

Issue addressed

This permits Studio's clipboard to have the ability to tell KCheckbox what it should be looking like.

Changelog

  • Description: Removes internal state management for checked & indeterminate in KCheckbox.
  • Products impact: Updated API
  • Addresses: Clipboard indeterminate selection incorrect studio#4636
  • Components: KCheckbox
  • Breaking: No
  • Impacts a11y: No
  • Guidance: If you use KCheckbox, it is your responsibility to handle the change event and update whether or not the given checked and indeterminate props reflect the reality that you expect.

Steps to test

Click all of the checkboxes and the states of indeterminacy vs checked-ness -- particularly in nested situations.

The most common in Kolibri is content selection. In Studio, this issue was found while debugging a problem with the Clipboard.

KOLIBRI:

  • Resource selection during import
  • During Quiz creation
  • During Lesson creation

STUDIO:

  • Clipboard
  • Channel editor

(optional) Implementation notes

At a high level, how did you implement this?

Does this introduce any tech-debt items?

Testing checklist

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical and brittle code paths are covered by unit tests
  • The change is described in the changelog section above

Reviewer guidance

  • Is the code clean and well-commented?
  • Are there tests for this change?
  • Are all UI components LTR and RTL compliant (if applicable)?
  • Add other things to check for here

After review

  • The changelog item has been pasted to the CHANGELOG.md

Comments

@nucleogenesis nucleogenesis changed the base branch from develop to release-v4 August 26, 2024 19:27
@nucleogenesis nucleogenesis force-pushed the kcheckbox-unopinionated branch 2 times, most recently from 4668f92 to 300ad9c Compare August 26, 2024 19:28
@nucleogenesis nucleogenesis marked this pull request as ready for review August 26, 2024 19:29
@AlexVelezLl
Copy link
Member

AlexVelezLl commented Aug 26, 2024

Code changes make sense to me. But I wonder if removing the local state management is a breaking change.

I would suggest to make a different PR to remove the internal state targeting to develop and explore there its implications. And leave this PR with the removal of the this.isCurrentlyIndeterminate = false; line when we are toggling the check, which I suspect would be the needed change to let the consumer have total control in the combination of the four possible combinations of checked/unchecked/indeterminate/non-indeterminate states (as we have a watcher for the checked and indeterminate states.

For example, this change breaks the docs page as it relies on the KCheckbox internal state:

Compartir.pantalla.-.2024-08-26.17_00_12.mp4

And there could be some other places where we could be relying on the KCheckbox internal state too (also because the checked prop isnt even marked as required).

CHANGELOG.md Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Leaving a note here that before merging it'd be good to revert CHANGELOG.md changes since the new GH action will now update the CHANGELOG.md after merging this PR by pasting the changelog from the PR description. Otherwise we'd have duplicate entries.

    KCheckbox had local data which are initialized to the given props for
    `indeterminate` and `checked` and then updated in a watcher. This
    resulted in that clicking a checkbox would always toggle it's
    `isCurrentlyChecked` value and setting `isCurrentlyIndeterminate` to
    false.

    The changes here instead have KCheckbox simply use the given prop values
    and does nothing to manage any internal state around whether it shows
    `indeterminate` and/or `checked`.

    This results in users of KCheckbox needing to be mindful of how they
    manage the values they pass into KCheckbox's props as the component will
    now reflect their values at all time
Copy link
Member

@AlexVelezLl AlexVelezLl left a comment

Choose a reason for hiding this comment

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

lgtm!

@AlexVelezLl
Copy link
Member

Thank you @nucleogenesis!

@AlexVelezLl AlexVelezLl merged commit 186b179 into learningequality:release-v4 Sep 3, 2024
8 checks passed
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

Successfully merging this pull request may close these issues.

3 participants