-
Notifications
You must be signed in to change notification settings - Fork 3
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 #526 from BalticAmadeus/make_formatting_button_to_…
…be_clearer add back formatting dropdown
- Loading branch information
Showing
3 changed files
with
64 additions
and
13 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/view/app/Components/Layout/Query/QueryDropdownMenu.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,58 @@ | ||
import { Box, ListItemIcon, ListItemText, Menu, MenuItem } from '@mui/material'; | ||
import CheckIcon from '@mui/icons-material/Check'; | ||
import { useState } from 'react'; | ||
import { ProBroButton } from '@assets/button'; | ||
|
||
interface QueryDropdownMenuProps { | ||
setIsFormatted: (isFormatted: boolean) => void; // Prop to set formatting state in parent | ||
} | ||
|
||
enum FormatType { | ||
JSON = 'JSON', | ||
PROGRESS = 'PROGRESS', | ||
} | ||
|
||
const QueryDropdownMenu: React.FC<QueryDropdownMenuProps> = ({ | ||
setIsFormatted, | ||
}) => { | ||
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null); | ||
const [selectedOption, setSelectedOption] = useState<FormatType>( | ||
FormatType.JSON | ||
); | ||
|
||
const handleFormat = (format: FormatType) => { | ||
if (format === FormatType.JSON) { | ||
setIsFormatted(false); | ||
} else if (format === FormatType.PROGRESS) { | ||
setIsFormatted(true); | ||
} | ||
setSelectedOption(format); | ||
setAnchorEl(null); | ||
}; | ||
|
||
return ( | ||
<Box display='inline-block'> | ||
<ProBroButton onClick={(event) => setAnchorEl(event.currentTarget)}> | ||
FORMAT | ||
</ProBroButton> | ||
<Menu | ||
id='format-menu' | ||
anchorEl={anchorEl} | ||
keepMounted | ||
open={Boolean(anchorEl)} | ||
onClose={() => setAnchorEl(null)} | ||
> | ||
{Object.values(FormatType).map((format) => ( | ||
<MenuItem key={format} onClick={() => handleFormat(format)}> | ||
<ListItemIcon> | ||
{selectedOption === format && <CheckIcon />} | ||
</ListItemIcon> | ||
<ListItemText primary={format} /> | ||
</MenuItem> | ||
))} | ||
</Menu> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default QueryDropdownMenu; |
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