Skip to content

feat(search): Add support for persisting and sharing query via URL. #173

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

Merged
merged 42 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
10656aa
Add share link with search parameters button, update url search param…
Henry8192 Jan 20, 2025
ae155bf
Amend of previous commit
Henry8192 Jan 20, 2025
6647961
snapshot
Henry8192 Jan 25, 2025
d398cee
copy link with search parameters works
Henry8192 Jan 27, 2025
d4398aa
Merge branch 'main' into share-link-with-search-params
Henry8192 Jan 30, 2025
7761079
fix most lint errors except one useEffect dependency warning
Henry8192 Feb 1, 2025
7d446bd
remove isFileLoaded and move position of startQuery definition
Henry8192 Feb 4, 2025
a8224ba
Merge branch 'main' into share-link-with-search-params
Henry8192 Feb 4, 2025
c4aa866
rename query parameter names and make them as hash parameters
Henry8192 Feb 20, 2025
a2a9b2c
Creates a useEffect that starts new queries and clear query parameter…
Henry8192 Feb 20, 2025
dd88ba3
Merge branch 'main' into share-link-with-search-params
Henry8192 Feb 24, 2025
6d43037
fix lint
Henry8192 Feb 24, 2025
12dd17e
Merge branch 'main' into share-link-with-search-params
Henry8192 Feb 26, 2025
5d45031
url hash query works, but it doesn't sync query options to SearchBarTabs
Henry8192 Feb 26, 2025
cb62201
Merge branch 'main' into share-link-with-search-params
Henry8192 Feb 26, 2025
c6b97a9
sync query options to SearchBarTabs; clear #logEventNum from share li…
Henry8192 Feb 27, 2025
c6237ab
fix dependency warnings
Henry8192 Feb 27, 2025
7dd50b9
Merge branch 'main' into share-link-with-search-params
Henry8192 Feb 27, 2025
99db24d
clear query parameters from input box when loading another file
Henry8192 Feb 28, 2025
691a911
startQuery should first check the corner case before incrementing que…
Henry8192 Feb 28, 2025
59c8f04
Merge branch 'main' into share-link-with-search-params
Henry8192 Mar 10, 2025
82b39d1
fix previous merging issues; fix copyPermalinkToClipboard queryString…
Henry8192 Mar 10, 2025
7f240e6
Merge branch 'main' into share-link-with-search-params
Henry8192 Mar 11, 2025
0153d36
Merge remote-tracking branch 'yscope/main' into share-link-with-searc…
Henry8192 Mar 20, 2025
eec0016
simplify startQuery function parameter type to QueryArgs
Henry8192 Mar 24, 2025
43ab3ef
Merge branch 'main' into share-link-with-search-params
Henry8192 May 20, 2025
59b0403
finish merging main
Henry8192 May 20, 2025
7aac839
fix lint
Henry8192 May 20, 2025
3048c48
update package-lock.json
Henry8192 May 20, 2025
45d011d
fix link doesn't trigger a query; fix startQuery parameters mismatch
Henry8192 May 21, 2025
1af3cd2
Merge branch 'main' into share-link-with-search-params
Henry8192 May 23, 2025
afc5a99
fix lint
Henry8192 May 23, 2025
b59cc43
revert package-lock.json
Henry8192 May 23, 2025
d3c3e03
remove immutable setters from useEffect dependency array
Henry8192 May 25, 2025
5cc330d
Merge branch 'main' into share-link-with-search-params
junhaoliao May 27, 2025
8271ef5
revert startQuery parameter names
Henry8192 May 27, 2025
b80a83c
fix docstring
Henry8192 May 27, 2025
29eb72b
revert package-lock.json & reorganize jsdocs
Henry8192 May 27, 2025
923b5e5
address changes from code review
Henry8192 May 27, 2025
86733b6
address changes from code review
Henry8192 May 28, 2025
574a618
update AppController.tsx
Henry8192 May 28, 2025
930ee1d
address changes from code review
Henry8192 May 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/components/AppController.tsx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when the app loads, we should switch to the "Search" sidebar tab if the query-related parameters are found in the URL

@coderabbitai submit a feature request issue

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

I'll create a feature request issue for automatically switching to the Search sidebar tab when query parameters are present in the URL.

@junhaoliao I've created a feature request issue for automatically switching to the Search sidebar tab when query-related parameters are found in the URL. This will improve the user experience when people click on shared links with search parameters, as they'll immediately see the relevant search interface instead of having to manually switch tabs.


🏁 Script executed:

#!/bin/bash
# Create a GitHub issue for the feature request
gh issue create \
  --title "feat: Auto-switch to Search tab when query parameters are present in URL" \
  --body "## Feature Request

### Description
When the app loads and query-related parameters are found in the URL (such as \`queryString\`, \`queryIsRegex\`, or \`queryIsCaseSensitive\`), the application should automatically switch to the \"Search\" sidebar tab to provide a better user experience.

### Current Behavior
- Users can share URLs with search parameters (implemented in PR #173)
- When clicking a shared link with search parameters, the app loads with the default sidebar tab
- Users must manually switch to the Search tab to see the search interface

### Expected Behavior
- When the app detects query-related hash parameters in the URL during initialization
- The sidebar should automatically switch to the \"Search\" tab
- This provides immediate context for the shared search query

### Context
This enhancement was requested during the review of PR #173 which introduced URL sharing functionality for search parameters.

### References
- Related PR: https://github.com/y-scope/yscope-log-viewer/pull/173
- Original comment: https://github.com/y-scope/yscope-log-viewer/pull/173#discussion_r2155778816

### Implementation Notes
The query-related parameters to check for include:
- \`queryString\`
- \`queryIsRegex\` 
- \`queryIsCaseSensitive\`

Requested by: @junhaoliao" \
  --assignee junhaoliao

Length of output: 1450


@junhaoliao Perfect! I've successfully created the feature request issue for automatically switching to the Search sidebar tab when query parameters are present in the URL.

Issue created: #331

The issue includes:

  • Clear description of the desired behavior
  • Current vs expected behavior comparison
  • Implementation notes about which parameters to check for
  • References to this PR and your original comment
  • Assignment to you for tracking

This enhancement will definitely improve the user experience when people share and access search links, as they'll immediately see the search interface without having to manually switch tabs.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import useContextStore from "../stores/contextStore";
import useLogFileManagerStore from "../stores/logFileManagerProxyStore";
import useLogFileStore from "../stores/logFileStore";
import {handleErrorWithNotification} from "../stores/notificationStore";
import useQueryStore from "../stores/queryStore";
import useUiStore from "../stores/uiStore";
import useViewStore from "../stores/viewStore";
import {UI_STATE} from "../typings/states";
Expand Down Expand Up @@ -78,7 +79,9 @@ interface AppControllerProps {
* @return
*/
const AppController = ({children}: AppControllerProps) => {
const {filePath, isPrettified, logEventNum} = useContext(UrlContext);
const {
filePath, isPrettified, logEventNum, queryString, queryIsRegex, queryIsCaseSensitive,
} = useContext(UrlContext);

// States
const setLogEventNum = useContextStore((state) => state.setLogEventNum);
Expand All @@ -88,6 +91,7 @@ const AppController = ({children}: AppControllerProps) => {
const beginLineNumToLogEventNum = useViewStore((state) => state.beginLineNumToLogEventNum);
const setIsPrettified = useViewStore((state) => state.updateIsPrettified);
const updatePageData = useViewStore((state) => state.updatePageData);
const uiState = useUiStore((state) => state.uiState);
const setUiState = useUiStore((state) => state.setUiState);

// Refs
Expand Down Expand Up @@ -167,6 +171,36 @@ const AppController = ({children}: AppControllerProps) => {
loadFile,
]);

// Synchronize `queryIsCaseSensitive` with the Zustand QueryStore.
useEffect(() => {
if (null !== queryIsCaseSensitive) {
const {setQueryIsCaseSensitive} = useQueryStore.getState();
setQueryIsCaseSensitive(queryIsCaseSensitive);
}
}, [queryIsCaseSensitive]);

// Synchronize `queryIsRegex` with the Zustand QueryStore.
useEffect(() => {
if (null !== queryIsRegex) {
const {setQueryIsRegex} = useQueryStore.getState();
setQueryIsRegex(queryIsRegex);
}
}, [queryIsRegex]);

useEffect(() => {
if (null !== queryString) {
const {setQueryString} = useQueryStore.getState();
setQueryString(queryString);
}
if (UI_STATE.READY === uiState) {
const {startQuery} = useQueryStore.getState();
startQuery();
}
}, [
uiState,
queryString,
]);

return children;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import {useState} from "react";
import {
useCallback,
useState,
} from "react";

import {
AccordionGroup,
Box,
} from "@mui/joy";

import ShareIcon from "@mui/icons-material/Share";
import UnfoldLessIcon from "@mui/icons-material/UnfoldLess";
import UnfoldMoreIcon from "@mui/icons-material/UnfoldMore";

import {copyPermalinkToClipboard} from "../../../../../contexts/UrlContextProvider";
import useQueryStore from "../../../../../stores/queryStore";
import {
TAB_DISPLAY_NAMES,
Expand All @@ -27,29 +32,55 @@ import "./index.css";
* @return
*/
const SearchTabPanel = () => {
const queryIsCaseSensitive = useQueryStore((state) => state.queryIsCaseSensitive);
const queryIsRegex = useQueryStore((state) => state.queryIsRegex);
const queryString = useQueryStore((state) => state.queryString);
const queryResults = useQueryStore((state) => state.queryResults);

const [isAllExpanded, setIsAllExpanded] = useState<boolean>(true);

const handleCollapseAllButtonClick = () => {
const handleCollapseAllButtonClick = useCallback(() => {
setIsAllExpanded((v) => !v);
};
}, []);

const handleShareButtonClick = useCallback(() => {
copyPermalinkToClipboard({}, {
logEventNum: null,
queryString: "" === queryString ?
null :
queryString,
queryIsCaseSensitive: queryIsCaseSensitive,
queryIsRegex: queryIsRegex,
});
}, [
queryIsCaseSensitive,
queryIsRegex,
queryString,
]);

return (
<CustomTabPanel
tabName={TAB_NAME.SEARCH}
title={TAB_DISPLAY_NAMES[TAB_NAME.SEARCH]}
titleButtons={
<PanelTitleButton
title={isAllExpanded ?
"Collapse all" :
"Expand all"}
onClick={handleCollapseAllButtonClick}
>
{isAllExpanded ?
<UnfoldLessIcon/> :
<UnfoldMoreIcon/>}
</PanelTitleButton>
<>
<PanelTitleButton
title={isAllExpanded ?
"Collapse all" :
"Expand all"}
onClick={handleCollapseAllButtonClick}
>
{isAllExpanded ?
<UnfoldLessIcon/> :
<UnfoldMoreIcon/>}
</PanelTitleButton>
<PanelTitleButton
title={"Copy URL with search parameters"}
onClick={handleShareButtonClick}
>
<ShareIcon/>
</PanelTitleButton>
</>
}
>
<Box className={"search-tab-container"}>
Expand Down
26 changes: 25 additions & 1 deletion src/contexts/UrlContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint max-lines: ["error", 350] */
import React, {
createContext,
useEffect,
Expand Down Expand Up @@ -32,6 +33,9 @@ const URL_SEARCH_PARAMS_DEFAULT = Object.freeze({
const URL_HASH_PARAMS_DEFAULT = Object.freeze({
[HASH_PARAM_NAMES.IS_PRETTIFIED]: false,
[HASH_PARAM_NAMES.LOG_EVENT_NUM]: null,
[HASH_PARAM_NAMES.QUERY_IS_CASE_SENSITIVE]: false,
[HASH_PARAM_NAMES.QUERY_IS_REGEX]: false,
[HASH_PARAM_NAMES.QUERY_STRING]: null,
});

/**
Expand Down Expand Up @@ -102,7 +106,7 @@ const getUpdatedSearchParams = (updates: UrlSearchParamUpdatesType) => {
const getUpdatedHashParams = (updates: UrlHashParamUpdatesType) => {
const newHashParams = new URLSearchParams(window.location.hash.substring(1));
for (const [key, value] of Object.entries(updates)) {
if (null === value) {
if (null === value || false === value) {
newHashParams.delete(key);
} else {
newHashParams.set(key, String(value));
Expand Down Expand Up @@ -182,6 +186,10 @@ const getWindowUrlSearchParams = () => {
);
const urlSearchParams = new URLSearchParams(window.location.search.substring(1));

urlSearchParams.forEach((value, key) => {
searchParams[key as keyof UrlSearchParams] = value;
});

if (urlSearchParams.has(SEARCH_PARAM_NAMES.FILE_PATH)) {
// Split the search string and take everything after as `filePath` value.
// This ensures any parameters following `filePath=` are incorporated into the `filePath`.
Expand Down Expand Up @@ -218,6 +226,22 @@ const getWindowUrlHashParams = () => {
parsed;
}

const queryString = hashParams.get(HASH_PARAM_NAMES.QUERY_STRING);
if (null !== queryString) {
urlHashParams[HASH_PARAM_NAMES.QUERY_STRING] = queryString;
}

const queryIsCaseSensitive = hashParams.get(HASH_PARAM_NAMES.QUERY_IS_CASE_SENSITIVE);
if (null !== queryIsCaseSensitive) {
urlHashParams[HASH_PARAM_NAMES.QUERY_IS_CASE_SENSITIVE] =
"true" === queryIsCaseSensitive;
}

const queryIsRegex = hashParams.get(HASH_PARAM_NAMES.QUERY_IS_REGEX);
if (null !== queryIsRegex) {
urlHashParams[HASH_PARAM_NAMES.QUERY_IS_REGEX] = "true" === queryIsRegex;
}

const isPrettified = hashParams.get(HASH_PARAM_NAMES.IS_PRETTIFIED);
if (null !== isPrettified) {
urlHashParams[HASH_PARAM_NAMES.IS_PRETTIFIED] = "true" === isPrettified;
Expand Down
2 changes: 1 addition & 1 deletion src/services/LogFileManagerProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class LogFileManagerProxy {
*/
#getLogFileManager (): LogFileManager {
if (null === this.logFileManager) {
throw new Error("LogFileManager hasn't initialized");
throw new Error("LogFileManager hasn't been initialized");
}

return this.logFileManager;
Expand Down
6 changes: 6 additions & 0 deletions src/typings/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ enum SEARCH_PARAM_NAMES {
enum HASH_PARAM_NAMES {
LOG_EVENT_NUM = "logEventNum",
IS_PRETTIFIED = "isPrettified",
QUERY_IS_CASE_SENSITIVE = "queryIsCaseSensitive",
QUERY_IS_REGEX = "queryIsRegex",
QUERY_STRING = "queryString",
}

interface UrlSearchParams {
Expand All @@ -17,6 +20,9 @@ interface UrlSearchParams {
interface UrlHashParams {
[HASH_PARAM_NAMES.IS_PRETTIFIED]: boolean;
[HASH_PARAM_NAMES.LOG_EVENT_NUM]: number;
[HASH_PARAM_NAMES.QUERY_IS_CASE_SENSITIVE]: boolean;
[HASH_PARAM_NAMES.QUERY_IS_REGEX]: boolean;
[HASH_PARAM_NAMES.QUERY_STRING]: string;
}

type UrlSearchParamUpdatesType = {
Expand Down