Skip to content

Commit 84183f7

Browse files
Ahmed-Labsandrewshie-sentry
authored andcommitted
feat(ui): Add hasExternalChanges prop to HybridFilter (#102957)
**Motivation** I'm currently working on a global filter component that sets values for filters using HybridFilter. However, I have an extra 'attribute' which is the operator of the filter which is not being set through the HybridFilter options, and instead within the custom body of the filter (i.e. its state is managed externally). I would like my external changes to also trigger the apply button, and once it is clicked, it triggers my custom onChange handler that saves options + operator. **Changes** - Adds hasExternalChanges to hybrid filter so components are able to externally trigger the apply button
1 parent 6f6a139 commit 84183f7

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

static/app/components/organizations/hybridFilter.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ export interface HybridFilterProps<Value extends SelectKey>
5252
* Useful for things like enforcing a selection count limit.
5353
*/
5454
disableCommit?: boolean;
55+
/**
56+
* Additional staged changes from external state that should trigger
57+
* the Apply/Cancel buttons.
58+
*/
59+
hasExternalChanges?: boolean;
5560
/**
5661
* Message to show in the menu footer
5762
*/
@@ -96,6 +101,7 @@ export function HybridFilter<Value extends SelectKey>({
96101
checkboxWrapper,
97102
checkboxPosition,
98103
disableCommit,
104+
hasExternalChanges = false,
99105
...selectProps
100106
}: HybridFilterProps<Value>) {
101107
/**
@@ -115,11 +121,13 @@ export function HybridFilter<Value extends SelectKey>({
115121
}, [onStagedValueChange, stagedValue]);
116122

117123
/**
118-
* Whether there are staged, uncommitted changes. Used to determine whether we should
119-
* show the "Cancel"/"Apply" buttons.
124+
* Whether there are staged, uncommitted changes, or external changes. Used to determine
125+
* whether we should show the "Cancel"/"Apply" buttons.
120126
*/
121127
const hasStagedChanges =
122-
stagedValue.length !== value.length || !stagedValue.every(val => value.includes(val));
128+
stagedValue.length !== value.length ||
129+
!stagedValue.every(val => value.includes(val)) ||
130+
hasExternalChanges;
123131

124132
const commit = useCallback(
125133
(val: Value[]) => {

0 commit comments

Comments
 (0)