new-log-viewer: Implement log-level filtering.#63
new-log-viewer: Implement log-level filtering.#63davemarco wants to merge 88 commits intoy-scope:mainfrom
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. |
junhaoliao
left a comment
There was a problem hiding this comment.
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 <junhao@junhao.ca>
# 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.
| 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.
| 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.
| // 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.
| updateWindowUrlHashParams({ | |
| logEventNum: newLogEventNum, | |
| }); | |
| updateWindowUrlHashParams({logEventNum: newLogEventNum}); |
| firstLogEventNumOnPage: firstLogEventNumOnPage.current, | ||
| lastLogEventNumOnPage: lastLogEventNumOnPage.current, |
There was a problem hiding this comment.
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.
| }, [ | |
| getClosestLogEventNum, | |
| ]); | |
| }, [getClosestLogEventNum]); |
| const newPageNum = 1 + firstLogEventNumOnPage.current.findLastIndex( | ||
| (value: number) => value <= newLogEventNum, | ||
| ); |
There was a problem hiding this comment.
Shall we check the return value of findLastIndex() against -1 ?
| if (0 === numFilteredEvents) { | ||
| setPageNum(0); | ||
| } |
There was a problem hiding this comment.
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.
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