feat: Add toggle for log message prettification (resolves #220).#223
feat: Add toggle for log message prettification (resolves #220).#223junhaoliao merged 16 commits intoy-scope:mainfrom
Conversation
WalkthroughThis pull request implements a new "prettify" toggle feature across the application. Documentation is updated with manual testing instructions, and dependencies for code formatting (js-beautify) are added. Multiple components now accept an Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant SB as StatusBarToggleButton
participant S as StatusBar Component
participant UC as UrlContextProvider
participant SC as StateContextProvider
participant MW as MainWorker
participant LFM as LogFileManager
U->>SB: Click toggle button
SB->>S: Trigger handleStatusButtonClick event
S->>UC: Update URL hash with isPrettified state
UC-->>SC: Propagate new isPrettified value
SC->>MW: Call loadPage(cursor, isPrettified)
MW->>LFM: Process loadPage with isPrettified flag
Possibly related issues
Possibly related PRs
Suggested reviewers
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (8)
src/components/MenuBar/NavigationBar.tsx (2)
1-18: Fix import formatting issuesThe imports have multiple formatting issues flagged by the static analysis tools:
- The MUI icons should use path imports and be named with "Icon" postfix
- Multiple elements in a single import should be broken into multiple lines
- Object curly spacing issues
Apply these changes to fix the formatting:
-import React, { useContext } from "react"; +import React from "react"; +import {useContext} from "react"; -import { ButtonGroup } from "@mui/joy"; +import {ButtonGroup} from "@mui/joy"; -import { AutoFixHighRounded, AutoFixOffRounded } from "@mui/icons-material"; +import AutoFixHighRoundedIcon from "@mui/icons-material/AutoFixHighRounded"; +import AutoFixOffRoundedIcon from "@mui/icons-material/AutoFixOffRounded"; 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 { UI_ELEMENT } from "../../typings/states"; -import { ACTION_NAME } from "../../utils/actions"; -import { ignorePointerIfFastLoading, isDisabled } from "../../utils/states"; +import {StateContext} from "../../contexts/StateContextProvider"; +import {UI_ELEMENT} from "../../typings/states"; +import {ACTION_NAME} from "../../utils/actions"; +import { + ignorePointerIfFastLoading, + isDisabled +} from "../../utils/states"; import MenuBarIconButton from "./MenuBarIconButton"; import MenuBarToggleButton from "./MenuBarToggleButton"; import PageNumInput from "./PageNumInput"; -import { UrlContext } from "../../contexts/UrlContextProvider"; +import {UrlContext} from "../../contexts/UrlContextProvider";🧰 Tools
🪛 ESLint
[error] 1-1: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 1-1: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 3-3: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 3-3: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 5-5: '@mui/icons-material' import is restricted from being used. Please use path imports and name your imports with postfix "Icon" to avoid confusions.
(no-restricted-imports)
[error] 5-5: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 5-5: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 5-5: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 5-5: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 5-5: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 11-11: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 11-11: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 12-12: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 12-12: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 13-13: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 13-13: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 14-14: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 14-14: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 14-14: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 14-14: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 14-14: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 18-18: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 18-18: There should be no space before '}'.
(@stylistic/object-curly-spacing)
56-63: Fix formatting issues in MenuBarToggleButton propsThe props have several formatting issues that should be fixed:
- Ternary expressions should be multiline for better readability
- Props should be sorted alphabetically
- Callbacks should be listed after other props
- The closing bracket placement needs adjustment
Apply these changes to fix the formatting:
<MenuBarToggleButton - data-action-name={isPrettified ?? false ? ACTION_NAME.PRETTIFY_OFF : ACTION_NAME.PRETTIFY_ON} - title={isPrettified ?? false ? "Prettify Off" : "Prettify On"} - isActive={!(isPrettified ?? false)} - onIcon={<AutoFixHighRounded />} - offIcon={<AutoFixOffRounded />} - onClick={handleNavButtonClick} + data-action-name={isPrettified ?? false + ? ACTION_NAME.PRETTIFY_OFF + : ACTION_NAME.PRETTIFY_ON + } + isActive={!(isPrettified ?? false)} + offIcon={<AutoFixOffRoundedIcon />} + onIcon={<AutoFixHighRoundedIcon />} + title={isPrettified ?? false + ? "Prettify Off" + : "Prettify On" + } + onClick={handleNavButtonClick} />🧰 Tools
🪛 ESLint
[error] 57-57: Expected newline between test and consequent of ternary expression.
(@stylistic/multiline-ternary)
[error] 57-57: Expected newline between consequent and alternate of ternary expression.
(@stylistic/multiline-ternary)
[error] 58-58: Expected newline between test and consequent of ternary expression.
(@stylistic/multiline-ternary)
[error] 58-58: Expected newline between consequent and alternate of ternary expression.
(@stylistic/multiline-ternary)
[error] 59-59: Props should be sorted alphabetically
(@stylistic/jsx-sort-props)
[error] 60-60: Callbacks must be listed after all other props
(@stylistic/jsx-sort-props)
[error] 60-60: A space is forbidden before closing bracket
(@stylistic/jsx-tag-spacing)
[error] 61-61: A space is forbidden before closing bracket
(@stylistic/jsx-tag-spacing)
[error] 62-62: Props should be sorted alphabetically
(@stylistic/jsx-sort-props)
[error] 63-63: The closing bracket must be placed after the last prop
(@stylistic/jsx-closing-bracket-location)
src/components/StatusBar/LogLevelSelect/index.tsx (2)
47-47: Fix import formatting to comply with project standards.The import has spacing issues that are causing linting errors.
-import { UrlContext } from "../../../contexts/UrlContextProvider"; +import {UrlContext} from "../../../contexts/UrlContextProvider";🧰 Tools
🪛 ESLint
[error] 47-47: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 47-47: There should be no space before '}'.
(@stylistic/object-curly-spacing)
157-160: Consider combining context hooks for consistency.You've added a separate
useContextcall for the UrlContext. Consider combining related context hooks or maintaining a consistent pattern for retrieving context values.-const {isPrettified} = useContext(UrlContext); -const [selectedLogLevels, setSelectedLogLevels] = useState<LOG_LEVEL[]>([]); -const {uiState, filterLogs} = useContext(StateContext); +const [selectedLogLevels, setSelectedLogLevels] = useState<LOG_LEVEL[]>([]); +const {isPrettified} = useContext(UrlContext); +const {uiState, filterLogs} = useContext(StateContext);or
-const {isPrettified} = useContext(UrlContext); -const [selectedLogLevels, setSelectedLogLevels] = useState<LOG_LEVEL[]>([]); -const {uiState, filterLogs} = useContext(StateContext); +const [selectedLogLevels, setSelectedLogLevels] = useState<LOG_LEVEL[]>([]); +const { + isPrettified, +} = useContext(UrlContext); +const { + uiState, + filterLogs, +} = useContext(StateContext);src/components/MenuBar/MenuBarToggleButton.tsx (1)
1-50: Apply consistent false == expression pattern per coding guidelines.According to the provided coding guidelines, the codebase should prefer
false == <expression>rather than!<expression>.Consider updating the conditional check in the component to follow this pattern:
- {isActive ? onIcon : offIcon} + {false == isActive ? offIcon : onIcon}🧰 Tools
🪛 ESLint
[error] 7-7: '@mui/icons-material' import is restricted from being used. Please use path imports and name your imports with postfix "Icon" to avoid confusions.
(no-restricted-imports)
[error] 7-7: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 7-7: Expected 2 empty lines after import statement not followed by another import.
(import/newline-after-import)
[error] 7-7: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 7-7: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 7-7: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 7-7: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 28-28: Expected indentation of 4 spaces but found 33.
(@stylistic/indent)
[error] 29-29: Expected indentation of 4 spaces but found 33.
(@stylistic/indent)
[error] 30-30: Expected indentation of 4 spaces but found 33.
(@stylistic/indent)
[error] 31-31: Expected indentation of 4 spaces but found 33.
(@stylistic/indent)
[error] 31-31: A space is forbidden before closing bracket
(@stylistic/jsx-tag-spacing)
[error] 31-31: Unexpected comment inline with code.
(no-inline-comments)
[error] 31-31: Expected comment to be above code.
(@stylistic/line-comment-position)
[error] 32-32: Expected indentation of 4 spaces but found 33.
(@stylistic/indent)
[error] 32-32: A space is forbidden before closing bracket
(@stylistic/jsx-tag-spacing)
[error] 32-32: Unexpected comment inline with code.
(no-inline-comments)
[error] 32-32: Expected comment to be above code.
(@stylistic/line-comment-position)
[error] 33-33: Expected indentation of 4 spaces but found 33.
(@stylistic/indent)
[error] 34-34: Expected indentation of 0 spaces but found 29.
(@stylistic/indent)
[error] 34-36: Block must not be padded by blank lines.
(@stylistic/padded-blocks)
[error] 37-37: Prop
titlemust be placed on a new line(@stylistic/jsx-max-props-per-line)
[error] 40-40: Need to wrap this literal in a JSX expression.
(@stylistic/jsx-curly-brace-presence)
[error] 43-43: Expected newline between test and consequent of ternary expression.
(@stylistic/multiline-ternary)
[error] 43-43: Expected newline between consequent and alternate of ternary expression.
(@stylistic/multiline-ternary)
src/services/LogFileManager/index.ts (2)
39-39: Fix styling issues with the import statement.The import statement for
js_beautifyhas several style issues:
- Expected 2 empty lines after the import (not followed by another import)
- Identifier
js_beautifyis not in camelCase-import js_beautify from "js-beautify"; +import jsBeautify from "js-beautify";🧰 Tools
🪛 ESLint
[error] 39-39: Expected 2 empty lines after import statement not followed by another import.
(import/newline-after-import)
[error] 39-39: Identifier 'js_beautify' is not in camel case.
(camelcase)
289-290: Refactor the ternary expression for better readability.The ternary expression has several style issues flagged by static analysis:
- Expected newlines between test, consequent, and alternate
- String concatenation should use template literals
- const printedMsg = (isPrettified) ? js_beautify(msg) + "\n" : msg; + const printedMsg = (false === isPrettified) + ? msg + : `${jsBeautify(msg)}\n`;Note: Changed the condition to follow the coding guideline of preferring
false === <expression>rather than!<expression>and inverted the logic to make it more readable.🧰 Tools
🪛 ESLint
[error] 289-289: Expected newline between test and consequent of ternary expression.
(@stylistic/multiline-ternary)
[error] 289-289: Expected newline between consequent and alternate of ternary expression.
(@stylistic/multiline-ternary)
[error] 289-289: Unexpected string concatenation.
(prefer-template)
src/contexts/StateContextProvider.tsx (1)
331-331: Conditional check style recommendationAccording to the coding guidelines,
false == <expression>is preferred over!<expression>.Replace
false === v.has(queryPageNum)withv.has(queryPageNum) == falseto align with the project's coding guidelines.- if (false === v.has(queryPageNum)) { + if (v.has(queryPageNum) == false) {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (13)
docs/src/dev-guide/contributing-validation.md(1 hunks)package.json(2 hunks)src/components/Editor/index.tsx(2 hunks)src/components/MenuBar/MenuBarToggleButton.tsx(1 hunks)src/components/MenuBar/NavigationBar.tsx(3 hunks)src/components/StatusBar/LogLevelSelect/index.tsx(3 hunks)src/contexts/StateContextProvider.tsx(10 hunks)src/contexts/UrlContextProvider.tsx(2 hunks)src/services/LogFileManager/index.ts(3 hunks)src/services/MainWorker.ts(3 hunks)src/typings/url.ts(1 hunks)src/typings/worker.ts(1 hunks)src/utils/actions.ts(3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Preferfalse == <expression>rather than!<expression>.
src/components/Editor/index.tsxsrc/typings/worker.tssrc/contexts/UrlContextProvider.tsxsrc/components/StatusBar/LogLevelSelect/index.tsxsrc/services/LogFileManager/index.tssrc/typings/url.tssrc/components/MenuBar/MenuBarToggleButton.tsxsrc/utils/actions.tssrc/components/MenuBar/NavigationBar.tsxsrc/services/MainWorker.tssrc/contexts/StateContextProvider.tsx
🧬 Code Definitions (5)
src/components/Editor/index.tsx (1)
src/utils/actions.ts (1)
ACTION_NAME(115-115)
src/contexts/UrlContextProvider.tsx (1)
src/typings/url.ts (1)
HASH_PARAM_NAMES(37-37)
src/components/StatusBar/LogLevelSelect/index.tsx (2)
src/contexts/UrlContextProvider.tsx (1)
UrlContext(280-280)src/contexts/StateContextProvider.tsx (1)
StateContext(598-598)
src/components/MenuBar/NavigationBar.tsx (3)
src/contexts/StateContextProvider.tsx (1)
StateContext(598-598)src/contexts/UrlContextProvider.tsx (1)
UrlContext(280-280)src/utils/actions.ts (1)
ACTION_NAME(115-115)
src/contexts/StateContextProvider.tsx (6)
src/typings/states.ts (1)
UI_STATE(101-101)src/typings/logs.ts (1)
LogLevelFilter(51-51)src/utils/actions.ts (1)
ACTION_NAME(115-115)src/typings/worker.ts (4)
EVENT_POSITION_ON_PAGE(189-189)CursorType(196-196)WORKER_REQ_CODE(190-190)CURSOR_CODE(187-187)src/contexts/UrlContextProvider.tsx (1)
UrlContext(280-280)src/typings/url.ts (1)
HASH_PARAM_NAMES(37-37)
🪛 ESLint
src/components/Editor/index.tsx
[error] 1-1: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 1-1: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 1-1: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 1-1: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 1-1: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 3-3: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 3-3: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 6-6: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 6-6: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 7-7: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 7-7: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 7-7: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 7-7: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 7-7: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 8-8: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 8-8: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 9-9: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 9-9: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 9-9: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 9-9: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 9-9: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 10-10: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 10-10: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 11-11: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 11-11: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 11-11: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 11-11: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 11-11: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 12-12: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 12-12: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 12-12: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 12-12: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 12-12: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 13-13: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 13-13: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 13-13: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 13-13: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 13-13: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 15-15: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 15-15: There should be no space before '}'.
(@stylistic/object-curly-spacing)
src/components/StatusBar/LogLevelSelect/index.tsx
[error] 47-47: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 47-47: There should be no space before '}'.
(@stylistic/object-curly-spacing)
src/services/LogFileManager/index.ts
[error] 39-39: Expected 2 empty lines after import statement not followed by another import.
(import/newline-after-import)
[error] 39-39: Identifier 'js_beautify' is not in camel case.
(camelcase)
[error] 289-289: Expected newline between test and consequent of ternary expression.
(@stylistic/multiline-ternary)
[error] 289-289: Expected newline between consequent and alternate of ternary expression.
(@stylistic/multiline-ternary)
[error] 289-289: Unexpected string concatenation.
(prefer-template)
src/components/MenuBar/MenuBarToggleButton.tsx
[error] 7-7: '@mui/icons-material' import is restricted from being used. Please use path imports and name your imports with postfix "Icon" to avoid confusions.
(no-restricted-imports)
[error] 7-7: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 7-7: Expected 2 empty lines after import statement not followed by another import.
(import/newline-after-import)
[error] 7-7: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 7-7: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 7-7: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 7-7: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 28-28: Expected indentation of 4 spaces but found 33.
(@stylistic/indent)
[error] 29-29: Expected indentation of 4 spaces but found 33.
(@stylistic/indent)
[error] 30-30: Expected indentation of 4 spaces but found 33.
(@stylistic/indent)
[error] 31-31: Expected indentation of 4 spaces but found 33.
(@stylistic/indent)
[error] 31-31: A space is forbidden before closing bracket
(@stylistic/jsx-tag-spacing)
[error] 31-31: Unexpected comment inline with code.
(no-inline-comments)
[error] 31-31: Expected comment to be above code.
(@stylistic/line-comment-position)
[error] 32-32: Expected indentation of 4 spaces but found 33.
(@stylistic/indent)
[error] 32-32: A space is forbidden before closing bracket
(@stylistic/jsx-tag-spacing)
[error] 32-32: Unexpected comment inline with code.
(no-inline-comments)
[error] 32-32: Expected comment to be above code.
(@stylistic/line-comment-position)
[error] 33-33: Expected indentation of 4 spaces but found 33.
(@stylistic/indent)
[error] 34-34: Expected indentation of 0 spaces but found 29.
(@stylistic/indent)
[error] 34-36: Block must not be padded by blank lines.
(@stylistic/padded-blocks)
[error] 37-37: Prop title must be placed on a new line
(@stylistic/jsx-max-props-per-line)
[error] 40-40: Need to wrap this literal in a JSX expression.
(@stylistic/jsx-curly-brace-presence)
[error] 43-43: Expected newline between test and consequent of ternary expression.
(@stylistic/multiline-ternary)
[error] 43-43: Expected newline between consequent and alternate of ternary expression.
(@stylistic/multiline-ternary)
src/components/MenuBar/NavigationBar.tsx
[error] 1-1: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 1-1: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 3-3: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 3-3: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 5-5: '@mui/icons-material' import is restricted from being used. Please use path imports and name your imports with postfix "Icon" to avoid confusions.
(no-restricted-imports)
[error] 5-5: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 5-5: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 5-5: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 5-5: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 5-5: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 11-11: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 11-11: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 12-12: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 12-12: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 13-13: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 13-13: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 14-14: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 14-14: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 14-14: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 14-14: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 14-14: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 18-18: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 18-18: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 57-57: Expected newline between test and consequent of ternary expression.
(@stylistic/multiline-ternary)
[error] 57-57: Expected newline between consequent and alternate of ternary expression.
(@stylistic/multiline-ternary)
[error] 58-58: Expected newline between test and consequent of ternary expression.
(@stylistic/multiline-ternary)
[error] 58-58: Expected newline between consequent and alternate of ternary expression.
(@stylistic/multiline-ternary)
[error] 59-59: Props should be sorted alphabetically
(@stylistic/jsx-sort-props)
[error] 60-60: Callbacks must be listed after all other props
(@stylistic/jsx-sort-props)
[error] 60-60: A space is forbidden before closing bracket
(@stylistic/jsx-tag-spacing)
[error] 61-61: A space is forbidden before closing bracket
(@stylistic/jsx-tag-spacing)
[error] 62-62: Props should be sorted alphabetically
(@stylistic/jsx-sort-props)
[error] 63-63: The closing bracket must be placed after the last prop
(@stylistic/jsx-closing-bracket-location)
src/contexts/StateContextProvider.tsx
[error] 2-2: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 2-2: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 2-2: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 2-2: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 2-2: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 6-6: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 6-6: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 7-7: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 7-7: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 8-8: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 8-8: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 9-9: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 9-9: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 9-9: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 9-9: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 9-9: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 10-10: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 10-10: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 10-10: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 10-10: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 10-10: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 11-11: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 11-11: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 11-11: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 11-11: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 11-11: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 12-12: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 12-12: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 13-13: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 13-13: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 14-14: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 14-14: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 14-14: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 14-14: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 14-14: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 26-26: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 26-26: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 26-26: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 26-26: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 26-26: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 27-27: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 27-27: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 27-27: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 27-27: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 27-27: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 28-28: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 28-28: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 28-28: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 28-28: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 28-28: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
[error] 29-29: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 29-29: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 30-30: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 30-30: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 450-450: Expected line before comment.
(@stylistic/lines-around-comment)
[error] 456-456: Expected line before comment.
(@stylistic/lines-around-comment)
[error] 462-462: There should be a linebreak after this element.
(@stylistic/array-element-newline)
[error] 464-464: 'isPrettified' is already declared in the upper scope on line 231 column 22.
(@typescript-eslint/no-shadow)
🪛 GitHub Check: lint-check
src/components/Editor/index.tsx
[failure] 7-7:
Imports must be broken into multiple lines if there are more than 1 elements
[failure] 6-6:
There should be no space before '}'
[failure] 6-6:
There should be no space after '{'
[failure] 3-3:
There should be no space before '}'
[failure] 3-3:
There should be no space after '{'
[failure] 1-1:
Expected a line break before this closing brace
[failure] 1-1:
There should be no space before '}'
[failure] 1-1:
There should be no space after '{'
[failure] 1-1:
Expected a line break after this opening brace
[failure] 1-1:
Imports must be broken into multiple lines if there are more than 1 elements
🪛 GitHub Actions: lint
src/components/Editor/index.tsx
[error] 1-1: Imports must be broken into multiple lines if there are more than 1 elements (import-newlines/enforce)
🔇 Additional comments (36)
docs/src/dev-guide/contributing-validation.md (1)
42-42: Added test case for new feature looks good!The additional item in the manual testing section correctly documents the need to test the new "Prettify" toggle functionality in both the status bar and address bar.
package.json (2)
32-32: Appropriate type definitions added!Adding
@types/js-beautifytype definitions is necessary for proper TypeScript support of the new prettifying feature.
58-58: Correct dependency placement!The
js-beautifylibrary is appropriately placed in devDependencies, which aligns with the PR objective of implementing the prettifying toggle functionality.src/components/MenuBar/NavigationBar.tsx (3)
31-31: Accessing context looks good!You're correctly retrieving the
isPrettifiedstate from the UrlContext.
38-40: Good action handling!The action handler now correctly includes checks for the new
PRETTIFY_ONandPRETTIFY_OFFactions.
57-59: Ensure consistent defensive null handlingThe code correctly uses the nullish coalescing operator
??to handle potential null/undefined values in theisPrettifiedstate. This is a good practice!🧰 Tools
🪛 ESLint
[error] 57-57: Expected newline between test and consequent of ternary expression.
(@stylistic/multiline-ternary)
[error] 57-57: Expected newline between consequent and alternate of ternary expression.
(@stylistic/multiline-ternary)
[error] 58-58: Expected newline between test and consequent of ternary expression.
(@stylistic/multiline-ternary)
[error] 58-58: Expected newline between consequent and alternate of ternary expression.
(@stylistic/multiline-ternary)
[error] 59-59: Props should be sorted alphabetically
(@stylistic/jsx-sort-props)
src/typings/worker.ts (3)
105-105: Properly extending worker request interfaceAdding the
isPrettifiedproperty to the LOAD_FILE request type ensures the worker can apply prettification when loading files.
109-109: Properly extending LOAD_PAGE request typeAdding the
isPrettifiedproperty to the LOAD_PAGE request type ensures the worker can apply prettification when navigating between pages.
114-114: Properly extending SET_FILTER request typeAdding the
isPrettifiedproperty to the SET_FILTER request type ensures the worker can maintain the prettification state when filters are applied.src/contexts/UrlContextProvider.tsx (2)
34-34: Added IS_PRETTIFIED parameter to URL_HASH_PARAMS_DEFAULT.The addition of this parameter follows the established pattern for URL hash parameters in the application.
216-222: Good implementation of prettify toggle URL parameter handling.The implementation correctly:
- Retrieves the parameter from hash params
- Converts string value "true" to boolean
- Sets a sensible default (false) when parameter is missing
This follows the established patterns for parameter handling in the application.
src/components/Editor/index.tsx (1)
131-132: Added prettify action handling.The implementation correctly handles the new prettify toggle actions by adding appropriate cases to the switch statement. This follows the established pattern for similar actions in the codebase.
src/components/StatusBar/LogLevelSelect/index.tsx (2)
179-181: Proper integration of isPrettified parameter.You've correctly passed the prettify state to the filter function with a fallback to
falseif the value is null. This ensures filtering maintains the prettify state.
182-186: Appropriate dependency array update.Adding
isPrettifiedto the dependency array ensures the callback will be recreated if the prettify state changes, which is necessary for proper reactivity.src/components/MenuBar/MenuBarToggleButton.tsx (2)
9-14: Well-defined interface with appropriate properties.The component interface is well-designed with appropriate props for customization of the toggle button.
16-26: Good documentation with JSDoc comments.The JSDoc comments clearly document the component's purpose and parameters.
src/services/LogFileManager/index.ts (1)
247-252: Method signature update looks good.The documentation and method signature have been properly updated to include the new
isPrettifiedparameter.src/typings/url.ts (2)
10-10: New enum value for prettify feature looks good.The addition of
IS_PRETTIFIEDto theHASH_PARAM_NAMESenum is appropriate for the new feature.
18-19: Interface update handles the new feature well.The
UrlHashParamsinterface has been properly updated to include the new prettify parameter and improve type safety by using enum values as keys.src/services/MainWorker.ts (3)
99-100: Parameter propagation to loadPage looks good.The
isPrettifiedparameter is now correctly passed to theloadPagemethod when loading a file.
109-110: Parameter propagation to loadPage looks good.The
isPrettifiedparameter is now correctly passed to theloadPagemethod when loading a page.
120-121: Parameter propagation to loadPage looks good.The
isPrettifiedparameter is now correctly passed to theloadPagemethod when setting a filter.src/utils/actions.ts (3)
8-9: New action names for prettify feature look good.The addition of
PRETTIFY_ONandPRETTIFY_OFFto theACTION_NAMEenum is appropriate for the new feature.
39-48: Verify the identical key bindings for opposing actions.Both
PRETTIFY_ONandPRETTIFY_OFFactions use the same key binding (Ctrl/Cmd + P), which could potentially cause conflicts. Verify that the application logic correctly handles this by toggling between these actions based on the current state.The approach of using the same keyboard shortcut for toggle actions is valid if the application determines which action to trigger based on the current prettify state. For example, when
isPrettifiedistrue, thePRETTIFY_OFFaction would be triggered, and vice versa.
97-98: Type updates for navigation actions look good.The
NavigationActionsMaptype has been properly updated to include the new prettify actions.src/contexts/StateContextProvider.tsx (11)
55-55: Update function signature to align with changesThe interface for
filterLogshas been updated to include theisPrettifiedparameter, which is necessary to support the new prettify feature. This change ensures that filtering operations can maintain the prettify state.
132-137: Handle prettify toggle in navigation actionsThe implementation correctly handles the prettify toggle actions by returning to the top of the current page when prettifying is enabled or disabled. This ensures a consistent user experience when toggling the prettify feature.
169-179: Add prettify support to page loadingThe
loadPageByCursorfunction now accepts theisPrettifiedparameter and passes it to the worker. This modification is necessary to maintain the prettify state when navigating between pages.
231-231: Access prettify state from URL contextThe code now correctly destructures the
isPrettifiedproperty from theUrlContext, allowing the component to access and respond to changes in the prettify state from the URL.
406-406: Pass prettify state when loading filesThe
loadFilefunction now includes theisPrettifiedstate in the worker request, ensuring that log files are loaded with the correct formatting based on the user's preference.
446-458: Update URL parameters for prettify toggleThe code correctly updates the URL hash parameters when the prettify state changes. The implementation avoids redundant page loading by returning early after updating the URL parameters, which is an optimization to prevent unnecessary re-renders.
🧰 Tools
🪛 ESLint
[error] 450-450: Expected line before comment.
(@stylistic/lines-around-comment)
[error] 456-456: Expected line before comment.
(@stylistic/lines-around-comment)
461-462: Include prettify state in page loading operationsThe
loadPageByActionfunction passes theisPrettifiedstate toloadPageByCursor, ensuring that the prettify preference is maintained during navigation. The null coalescing operator provides a safe default value.🧰 Tools
🪛 ESLint
[error] 413-462: Arrow function has too many statements (22). Maximum allowed is 20.
(max-statements)
[error] 462-462: There should be a linebreak after this element.
(@stylistic/array-element-newline)
472-472: Pass prettify state in filter requestsThe worker request now includes the
isPrettifiedparameter, ensuring that filtered log messages maintain the correct formatting state.
500-514: Add effect hook to handle prettify state changesThis new
useEffecthook triggers a page reload whenever theisPrettifiedstate changes, ensuring that the UI reflects the current prettifying setting. The implementation correctly creates a cursor to the top of the current page.
542-542: Include prettify state in event-based navigationThe code now passes the
isPrettifiedstate toloadPageByCursorwhen navigating to a specific event, ensuring that the prettify preference is maintained during this type of navigation.
194-194: Update conditional check styleAccording to the coding guidelines,
false == <expression>is preferred over!<expression>.The code already follows this guideline, using
false === isWithinBounds(...)instead of!isWithinBounds(...).
| import { | ||
| IconButton, | ||
| IconButtonProps, | ||
| Tooltip, | ||
| TooltipTypeMap, | ||
| } from "@mui/joy"; | ||
| import { Check, Close } from "@mui/icons-material"; | ||
|
|
There was a problem hiding this comment.
Import formatting and naming issues.
The imports have formatting issues and don't follow project naming conventions for icon imports.
According to the static analysis:
- Icon imports should have the "Icon" postfix
- Multiple imports should be broken into multiple lines
-import {
- IconButton,
- IconButtonProps,
- Tooltip,
- TooltipTypeMap,
-} from "@mui/joy";
-import { Check, Close } from "@mui/icons-material";
+import {
+ IconButton,
+ IconButtonProps,
+ Tooltip,
+ TooltipTypeMap,
+} from "@mui/joy";
+
+import CheckIcon from "@mui/icons-material/Check";
+import CloseIcon from "@mui/icons-material/Close";📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import { | |
| IconButton, | |
| IconButtonProps, | |
| Tooltip, | |
| TooltipTypeMap, | |
| } from "@mui/joy"; | |
| import { Check, Close } from "@mui/icons-material"; | |
| import { | |
| IconButton, | |
| IconButtonProps, | |
| Tooltip, | |
| TooltipTypeMap, | |
| } from "@mui/joy"; | |
| import CheckIcon from "@mui/icons-material/Check"; | |
| import CloseIcon from "@mui/icons-material/Close"; |
🧰 Tools
🪛 ESLint
[error] 7-7: '@mui/icons-material' import is restricted from being used. Please use path imports and name your imports with postfix "Icon" to avoid confusions.
(no-restricted-imports)
[error] 7-7: Imports must be broken into multiple lines if there are more than 1 elements.
(import-newlines/enforce)
[error] 7-7: Expected 2 empty lines after import statement not followed by another import.
(import/newline-after-import)
[error] 7-7: Expected a line break after this opening brace.
(@stylistic/object-curly-newline)
[error] 7-7: There should be no space after '{'.
(@stylistic/object-curly-spacing)
[error] 7-7: There should be no space before '}'.
(@stylistic/object-curly-spacing)
[error] 7-7: Expected a line break before this closing brace.
(@stylistic/object-curly-newline)
There was a problem hiding this comment.
I agree with the rabbit.
There was a problem hiding this comment.
@Henry8192 Great! Following the project's import naming conventions (using "Icon" suffix and properly formatting imports) will help maintain consistency across the codebase. These standards make the code more readable and easier to maintain for the entire team.
| }, [loadFile, isPrettified]); | ||
|
|
||
| const filterLogs = useCallback((filter: LogLevelFilter) => { | ||
| const filterLogs = useCallback((filter: LogLevelFilter, isPrettified: boolean) => { |
There was a problem hiding this comment.
Fix parameter shadowing issue
The parameter isPrettified shadows the variable with the same name from the upper scope (line 231), which can lead to confusion and potential bugs.
Rename the parameter to avoid shadowing:
-const filterLogs = useCallback((filter: LogLevelFilter, isPrettified: boolean) => {
+const filterLogs = useCallback((filter: LogLevelFilter, isPrettifiedState: boolean) => {And update its usage on line 472:
- isPrettified: isPrettified
+ isPrettified: isPrettifiedState📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const filterLogs = useCallback((filter: LogLevelFilter, isPrettified: boolean) => { | |
| const filterLogs = useCallback((filter: LogLevelFilter, isPrettifiedState: boolean) => { | |
| // ... other code ... | |
| return { | |
| // ... possible other properties ... | |
| isPrettified: isPrettifiedState | |
| }; | |
| }, []); |
🧰 Tools
🪛 ESLint
[error] 464-464: 'isPrettified' is already declared in the upper scope on line 231 column 22.
(@typescript-eslint/no-shadow)
|
When I test, after loading the test log file, since there are 10003 log messages in total, it will first open at the second page (I think it is because the I can think of a rough improvement (should I create an issue for this?) is to add a "jump to begin" and "jump to end" button which are similar to "first page" and "last page" but with smaller scope, so that we can jump to the first log message or the last log message in the current page easily. I think it should be easy because when I read the code it already provide the ability to do this. |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/services/LogFileManager/index.ts (1)
2-2: Use camelCase for imported namesThe imported
js_beautifyfunction doesn't follow the camelCase naming convention used throughout the codebase.-import js_beautify from "js-beautify"; +import jsBeautify from "js-beautify";You'll need to update all usages of this variable in the file as well.
🧰 Tools
🪛 ESLint
[error] 2-2: Identifier 'js_beautify' is not in camel case.
(camelcase)
🪛 GitHub Check: lint-check
[failure] 2-2:
Identifier 'js_beautify' is not in camel casesrc/contexts/StateContextProvider.tsx (1)
435-435: Fix object key orderingThe object keys should be in alphabetical order according to the linting rules.
workerPostReq(mainWorkerRef.current, WORKER_REQ_CODE.LOAD_FILE, { cursor: cursor, decoderOptions: getConfig(CONFIG_KEY.DECODER_OPTIONS), fileSrc: fileSrc, - pageSize: getConfig(CONFIG_KEY.PAGE_SIZE), - isPrettified: isPrettified ?? false, + isPrettified: isPrettified ?? false, + pageSize: getConfig(CONFIG_KEY.PAGE_SIZE), });🧰 Tools
🪛 GitHub Check: lint-check
[failure] 435-435:
Expected object keys to be in natural ascending order. 'isPrettified' should be before 'pageSize'🪛 GitHub Actions: lint
[warning] 435-435: Expected object keys to be in natural ascending order. 'isPrettified' should be before 'pageSize' (sort-keys)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
src/components/Editor/index.tsx(1 hunks)src/components/MenuBar/MenuBarToggleButton.tsx(1 hunks)src/components/MenuBar/NavigationBar.tsx(3 hunks)src/components/StatusBar/LogLevelSelect/index.tsx(1 hunks)src/contexts/StateContextProvider.tsx(10 hunks)src/services/LogFileManager/index.ts(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
- src/components/StatusBar/LogLevelSelect/index.tsx
- src/components/Editor/index.tsx
- src/components/MenuBar/NavigationBar.tsx
- src/components/MenuBar/MenuBarToggleButton.tsx
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Preferfalse == <expression>rather than!<expression>.
src/contexts/StateContextProvider.tsxsrc/services/LogFileManager/index.ts
🧬 Code Definitions (2)
src/contexts/StateContextProvider.tsx (4)
src/utils/actions.ts (1)
ACTION_NAME(115-115)src/typings/worker.ts (4)
EVENT_POSITION_ON_PAGE(189-189)CursorType(196-196)WORKER_REQ_CODE(190-190)CURSOR_CODE(187-187)src/contexts/UrlContextProvider.tsx (2)
UrlContext(280-280)updateWindowUrlHashParams(276-276)src/typings/url.ts (1)
HASH_PARAM_NAMES(37-37)
src/services/LogFileManager/index.ts (1)
src/typings/worker.ts (3)
CursorType(196-196)WorkerResp(201-201)WORKER_RESP_CODE(191-191)
🪛 GitHub Check: lint-check
src/contexts/StateContextProvider.tsx
[failure] 435-435:
Expected object keys to be in natural ascending order. 'isPrettified' should be before 'pageSize'
src/services/LogFileManager/index.ts
[failure] 2-2:
Identifier 'js_beautify' is not in camel case
🪛 GitHub Actions: lint
src/contexts/StateContextProvider.tsx
[warning] 435-435: Expected object keys to be in natural ascending order. 'isPrettified' should be before 'pageSize' (sort-keys)
🪛 ESLint
src/services/LogFileManager/index.ts
[error] 2-2: Identifier 'js_beautify' is not in camel case.
(camelcase)
🔇 Additional comments (13)
src/services/LogFileManager/index.ts (3)
248-249: JSDoc update looks goodThe JSDoc has been properly updated to describe the new parameter.
253-253: Method signature change looks appropriateAdding the
isPrettifiedparameter to theloadPagemethod is a good way to implement the prettifying toggle feature.
290-294: Conditional formatting logic looks goodThe implementation correctly applies formatting only when the
isPrettifiedflag is true. The ternary operator provides a clean approach to conditional formatting.src/contexts/StateContextProvider.tsx (10)
31-34: Import updates look goodThe imports have been correctly updated to include the URL hash parameter names needed for the prettify feature.
161-166: Handling of prettify actions in page navigation looks goodThe additional cases handle the prettify toggle actions appropriately, preserving the current page number and setting the position to the top of the page.
203-203: Parameter addition looks goodThe
isPrettifiedparameter has been correctly added to theloadPageByCursorfunction.
207-207: Parameter passing looks goodPassing the
isPrettifiedparameter to the worker request ensures that the prettify state is properly communicated.
475-487: URL parameter update on prettify actions looks goodThe code correctly updates the URL hash parameters when the prettify state changes without triggering a page reload.
530-544: Good implementation of page reload on prettify state changeAdding this effect ensures that when the prettify state changes, the current page is reloaded with the new prettify setting. The implementation correctly preserves the current page position.
502-502: Passing prettify state to filter logs looks goodThe
filterLogsfunction now correctly passes the prettify state when setting the log level filter.
572-572: Consistent use of prettify parameter in loadPageByCursor callsThis ensures that all page loads respect the current prettify state.
490-490: Good update to loadPageByCursor callThe
loadPageByCursorfunction call has been updated to include the prettify state from the URL context.
464-464: Fix shadowing issue with isPrettified parameterThe parameter
isPrettifiedshadows the variable with the same name from the upper scope (line 260), which can lead to confusion and potential bugs.Rename the parameter to avoid shadowing:
-const filterLogs = useCallback((filter: LogLevelFilter) => { +const filterLogs = useCallback((filter: LogLevelFilter, isPrettifiedState: boolean) => {And update its usage on line 502:
- isPrettified: isPrettified ?? false, + isPrettified: isPrettifiedState ?? false,
|
I fixed some linting issues but I have a few questions: I don't know a good ways to fix these two issues, could you give me some advices? Another question is about React's hook. Since I added a new argument in There are some return statements can exit the function before to ensure that the page will be loaded again after updating the |
|
Sorry to bother UI team, could anyone take a look of this PR (and my questions in the last comment, which block the pipeline). I will try to fix them and potential reviewer comments by tomorrow morning to make the PR ready to merge, otherwise I maybe have less time over this long weekend in China (it will be Qingming Festival, and I need to go back home and spend time with my family). |
No problem! We discussed offline but I realize I didn't post a response here. Thanks again for helping and the attempt to lint the code. I'm taking a look at the code / lint issues now. |
junhaoliao
left a comment
There was a problem hiding this comment.
Thanks again for your contributions! The changes are mostly clean. I truly appreciate that
| return; | ||
| } | ||
|
|
||
| if (navAction.code === ACTION_NAME.PRETTIFY_ON) { |
There was a problem hiding this comment.
this is nice, but i'm not entirely sure if we need a NavAction for this. Can we refer to the handling of WORD_WRAP and see if the changes can be done similarly?
Don't hesitate to let me know if you think accessing the latest value of isPrettified is an issue. I can look further if that's the case
There was a problem hiding this comment.
Here I just wanted to make it consistent with other button (because I put the prettify button left to the first page button in the Navigation bar). If we want to remove it here, I can come up with two ways:
- Import
updateWindowUrlHashParamsfunction toNavigationBar.tsxso that I candirectly update the URL so that theisPrettifiedcan be updated in theUrlContext. - I add it as a separated button like
ExportLogsButtoninMenuBar/index.tsx, and put it before the divider of theNavigationBar, and importupdateWindowUrlHashParamsin that new.tsxfile and implement the same logic.
There was a problem hiding this comment.
make it consistent with other button (because I put the prettify button left to the first page button in the Navigation bar)
ah, gotcha. can we add it as a status bar button (in the right bottom of the window)? That way it will match the semantics in VSCode better. Sorry for the previous oversight!
I can come up with two ways
yup, i think what you propose will work. Let's make helper functions, if appropriate, to avoid duplicating the logic in both. To get the latest value of isToggled in a non-reactive function, we can use getWindowUrlHashParams(). (might need to export getWindowUrlHashParams first
There was a problem hiding this comment.
I move and rename the MenuBarToggleButton to StatusBarToggleButton, and put the button in left to the "Log Level"

And I also simulate the code style of the NavigationBar so I implement a handleStatusButtonClick function in the StatusBar so that I can get the state variable from UrlContext. Let me know if this way is bad.
There was a problem hiding this comment.
Actionable comments posted: 1
🔭 Outside diff range comments (2)
src/contexts/StateContextProvider.tsx (2)
81-89:⚠️ Potential issueUpdate the
filterLogsinterface to match its implementation.The implementation of
filterLogs(at line 488) now accepts a second parameterisPrettified, but the interface definition hasn't been updated to reflect this change.- filterLogs: (filter: LogLevelFilter) => void; + filterLogs: (filter: LogLevelFilter, isPrettified?: boolean) => void;
442-486:⚠️ Potential issueRefactor the function to address linting error.
The arrow function has too many statements (21) while the maximum allowed is 20, causing a linting error.
Consider extracting the logic for handling different navigation actions into separate functions:
- const loadPageByAction = useCallback((navAction: NavigationAction) => { + const handleReloadAction = useCallback((navAction: NavigationAction) => { + if (null === fileSrcRef.current || null === logEventNumRef.current) { + throw new Error(`Unexpected fileSrc=${JSON.stringify(fileSrcRef.current) + }, logEventNum=${logEventNumRef.current} when reloading.`); + } + loadFile(fileSrcRef.current, { + code: CURSOR_CODE.EVENT_NUM, + args: {eventNum: logEventNumRef.current}, + }); + }, [loadFile]); + + const loadPageByAction = useCallback((navAction: NavigationAction) => { if (null === mainWorkerRef.current) { console.error("Unexpected null mainWorkerRef.current"); return; } if (navAction.code === ACTION_NAME.RELOAD) { - if (null === fileSrcRef.current || null === logEventNumRef.current) { - throw new Error(`Unexpected fileSrc=${JSON.stringify(fileSrcRef.current) - }, logEventNum=${logEventNumRef.current} when reloading.`); - } - loadFile(fileSrcRef.current, { - code: CURSOR_CODE.EVENT_NUM, - args: {eventNum: logEventNumRef.current}, - }); + handleReloadAction(navAction); return; }🧰 Tools
🪛 GitHub Check: lint-check
[failure] 442-442:
Arrow function has too many statements (21). Maximum allowed is 20🪛 ESLint
[error] 442-486: Arrow function has too many statements (21). Maximum allowed is 20.
(max-statements)
🪛 GitHub Actions: lint
[error] 442-442: ESLint: Arrow function has too many statements (21). Maximum allowed is 20 (max-statements)
♻️ Duplicate comments (1)
src/services/LogFileManager/index.ts (1)
2-2:⚠️ Potential issueUse proper import naming convention.
The import statement uses camel case for a function that starts with an uppercase letter, which triggers an ESLint error.
-import JsBeautify from "js-beautify"; +import jsBeautify from "js-beautify";
🧹 Nitpick comments (2)
src/contexts/StateContextProvider.tsx (2)
529-543: Consider using a consistent approach for state references.The effect directly uses both
isPrettifiedandlogEventNumRef.current, which may cause inconsistencies.For consistency, consider using the ref value throughout:
const cursor: CursorType = { code: CURSOR_CODE.EVENT_NUM, args: {eventNum: logEventNumRef.current ?? 1}, }; setUiState(UI_STATE.FAST_LOADING); - loadPageByCursor(mainWorkerRef.current, cursor, isPrettified ?? false); + loadPageByCursor(mainWorkerRef.current, cursor, isPrettifiedRef.current); }, [ - isPrettified, + // No dependencies needed if using refs consistently ]);
571-576: Consistent use of state references.Similar to the previous comment, consider using
isPrettifiedRef.currentconsistently rather thanisPrettified ?? false.setUiState(UI_STATE.FAST_LOADING); - loadPageByCursor(mainWorkerRef.current, cursor, isPrettified ?? false); + loadPageByCursor(mainWorkerRef.current, cursor, isPrettifiedRef.current); }, [ - isPrettified, logEventNum, numEvents, ]);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
src/components/Editor/index.tsx(1 hunks)src/components/MenuBar/ExportLogsButton.tsx(1 hunks)src/components/MenuBar/MenuBarIconButton.tsx(1 hunks)src/components/MenuBar/MenuBarToggleButton.tsx(1 hunks)src/components/MenuBar/NavigationBar.tsx(4 hunks)src/contexts/StateContextProvider.tsx(11 hunks)src/contexts/UrlContextProvider.tsx(2 hunks)src/services/LogFileManager/index.ts(3 hunks)src/utils/actions.ts(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
- src/components/Editor/index.tsx
- src/components/MenuBar/MenuBarToggleButton.tsx
- src/utils/actions.ts
- src/contexts/UrlContextProvider.tsx
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Preferfalse == <expression>rather than!<expression>.
src/components/MenuBar/ExportLogsButton.tsxsrc/components/MenuBar/MenuBarIconButton.tsxsrc/components/MenuBar/NavigationBar.tsxsrc/contexts/StateContextProvider.tsxsrc/services/LogFileManager/index.ts
🧬 Code Graph Analysis (3)
src/components/MenuBar/NavigationBar.tsx (3)
src/contexts/StateContextProvider.tsx (1)
StateContext(628-628)src/contexts/UrlContextProvider.tsx (1)
UrlContext(277-277)src/utils/actions.ts (1)
ACTION_NAME(108-108)
src/contexts/StateContextProvider.tsx (6)
src/utils/actions.ts (1)
ACTION_NAME(108-108)src/typings/worker.ts (1)
CursorType(196-196)src/contexts/UrlContextProvider.tsx (2)
UrlContext(277-277)updateWindowUrlHashParams(273-273)src/utils/config.ts (1)
getConfig(182-182)src/typings/config.ts (1)
CONFIG_KEY(44-44)src/typings/url.ts (1)
HASH_PARAM_NAMES(37-37)
src/services/LogFileManager/index.ts (1)
src/typings/worker.ts (3)
CursorType(196-196)WorkerResp(201-201)WORKER_RESP_CODE(191-191)
🪛 GitHub Actions: lint
src/contexts/StateContextProvider.tsx
[error] 442-442: ESLint: Arrow function has too many statements (21). Maximum allowed is 20 (max-statements)
🪛 GitHub Check: lint-check
src/services/LogFileManager/index.ts
[failure] 291-291:
A function with a name starting with an uppercase letter should only be used as a constructor
🪛 ESLint
src/services/LogFileManager/index.ts
[error] 291-291: A function with a name starting with an uppercase letter should only be used as a constructor.
(new-cap)
🔇 Additional comments (23)
src/components/MenuBar/ExportLogsButton.tsx (1)
34-34: Property name updated for consistency.The
titleprop has been correctly updated totooltipTitleto match the changes in the MenuBarIconButton component interface.src/components/MenuBar/MenuBarIconButton.tsx (4)
11-11: New optional property added to interface.The
tooltipTitleoptional string property replaces the previoustitleproperty, providing better semantics by clearly differentiating from HTML's native title attribute.
18-19: JSDoc updated to reflect parameter name change.The documentation now correctly references the renamed parameter
tooltipTitleinstead oftitle, with added context about its purpose.
25-26: Function parameter renamed for clarity.The parameter name has been changed from
titletotooltipTitleto be more descriptive and consistent with the interface definition.
30-31: Tooltip component updated to use new property name.The
titleprop in the Tooltip component now correctly references the renamedtooltipTitleparameter.src/services/LogFileManager/index.ts (2)
248-249: Documentation updated for new parameter.The JSDoc comment has been appropriately updated to document the new
isPrettifiedparameter.
253-253: Method signature extended to support prettify feature.The
loadPagemethod now correctly accepts anisPrettifiedboolean parameter to determine whether log messages should be formatted.src/components/MenuBar/NavigationBar.tsx (7)
5-6: Added MUI icons for toggle button states.Appropriate icons have been imported to represent the on/off states of the prettify feature.
13-13: Added UrlContext import for accessing prettify state.The UrlContext is now imported to access the
isPrettifiedstate, which is stored in the URL parameters.
21-21: Added import for new toggle button component.The MenuBarToggleButton component has been imported to provide the prettify toggle functionality.
31-35: Context usage expanded to access prettify state.The component now uses both StateContext and UrlContext to access the necessary state variables, with appropriate destructuring.
42-42: Action handling extended for toggle prettify functionality.The conditional check now includes the TOGGLE_PRETTIFY action, allowing the navigation button click handler to process this new action.
59-67: New toggle button added for prettify functionality.The MenuBarToggleButton component is properly configured with appropriate props:
- Active state is inversely tied to isPrettified (active when not prettified)
- Different icons for on/off states
- Dynamic tooltip text based on current state
- Proper action name for event handling
This implementation follows the design pattern of other navigation buttons while adding toggle functionality.
70-70: Updated tooltip property names for consistency.All MenuBarIconButton components have been updated to use
tooltipTitleinstead oftitle, maintaining consistency with the component interface changes.Also applies to: 77-77, 87-87, 94-94
src/contexts/StateContextProvider.tsx (9)
31-34: LGTM - Added required imports for URL parameters.The addition of the imports for URL parameters is necessary for the new prettify feature.
161-165: LGTM - Proper handling of prettify toggle.The implementation correctly handles the
TOGGLE_PRETTIFYaction by returning to the top of the current page.
197-203: LGTM - Well-documented parameter addition.The addition of the
isPrettifiedparameter is well documented and properly integrated into the function signature.
259-259: LGTM - Added URL context property.The addition of
isPrettifiedto the destructured properties fromUrlContextis necessary for accessing the prettify state from the URL.
280-280: LGTM - Added state reference with proper initialization.The
isPrettifiedRefis correctly initialized with the URL value, defaulting tofalseif not provided.
434-440: LGTM - Updated worker request with prettify state.The function now correctly passes the prettify state to the worker and includes it in the dependency array.
475-482: LGTM - Proper implementation of prettify toggle action.The code correctly updates the
isPrettifiedRefand the URL hash parameters when handling the toggle action.
496-497: LGTM - Added prettify state to filter request.The prettify state is correctly included in the worker request for setting the filter.
500-503: LGTM - Added synchronization for prettify state.The effect correctly synchronizes the
isPrettifiedRefwith theisPrettifiedvalue from the URL context.
| const printedMsg = (isPrettified) ? | ||
| `${JsBeautify(msg)}\n` : | ||
| msg; | ||
|
|
||
| messages.push(printedMsg); |
There was a problem hiding this comment.
Conditional formatting logic implemented.
The code now applies JS beautification to log messages when isPrettified is true. However, there's a linting issue with the function naming.
- const printedMsg = (isPrettified) ?
- `${JsBeautify(msg)}\n` :
+ const printedMsg = (isPrettified) ?
+ `${jsBeautify(msg)}\n` :Also note that function currentLine += msg.split("\n").length - 1; on line 296 may produce incorrect results after beautification since it's still using the original message to count lines. Consider using the formatted message length instead:
- currentLine += msg.split("\n").length - 1;
+ currentLine += printedMsg.split("\n").length - 1;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const printedMsg = (isPrettified) ? | |
| `${JsBeautify(msg)}\n` : | |
| msg; | |
| messages.push(printedMsg); | |
| const printedMsg = (isPrettified) ? | |
| `${jsBeautify(msg)}\n` : | |
| msg; | |
| messages.push(printedMsg); | |
| // ... (other code) | |
| currentLine += printedMsg.split("\n").length - 1; |
🧰 Tools
🪛 GitHub Check: lint-check
[failure] 291-291:
A function with a name starting with an uppercase letter should only be used as a constructor
🪛 ESLint
[error] 291-291: A function with a name starting with an uppercase letter should only be used as a constructor.
(new-cap)
| import Check from "@mui/icons-material/Check"; | ||
| import Close from "@mui/icons-material/Close"; |
There was a problem hiding this comment.
to follow the convention in mui official docs:
| import Check from "@mui/icons-material/Check"; | |
| import Close from "@mui/icons-material/Close"; | |
| import CheckIcon from "@mui/icons-material/Check"; | |
| import CloseIcon from "@mui/icons-material/Close"; |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (6)
src/components/StatusBar/StatusBarToggleButton.tsx (4)
12-18: Interface naming inconsistency.The component is named
StatusBarToggleButtonbut the interface is namedMenuBarToggleButtonProps. This creates confusion about the component's purpose and location.For better consistency, rename the interface:
-interface MenuBarToggleButtonProps extends IconButtonProps { +interface StatusBarToggleButtonProps extends IconButtonProps { tooltipPlacement?: TooltipTypeMap["props"]["placement"]; tooltipTitle?: string; isActive?: boolean; onIcon?: React.ReactNode; offIcon?: React.ReactNode; }Make sure to also update line 39 where the interface is used.
39-39: Update interface reference.If you rename the interface as suggested earlier, update this reference too.
-}: MenuBarToggleButtonProps) => { +}: StatusBarToggleButtonProps) => {
44-44: Remove space after spread operator.There's an extra space after the spread operator which is not consistent with standard formatting.
- {... tooltipPlacement && {placement: tooltipPlacement}} + {...tooltipPlacement && {placement: tooltipPlacement}}
45-55: Wrapping in a span adds unnecessary nesting.Using a span solely as a tooltip container can be avoided as Material UI's Tooltip component already handles this internally.
Consider simplifying the structure:
<Tooltip title={tooltipTitle} {...tooltipPlacement && {placement: tooltipPlacement}} > - <span> <IconButton size={"sm"} {...rest} > {isActive ? onIcon : offIcon} </IconButton> - </span> </Tooltip>This creates a simpler DOM structure while maintaining the same functionality.
src/components/StatusBar/index.tsx (2)
87-89: Simplify conditional tooltip text.The current implementation uses a nullish coalescing operator followed by a ternary, which is unnecessarily complex.
- tooltipTitle={isPrettified ?? false ? - "Prettify Off" : - "Prettify On"} + tooltipTitle={isPrettified ? "Prettify Off" : "Prettify On"}This is cleaner and achieves the same result, as JavaScript already treats undefined as false in conditionals.
48-57: Preferfalse === <expression>over!<expression>According to the coding guidelines, we should prefer
false === <expression>over!<expression>.switch (actionName) { case ACTION_NAME.TOGGLE_PRETTIFY: updateWindowUrlHashParams({ - [HASH_PARAM_NAMES.IS_PRETTIFIED]: !isPrettified, + [HASH_PARAM_NAMES.IS_PRETTIFIED]: false === isPrettified, }); break; default: console.error(`Unexpected action: ${actionName}`); break; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
src/components/MenuBar/MenuBarIconButton.tsx(1 hunks)src/components/MenuBar/NavigationBar.tsx(3 hunks)src/components/StatusBar/StatusBarToggleButton.tsx(1 hunks)src/components/StatusBar/index.tsx(4 hunks)src/contexts/StateContextProvider.tsx(9 hunks)src/services/LogFileManager/index.ts(3 hunks)
✅ Files skipped from review due to trivial changes (1)
- src/components/MenuBar/NavigationBar.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
- src/components/MenuBar/MenuBarIconButton.tsx
- src/services/LogFileManager/index.ts
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Preferfalse == <expression>rather than!<expression>.
src/components/StatusBar/StatusBarToggleButton.tsxsrc/components/StatusBar/index.tsxsrc/contexts/StateContextProvider.tsx
🧬 Code Graph Analysis (2)
src/components/StatusBar/index.tsx (3)
src/contexts/UrlContextProvider.tsx (2)
UrlContext(277-277)updateWindowUrlHashParams(273-273)src/utils/actions.ts (1)
ACTION_NAME(108-108)src/typings/url.ts (1)
HASH_PARAM_NAMES(37-37)
src/contexts/StateContextProvider.tsx (5)
src/typings/states.ts (1)
UI_STATE(101-101)src/typings/worker.ts (3)
CursorType(196-196)WORKER_REQ_CODE(190-190)CURSOR_CODE(187-187)src/contexts/UrlContextProvider.tsx (1)
UrlContext(277-277)src/utils/config.ts (1)
getConfig(182-182)src/typings/config.ts (1)
CONFIG_KEY(44-44)
🪛 GitHub Check: lint-check
src/contexts/StateContextProvider.tsx
[failure] 555-555:
React Hook useEffect has a missing dependency: 'isPrettified'. Either include it or remove the dependency array
🪛 GitHub Actions: lint
src/contexts/StateContextProvider.tsx
[warning] 555-555: React Hook useEffect has a missing dependency: 'isPrettified'. Either include it or remove the dependency array.
🔇 Additional comments (6)
src/components/StatusBar/StatusBarToggleButton.tsx (1)
1-61: The component looks good overall.The StatusBarToggleButton component is well-structured and includes proper documentation. It provides flexibility with customizable icons and tooltip placement, making it reusable.
src/components/StatusBar/index.tsx (1)
45-58: Well-structured event handler.The
handleStatusButtonClickfunction is well-structured, using a switch statement that can easily accommodate additional actions in the future.src/contexts/StateContextProvider.tsx (4)
483-486: Good implementation of state synchronization.The useEffect hook for synchronizing
isPrettifiedRefwithisPrettifiedis implemented correctly and ensures that the ref always has the latest value.
272-272: Ensure consistent initialization.The
isPrettifiedRefis initialized withisPrettified ?? false, which is good for handling the nullable state value.
425-427: Good implementation of isPrettified parameter.The
loadFilefunction correctly passes theisPrettifiedparameter, ensuring proper initialization of the file with the prettify state.
478-480: Using ref for stable callback definitions.Using
isPrettifiedRef.currentin thefilterLogsfunction is a good pattern to avoid re-creating the callback when theisPrettifiedstate changes.
src/components/StatusBar/index.tsx
Outdated
|
|
||
| <StatusBarToggleButton | ||
| data-action-name={ACTION_NAME.TOGGLE_PRETTIFY} | ||
| isActive={!isPrettified} |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Inverted logic in isActive prop.
The isActive prop is set to !isPrettified, which is counterintuitive - users would expect the button to be active when prettification is enabled, not disabled.
- isActive={!isPrettified}
+ isActive={isPrettified === true}This makes the button state align with the actual feature state.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| isActive={!isPrettified} | |
| isActive={isPrettified === true} |
src/components/StatusBar/index.tsx
Outdated
| data-action-name={ACTION_NAME.TOGGLE_PRETTIFY} | ||
| isActive={!isPrettified} | ||
| offIcon={<AutoFixOffRoundedIcon/>} | ||
| tooltipTitle={isPrettified ?? false ? | ||
| "Prettify Off" : | ||
| "Prettify On"} | ||
| onClick={handleStatusButtonClick} | ||
| onIcon={<AutoFixHighRoundedIcon/>}/> | ||
|
|
There was a problem hiding this comment.
🛠️ Refactor suggestion
Consider inverting tooltip text and icon logic.
Currently, the icons and tooltip text don't clearly match the state they represent. When prettification is ON, the tooltip says "Prettify Off", which is confusing.
Consider this more intuitive approach:
<StatusBarToggleButton
data-action-name={ACTION_NAME.TOGGLE_PRETTIFY}
- isActive={!isPrettified}
- offIcon={<AutoFixOffRoundedIcon/>}
- tooltipTitle={isPrettified ?? false ?
- "Prettify Off" :
- "Prettify On"}
+ isActive={isPrettified === true}
+ onIcon={<AutoFixHighRoundedIcon/>}
+ offIcon={<AutoFixOffRoundedIcon/>}
+ tooltipTitle={isPrettified ? "Turn Prettify Off" : "Turn Prettify On"}
onClick={handleStatusButtonClick}
- onIcon={<AutoFixHighRoundedIcon/>}/>
+ />This makes the tooltip indicate the action that will happen when clicked, rather than the current state.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| <StatusBarToggleButton | |
| data-action-name={ACTION_NAME.TOGGLE_PRETTIFY} | |
| isActive={!isPrettified} | |
| offIcon={<AutoFixOffRoundedIcon/>} | |
| tooltipTitle={isPrettified ?? false ? | |
| "Prettify Off" : | |
| "Prettify On"} | |
| onClick={handleStatusButtonClick} | |
| onIcon={<AutoFixHighRoundedIcon/>}/> | |
| <StatusBarToggleButton | |
| data-action-name={ACTION_NAME.TOGGLE_PRETTIFY} | |
| isActive={isPrettified === true} | |
| onIcon={<AutoFixHighRoundedIcon/>} | |
| offIcon={<AutoFixOffRoundedIcon/>} | |
| tooltipTitle={isPrettified ? "Turn Prettify Off" : "Turn Prettify On"} | |
| onClick={handleStatusButtonClick} | |
| /> |
| loadPageByCursor(mainWorkerRef.current, cursor, isPrettified ?? false); | ||
| }, [ | ||
| numEvents, | ||
| logEventNum, | ||
| numEvents, | ||
| ]); |
There was a problem hiding this comment.
Missing dependency in useEffect.
The useEffect hook is missing isPrettified in its dependency array, as flagged by the static analysis tool.
}, [
logEventNum,
numEvents,
+ isPrettified,
]);Without this, changes to isPrettified won't properly trigger this effect, potentially causing stale state issues.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| loadPageByCursor(mainWorkerRef.current, cursor, isPrettified ?? false); | |
| }, [ | |
| numEvents, | |
| logEventNum, | |
| numEvents, | |
| ]); | |
| loadPageByCursor(mainWorkerRef.current, cursor, isPrettified ?? false); | |
| }, [ | |
| logEventNum, | |
| numEvents, | |
| isPrettified, | |
| ]); |
🧰 Tools
🪛 GitHub Check: lint-check
[failure] 555-555:
React Hook useEffect has a missing dependency: 'isPrettified'. Either include it or remove the dependency array
🪛 GitHub Actions: lint
[warning] 555-555: React Hook useEffect has a missing dependency: 'isPrettified'. Either include it or remove the dependency array.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/components/StatusBar/index.tsx (1)
45-58: Adhere to codebase style guide for boolean comparison.The toggle action follows the correct pattern for event handling, but there's a minor deviation from the coding guidelines.
According to the project's coding guidelines, you should prefer explicit comparison for boolean expressions.
- [HASH_PARAM_NAMES.IS_PRETTIFIED]: !isPrettified, + [HASH_PARAM_NAMES.IS_PRETTIFIED]: false == isPrettified,src/components/StatusBar/StatusBarToggleButton.tsx (3)
14-24: Remove redundant properties from StatusBarToggleButtonProps interface.The interface includes both a structured
iconsobject and individualonIcon/offIconproperties, but only theiconsobject is used in the component implementation. This creates confusion about which properties should be used.interface StatusBarToggleButtonProps extends IconButtonProps { icons?: { active?: React.ReactNode; inactive?: React.ReactNode; }; isActive: boolean; - onIcon?: React.ReactNode; - offIcon?: React.ReactNode; tooltipPlacement?: TooltipTypeMap["props"]["placement"]; tooltipTitle?: string; }
28-36: Update JSDoc to match implementation parameters.The JSDoc references
props.rest, but the component destructures it as justrest. For consistency and clarity, update the JSDoc.* @param props.icons Icons to use for the active and inactive states. * @param props.isActive * @param props.tooltipPlacement Tooltip position. * @param props.tooltipTitle Tooltip title, to discern with native HTML tooltip. -* @param props.rest Other IconButton props. +* @param rest Other IconButton props.
50-50: Improve readability of conditional tooltip placement.The current spread operator with a condition works but is not as readable as it could be. Consider using a more explicit approach.
- {... tooltipPlacement && {placement: tooltipPlacement}} + placement={tooltipPlacement}This change works because the
placementprop will be undefined whentooltipPlacementis not provided, which has the same effect as not setting the prop at all.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
src/components/Editor/index.tsx(5 hunks)src/components/MenuBar/NavigationBar.tsx(3 hunks)src/components/StatusBar/StatusBarToggleButton.tsx(1 hunks)src/components/StatusBar/index.tsx(4 hunks)src/contexts/StateContextProvider.tsx(10 hunks)src/typings/states.ts(5 hunks)src/utils/actions.ts(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
- src/utils/actions.ts
- src/components/Editor/index.tsx
- src/components/MenuBar/NavigationBar.tsx
- src/contexts/StateContextProvider.tsx
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Preferfalse == <expression>rather than!<expression>.
src/typings/states.tssrc/components/StatusBar/StatusBarToggleButton.tsxsrc/components/StatusBar/index.tsx
🧬 Code Graph Analysis (1)
src/components/StatusBar/index.tsx (4)
src/contexts/UrlContextProvider.tsx (2)
UrlContext(277-277)updateWindowUrlHashParams(273-273)src/utils/actions.ts (1)
ACTION_NAME(107-107)src/typings/url.ts (1)
HASH_PARAM_NAMES(37-37)src/typings/states.ts (1)
UI_ELEMENT(105-105)
🔇 Additional comments (7)
src/typings/states.ts (2)
39-39: Addition of PRETTIFY_BUTTON looks good.The UI_ELEMENT enum has been expanded with a new PRETTIFY_BUTTON entry. This follows the pattern of other UI elements in the codebase.
65-65: Appropriate UI state configuration for the prettify button.The button is correctly disabled during the UNOPENED and FILE_LOADING states, and enabled during FAST_LOADING and READY states. This is consistent with the behavior of other UI elements that should only be available when a log file is loaded.
Also applies to: 76-76, 87-87, 98-98
src/components/StatusBar/index.tsx (4)
1-24: Imports are organized appropriately.The new imports required for the prettify feature have been added correctly. The IconButton imports, action names, and context providers are all properly organized.
43-43: Correctly destructured isPrettified from UrlContext.The isPrettified state is now extracted alongside logEventNum from the UrlContext, allowing it to be used in the component.
60-60: Good use of isDisabled utility.Correctly utilizes the isDisabled utility to check if the prettify button should be disabled based on the current UI state. This ensures the button follows the same behavior as other UI elements.
87-98: Properly implemented toggle button with clear state indication.The StatusBarToggleButton implementation looks good with appropriate props for action name, disabled state, icons, and tooltip. The button's state and tooltip text are correctly tied to the isPrettified state.
src/components/StatusBar/StatusBarToggleButton.tsx (1)
52-65: Well-structured toggle button with appropriate accessibility attributes.The button implementation is solid with good use of aria-pressed for accessibility and correct handling of the icons based on the active state. The size and variant choices are appropriate for a status bar button.
|
For the PR title, how about: I tend not to mention "button" since we added many different types of toggles in this PR: a status bar button, a URL hash parameter, and a monaco editor action. pretty awesome! @coderabbitai since we're marking #220 as resolved, please submit an issue for a request to improve the performance of the prettification function. related changes have been submitted to #225 . |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chainLet me gather more information about the prettification implementation and PR #225. Let me check how the js-beautify library is imported and used in the code. I'll create a new issue for improving the performance of the prettification function. @junhaoliao I've created a new issue for improving the performance of the prettification function. The issue is now assigned to you and references the relevant PRs and original feature request. The issue focuses on evaluating the current js-beautify implementation and exploring more performant alternatives, especially for large log files. 🏁 Script executed: Length of output: 971 🏁 Script executed: Length of output: 2922 🏁 Script executed: Length of output: 70 🏁 Script executed: Length of output: 1153 @junhaoliao I've created a new issue (#230) for improving the performance of the log message prettification function, as you requested. The issue outlines the current implementation using js-beautify and proposes investigating performance improvements and custom solutions. I agree with your suggestion for the PR title. "feat: Add toggle for log message prettification (resolves #220)" better represents the comprehensive implementation that includes the status bar button, URL hash parameter, and monaco editor action - not just a button. It's a more accurate description of the work completed in this PR. |
|
|
||
| const isPrettified = hashParams.get(HASH_PARAM_NAMES.IS_PRETTIFIED); | ||
| if (null !== isPrettified) { | ||
| urlHashParams[HASH_PARAM_NAMES.IS_PRETTIFIED] = "true" === isPrettified; |
There was a problem hiding this comment.
urlHashParams[HASH_PARAM_NAMES.IS_PRETTIFIED] = "true" === isPrettified;
What if user types "TRUE"?
| setUiState(UI_STATE.FAST_LOADING); | ||
| loadPageByCursor(mainWorkerRef.current, cursor, isPrettified ?? false); | ||
| }, [ | ||
| isPrettified, |
There was a problem hiding this comment.
What if the url initially doesn't contain isPrettified property and later decides to add isPrettified=false? This should be a no-op, instead of triggering this function to load twice.
|
|
||
| const cursor: CursorType = { | ||
| code: CURSOR_CODE.EVENT_NUM, | ||
| args: {eventNum: logEventNumRef.current ?? 1}, |
There was a problem hiding this comment.
I would suggest this:
let cursor: CursorType = {code: CURSOR_CODE.LAST_EVENT, args: null};
if (URL_HASH_PARAMS_DEFAULT.logEventNum !== logEventNumRef.current) {
cursor = {
code: CURSOR_CODE.EVENT_NUM,
args: {eventNum: logEventNumRef.current},
};
}
There was a problem hiding this comment.
This is exactly what we did for filePath update.
|
@coderabbitai Create an issue about the overflowing |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain@Henry8192 I've created a new issue about the StatusBarToggleButton overflow problem. The issue describes how the prettify button causes scroll bars to appear at certain zoom scales, and it's now assigned to you for tracking. 🏁 Script executed: Length of output: 1184 @Henry8192 I've successfully created issue #252 titled "UI: StatusBarToggleButton (prettify button) overflow causes scroll bars at certain zoom scales". The issue has been assigned to you and includes detailed information about the problem, steps to reproduce, expected behavior, and suggestions for potential fixes. You can access it here: #252 🎉 Success! 🎊 If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
Description
This PR is to implement the first sub task as discussed in #220 . I implemented the following things per the discussion:
js-beautifyto format the log messages (will switch to our own solution soon).Checklist
breaking change.
Validation performed
Since I can think of a lot of cases, here I only manually test for critical functionalities:
logger.info("some message {123} someFunc(123,123) {return 1;}")and a couple of messages of other log levels to test compatibility with log level filter. After loading file, click the prettify button, all log messages in the current page are formated.isPrettified=parameter.isPrettified=parameter and toggle it in the URL, repeat 1~4, it also works as the same.isPrettifiedset to true in the current URL, load a new log file, the log messages will be prettified. And ifisPrettifiedis not set or is false, then the loaded new file will not be prettified.Summary by CodeRabbit
Documentation
New Features