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

new-log-viewer: Add event cursor, refactor state context, and redesign load page methods to support discontinuous log event numbers in preparation for log level filtering. #76

Merged
merged 33 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
370af54
first draft
davemarco Sep 24, 2024
96927bf
next pass
davemarco Sep 24, 2024
fcd0ee9
fix lint
davemarco Sep 24, 2024
d88bc3d
small changes
davemarco Sep 24, 2024
ceb8a4d
small change
davemarco Sep 24, 2024
479c1a8
Merge branch 'main' into page
davemarco Sep 24, 2024
4d1e70a
small change after merge
davemarco Sep 24, 2024
662619b
add utils to shorten file
davemarco Sep 24, 2024
ed2d9c4
fix page size error
davemarco Sep 24, 2024
26a0d02
fix bug with loadpage rerender
davemarco Sep 24, 2024
b32c5bd
add comments describing broken behaviour until cursor done
davemarco Sep 24, 2024
c6f1f5f
small changes
davemarco Sep 24, 2024
d2ed5b9
move newLogEvent so better placed for future PR
davemarco Sep 24, 2024
0050180
remove print
davemarco Sep 24, 2024
a523d18
added basic log event cursor and cleanup cursor switch in logFileManager
davemarco Sep 25, 2024
cf096fa
small changes
davemarco Sep 25, 2024
99f4003
Apply suggestions from code review
davemarco Sep 27, 2024
78a1f8f
kirk review
davemarco Sep 27, 2024
a11295a
add comment
davemarco Sep 27, 2024
18599f1
Apply suggestions from code review
davemarco Sep 30, 2024
829ba10
kirk review 2
davemarco Sep 30, 2024
1572a91
new comment from kirk
davemarco Sep 30, 2024
1e6ad3f
small nit
davemarco Sep 30, 2024
31012ff
fix off-by-error related to end num now exclusive
davemarco Sep 30, 2024
6200bd4
Apply suggestions from code review
davemarco Oct 1, 2024
6f43e7f
move function and other
davemarco Oct 1, 2024
d266ce7
move null check
davemarco Oct 1, 2024
0419552
add more lines
davemarco Oct 1, 2024
3887f76
Remove log.
kirkrodrigues Oct 1, 2024
808a7e1
Remove extra newline.
kirkrodrigues Oct 1, 2024
d8b32ea
small wording change so i am last pusher
davemarco Oct 1, 2024
a55a3c8
Merge branch 'page' of github.com:davemarco/yscope-log-viewer-fork in…
davemarco Oct 1, 2024
c26459d
small change so last pusher
davemarco Oct 1, 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as monaco from "monaco-editor/esm/vs/editor/editor.api.js";

