Skip to content

Commit

Permalink
new-log-viewer: Implement MenuBar and StatusBar with JoyUI components…
Browse files Browse the repository at this point in the history
…; add JoyUI custom app theme. (#59)
  • Loading branch information
Henry8192 authored Sep 12, 2024
1 parent d9b6192 commit cfa9274
Show file tree
Hide file tree
Showing 23 changed files with 2,472 additions and 1,597 deletions.
2,906 changes: 1,625 additions & 1,281 deletions new-log-viewer/package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions new-log-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
},
"homepage": "https://github.com/y-scope/yscope-log-viewer#readme",
"dependencies": {
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@mui/icons-material": "^6.1.0",
"@mui/joy": "^5.0.0-beta.48",
"axios": "^1.7.2",
"clp-ffi-js": "^0.1.0",
"dayjs": "^1.11.11",
Expand Down
12 changes: 5 additions & 7 deletions new-log-viewer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import UrlContextProvider from "./contexts/UrlContextProvider";
*/
const App = () => {
return (
<>
<UrlContextProvider>
<StateContextProvider>
<Layout/>
</StateContextProvider>
</UrlContextProvider>
</>
<UrlContextProvider>
<StateContextProvider>
<Layout/>
</StateContextProvider>
</UrlContextProvider>
);
};

Expand Down
2 changes: 0 additions & 2 deletions new-log-viewer/src/components/DropFileContainer/index.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.drop-file-container {
width: 100%;
height: 100%;
position: relative;
}

Expand Down
3 changes: 3 additions & 0 deletions new-log-viewer/src/components/Editor/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.editor {
height: calc(100vh - var(--ylv-menu-bar-height) - var(--ylv-status-bar-height));
}
82 changes: 63 additions & 19 deletions new-log-viewer/src/components/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import {
import {Nullable} from "../../typings/common";
import {CONFIG_KEY} from "../../typings/config";
import {BeginLineNumToLogEventNumMap} from "../../typings/worker";
import {EDITOR_ACTIONS} from "../../utils/actions";
import {
ACTION_NAME,
EDITOR_ACTIONS,
handleAction,
} from "../../utils/actions";
import {
CONFIG_DEFAULT,
getConfig,
Expand All @@ -27,22 +31,18 @@ import {
getMapValueWithNearestLessThanOrEqualKey,
} from "../../utils/data";
import MonacoInstance from "./MonacoInstance";
import {CustomActionCallback} from "./MonacoInstance/typings";
import {goToPositionAndCenter} from "./MonacoInstance/utils";

import "./index.css";

interface EditorProps {
onCustomAction: CustomActionCallback,
}

/**
* Renders a read-only editor for viewing logs.
*
* @param props
* @param props.onCustomAction
* @return
*/
const Editor = ({onCustomAction}: EditorProps) => {
const {logData, beginLineNumToLogEventNum} = useContext(StateContext);
const Editor = () => {
const {beginLineNumToLogEventNum, logData, numEvents} = useContext(StateContext);
const {logEventNum} = useContext(UrlContext);

const [lineNum, setLineNum] = useState<number>(1);
Expand All @@ -51,8 +51,40 @@ const Editor = ({onCustomAction}: EditorProps) => {
);
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);
break;
case ACTION_NAME.PAGE_TOP:
goToPositionAndCenter(editor, {lineNumber: 1, column: 1});
break;
case ACTION_NAME.PAGE_BOTTOM: {
const lineCount = editor.getModel()?.getLineCount();
if ("undefined" === typeof lineCount) {
break;
}
goToPositionAndCenter(editor, {lineNumber: lineCount, column: 1});
break;
}
default:
break;
}
}, []);

/**
* Sets `editorRef` and configures callbacks for mouse down detection.
*/
Expand Down Expand Up @@ -123,9 +155,19 @@ const Editor = ({onCustomAction}: EditorProps) => {
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 || true === isMouseDownRef.current) {
if (null === editorRef.current || isMouseDownRef.current) {
// Don't update the line number if the user is actively selecting text.
return;
}
Expand All @@ -144,15 +186,17 @@ const Editor = ({onCustomAction}: EditorProps) => {
]);

return (
<MonacoInstance
actions={EDITOR_ACTIONS}
beforeTextUpdate={resetCachedPageSize}
lineNum={lineNum}
text={logData}
onCursorExplicitPosChange={handleCursorExplicitPosChange}
onCustomAction={onCustomAction}
onMount={handleMount}
onTextUpdate={restoreCachedPageSize}/>
<div className={"editor"}>
<MonacoInstance
actions={EDITOR_ACTIONS}
beforeTextUpdate={resetCachedPageSize}
lineNum={lineNum}
text={logData}
onCursorExplicitPosChange={handleCursorExplicitPosChange}
onCustomAction={handleEditorCustomAction}
onMount={handleMount}
onTextUpdate={restoreCachedPageSize}/>
</div>
);
};

Expand Down
Loading

0 comments on commit cfa9274

Please sign in to comment.