Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add load state in <StateContextProvider/> and disable UI elements based on the state. #88

Merged
merged 43 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9c7ad68
Add load state for UI components.
junhaoliao Oct 3, 2024
90de515
Refactor loading state styling in DropFileContainer.
junhaoliao Oct 3, 2024
6795933
Refactor the loading state check to use a constant `isLoading` variab…
junhaoliao Oct 3, 2024
59bf592
Add docs for LOAD_STATE.
junhaoliao Oct 3, 2024
76f497f
Complete docs for LOAD_STATE.
junhaoliao Oct 3, 2024
b9397a8
Remove unreachable code in cursor navigation function.
junhaoliao Oct 3, 2024
8345aa3
Merge remote-tracking branch 'junhao/main' into load-state
junhaoliao Oct 11, 2024
8df7a0e
Merge branch 'main' into load-state
junhaoliao Oct 11, 2024
c6027e0
Disable log level controls during load state.
junhaoliao Oct 11, 2024
79b5113
Prevent log level selection when log file is unopened; allow the log …
junhaoliao Oct 11, 2024
60aadbf
Do not change load state when the worker isn't created.
junhaoliao Oct 11, 2024
70e96df
Refactor loading progress styles in MenuBar component.
junhaoliao Oct 11, 2024
61e35db
collapse state space
davemarco Oct 12, 2024
e9b3a7c
small cleanup
davemarco Oct 12, 2024
119cde1
fix lint
davemarco Oct 12, 2024
88f4e4c
add exporting state
davemarco Oct 14, 2024
b88d5b9
fix stuff
davemarco Oct 14, 2024
366815e
fix lint
davemarco Oct 14, 2024
b48388a
add grid so states can be seen in code. Docs better in code
davemarco Oct 17, 2024
95692a9
small changes
davemarco Oct 17, 2024
6845397
small changes
davemarco Oct 17, 2024
e15aab3
fix lint
davemarco Oct 17, 2024
0504ddf
make fancier
davemarco Oct 17, 2024
9fe231b
small change
davemarco Oct 17, 2024
7b80749
junhao disable pointer request
davemarco Oct 18, 2024
aaef52c
Update new-log-viewer/src/utils/states.ts
davemarco Oct 18, 2024
16c73a9
Update new-log-viewer/src/utils/states.ts
davemarco Oct 18, 2024
aa1edd7
Update new-log-viewer/src/components/MenuBar/PageNumInput.tsx
davemarco Oct 18, 2024
43a2cee
Update new-log-viewer/src/index.css
davemarco Oct 18, 2024
6393cf3
junhao review + remove non neccesary pointer events class
davemarco Oct 18, 2024
c0840ba
Merge branch 'load-state' of github.com:junhaoliao/yscope-log-viewer …
davemarco Oct 18, 2024
f01bea4
Merge branch 'refs/heads/main' into load-state
junhaoliao Oct 19, 2024
6b51a48
Refactor the LinearProgress component in MenuBar to use the 'thicknes…
junhaoliao Oct 19, 2024
5960765
Merge branch 'main' into load-state
davemarco Oct 21, 2024
49eeefa
Update new-log-viewer/src/utils/states.ts
davemarco Oct 21, 2024
4a8a165
Update new-log-viewer/src/contexts/StateContextProvider.tsx
davemarco Oct 21, 2024
fa7c233
fix lint
davemarco Oct 21, 2024
c80596c
new approach based on slack
davemarco Oct 21, 2024
c22611d
add missing file
davemarco Oct 21, 2024
be12a2d
Apply suggestions from code review
davemarco Oct 21, 2024
5f1e0ad
get rid of type
davemarco Oct 21, 2024
a11be54
make drag and drop false
davemarco Oct 21, 2024
e99fd13
Enable DRAG_AND_DROP during FAST_LOADING to align the behaviour with …
junhaoliao Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions new-log-viewer/src/components/DropFileContainer/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@

background-color: #f3f3f3;
}

.hover-message-loading {
background-color: #fce4e4;
}
19 changes: 15 additions & 4 deletions new-log-viewer/src/components/DropFileContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import React, {
} from "react";

