forked from RedHatInsights/insights-inventory-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "feat(RHINENG-9687): create system type filter (RedHat…
…Insights#2190)"" This reverts commit 4c9d70f.
- Loading branch information
1 parent
ffbb440
commit af30ecc
Showing
8 changed files
with
144 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]; | ||
}; |