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
156ec8f3a8
commit
587e340071
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}>
|
||||
|
||||
@@ -116,12 +116,15 @@ public class DataPacketJsonConverter : JsonConverter<DataPacket> {
|
||||
}
|
||||
if (t == typeof(double)) {
|
||||
return NullCheckWrapper(v => {
|
||||
var dbl = ConvertUtils.try_convert(v, double.NaN);
|
||||
var dbl = Equals(v, DBNull.Value) ? double.NaN : (double)v;
|
||||
JsonSerializer.Serialize(writer, dbl, options);
|
||||
});
|
||||
}
|
||||
if (t == typeof(float)) {
|
||||
return NullCheckWrapper(v => writer.WriteNumberValue((float)v));
|
||||
return NullCheckWrapper(v => {
|
||||
var flt = Equals(v, DBNull.Value) ? float.NaN : (float)v;
|
||||
writer.WriteNumberValue(flt);
|
||||
});
|
||||
}
|
||||
if (t == typeof(bool)) {
|
||||
return NullCheckWrapper(v => writer.WriteBooleanValue((bool)v));
|
||||
|
||||
Reference in new issue
Block a user