fix: Copy canned queries to clipboard on click
Instead of trying to update the text directly, which causes the front end to overwrite the user's changes everytime the data updates from then on.
This commit is contained in:
1 parent
89845ace1c
commit
32599bdeff
2 files changed
+30
-6
No files matched your search
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
|
||||
import Tooltip from '@mui/material/Tooltip';
|
||||
import ChevronLeftRounded from "@mui/icons-material/ChevronLeftRounded"
|
||||
import ChevronRightRounded from '@mui/icons-material/ChevronRightRounded';
|
||||
import FileCopyIcon from '@mui/icons-material/FileCopy';
|
||||
import './SideBar.css';
|
||||
|
||||
const Sidebar = ({ onSelection, onOpened, onClosed }) => {
|
||||
@@ -24,9 +25,17 @@ const Sidebar = ({ onSelection, onOpened, onClosed }) => {
|
||||
}
|
||||
}
|
||||
};
|
||||
const onMenuItemClick = (event, cannedQuery) => {
|
||||
console.info(`menu item clicked: ${cannedQuery.name}`);
|
||||
onSelection(cannedQuery);
|
||||
// const onMenuItemClick = (event, cannedQuery) => {
|
||||
// console.info(`menu item clicked: ${cannedQuery.name}`);
|
||||
// onSelection(cannedQuery);
|
||||
// };
|
||||
const onMenuItemClick = async (event, cannedQuery) => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(cannedQuery.query.join("\n"));
|
||||
alert(`Copied ${cannedQuery.name} to clipboard`);
|
||||
} catch (err) {
|
||||
console.error('Failed to copy query text: ', err);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
@@ -62,7 +71,19 @@ const Sidebar = ({ onSelection, onOpened, onClosed }) => {
|
||||
<div className={menuItemContentClass}>
|
||||
<span className='button-text'>{cq.name}</span>
|
||||
</div>
|
||||
</Button>)}
|
||||
</Button>)
|
||||
}
|
||||
{/* {cannedQueries.map(cq =>
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
startIcon={<FileCopyIcon />}
|
||||
onClick={onMenuItemClick}
|
||||
>
|
||||
<div className={menuItemContentClass}>
|
||||
<span className='button-text'>{cq.name}</span>
|
||||
</div>
|
||||
</Button>)} */}
|
||||
</div>
|
||||
<Tooltip title={toggleButtonTitle}>
|
||||
<Button onClick={toggleIsOpen}>
|
||||
|
||||
Reference in new issue
Block a user