FIX[WebApp]: Some fixes to the DeleteWorkbook and Import dialogs

This commit is contained in:
Nicolás Hatcher
2024-12-19 20:56:48 +01:00
parent 44f7929f4e
commit 13b1157c61
3 changed files with 92 additions and 49 deletions

View File

@@ -1,21 +1,24 @@
import styled from "@emotion/styled"; import styled from "@emotion/styled";
import { Trash2 } from "lucide-react"; import { Trash2 } from "lucide-react";
import { forwardRef, useEffect } from "react"; import { useEffect, useRef } from "react";
import { theme } from "../theme";
interface DeleteWorkbookDialogProperties {
onClose: () => void;
onConfirm: () => void;
workbookName: string;
}
function DeleteWorkbookDialog(properties: DeleteWorkbookDialogProperties) {
const deleteButtonRef = useRef<HTMLButtonElement>(null);
export const DeleteWorkbookDialog = forwardRef<
HTMLDivElement,
{
onClose: () => void;
onConfirm: () => void;
workbookName: string;
}
>((properties, ref) => {
useEffect(() => { useEffect(() => {
const root = document.getElementById("root"); const root = document.getElementById("root");
if (root) { if (root) {
root.style.filter = "blur(2px)"; root.style.filter = "blur(2px)";
} }
if (deleteButtonRef.current) {
deleteButtonRef.current.focus();
}
return () => { return () => {
const root = document.getElementById("root"); const root = document.getElementById("root");
if (root) { if (root) {
@@ -26,8 +29,12 @@ export const DeleteWorkbookDialog = forwardRef<
return ( return (
<DialogWrapper <DialogWrapper
ref={ref}
tabIndex={-1} tabIndex={-1}
onKeyDown={(event) => {
if (event.code === "Escape") {
properties.onClose();
}
}}
role="dialog" role="dialog"
aria-labelledby="delete-dialog-title" aria-labelledby="delete-dialog-title"
aria-describedby="delete-dialog-description" aria-describedby="delete-dialog-description"
@@ -47,6 +54,7 @@ export const DeleteWorkbookDialog = forwardRef<
properties.onConfirm(); properties.onConfirm();
properties.onClose(); properties.onClose();
}} }}
ref={deleteButtonRef}
> >
Yes, delete workbook Yes, delete workbook
</DeleteButton> </DeleteButton>
@@ -55,10 +63,25 @@ export const DeleteWorkbookDialog = forwardRef<
</ContentWrapper> </ContentWrapper>
</DialogWrapper> </DialogWrapper>
); );
}); }
DeleteWorkbookDialog.displayName = "DeleteWorkbookDialog"; DeleteWorkbookDialog.displayName = "DeleteWorkbookDialog";
// some colors taken from the IronCalc palette
const COMMON_WHITE = "#FFF";
const COMMON_BLACK = "#272525";
const ERROR_MAIN = "#EB5757";
const ERROR_DARK = "#CB4C4C";
const GREY_200 = "#EEEEEE";
const GREY_300 = "#E0E0E0";
const GREY_700 = "#616161";
const GREY_900 = "#333333";
const PRIMARY_MAIN = "#F2994A";
const PRIMARY_DARK = "#D68742";
const DialogWrapper = styled.div` const DialogWrapper = styled.div`
position: fixed; position: fixed;
top: 50%; top: 50%;
@@ -70,7 +93,7 @@ const DialogWrapper = styled.div`
gap: 16px; gap: 16px;
padding: 12px; padding: 12px;
border-radius: 8px; border-radius: 8px;
box-shadow: 0px 1px 3px 0px ${theme.palette.common.black}1A; box-shadow: 0px 1px 3px 0px ${COMMON_BLACK}1A;
width: 280px; width: 280px;
max-width: calc(100% - 40px); max-width: calc(100% - 40px);
z-index: 50; z-index: 50;
@@ -84,9 +107,9 @@ const IconWrapper = styled.div`
width: 36px; width: 36px;
height: 36px; height: 36px;
border-radius: 4px; border-radius: 4px;
background-color: ${theme.palette.error.main}1A; background-color: ${ERROR_MAIN}1A;
margin: 12px auto 0 auto; margin: 12px auto 0 auto;
color: ${theme.palette.error.main}; color: ${ERROR_MAIN};
svg { svg {
width: 16px; width: 16px;
height: 16px; height: 16px;
@@ -106,13 +129,13 @@ const Title = styled.h2`
margin: 0; margin: 0;
font-weight: 600; font-weight: 600;
font-size: inherit; font-size: inherit;
color: ${theme.palette.grey["900"]}; color: ${GREY_900};
`; `;
const Body = styled.p` const Body = styled.p`
margin: 0; margin: 0;
text-align: center; text-align: center;
color: ${theme.palette.grey["900"]}; color: ${GREY_900};
font-size: 12px; font-size: 12px;
`; `;
@@ -126,8 +149,8 @@ const ButtonGroup = styled.div`
const Button = styled.button` const Button = styled.button`
cursor: pointer; cursor: pointer;
color: ${theme.palette.common.white}; color: ${COMMON_WHITE};
background-color: ${theme.palette.primary.main}; background-color: ${PRIMARY_MAIN};
padding: 0px 10px; padding: 0px 10px;
height: 36px; height: 36px;
border-radius: 4px; border-radius: 4px;
@@ -139,22 +162,24 @@ const Button = styled.button`
text-overflow: ellipsis; text-overflow: ellipsis;
transition: background-color 150ms; transition: background-color 150ms;
&:hover { &:hover {
background-color: ${theme.palette.primary.dark}; background-color: ${PRIMARY_DARK};
} }
`; `;
const DeleteButton = styled(Button)` const DeleteButton = styled(Button)`
background-color: ${theme.palette.error.main}; background-color: ${ERROR_MAIN};
color: ${theme.palette.common.white}; color: ${COMMON_WHITE};
&:hover { &:hover {
background-color: ${theme.palette.error.dark}; background-color: ${ERROR_DARK};
} }
`; `;
const CancelButton = styled(Button)` const CancelButton = styled(Button)`
background-color: ${theme.palette.grey["200"]}; background-color: ${GREY_200};
color: ${theme.palette.grey["700"]}; color: ${GREY_700};
&:hover { &:hover {
background-color: ${theme.palette.grey["300"]}; background-color: ${GREY_300};
} }
`; `;
export default DeleteWorkbookDialog;

View File

@@ -2,8 +2,8 @@ import styled from "@emotion/styled";
import { Menu, MenuItem, Modal } from "@mui/material"; import { Menu, MenuItem, Modal } from "@mui/material";
import { Check, FileDown, FileUp, Plus, Trash2 } from "lucide-react"; import { Check, FileDown, FileUp, Plus, Trash2 } from "lucide-react";
import { useRef, useState } from "react"; import { useRef, useState } from "react";
import { DeleteWorkbookDialog } from "./DeleteWorkbookDialog"; import DeleteWorkbookDialog from "./DeleteWorkbookDialog";
import { UploadFileDialog } from "./UploadFileDialog"; import UploadFileDialog from "./UploadFileDialog";
import { getModelsMetadata, getSelectedUuid } from "./storage"; import { getModelsMetadata, getSelectedUuid } from "./storage";
export function FileMenu(props: { export function FileMenu(props: {
@@ -105,10 +105,6 @@ export function FileMenu(props: {
<Modal <Modal
open={isImportMenuOpen} open={isImportMenuOpen}
onClose={() => { onClose={() => {
const root = document.getElementById("root");
if (root) {
root.style.filter = "";
}
setImportMenuOpen(false); setImportMenuOpen(false);
}} }}
aria-labelledby="modal-modal-title" aria-labelledby="modal-modal-title"
@@ -117,10 +113,6 @@ export function FileMenu(props: {
<> <>
<UploadFileDialog <UploadFileDialog
onClose={() => { onClose={() => {
const root = document.getElementById("root");
if (root) {
root.style.filter = "";
}
setImportMenuOpen(false); setImportMenuOpen(false);
}} }}
onModelUpload={props.onModelUpload} onModelUpload={props.onModelUpload}
@@ -133,11 +125,13 @@ export function FileMenu(props: {
aria-labelledby="delete-dialog-title" aria-labelledby="delete-dialog-title"
aria-describedby="delete-dialog-description" aria-describedby="delete-dialog-description"
> >
<DeleteWorkbookDialog <>
onClose={() => setDeleteDialogOpen(false)} <DeleteWorkbookDialog
onConfirm={props.onDelete} onClose={() => setDeleteDialogOpen(false)}
workbookName={selectedUuid ? models[selectedUuid] : ""} onConfirm={props.onDelete}
/> workbookName={selectedUuid ? models[selectedUuid] : ""}
/>
</>
</Modal> </Modal>
</> </>
); );

View File

@@ -1,17 +1,34 @@
import styled from "@emotion/styled"; import styled from "@emotion/styled";
import { BookOpen, FileUp } from "lucide-react"; import { BookOpen, FileUp } from "lucide-react";
import { type DragEvent, useRef, useState } from "react"; import { type DragEvent, useEffect, useRef, useState } from "react";
export function UploadFileDialog(properties: { function UploadFileDialog(properties: {
onClose: () => void; onClose: () => void;
onModelUpload: (blob: ArrayBuffer, fileName: string) => Promise<void>; onModelUpload: (blob: ArrayBuffer, fileName: string) => Promise<void>;
}) { }) {
const [hover, setHover] = useState(false); const [hover, setHover] = useState(false);
const [message, setMessage] = useState(""); const [message, setMessage] = useState("");
const fileInputRef = useRef<HTMLInputElement>(null); const fileInputRef = useRef<HTMLInputElement>(null);
const crossRef = useRef<HTMLDivElement>(null);
const { onModelUpload } = properties; const { onModelUpload } = properties;
useEffect(() => {
const root = document.getElementById("root");
if (root) {
root.style.filter = "blur(2px)";
}
if (crossRef.current) {
crossRef.current.focus();
}
return () => {
const root = document.getElementById("root");
if (root) {
root.style.filter = "none";
}
};
}, []);
const handleClose = () => { const handleClose = () => {
properties.onClose(); properties.onClose();
}; };
@@ -79,12 +96,16 @@ export function UploadFileDialog(properties: {
reader.readAsArrayBuffer(file); reader.readAsArrayBuffer(file);
}; };
const root = document.getElementById("root");
if (root) {
root.style.filter = "blur(4px)";
}
return ( return (
<UploadDialog> <UploadDialog
tabIndex={-1}
role="dialog"
onKeyDown={(event) => {
if (event.code === "Escape") {
handleClose();
}
}}
>
<UploadTitle> <UploadTitle>
<span style={{ flexGrow: 2, marginLeft: 12 }}> <span style={{ flexGrow: 2, marginLeft: 12 }}>
Import an .xlsx file Import an .xlsx file
@@ -92,7 +113,8 @@ export function UploadFileDialog(properties: {
<Cross <Cross
style={{ marginRight: 12 }} style={{ marginRight: 12 }}
onClick={handleClose} onClick={handleClose}
onKeyDown={() => {}} ref={crossRef}
tabIndex={0}
> >
<svg <svg
width="16" width="16"
@@ -300,3 +322,5 @@ const DropZone = styled("div")`
gap: 16px; gap: 16px;
transition: 0.2s ease-in-out; transition: 0.2s ease-in-out;
`; `;
export default UploadFileDialog;