-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): is:external and is:not:external filter
- Loading branch information
alice.juan
committed
Mar 21, 2024
1 parent
c9469ce
commit f4add08
Showing
2 changed files
with
71 additions
and
4 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
61 changes: 61 additions & 0 deletions
61
taxonomy-editor-frontend/src/pages/project/search/ThreeOptionsSwitch.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,61 @@ | ||
import { ToggleButton, ToggleButtonGroup, Typography } from "@mui/material" | ||
import React, { Dispatch, SetStateAction } from "react"; | ||
|
||
const toggleTheme = { | ||
"& .MuiToggleButton-root": { | ||
color: "#341100", | ||
"&.Mui-selected": { | ||
color: "#341100", | ||
}, | ||
borderColor: "rgba(0, 0, 0, 0.23)", | ||
}, | ||
}; | ||
|
||
type ThreeOptionsSwitchType = { | ||
filterValue: string, | ||
setFilterValue: Dispatch<SetStateAction<string>>, | ||
options: {[key: string]: { text: string; isNegated: boolean}}; | ||
setQ: Dispatch<SetStateAction<string>>; | ||
keySearchTerm: string; | ||
setCurrentPage: Dispatch<SetStateAction<number>>; | ||
} | ||
|
||
export const ThreeOptionsSwitch = ({filterValue, setFilterValue, options, setQ, keySearchTerm, setCurrentPage}:ThreeOptionsSwitchType) => { | ||
|
||
const handleChange = ( | ||
event: React.MouseEvent<HTMLElement>, | ||
newValue: string, | ||
) => { | ||
setFilterValue(newValue); | ||
setCurrentPage(1); | ||
let newFilterExpression=""; | ||
if (options[newValue].isNegated) { | ||
newFilterExpression = ` is:not:${keySearchTerm}`; | ||
} else { | ||
newFilterExpression = ` is:${keySearchTerm}`; | ||
} | ||
setQ((prevQ) => { | ||
prevQ = prevQ.replace(`is:not:${keySearchTerm}`,""); | ||
prevQ = prevQ.replace(`is:${keySearchTerm}`,""); | ||
return prevQ+newFilterExpression; | ||
}); | ||
}; | ||
return ( | ||
<div style={{ display: 'flex', flexDirection: 'column' }}> | ||
<Typography variant="subtitle1" gutterBottom sx={{mb:0, m:"8px", color:"#341100"}}> | ||
Taxonomy | ||
</Typography> | ||
<ToggleButtonGroup | ||
sx={toggleTheme} | ||
value={filterValue} | ||
exclusive | ||
onChange={handleChange} | ||
aria-label="Platform" | ||
> | ||
{Object.entries(options).map(([value,option]) => ( | ||
<ToggleButton key={value} value={value} sx={{height:"2em"}}>{option.text}</ToggleButton> | ||
))} | ||
</ToggleButtonGroup> | ||
</div> | ||
) | ||
} |