-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #239 from opossum-tool/multiselect
Add multiselect in place of checkbox for the filters
- Loading branch information
Showing
13 changed files
with
447 additions
and
170 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// SPDX-FileCopyrightText: Facebook, Inc. and its affiliates | ||
// SPDX-FileCopyrightText: TNG Technology Consulting GmbH <https://www.tngtech.com> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React, { ReactElement } from 'react'; | ||
import MuiFormControl from '@mui/material/FormControl'; | ||
import MuiInputLabel from '@mui/material/InputLabel'; | ||
import MuiMenuItem from '@mui/material/MenuItem'; | ||
import MuiSelect from '@mui/material/Select'; | ||
import MuiChip from '@mui/material/Chip'; | ||
import MuiBox from '@mui/material/Box'; | ||
import MuiOutlinedInput from '@mui/material/OutlinedInput'; | ||
import { FilterType } from '../../enums/enums'; | ||
import { useAppDispatch, useAppSelector } from '../../state/hooks'; | ||
import { updateActiveFilters } from '../../state/actions/view-actions/view-actions'; | ||
import { getActiveFilters } from '../../state/selectors/view-selector'; | ||
import { makeStyles } from '@mui/styles'; | ||
import { OpossumColors } from '../../shared-styles'; | ||
|
||
const ITEM_HEIGHT = 48; | ||
const ITEM_PADDING_TOP = 8; | ||
const FILTERS = [ | ||
FilterType.OnlyFollowUp, | ||
FilterType.OnlyFirstParty, | ||
FilterType.HideFirstParty, | ||
]; | ||
|
||
const useStyles = makeStyles({ | ||
dropDownForm: { | ||
width: '170px', | ||
margin: '12px 4px', | ||
backgroundColor: OpossumColors.white, | ||
'& fieldset': { | ||
borderRadius: 0, | ||
}, | ||
'& label': { | ||
backgroundColor: OpossumColors.white, | ||
padding: '1px 3px', | ||
}, | ||
}, | ||
dropDownSelect: { | ||
height: '65px', | ||
}, | ||
dropDownBox: { | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
gap: 0.5, | ||
}, | ||
}); | ||
|
||
export function FilterMultiSelect(): ReactElement { | ||
const classes = useStyles(); | ||
const dispatch = useAppDispatch(); | ||
const activeFilters = Array.from(useAppSelector(getActiveFilters)); | ||
|
||
const updateFilters = (filter: FilterType): void => { | ||
dispatch(updateActiveFilters(filter)); | ||
}; | ||
|
||
function getMenuItems(): Array<ReactElement> { | ||
return FILTERS.map((filter) => ( | ||
<MuiMenuItem | ||
dense | ||
aria-label={filter} | ||
key={filter} | ||
value={filter} | ||
onClick={(event): void => { | ||
updateFilters(event.currentTarget.textContent as FilterType); | ||
}} | ||
> | ||
{filter} | ||
</MuiMenuItem> | ||
)); | ||
} | ||
|
||
return ( | ||
<MuiFormControl className={classes.dropDownForm} size="small"> | ||
<MuiInputLabel shrink={true}>Filter</MuiInputLabel> | ||
<MuiSelect | ||
className={classes.dropDownSelect} | ||
data-testid="test-id-filter-multi-select" | ||
multiple | ||
value={activeFilters} | ||
input={<MuiOutlinedInput />} | ||
renderValue={(selectedFilters): ReactElement => ( | ||
<MuiBox className={classes.dropDownBox}> | ||
{selectedFilters.map((filter) => ( | ||
<MuiChip | ||
key={filter} | ||
label={filter} | ||
size="small" | ||
onMouseDown={(event): void => { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
}} | ||
onDelete={(): void => { | ||
updateFilters(filter); | ||
}} | ||
/> | ||
))} | ||
</MuiBox> | ||
)} | ||
MenuProps={{ | ||
PaperProps: { | ||
style: { | ||
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP, | ||
width: 170, | ||
}, | ||
}, | ||
}} | ||
> | ||
{getMenuItems()} | ||
</MuiSelect> | ||
</MuiFormControl> | ||
); | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Frontend/Components/Filter/__tests__/FilterMultiSelect.test.tsx
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,30 @@ | ||
// SPDX-FileCopyrightText: Facebook, Inc. and its affiliates | ||
// SPDX-FileCopyrightText: TNG Technology Consulting GmbH <https://www.tngtech.com> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { FilterMultiSelect } from '../FilterMultiSelect'; | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { | ||
expectFilterIsShown, | ||
openDropDown, | ||
} from '../../../test-helpers/general-test-helpers'; | ||
import { FilterType } from '../../../enums/enums'; | ||
import { Provider } from 'react-redux'; | ||
import { createAppStore } from '../../../state/configure-store'; | ||
|
||
describe('FilterMultiSelect', () => { | ||
test('renders the filters in a dropdown', () => { | ||
const store = createAppStore(); | ||
render( | ||
<Provider store={store}> | ||
<FilterMultiSelect /> | ||
</Provider> | ||
); | ||
openDropDown(screen); | ||
expectFilterIsShown(screen, FilterType.OnlyFirstParty); | ||
expectFilterIsShown(screen, FilterType.OnlyFollowUp); | ||
expectFilterIsShown(screen, FilterType.HideFirstParty); | ||
}); | ||
}); |
Oops, something went wrong.