-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(RHINENG-9687): create system type filter (#2190)
* feat(RHINENG-9687): create system type filter * chore(RHINENG-9687): gate the filter with flags * chore: add labels to system type icons * chore: update test snapshots
- Loading branch information
1 parent
212c1d8
commit a14c486
Showing
8 changed files
with
142 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useState } from 'react'; | ||
import { | ||
SYSTEM_TYPE_KEY, | ||
systemTypeOptions as defaultSystemTypeOptions, | ||
} from '../../Utilities/index'; | ||
|
||
export const systemTypeFilterState = { systemTypeFilter: [] }; | ||
export const SYSTEM_TYPE_FILTER = 'SYSTEM_TYPE_FILTER'; | ||
export const systemTypeFilterReducer = (_state, { type, payload }) => ({ | ||
...(type === SYSTEM_TYPE_FILTER && { | ||
systemTypeFilter: payload, | ||
}), | ||
}); | ||
|
||
export const useSystemTypeFilter = ( | ||
[state, dispatch] = [systemTypeFilterState] | ||
) => { | ||
let [filterStateValue, setStateValue] = useState([]); | ||
const systemTypeValue = dispatch ? state.systemTypeFilter : filterStateValue; | ||
const setValue = dispatch | ||
? (newValue) => dispatch({ type: SYSTEM_TYPE_FILTER, payload: newValue }) | ||
: setStateValue; | ||
|
||
const filter = { | ||
label: 'System type', | ||
value: 'not_nil', | ||
type: 'checkbox', | ||
filterValues: { | ||
value: systemTypeValue, | ||
onChange: (_e, value) => { | ||
setValue(value); | ||
}, | ||
items: defaultSystemTypeOptions, | ||
}, | ||
}; | ||
|
||
const chip = | ||
systemTypeValue?.length > 0 | ||
? [ | ||
{ | ||
category: 'System type', | ||
type: SYSTEM_TYPE_KEY, | ||
chips: defaultSystemTypeOptions | ||
.filter(({ value }) => systemTypeValue.includes(value)) | ||
.map(({ label, ...props }) => ({ name: label, ...props })), | ||
}, | ||
] | ||
: []; | ||
|
||
return [filter, chip, systemTypeValue, setValue]; | ||
}; |