mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
prevent strings from being pasted in number type fields
This commit is contained in:
@@ -7,6 +7,7 @@ import Paste from "@mui/icons-material/ContentPaste";
|
||||
import { useProjectContext } from "@src/contexts/ProjectContext";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { SelectedCell } from "@src/atoms/ContextMenu";
|
||||
import { getFieldProp, getColumnType } from "@src/components/fields";
|
||||
|
||||
export interface IContextMenuActions {
|
||||
label: string;
|
||||
@@ -48,15 +49,26 @@ export default function BasicContextMenuActions(
|
||||
} catch (error) {
|
||||
enqueueSnackbar(`Failed to cut: ${error}`, { variant: "error" });
|
||||
}
|
||||
|
||||
handleClose();
|
||||
};
|
||||
|
||||
const handlePaste = async () => {
|
||||
try {
|
||||
const text = await navigator.clipboard.readText();
|
||||
const paste = await JSON.parse(text);
|
||||
updateCell?.(selectedRow?.ref, selectedCol.key, paste);
|
||||
const cellDataType = getFieldProp("dataType", getColumnType(selectedCol));
|
||||
let parsed;
|
||||
if (cellDataType === "number") {
|
||||
parsed = Number(text);
|
||||
if (isNaN(parsed)) {
|
||||
enqueueSnackbar(`Failed to paste: ${text} is not a number`, {
|
||||
variant: "error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
parsed = await JSON.parse(text);
|
||||
}
|
||||
updateCell?.(selectedRow?.ref, selectedCol.key, parsed);
|
||||
} catch (error) {
|
||||
enqueueSnackbar(`Failed to paste: ${error}`, { variant: "error" });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user