From 406b76ce255b40c0af4fabd028ca98fa66ee18b5 Mon Sep 17 00:00:00 2001
From: Henry <50559854+Henry8192@users.noreply.github.com>
Date: Tue, 17 Sep 2024 22:14:31 -0400
Subject: [PATCH] Introduce 8px padding to .menu-bar for better spacing. Add
.menu-bar-filename class to CSS.
---
.../components/MenuBar/ExportLogsButton.tsx | 58 +++++++++++++++++++
.../src/components/MenuBar/index.tsx | 11 +---
.../src/contexts/StateContextProvider.tsx | 8 ++-
.../src/services/LogExportManager.ts | 19 ++++--
4 files changed, 81 insertions(+), 15 deletions(-)
create mode 100644 new-log-viewer/src/components/MenuBar/ExportLogsButton.tsx
diff --git a/new-log-viewer/src/components/MenuBar/ExportLogsButton.tsx b/new-log-viewer/src/components/MenuBar/ExportLogsButton.tsx
new file mode 100644
index 00000000..161e1e6a
--- /dev/null
+++ b/new-log-viewer/src/components/MenuBar/ExportLogsButton.tsx
@@ -0,0 +1,58 @@
+import {useContext} from "react";
+
+import {
+ CircularProgress,
+ Typography,
+} from "@mui/joy";
+
+import DownloadIcon from "@mui/icons-material/Download";
+
+import {StateContext} from "../../contexts/StateContextProvider";
+import {
+ EXPORT_LOG_PROGRESS_COMPLETE,
+ EXPORT_LOG_PROGRESS_INITIALIZATION,
+} from "../../services/LogExportManager";
+import SmallIconButton from "./SmallIconButton";
+
+
+/**
+ * Represents a button for triggering log exports and displays the progress.
+ *
+ * @return
+ */
+export const ExportLogsButton = () => {
+ const {exportLogs, exportProgress} = useContext(StateContext);
+ const handleExportLogsButtonClick = () => {
+ exportLogs();
+ };
+
+
+ return (
+
+ {null === exportProgress || EXPORT_LOG_PROGRESS_INITIALIZATION === exportProgress ?
+ :
+
+ {EXPORT_LOG_PROGRESS_COMPLETE === exportProgress ?
+ :
+
+ {Math.ceil(exportProgress * 100)}
+ }
+ }
+
+ );
+};
+
+export default ExportLogsButton;
diff --git a/new-log-viewer/src/components/MenuBar/index.tsx b/new-log-viewer/src/components/MenuBar/index.tsx
index f3cd059d..1e345069 100644
--- a/new-log-viewer/src/components/MenuBar/index.tsx
+++ b/new-log-viewer/src/components/MenuBar/index.tsx
@@ -11,7 +11,6 @@ import {
} from "@mui/joy";
import DescriptionIcon from "@mui/icons-material/Description";
-import DownloadIcon from "@mui/icons-material/Download";
import FileOpenIcon from "@mui/icons-material/FileOpen";
import SettingsIcon from "@mui/icons-material/Settings";
@@ -19,6 +18,7 @@ import {StateContext} from "../../contexts/StateContextProvider";
import {CURSOR_CODE} from "../../typings/worker";
import {openFile} from "../../utils/file";
import SettingsModal from "../modals/SettingsModal";
+import ExportLogsButton from "./ExportLogsButton";
import NavigationBar from "./NavigationBar";
import SmallIconButton from "./SmallIconButton";
@@ -31,7 +31,7 @@ import "./index.css";
* @return
*/
const MenuBar = () => {
- const {fileName, exportLogs, loadFile} = useContext(StateContext);
+ const {fileName, loadFile} = useContext(StateContext);
const [isSettingsModalOpen, setIsSettingsModalOpen] = useState(false);
@@ -49,9 +49,6 @@ const MenuBar = () => {
setIsSettingsModalOpen(true);
};
- const handleExportLogsButtonClick = () => {
- exportLogs();
- };
return (
<>
@@ -81,9 +78,7 @@ const MenuBar = () => {
>
-
-
-
+
,
logData: string,
numEvents: number,
numPages: number,
@@ -58,6 +59,7 @@ const StateContext = createContext({} as StateContextType);
*/
const STATE_DEFAULT: Readonly = Object.freeze({
beginLineNumToLogEventNum: new Map(),
+ exportProgress: null,
fileName: "",
logData: "Loading...",
numEvents: 0,
@@ -140,6 +142,8 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
const {filePath, logEventNum} = useContext(UrlContext);
const [fileName, setFileName] = useState(STATE_DEFAULT.fileName);
+ const [exportProgress, setExportProgress] =
+ useState>(STATE_DEFAULT.exportProgress);
const [logData, setLogData] = useState(STATE_DEFAULT.logData);
const [numEvents, setNumEvents] = useState(STATE_DEFAULT.numEvents);
const beginLineNumToLogEventNumRef =
@@ -157,7 +161,8 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
switch (code) {
case WORKER_RESP_CODE.CHUNK_DATA:
if (null !== logExportManagerRef.current) {
- logExportManagerRef.current.appendChunkData(args.logs);
+ const progress = logExportManagerRef.current.appendChunkData(args.logs);
+ setExportProgress(progress);
}
break;
case WORKER_RESP_CODE.LOG_FILE_INFO:
@@ -314,6 +319,7 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {