1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-13 11:17:26 +02:00
unleash.unleash/frontend/src/component/feature/FeatureStrategy/FeatureStrategyConstraints
Thomas Heartman e4ead3bd67
Refactor: get rid of editable constraint wrapper (#9921)
This (admittedly pretty big) PR removes a component layer, moves all
logic for updating constraint values into a single module, and dumbs
down other components.

The main changes are:
- EditableConstraintWrapper is gone. All the logic in there has been
moved into the new `useEditableConstraint` hook. Previously it was split
between the wrapper, editableConstraint itself, the legalValues
component.
- the `useEditableConstraint` hook accepts a constraint and a save
function and returns an editable version of that constraint, the
validator for input values, a function that accepts update commands,
and, when relevant, existing and deleted legal values.
- All the logic for updating a constraint now exists in the
`constraint-reducer` file. As a pure function, it'll be easy to unit
test pretty thoroughly to make sure all commands work as they should
(tests will come later)
- The legal values selector has been dumbed down consiberably as it no
longer needs to create its own internal weak map. The internal
representation of selected values is now a set, so any kind of lookup is
now constant time, which should remove the need for the extra layer of
abstraction.

## Discussion points

I know the reducer pattern isn't one we use a *lot* in Unleash, but I
found a couple examples of it in the front end and it's also quite
similar to how we handle state updates to change request states. I'd be
happy to find a different way to represent it if we can keep it in a
single, testable interface.

Semi-relatedly: I've exposed the actions to submit for the updates at
the moment, but we could map these to functions instead. It'd make
invocations a little easier (you wouldn't need to specify the action
yourself; only use the payload as a function arg if there is one), but
we'd end up doing more mapping to create them. I'm not sure it's worth
it, but I also don't mind if we do 💁🏼
2025-05-09 11:47:22 +02:00
..
FeatureStrategyConstraintAccordionList Refactor: get rid of editable constraint wrapper (#9921) 2025-05-09 11:47:22 +02:00
RecentlyUsedConstraints chore: align recently used constraints to designs (#9904) 2025-05-06 15:42:38 +03:00
useEditableConstraint Refactor: get rid of editable constraint wrapper (#9921) 2025-05-09 11:47:22 +02:00
AddSingleValueWidget.tsx chore(1-3639): constraint validation (#9909) 2025-05-06 15:21:33 +02:00
AddValuesPopover.tsx chore(1-3679): use numeric input mode for numbers. (#9875) 2025-05-05 11:30:52 +02:00
AddValuesWidget.tsx chore(1-3639): constraint validation (#9909) 2025-05-06 15:21:33 +02:00
ConstraintDateInput.tsx chore(1-3639): constraint validation (#9909) 2025-05-06 15:21:33 +02:00
ConstraintOperatorSelect.tsx chore: second design pass for editable constraints (#9843) 2025-04-25 10:37:04 +00:00
ConstraintValueSearch.tsx feat: 1-3652/legal value selector visual update (#9829) 2025-04-24 12:17:05 +02:00
EditableConstraint.tsx Refactor: get rid of editable constraint wrapper (#9921) 2025-05-09 11:47:22 +02:00
FeatureStrategyConstraints.tsx fix: strategy targeting numeric also check value field (#6774) 2024-04-04 11:48:51 +02:00
LegalValuesSelector.tsx Refactor: get rid of editable constraint wrapper (#9921) 2025-05-09 11:47:22 +02:00
resolve-legal-values.ts 1-3687/input mode separation (#9882) 2025-05-02 12:30:38 +02:00
ValueList.tsx Refactor: get rid of editable constraint wrapper (#9921) 2025-05-09 11:47:22 +02:00