Skip to content
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

[Workspace] Add global search bar into left nav #8538

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

Hailong-am
Copy link
Collaborator

@Hailong-am Hailong-am commented Oct 10, 2024

Description

This PR is add search bar into left nav, the search bar supports search pages in and out of workspace.

saved objects is not supported yet.

globalsearch.mov

Issues Resolved

part of #1854
and #4055

Screenshot

Testing the changes

Changelog

  • feat: [Workspace] Add global search bar into left nav

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

@Hailong-am Hailong-am changed the title [] [Workspace] Add search bar into left nav Oct 10, 2024
Copy link
Contributor

❌ Empty Changelog Section

The Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section.

Copy link
Contributor

❌ Empty Changelog Section

The Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section.

Copy link

codecov bot commented Oct 10, 2024

Codecov Report

Attention: Patch coverage is 77.21519% with 36 lines in your changes missing coverage. Please review.

Project coverage is 60.94%. Comparing base (794757d) to head (ea06fd1).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...core/public/chrome/ui/header/header_search_bar.tsx 77.77% 12 Missing and 2 partials ⚠️
...pace/public/components/global_search/page_item.tsx 80.00% 4 Missing and 1 partial ⚠️
.../components/global_search/search_pages_command.tsx 77.27% 2 Missing and 3 partials ⚠️
src/plugins/dev_tools/public/dev_tools_icon.tsx 50.00% 3 Missing ⚠️
src/plugins/dev_tools/public/plugin.ts 70.00% 3 Missing ⚠️
...chrome/ui/header/collapsible_nav_group_enabled.tsx 33.33% 0 Missing and 2 partials ⚠️
src/plugins/workspace/public/plugin.ts 33.33% 2 Missing ⚠️
src/core/public/chrome/chrome_service.mock.ts 0.00% 1 Missing ⚠️
src/plugins/dev_tools/public/application.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8538      +/-   ##
==========================================
- Coverage   60.95%   60.94%   -0.01%     
==========================================
  Files        3777     3786       +9     
  Lines       89641    89904     +263     
  Branches    14046    14091      +45     
==========================================
+ Hits        54643    54796     +153     
- Misses      31584    31692     +108     
- Partials     3414     3416       +2     
Flag Coverage Δ
Linux_1 29.10% <33.07%> (+0.01%) ⬆️
Linux_2 56.34% <78.75%> (+0.06%) ⬆️
Linux_3 37.67% <24.07%> (-0.08%) ⬇️
Linux_4 29.89% <6.25%> (-0.04%) ⬇️
Windows_1 29.13% <33.07%> (+0.03%) ⬆️
Windows_2 56.30% <78.75%> (+0.06%) ⬆️
Windows_3 37.67% <24.07%> (-0.08%) ⬇️
Windows_4 29.88% <6.25%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

❌ Entry Too Long

Entry is 107 characters long, which is 7 characters longer than the maximum allowed length of 100 characters. Please revise your entry to be within the maximum length.

opensearch-changeset-bot bot added a commit to Hailong-am/OpenSearch-Dashboards that referenced this pull request Oct 10, 2024
Signed-off-by: Hailong Cui <[email protected]>

search bar on left nav

Signed-off-by: Hailong Cui <[email protected]>

compressed input

Signed-off-by: Hailong Cui <[email protected]>
Signed-off-by: Hailong Cui <[email protected]>
Signed-off-by: Hailong Cui <[email protected]>

add more unit test

Signed-off-by: Hailong Cui <[email protected]>
@Hailong-am Hailong-am changed the title [Workspace] Add search bar into left nav [Workspace] Add global search bar into left nav Oct 10, 2024
@Hailong-am Hailong-am marked this pull request as ready for review October 10, 2024 05:00
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const [panelWidth, setPanelWidth] = useState(0);
const inputRef = (node: HTMLElement | null) => setInputEl(node);
const [inputEl, setInputEl] = useState<HTMLElement | null>(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use ref object to store the button ref? There is a extra rendering after setInputEl called.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is by intention, inputEl is used as dependency for resize.

const onResize = useCallback(() => {
    if (inputEl) {
      const width = inputEl.getBoundingClientRect().width;
      setPanelWidth(width);
    }
  }, [inputEl, setPanelWidth]);

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to regenerate onResize after every inputEl change? I'm prefer using code below if doesn't update every time.

const inputElRef = useRef<HTMLElement | null>(null);
const inputRef = (node: HTMLElement | null) => inputElRef.current = node;

const onResize = useCallback(() => {
    if (inputElRef.current) {
      const width = inputElRef.current.getBoundingClientRect().width;
      setPanelWidth(width);
    }
  }, []);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Found that we can remove onResize as it will adjust the panel width when focus.

and changed to const inputElRef = useRef<HTMLElement | null>(null); as well.

Signed-off-by: Hailong Cui <[email protected]>
/**
* @experimental
*/
export interface GlobalSearchStrategy {
Copy link
Member

Choose a reason for hiding this comment

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

Can we not use search strategy as the name? We already have a concept of search strategy in the application. This is used for the actual search queries. Lets call these commands. Here is a really good extensible model that VS code uses for their global search. https://code.visualstudio.com/api/references/contribution-points#contributes.commands

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

rename it to searchCommand

* @param value search query
* @param callback callback function when search is done
*/
doSearch(value: string, callback?: () => void): Promise<ReactNode[]>;
Copy link
Member

Choose a reason for hiding this comment

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

How about run. This works well with the term command too. So it will be command.run(props)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

rename this method name to run as well

@ashwin-pc
Copy link
Member

ashwin-pc commented Oct 11, 2024

So here's what i had in mind for that project (And we can impliment a subset of that today for the sake of time)

  1. We have a global command service
  2. We also have a global search bar
  3. The default behaviour of the search bar is to search for applications/pages
  4. if the @ symbol is specified we search for saved objects
  5. If the > is specified, we show the available commands using the command service

Plugins can only register commands. Pages and saved objects are used by default but we dont expose this

This is very similar to how VS code does it and its really elagant.

cc: @kgcreative

If we dont want to go that far right now, lets keep the search bar simple and not expose any API's. This is not something we need to rush and will not be easy to walk back on in the future :)

@Hailong-am
Copy link
Collaborator Author

So here's what i had in mind for that project (And we can impliment a subset of that today for the sake of time)

  1. We have a global command service
  2. We also have a global search bar
  3. The default behaviour of the search bar is to search for applications/pages
  4. if the @ symbol is specified we search for saved objects
  5. If the > is specified, we show the available commands using the command service

Plugins can only register commands. Pages and saved objects are used by default but we dont expose this

This is very similar to how VS code does it and its really elagant.

cc: @kgcreative

If we dont want to go that far right now, lets keep the search bar simple and not expose any API's. This is not something we need to rush and will not be easy to walk back on in the future :)

Thanks for sharing your thought on this,

  1. saved objects search will come with next PR
  2. we can have some examples/use cases of commands after that we can have it implemented

Signed-off-by: Hailong Cui <[email protected]>
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.

3 participants