Skip to content

Commit

Permalink
add parameters for queryLogs()
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry8192 committed Oct 7, 2024
1 parent 9a3cca9 commit 8aa0c14
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 5 additions & 1 deletion new-log-viewer/src/components/MenuBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const MenuBar = () => {

const [isSettingsModalOpen, setIsSettingsModalOpen] = useState<boolean>(false);

const handleSearchButtonClick = () => {
queryLogs("scheduled", false, false);
};

const handleOpenFileButtonClick = () => {
openFile((file) => {
loadFile(file, {code: CURSOR_CODE.LAST_EVENT, args: null});
Expand Down Expand Up @@ -80,7 +84,7 @@ const MenuBar = () => {
</SmallIconButton>
<ExportLogsButton/>
<SmallIconButton
onClick={queryLogs}
onClick={handleSearchButtonClick}
>
<SearchIcon/>
</SmallIconButton>
Expand Down
17 changes: 11 additions & 6 deletions new-log-viewer/src/contexts/StateContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ interface StateContextType {
exportLogs: () => void,
loadFile: (fileSrc: FileSrcType, cursor: CursorType) => void,
loadPage: (newPageNum: number) => void,
queryLogs: () => void,
queryLogs: (searchString: string, isRegex: boolean, isCaseSensitive: boolean) => void,
}
const StateContext = createContext<StateContextType>({} as StateContextType);

Expand Down Expand Up @@ -140,7 +140,7 @@ const workerPostReq = <T extends WORKER_REQ_CODE>(
* @param props.children
* @return
*/
// eslint-disable-next-line max-lines-per-function
// eslint-disable-next-line max-lines-per-function,max-statements
const StateContextProvider = ({children}: StateContextProviderProps) => {
const {filePath, logEventNum} = useContext(UrlContext);

Expand Down Expand Up @@ -190,6 +190,7 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
break;
}
case WORKER_RESP_CODE.CHUNK_RESULT:
console.log(`[MainWorker -> Renderer] CHUNK_RESULT: ${JSON.stringify(args)}`);
for (const [pageNumStr, results] of Object.entries(args)) {
const pageNum = parseInt(pageNumStr, 10);
if (!queryResults.current[pageNum]) {
Expand All @@ -204,16 +205,20 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
}
}, []);

const queryLogs = useCallback(() => {
const queryLogs = useCallback((
searchString: string,
isRegex: boolean,
isCaseSensitive: boolean
) => {
if (null === mainWorkerRef.current) {
console.error("Unexpected null mainWorkerRef.current");

return;
}
workerPostReq(mainWorkerRef.current, WORKER_REQ_CODE.QUERY_LOG, {
searchString: "scheduled",
isRegex: false,
isCaseSensitive: false,
searchString: searchString,
isRegex: isRegex,
isCaseSensitive: isCaseSensitive,
});
}, []);

Expand Down

0 comments on commit 8aa0c14

Please sign in to comment.