import {StateContext} from "../../contexts/StateContextProvider";
import {CURSOR_CODE} from "../../typings/worker";
import {
CURSOR_CODE,
LOAD_STATE,
} from "../../typings/worker";

import "./index.css";

Expand All @@ -21,8 +24,9 @@ interface DropFileContextProviderProps {
* @return
*/
const DropFileContainer = ({children}: DropFileContextProviderProps) => {
const {loadFile} = useContext(StateContext);
const {loadFile, loadState} = useContext(StateContext);
davemarco marked this conversation as resolved.
Show resolved Hide resolved
const [isFileHovering, setIsFileHovering] = useState(false);
const isLoading = LOAD_STATE.LOADING_FILE === loadState || LOAD_STATE.EXPORTING === loadState;

const handleDrag = (ev: React.DragEvent<HTMLDivElement>) => {
ev.preventDefault();
Expand Down Expand Up @@ -52,6 +56,9 @@ const DropFileContainer = ({children}: DropFileContextProviderProps) => {
ev.stopPropagation();

setIsFileHovering(false);
if (isLoading) {
return;
}

const [file] = ev.dataTransfer.files;
if ("undefined" === typeof file) {
Expand All @@ -78,10 +85,14 @@ const DropFileContainer = ({children}: DropFileContextProviderProps) => {
onDrop={handleDrop}
>
<div
className={"hover-message"}
className={`hover-message ${isLoading ?
"hover-message-loading" :
""}`}
davemarco marked this conversation as resolved.
Show resolved Hide resolved
onDrop={handleDrop}
>
Drop file to view
{isLoading ?
"Drop is disabled during loading" :
"Drop file to view"}
</div>
</div>
)}
Expand Down
8 changes: 3 additions & 5 deletions new-log-viewer/src/components/MenuBar/ExportLogsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
EXPORT_LOG_PROGRESS_VALUE_MAX,
EXPORT_LOG_PROGRESS_VALUE_MIN,
} from "../../services/LogExportManager";
import {LOAD_STATE} from "../../typings/worker";
import SmallIconButton from "./SmallIconButton";


Expand All @@ -21,16 +22,13 @@ import SmallIconButton from "./SmallIconButton";
* @return
*/
const ExportLogsButton = () => {
const {exportLogs, exportProgress, fileName} = useContext(StateContext);
const {exportLogs, exportProgress, loadState} = useContext(StateContext);

return (
<SmallIconButton
disabled={
// eslint-disable-next-line no-warning-comments
// TODO: Replace `"" === fileName` with a more specific context variable that
// indicates whether the file has been loaded.
(null !== exportProgress && EXPORT_LOG_PROGRESS_VALUE_MAX !== exportProgress) ||
"" === fileName
loadState !== LOAD_STATE.READY
}
onClick={exportLogs}
>
Expand Down
34 changes: 22 additions & 12 deletions new-log-viewer/src/components/MenuBar/NavigationBar.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import React, {useContext} from "react";

import {
ButtonGroup,
IconButton,
} from "@mui/joy";

import NavigateBefore from "@mui/icons-material/NavigateBefore";
import NavigateNext from "@mui/icons-material/NavigateNext";
import SkipNext from "@mui/icons-material/SkipNext";
import SkipPrevious from "@mui/icons-material/SkipPrevious";

import {StateContext} from "../../contexts/StateContextProvider";
import {LOAD_STATE} from "../../typings/worker";
import {ACTION_NAME} from "../../utils/actions";
import PageNumInput from "./PageNumInput";
import SmallIconButton from "./SmallIconButton";


/**
Expand All @@ -17,7 +22,7 @@ import SmallIconButton from "./SmallIconButton";
* @return
*/
const NavigationBar = () => {
const {loadPageByAction} = useContext(StateContext);
const {loadState, loadPageByAction} = useContext(StateContext);

const handleNavButtonClick = (event: React.MouseEvent<HTMLButtonElement>) => {
const {actionName} = event.currentTarget.dataset;
Expand All @@ -34,35 +39,40 @@ const NavigationBar = () => {
};

return (
<>
<SmallIconButton
<ButtonGroup
disabled={loadState !== LOAD_STATE.READY}
size={"sm"}
spacing={0.01}
variant={"plain"}
>
<IconButton
data-action-name={ACTION_NAME.FIRST_PAGE}
onClick={handleNavButtonClick}
>
<SkipPrevious/>
</SmallIconButton>
<SmallIconButton
</IconButton>
<IconButton
data-action-name={ACTION_NAME.PREV_PAGE}
onClick={handleNavButtonClick}
>
<NavigateBefore/>
</SmallIconButton>
</IconButton>

<PageNumInput/>

<SmallIconButton
<IconButton
data-action-name={ACTION_NAME.NEXT_PAGE}
onClick={handleNavButtonClick}
>
<NavigateNext/>
</SmallIconButton>
<SmallIconButton
</IconButton>
<IconButton
data-action-name={ACTION_NAME.LAST_PAGE}
onClick={handleNavButtonClick}
>
<SkipNext/>
</SmallIconButton>
</>
</IconButton>
</ButtonGroup>
);
};

Expand Down
7 changes: 6 additions & 1 deletion new-log-viewer/src/components/MenuBar/PageNumInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {Typography} from "@mui/joy";
import Input from "@mui/joy/Input";

import {StateContext} from "../../contexts/StateContextProvider";
import {LOAD_STATE} from "../../typings/worker";
import {ACTION_NAME} from "../../utils/actions";

import "./PageNumInput.css";
Expand All @@ -23,7 +24,7 @@ const PAGE_NUM_INPUT_FIT_EXTRA_WIDTH = 2;
* @return
*/
const PageNumInput = () => {
const {loadPageByAction, numPages, pageNum} = useContext(StateContext);
const {loadState, loadPageByAction, numPages, pageNum} = useContext(StateContext);

const [isEditing, setIsEditing] = useState<boolean>(false);
const inputRef = useRef<HTMLInputElement>(null);
Expand Down Expand Up @@ -79,13 +80,17 @@ const PageNumInput = () => {
>
<Input
className={"page-num-input"}
disabled={loadState !== LOAD_STATE.READY}
size={"sm"}
slotProps={{input: {ref: inputRef}}}
type={"number"}
endDecorator={
<Typography
className={"page-num-input-num-pages-text"}
level={"body-md"}
sx={loadState !== LOAD_STATE.READY ?
{color: "neutral.plainDisabledColor"} :
{}}
>
{"/ "}
{numPages}
Expand Down
10 changes: 10 additions & 0 deletions new-log-viewer/src/components/MenuBar/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@
flex-grow: 1;
padding-left: 10px;
}

.menu-bar-loading-progress {
/* stylelint-disable-next-line custom-property-pattern */
--LinearProgress-thickness: 2px !important;
/* stylelint-disable-next-line custom-property-pattern */
--LinearProgress-progressThickness: 2px !important;

z-index: var(--ylv-loading-progress-z-index);
margin-bottom: -2px;
}
18 changes: 16 additions & 2 deletions new-log-viewer/src/components/MenuBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {useContext} from "react";
import {
Divider,
IconButton,
LinearProgress,
Sheet,
Tooltip,
Typography,
Expand All @@ -11,7 +12,10 @@ import {
import FolderOpenIcon from "@mui/icons-material/FolderOpen";

import {StateContext} from "../../contexts/StateContextProvider";
import {CURSOR_CODE} from "../../typings/worker";
import {
CURSOR_CODE,
LOAD_STATE,
} from "../../typings/worker";
import {openFile} from "../../utils/file";
import ExportLogsButton from "./ExportLogsButton";
import NavigationBar from "./NavigationBar";
Expand All @@ -25,14 +29,16 @@ import "./index.css";
* @return
*/
const MenuBar = () => {
const {fileName, loadFile} = useContext(StateContext);
const {fileName, loadState, loadFile} = useContext(StateContext);

const handleOpenFile = () => {
openFile((file) => {
loadFile(file, {code: CURSOR_CODE.LAST_EVENT, args: null});
});
};

const isLoading = LOAD_STATE.LOADING_FILE === loadState;

return (
<>
<Sheet className={"menu-bar"}>
Expand All @@ -52,6 +58,10 @@ const MenuBar = () => {
>
<IconButton
size={"sm"}
disabled={
loadState === LOAD_STATE.LOADING_FILE ||
loadState === LOAD_STATE.EXPORTING
}
onClick={handleOpenFile}
>
<FolderOpenIcon className={"menu-bar-open-file-icon"}/>
Expand All @@ -72,6 +82,10 @@ const MenuBar = () => {

<ExportLogsButton/>
</Sheet>
{isLoading &&
<LinearProgress
className={"menu-bar-loading-progress"}
size={"sm"}/>}
</>
);
};
Expand Down
36 changes: 23 additions & 13 deletions new-log-viewer/src/components/StatusBar/LogLevelSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
LOG_LEVEL_NAMES,
MAX_LOG_LEVEL,
} from "../../../typings/logs";
import {LOAD_STATE} from "../../../typings/worker";
import {range} from "../../../utils/data";
import LogLevelChip from "./LogLevelChip";

Expand Down Expand Up @@ -125,26 +126,29 @@ interface ClearFiltersOptionProps {
* @param props.onClick
* @return
*/
const ClearFiltersOption = ({onClick}: ClearFiltersOptionProps) => (
<Option
value={INVALID_LOG_LEVEL_VALUE}
onClick={onClick}
>
<ListItemDecorator>
<CloseIcon/>
</ListItemDecorator>
Clear filters
</Option>
);
const ClearFiltersOption = ({onClick}: ClearFiltersOptionProps) => {
davemarco marked this conversation as resolved.
Show resolved Hide resolved
return (
<Option
value={INVALID_LOG_LEVEL_VALUE}
onClick={onClick}
>
<ListItemDecorator>
<CloseIcon/>
</ListItemDecorator>
Clear filters
</Option>
);
};

/**
* Renders a dropdown box for selecting log levels.
*
* @return
*/
const LogLevelSelect = () => {
const {loadState, setLogLevelFilter} = useContext(StateContext);

const [selectedLogLevels, setSelectedLogLevels] = useState<LOG_LEVEL[]>([]);
const {setLogLevelFilter} = useContext(StateContext);

const handleRenderValue = (selected: SelectValue<SelectOption<LOG_LEVEL>, true>) => (
<Box className={"log-level-select-render-value-box"}>
Expand Down Expand Up @@ -206,6 +210,7 @@ const LogLevelSelect = () => {
return (
<Select
className={"log-level-select"}
disabled={LOAD_STATE.READY !== loadState}
multiple={true}
renderValue={handleRenderValue}
size={"sm"}
Expand All @@ -222,7 +227,12 @@ const LogLevelSelect = () => {
</IconButton>
</Tooltip>}
placeholder={
<Chip className={"log-level-select-render-value-box-label"}>
<Chip
className={"log-level-select-render-value-box-label"}
sx={loadState !== LOAD_STATE.READY ?
{color: "neutral.plainDisabledColor"} :
{}}
>
Log Level
</Chip>
}
Expand Down
7 changes: 6 additions & 1 deletion new-log-viewer/src/components/StatusBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
copyPermalinkToClipboard,
UrlContext,
} from "../../contexts/UrlContextProvider";
import {LOAD_STATE} from "../../typings/worker";
import LogLevelSelect from "./LogLevelSelect";

import "./index.css";
Expand All @@ -27,7 +28,7 @@ const handleCopyLinkButtonClick = () => {
* @return
*/
const StatusBar = () => {
const {numEvents} = useContext(StateContext);
const {loadState, numEvents} = useContext(StateContext);
const {logEventNum} = useContext(UrlContext);

return (
Expand All @@ -42,6 +43,10 @@ const StatusBar = () => {
color={"primary"}
size={"sm"}
variant={"soft"}
disabled={
loadState === LOAD_STATE.UNOPENED ||
loadState === LOAD_STATE.LOADING_FILE
}
onClick={handleCopyLinkButtonClick}
>
{"Log Event "}
Expand Down
Loading
Loading