import {Nullable} from "../../../typings/common";
import {ActionType} from "../../../utils/actions";
import {EditorAction} from "../../../utils/actions";
import {clamp} from "../../../utils/math";
import type {
CursorExplicitPosChangeCallback,
Expand Down Expand Up @@ -152,7 +152,7 @@ const setupMobileZoom = (
*/
const setupCustomActions = (
editor: monaco.editor.IStandaloneCodeEditor,
actions: ActionType[],
actions: EditorAction[],
onCustomAction: CustomActionCallback
) => {
actions.forEach(({actionName, label, keyBindings}) => {
Expand Down
4 changes: 2 additions & 2 deletions new-log-viewer/src/components/Editor/MonacoInstance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {

import * as monaco from "monaco-editor/esm/vs/editor/editor.api";

import {ActionType} from "../../../utils/actions";
import {EditorAction} from "../../../utils/actions";
import {
BeforeMountCallback,
BeforeTextUpdateCallback,
Expand All @@ -23,7 +23,7 @@ import "./index.css";


interface MonacoEditorProps {
actions: ActionType[],
actions: EditorAction[],
lineNum: number,
text: string,
themeName: "dark" | "light",
Expand Down
4 changes: 2 additions & 2 deletions new-log-viewer/src/components/Editor/MonacoInstance/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as monaco from "monaco-editor/esm/vs/editor/editor.api.js";

import {ActionType} from "../../../utils/actions";
import {EditorAction} from "../../../utils/actions";
import {
setupCursorExplicitPosChangeCallback,
setupCustomActions,
Expand Down Expand Up @@ -40,7 +40,7 @@ const goToPositionAndCenter = (
*/
const createMonacoEditor = (
editorContainer: HTMLDivElement,
actions: ActionType[],
actions: EditorAction[],
handlers: CustomMonacoEditorHandlers
): monaco.editor.IStandaloneCodeEditor => {
setupCustomLogLanguage();
Expand Down
22 changes: 3 additions & 19 deletions new-log-viewer/src/components/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {BeginLineNumToLogEventNumMap} from "../../typings/worker";
import {
ACTION_NAME,
EDITOR_ACTIONS,
handleAction,
} from "../../utils/actions";
import {
CONFIG_DEFAULT,
Expand Down Expand Up @@ -63,7 +62,7 @@ const resetCachedPageSize = () => {
const Editor = () => {
const {mode, systemMode} = useColorScheme();

const {beginLineNumToLogEventNum, logData, numEvents} = useContext(StateContext);
const {beginLineNumToLogEventNum, logData, loadPageByAction} = useContext(StateContext);
const {logEventNum} = useContext(UrlContext);

const [lineNum, setLineNum] = useState<number>(1);
Expand All @@ -72,23 +71,18 @@ const Editor = () => {
);
const editorRef = useRef<Nullable<monaco.editor.IStandaloneCodeEditor>>(null);
const isMouseDownRef = useRef<boolean>(false);
const logEventNumRef = useRef<Nullable<number>>(logEventNum);
const numEventsRef = useRef<Nullable<number>>(numEvents);
const pageSizeRef = useRef(getConfig(CONFIG_KEY.PAGE_SIZE));

const handleEditorCustomAction = useCallback((
editor: monaco.editor.IStandaloneCodeEditor,
actionName: ACTION_NAME
) => {
if (null === logEventNumRef.current || null === numEventsRef.current) {
return;
}
switch (actionName) {
case ACTION_NAME.FIRST_PAGE:
case ACTION_NAME.PREV_PAGE:
case ACTION_NAME.NEXT_PAGE:
case ACTION_NAME.LAST_PAGE:
handleAction(actionName, logEventNumRef.current, numEventsRef.current);
loadPageByAction({code: actionName, args: null});
break;
case ACTION_NAME.PAGE_TOP:
goToPositionAndCenter(editor, {lineNumber: 1, column: 1});
Expand All @@ -104,7 +98,7 @@ const Editor = () => {
default:
break;
}
}, []);
}, [loadPageByAction]);

/**
* Sets `editorRef` and configures callbacks for mouse down detection.
Expand Down Expand Up @@ -162,16 +156,6 @@ const Editor = () => {
beginLineNumToLogEventNumRef.current = beginLineNumToLogEventNum;
}, [beginLineNumToLogEventNum]);

// Synchronize `logEventNumRef` with `logEventNum`.
useEffect(() => {
logEventNumRef.current = logEventNum;
}, [logEventNum]);

// Synchronize `numEventsRef` with `numEvents`.
useEffect(() => {
numEventsRef.current = numEvents;
}, [numEvents]);

// On `logEventNum` update, update line number in the editor.
useEffect(() => {
if (null === editorRef.current || isMouseDownRef.current) {
Expand Down
25 changes: 12 additions & 13 deletions new-log-viewer/src/components/MenuBar/NavigationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import SkipNext from "@mui/icons-material/SkipNext";
import SkipPrevious from "@mui/icons-material/SkipPrevious";

import {StateContext} from "../../contexts/StateContextProvider";
import {UrlContext} from "../../contexts/UrlContextProvider";
import {
ACTION_NAME,
handleAction,
} from "../../utils/actions";
import {ACTION_NAME} from "../../utils/actions";
import PageNumInput from "./PageNumInput";
import SmallIconButton from "./SmallIconButton";

Expand All @@ -21,16 +17,19 @@ import SmallIconButton from "./SmallIconButton";
* @return
*/
const NavigationBar = () => {
const {numEvents} = useContext(StateContext);
const {logEventNum} = useContext(UrlContext);
const {loadPageByAction} = useContext(StateContext);

const handleNavButtonClick = (event: React.MouseEvent<HTMLButtonElement>) => {
if (null === logEventNum) {
return;
}
const {actionName} = event.currentTarget.dataset as { actionName: ACTION_NAME };
if (Object.values(ACTION_NAME).includes(actionName)) {
handleAction(actionName, logEventNum, numEvents);
const {actionName} = event.currentTarget.dataset;

// Ensure `actionName` is a valid navigation action code with no args.
if (
actionName === ACTION_NAME.FIRST_PAGE ||
actionName === ACTION_NAME.PREV_PAGE ||
actionName === ACTION_NAME.NEXT_PAGE ||
actionName === ACTION_NAME.LAST_PAGE
) {
loadPageByAction({code: actionName, args: null});
}
};

Expand Down
15 changes: 8 additions & 7 deletions 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 {ACTION_NAME} from "../../utils/actions";

import "./PageNumInput.css";

Expand All @@ -22,10 +23,7 @@ const PAGE_NUM_INPUT_FIT_EXTRA_WIDTH = 2;
* @return
*/
const PageNumInput = () => {
const {loadPage, numPages, pageNum} = useContext(StateContext);
const adjustedPageNum = (null === pageNum) ?
0 :
pageNum;
const {loadPageByAction, numPages, pageNum} = useContext(StateContext);

const [isEditing, setIsEditing] = useState<boolean>(false);
const inputRef = useRef<HTMLInputElement>(null);
Expand All @@ -38,7 +36,10 @@ const PageNumInput = () => {
return;
}

loadPage(Number(inputRef.current.value));
loadPageByAction({
code: ACTION_NAME.SPECIFIC_PAGE,
args: {pageNum: Number(inputRef.current.value)},
});
setIsEditing(false);
};

Expand Down Expand Up @@ -68,9 +69,9 @@ const PageNumInput = () => {
if (null === inputRef.current) {
return;
}
inputRef.current.value = adjustedPageNum.toString();
inputRef.current.value = pageNum.toString();
adjustInputWidth();
}, [adjustedPageNum]);
}, [pageNum]);

return (
<form
Expand Down
Loading
Loading