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

lib: Fix DynamicListForm state confusion on removals #19825

Merged
merged 3 commits into from
Jan 9, 2024
Merged

Commits on Jan 8, 2024

  1. lib: Rename DynamicListForm.jsx to cockpit-components-dynamic-list.jsx

    We name all other custom Cockpit components in that form.
    martinpitt committed Jan 8, 2024
    Configuration menu
    Copy the full SHA
    0d3e4ce View commit details
    Browse the repository at this point in the history
  2. lib: Clean up state copies in DynamicListForm

    Drop the unnecessary list copies in setState() callbacks. `onChange()`
    is not supposed to modify its argument.
    
    Use a spread for making a list copy in removeItem(), and creating the
    new `list` entry in addItem().
    martinpitt committed Jan 8, 2024
    Configuration menu
    Copy the full SHA
    d0ba418 View commit details
    Browse the repository at this point in the history
  3. lib: Fix DynamicListForm state confusion on removals

    When deleting an item, set it to `undefined` (i.e. keep it as a hole in
    `list`) instead of completely removing it. Before, removing the first
    item shifted all the indexes around, which broke keys/ids and the state
    handling, so that it appeared as if the wrong element got deleted.
    
    With that, `list.length` becomes meaningless. Adjust the emptiness check
    in the render function. Entirely drop `itemCount` -- nothing uses that,
    and it's a bit expensive to compute, so let's only introduce this when
    there is an actual use case.
    
    https://issues.redhat.com/browse/RHEL-19598
    martinpitt committed Jan 8, 2024
    Configuration menu
    Copy the full SHA
    349c6c1 View commit details
    Browse the repository at this point in the history