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 13 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;
}
13 changes: 4 additions & 9 deletions new-log-viewer/src/components/DropFileContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
} from "react";

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

Check failure on line 7 in new-log-viewer/src/components/DropFileContainer/index.tsx

View workflow job for this annotation

GitHub Actions / lint-check

Imports must not be broken into multiple lines if there are 1 or less elements

Check failure on line 7 in new-log-viewer/src/components/DropFileContainer/index.tsx

View workflow job for this annotation

GitHub Actions / lint-check

Unexpected line break after this opening brace
CURSOR_CODE,
} from "../../typings/worker";

Check failure on line 9 in new-log-viewer/src/components/DropFileContainer/index.tsx

View workflow job for this annotation

GitHub Actions / lint-check

Unexpected line break before this closing brace
davemarco marked this conversation as resolved.
Show resolved Hide resolved

import "./index.css";

Expand All @@ -21,7 +23,7 @@
* @return
*/
const DropFileContainer = ({children}: DropFileContextProviderProps) => {
const {loadFile} = useContext(StateContext);
const {loadFile, loadState} = useContext(StateContext);

Check failure on line 26 in new-log-viewer/src/components/DropFileContainer/index.tsx

View workflow job for this annotation

GitHub Actions / lint-check

'loadState' is assigned a value but never used
davemarco marked this conversation as resolved.
Show resolved Hide resolved
const [isFileHovering, setIsFileHovering] = useState(false);

const handleDrag = (ev: React.DragEvent<HTMLDivElement>) => {
Expand Down Expand Up @@ -52,7 +54,6 @@
ev.stopPropagation();

setIsFileHovering(false);

const [file] = ev.dataTransfer.files;
if ("undefined" === typeof file) {
console.warn("No file dropped.");
Expand All @@ -73,16 +74,10 @@
<div onDrop={handleDrop}>
{children}
{isFileHovering && (
<div

Check failure on line 77 in new-log-viewer/src/components/DropFileContainer/index.tsx

View workflow job for this annotation

GitHub Actions / lint-check

Empty components are self-closing
className={"hover-mask"}
onDrop={handleDrop}
>
<div
className={"hover-message"}
onDrop={handleDrop}
>
Drop file to view
</div>
</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
5 changes: 4 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 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 @@
* @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,15 @@
>
<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' } : {}}

Check warning on line 91 in new-log-viewer/src/components/MenuBar/PageNumInput.tsx

View workflow job for this annotation

GitHub Actions / lint-check

This line has a length of 106. Maximum allowed is 100

Check failure on line 91 in new-log-viewer/src/components/MenuBar/PageNumInput.tsx

View workflow job for this annotation

GitHub Actions / lint-check

Expected newline between test and consequent of ternary expression

Check failure on line 91 in new-log-viewer/src/components/MenuBar/PageNumInput.tsx

View workflow job for this annotation

GitHub Actions / lint-check

Expected newline between consequent and alternate of ternary expression

Check failure on line 91 in new-log-viewer/src/components/MenuBar/PageNumInput.tsx

View workflow job for this annotation

GitHub Actions / lint-check

There should be no space after '{'

Check warning on line 91 in new-log-viewer/src/components/MenuBar/PageNumInput.tsx

View workflow job for this annotation

GitHub Actions / lint-check

Strings must use doublequote

Check failure on line 91 in new-log-viewer/src/components/MenuBar/PageNumInput.tsx

View workflow job for this annotation

GitHub Actions / lint-check

There should be no space before '}'
>
{"/ "}
{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;
}
14 changes: 12 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 === loadState;

return (
<>
<Sheet className={"menu-bar"}>
Expand Down Expand Up @@ -72,6 +78,10 @@ const MenuBar = () => {

<ExportLogsButton/>
</Sheet>
{isLoading &&
<LinearProgress
className={"menu-bar-loading-progress"}
size={"sm"}/>}
</>
);
};
Expand Down
35 changes: 22 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 @@
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,30 @@
* @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) => {

Check failure on line 129 in new-log-viewer/src/components/StatusBar/LogLevelSelect/index.tsx

View workflow job for this annotation

GitHub Actions / lint-check

Block must not be padded by blank lines
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 @@ -211,6 +216,7 @@
size={"sm"}
value={selectedLogLevels}
variant={"soft"}
disabled = {LOAD_STATE.READY !== loadState}
davemarco marked this conversation as resolved.
Show resolved Hide resolved
indicator={0 === selectedLogLevels.length ?
<KeyboardArrowUpIcon/> :
<Tooltip title={"Clear filters"}>
Expand All @@ -222,7 +228,10 @@
</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' } : {}}

Check warning on line 233 in new-log-viewer/src/components/StatusBar/LogLevelSelect/index.tsx

View workflow job for this annotation

GitHub Actions / lint-check

This line has a length of 102. Maximum allowed is 100

Check warning on line 233 in new-log-viewer/src/components/StatusBar/LogLevelSelect/index.tsx

View workflow job for this annotation

GitHub Actions / lint-check

Strings must use doublequote
davemarco marked this conversation as resolved.
Show resolved Hide resolved
>
Log Level
</Chip>
}
Expand Down
6 changes: 4 additions & 2 deletions 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 @@ -40,10 +41,11 @@ const StatusBar = () => {
</Typography>
<Button
color={"primary"}
disabled={loadState !== LOAD_STATE.READY}
size={"sm"}
variant={"soft"}
onClick={handleCopyLinkButtonClick}
>
>
{"Log Event "}
{logEventNum}
{" / "}
Expand Down
Loading
Loading