-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new-log-viewer: Implement log-level filtering. #63
Conversation
Need to handle case where decoder options can change |
Despite the fact that not necessary to update PR since the the page is always refreshed (i.e. logs are rebuilt) when decoder option change. I added a guard to reparse logs when decoder options change in case option design changes in future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! I took a brief look and the code looks mostly good to me. Let's clean up the code with ESLint and we can do a more thorough round of review.
Co-authored-by: Junhao Liao <[email protected]>
# Conflicts: # new-log-viewer/src/services/LogFileManager.ts # new-log-viewer/src/typings/decoders.ts
…OPTIONS.logLevelFilter=null in CONFIG_DEFAULT.
… switching in the renderer.
newLogEventNum = logEventNumOnPage.at(-1) as number; | ||
|
||
return newLogEventNum; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newLogEventNum = logEventNumOnPage.at(-1) as number; | |
return newLogEventNum; | |
return logEventNumOnPage.at(-1) as number; |
// that actually exists on the page. | ||
const getClosestLogEventNum = useCallback( | ||
(beginLineNumToLogEventNum: BeginLineNumToLogEventNumMap) => { | ||
let newLogEventNum: Nullable<number> = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let newLogEventNum: Nullable<number> = null; |
// Find first logEventNum smaller or equal to user provided logEventNum. | ||
for (let i = logEventNumOnPage.length; 0 < i; i--) { | ||
if ((logEventNumOnPage[i] as number) <= logEventNumRef.current) { | ||
newLogEventNum = logEventNumOnPage[i] as number; | ||
break; | ||
} | ||
} | ||
|
||
if (!newLogEventNum) { | ||
// If no nums on page are smaller than user logEventNum, user logEventNum is the | ||
// smallest so we should just return the smallest value on the page. | ||
newLogEventNum = logEventNumOnPage[0] as number; | ||
} | ||
|
||
return newLogEventNum; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Find first logEventNum smaller or equal to user provided logEventNum. | |
for (let i = logEventNumOnPage.length; 0 < i; i--) { | |
if ((logEventNumOnPage[i] as number) <= logEventNumRef.current) { | |
newLogEventNum = logEventNumOnPage[i] as number; | |
break; | |
} | |
} | |
if (!newLogEventNum) { | |
// If no nums on page are smaller than user logEventNum, user logEventNum is the | |
// smallest so we should just return the smallest value on the page. | |
newLogEventNum = logEventNumOnPage[0] as number; | |
} | |
return newLogEventNum; | |
// Find first logEventNum smaller or equal to user provided logEventNum. | |
const closestLogEventNum = logEventNumOnPage.findLast((logEventNum) => logEventNum <= logEventNumRef.current); | |
// Return the closest found or fallback to the smallest value on the page. | |
return closestLogEventNum ?? logEventNumOnPage[0] as number; |
updateWindowUrlHashParams({ | ||
logEventNum: newLogEventNum, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updateWindowUrlHashParams({ | |
logEventNum: newLogEventNum, | |
}); | |
updateWindowUrlHashParams({logEventNum: newLogEventNum}); |
firstLogEventNumOnPage: firstLogEventNumOnPage.current, | ||
lastLogEventNumOnPage: lastLogEventNumOnPage.current, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just so we don't forget this discussion: https://github.com/y-scope/yscope-log-viewer/pull/63/files/7bd410b3514b70e3ff86d0cde2cec5e7fa0f8aea#r1768810124
I'm fine if we want to init the refs with literals. e.g.,
const firstLogEventNumOnPage = useRef<number[]>([]);
const lastLogEventNumOnPage = useRef<number[]>([]);
}, [ | ||
getClosestLogEventNum, | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}, [ | |
getClosestLogEventNum, | |
]); | |
}, [getClosestLogEventNum]); |
const newPageNum = 1 + firstLogEventNumOnPage.current.findLastIndex( | ||
(value: number) => value <= newLogEventNum, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we check the return value of findLastIndex() against -1 ?
if (0 === numFilteredEvents) { | ||
setPageNum(0); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we use the constants from STATE_DEFAULT
?
return null; | ||
setLogLevelFilter (logLevelFilter: LogLevelFilter): boolean { | ||
this.#filterLogs(logLevelFilter); | ||
this.#isFiltered = Boolean(logLevelFilter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the discussion at https://github.com/y-scope/yscope-log-viewer/pull/63/files#r1768464251 , I feel this can be more readable:
this.#isFiltered = Boolean(logLevelFilter); | |
this.#isFiltered = (null !== logLevelFilter); |
Thanks for the additional comments, @junhaoliao. Since this PR ended up being quite large and we are reworking the design, @davemarco is going to submit smaller PRs rather than trying to refactor this one completely. |
@kirkrodrigues @davemarco i think we can close this now, right? |
Closing this since it has been implemented in the other PRs. |
References
new-log-viewer series: #45 #46 #48 #51 #52 #53 #54 #55 #56 #59 #60 #61 #62
Description
Validation performed