Skip to content

Commit

Permalink
Merge pull request #526 from BalticAmadeus/make_formatting_button_to_…
Browse files Browse the repository at this point in the history
…be_clearer

add back formatting dropdown
  • Loading branch information
abelzis authored Feb 6, 2024
2 parents f0b1cba + d40b130 commit d6124a6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
58 changes: 58 additions & 0 deletions src/view/app/Components/Layout/Query/QueryDropdownMenu.tsx
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;
16 changes: 4 additions & 12 deletions src/view/app/Components/Layout/Query/QueryFormHead.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import ExportPopup from '@Query/Export';
import { ExportPopupProps } from '@Query/Export/export';
import { ProBroButton } from '@assets/button';
import RawOffTwoToneIcon from '@mui/icons-material/RawOffTwoTone';
import RawOnTwoToneIcon from '@mui/icons-material/RawOnTwoTone';
import PlayArrowTwoToneIcon from '@mui/icons-material/PlayArrowTwoTone';
import { MouseEventHandler, useEffect } from 'react';
import UpdatePopup from '@Query/Update';
Expand All @@ -11,6 +9,7 @@ import { Box, Stack, Typography } from '@mui/material';
import QueryAutocompleteInput, {
QueryAutocompleteInputProps,
} from './QueryAutocompleteInput';
import QueryDropdownMenu from './QueryDropdownMenu';

interface QueryFormHeadProps
extends QueryAutocompleteInputProps,
Expand All @@ -21,6 +20,7 @@ interface QueryFormHeadProps
onButtonClick?: MouseEventHandler<HTMLButtonElement>;
formatButtonOnClick: MouseEventHandler<HTMLButtonElement>;
isFormatted: boolean;
setIsFormatted: (value: boolean) => void;
}

/**
Expand All @@ -33,6 +33,7 @@ const QueryFormHead: React.FC<QueryFormHeadProps> = ({
onButtonClick,
formatButtonOnClick,
isFormatted,
setIsFormatted,
...otherProps
}) => {
useEffect(() => {
Expand Down Expand Up @@ -64,16 +65,7 @@ const QueryFormHead: React.FC<QueryFormHeadProps> = ({
selectedRows={otherProps.selectedRows}
isWindowSmall={isWindowSmall}
/>
<ProBroButton
onClick={formatButtonOnClick}
startIcon={
isFormatted ? (
<RawOffTwoToneIcon />
) : (
<RawOnTwoToneIcon />
)
}
/>
<QueryDropdownMenu setIsFormatted={setIsFormatted} />
<UpdatePopup
selectedRows={otherProps.selectedRows}
columns={otherProps.columns}
Expand Down
3 changes: 2 additions & 1 deletion src/view/app/Query/query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function QueryForm({
setWindowHeight(window.innerHeight);
};

let inputQuery: HTMLButtonElement = undefined;
const inputQuery: HTMLButtonElement = undefined;
useEffect(() => {
if (inputQuery) {
inputQuery.click();
Expand Down Expand Up @@ -586,6 +586,7 @@ function QueryForm({
sortColumns={sortColumns}
filters={filters}
selectedRows={selectedRows}
setIsFormatted={setIsFormatted}
formatButtonOnClick={() => {
setIsFormatted(!isFormatted);
}}
Expand Down

0 comments on commit d6124a6

Please sign in to comment.