Skip to content

feat: add search history for search page #749

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 8 commits into from
Apr 17, 2025

Conversation

LYHuang
Copy link

@LYHuang LYHuang commented Apr 11, 2025

  • save search history for search page
  • record number limit to 10
  • add search history relate function
  • support both sql and lucene search
  • test
Screen.Recording.2025-04-14.at.4.55.34.AM.mov

ref: hdx-1565

Copy link

changeset-bot bot commented Apr 11, 2025

🦋 Changeset detected

Latest commit: b524242

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@hyperdx/app Patch
@hyperdx/api Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

- save search history for search page
- record number limit to 10
- add search history relate function
- support both sql and lucene search
- test

ref: hdx-1565
@LYHuang LYHuang force-pushed the mh/hdx-1565-save-search-history branch from b7ea626 to 1e6ba3b Compare April 11, 2025 16:13
@LYHuang LYHuang marked this pull request as ready for review April 14, 2025 12:03
@@ -149,6 +200,7 @@ export default function SQLInlineEditor({

const updateAutocompleteColumns = useCallback(
(viewRef: EditorView) => {
const currentText = viewRef.state.doc.toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a note (and this is probably fine for now, but just calling it out). If a user were to search for a value while in other places in the app (see screenshot), that particular search doesn't show up in the search history. I think it's natural given that we are only capturing true user input, but I wanted to call it out so it's known.

image

Copy link
Author

Choose a reason for hiding this comment

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

good call, I will make a ticket for this.

@LYHuang LYHuang requested a review from teeohhem April 15, 2025 09:58
}
};
return [queryHistory, setQueryHistory] as const;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this can be simplified to

const setQueryHistory = (query: string) => {
  try {
    const trimmed = query.trim();
    if (!type || !trimmed) return;

    const deduped = [trimmed, ...queryHistory.filter(q => q !== trimmed)];
    const limited = deduped.slice(0, QUERY_LOCAL_STORAGE.LIMIT);

    _setQueryHistory(limited);
  } catch (e) {
    console.log(`Failed to cache query history: ${e.message}`);
  }
};

Copy link
Author

Choose a reason for hiding this comment

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

yeah, good call, I don't have to dedupe whole localStorage.

value.length === 0 &&
queryHistoryType &&
queryHistoryList.length > 0 && (
<div className="border-top border-dark fs-8 py-2">
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: for readability and transparency, you could make this a var
const shouldShowSearchHistory = value.length === 0 && queryHistoryType && queryHistoryList.length > 0;

onClick={() => {
onSelectSearchHistory(value);
}}
>
Copy link
Contributor

@teeohhem teeohhem Apr 16, 2025

Choose a reason for hiding this comment

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

I know this seems minor, but I think we should be using actual buttons here instead of a div role="button" . The reason has to do with enhanced accessibility and tabbability in the UI.

{queryHistoryList.map(({ value, label }, i) => (
    <UnstyledButton
      key={value}
      className={clsx(
        'd-block w-100 text-start text-muted fw-normal px-3 py-2 fs-8',
        selectedQueryHistoryIndex === i && 'bg-hdx-dark'
      )}
      onMouseOver={() => setSelectedQueryHistoryIndex(i)}
      onClick={() => onSelectSearchHistory(value)}
    >
      <span className="me-1 text-truncate">{label}</span>
    </UnstyledButton>
  ))}

Copy link
Author

Choose a reason for hiding this comment

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

Sure thing, and thanks for the example, learn a lot from it.

@@ -213,6 +274,9 @@ export default function AutocompleteInput({
suggestedProperties[selectedAutocompleteIndex].value,
);
} else {
if (queryHistoryType) {
setQueryHistory(value);
}
onSubmit?.();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a heads up. In a separate PR, I will add icons for these as part of the larger story for adding icons next to items in the dropdown.

image

@LYHuang LYHuang closed this Apr 16, 2025
@LYHuang LYHuang reopened this Apr 16, 2025
Copy link

vercel bot commented Apr 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hyperdx-v2-oss-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 17, 2025 8:20pm

@kodiakhq kodiakhq bot merged commit 8c95b9e into v2 Apr 17, 2025
5 of 6 checks passed
@kodiakhq kodiakhq bot deleted the mh/hdx-1565-save-search-history branch April 17, 2025 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants