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

add header search bar #81

Merged
merged 12 commits into from
Apr 17, 2023
Merged

add header search bar #81

merged 12 commits into from
Apr 17, 2023

Conversation

frzifus
Copy link
Contributor

@frzifus frzifus commented Apr 11, 2023

This pr is a poc for a search bar based on the fzf lib.

In addition to the listings of aws, gcp and azure images, another tab leading to a search is added. There you will find an unoptimized search, which renders all hits as links to the detail api point in the page.

image
image

Closes #75

deprecated details

Example:

grafik

During the implementation, I noticed that there is no modal for a detailed view of the images. This means that it is not possible to share specific images as a link. Does it make sense to add a route for it?

Another point is the search. Maybe it makes more sense to put the bar immediately in the "headline" and limit the suggestions (hits with the highest score) to 5-10 items. Similar to the google search.

grafik

wdyt @FKolwa @major @schogges @miyunari ?

Copy link
Contributor Author

@frzifus frzifus left a comment

Choose a reason for hiding this comment

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

Well done @FKolwa! I like the new search performance 🥇

src/app/routes.tsx Outdated Show resolved Hide resolved
Comment on lines 27 to 29
React.useEffect(() => {
loadData()
})
Copy link
Contributor

@schogges schogges Apr 14, 2023

Choose a reason for hiding this comment

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

I guess loadData should only run when Search is getting mounted. Therefore I would recommend to add an empty dependency array, otherwise it would run on every render.

Suggested change
React.useEffect(() => {
loadData()
})
React.useEffect(() => {
loadData()
}, [])

Same for the effect in src/app/Pages/Browser/Search.tsx, not sure what will stay 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The behavior was already discovered, but interesting fix 😄

Copy link
Member

Choose a reason for hiding this comment

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

I guess loadData should only run when Search is getting mounted. Therefore I would recommend to add an empty dependency array, otherwise it would run on every render.

Same for the effect in src/app/Pages/Browser/Search.tsx, not sure what will stay 🙂

Nice, great find! The sad thing is I ran into an issue on the image detail view in which the component stayed mounted after selecting a new image version which had the exact same fix (by monitoring the props passed in with the path) but I completely ignore this onEffect call.. face palm

frzifus and others added 4 commits April 15, 2023 10:13
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
Replace fzf with fuzzysort for more accuracy and performance
Highlight search results
Print results to application launcher window
Add new dynamic routes for /image/<provider>/<region>/<imageName>
Co-authored-by: Mo <mf.89@gmx.de>
@frzifus
Copy link
Contributor Author

frzifus commented Apr 15, 2023

@FKolwa @schogges do not wonder, I updated the branch and did some clean-up. 💅

One thing i noticed is, direct links do still not work.
image

@frzifus frzifus requested review from schogges and FKolwa April 15, 2023 08:24
@frzifus frzifus marked this pull request as ready for review April 15, 2023 08:25
@frzifus
Copy link
Contributor Author

frzifus commented Apr 15, 2023

@frzifus frzifus changed the title poc: search bar add header search bar Apr 15, 2023
@FKolwa
Copy link
Member

FKolwa commented Apr 15, 2023

One thing i noticed is, direct links do still not work. !

Yeah thats an issue for the WSGI server (the webpack server) running on your local machine. I think this is related to the missing 404 redirect in the development environment. The one page application is redirecting subdirectory calls to the router (or simpler, calls index.html) and renders the subpage accordingly. This works fine in our staging environment or in production but the webpack server does not (yet) know how to handle these calls. We should open an issue for that.

@FKolwa
Copy link
Member

FKolwa commented Apr 15, 2023

Weird https://localhost:9000/browser/google/global/rhel_9_arm64 does work, while https://localhost:9000/browser/google/global/rhel_8.2_sap_x86_64 does not. 🦝

Yeah I ran into the exact same thing. I don't know why some of them are properly redirect and others won't. In prod the CDN handles the proper redirect just fine, the dev server doesn't..

Copy link
Member

@FKolwa FKolwa left a comment

Choose a reason for hiding this comment

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

Only a little cleanup left and the missing package-lock changes need to be committed but everything else looks amazing! Thanks for doing this!

package.json Outdated Show resolved Hide resolved
src/app/components/Search.tsx Outdated Show resolved Hide resolved
@@ -45,19 +47,25 @@ const routes: AppRouteConfig[] = [
component: <AWSImageBrowser title='Cloud Image Directory | AWS Image Browser'/>,
exact: true,
label: 'AWS',
path: '/browser/AWS',
path: '/browser/aws',
Copy link
Member

Choose a reason for hiding this comment

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

Nice, thanks for fixing this.
This always annoyed me and I always forgot to fix it in the end

Copy link
Contributor

@schogges schogges left a comment

Choose a reason for hiding this comment

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

Well done everyone, this is working pretty smooth 🎉 👍 I just checked out the branch locally and have some more feedback 🙂


return (
<>
{/* TODO: https://hy.reactjs.org/docs/hooks-reference.html#usecallback */}
Copy link
Contributor

Choose a reason for hiding this comment

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

This TODO seems to be misplaced now. I guess this was meant to be a TODO for handleChange 🤔 🙂

src/app/components/Search.tsx Outdated Show resolved Hide resolved
src/app/components/Search.tsx Outdated Show resolved Hide resolved
src/app/Pages/ImageDetails.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@schogges schogges left a comment

Choose a reason for hiding this comment

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

🚀

frzifus and others added 5 commits April 16, 2023 10:10
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
Co-authored-by: FKolwa <47077340+FKolwa@users.noreply.github.com>
Co-authored-by: Mo <mf.89@gmx.de>
Co-authored-by: Mo <mf.89@gmx.de>
@frzifus frzifus force-pushed the poc_search branch 3 times, most recently from 18a2fff to 9cec98b Compare April 16, 2023 08:33
@frzifus
Copy link
Contributor Author

frzifus commented Apr 16, 2023

hm... seems there is still an issue with fetch in the unittests. if i understand it correctly, the problem is that fetch is not available. Which confuses me a bit. It should be available since v18.x that is used in the CI.

Anyway, I tried to install node-fetch. But that seems to expect types. Adding the type Map<string, number> as data response type in app/components/ImageDataTable.tsx fixed this, but when i tried to run webpack-dev afterwards, it seemed like hundreds of packages were missing.

For now, I have reverted the changes, what would you suggest to fix this? @FKolwa @schogges ? 🐎


https://stackoverflow.com/questions/48433783/referenceerror-fetch-is-not-defined

@FKolwa
Copy link
Member

FKolwa commented Apr 16, 2023

Anyway, I tried to install node-fetch. But that seems to expect types. Adding the type Map<string, number> as data response type in app/components/ImageDataTable.tsx fixed this, but when i tried to run webpack-dev afterwards, it seemed like hundreds of packages were missing.

Hmm. Okay so one problem is that fetch is a browser specific tool. As our jest tests aren't running in an actual browser fetch is simply not available. We didn't have this issue in our tests so far because they weren't testing anything where fetch was executed. Jest can run in different test environments, one of them is node. The node-fetch package was specifically made for enabling fetch in node. Our current test environment uses jsdom instead of node which at this moment doesn't support fetch (jestjs/jest#13834) .

So I'd say there are at least two ways of doing this: Further try to find a way around fetch in jsdom or try to rewrite our tests to use node instead (and require node-fetch in test-setup.js).

What do you think? @frzifus @schogges

@schogges
Copy link
Contributor

schogges commented Apr 16, 2023

Seems like even though they announced to remove the --experimental-fetch flag with release of v18, this was not the case.
I guess the easiest way to fix this now would be to use platform agnostic cross-fetch.
Another option for the future might be to use something like react-query as it ships some more features like caching, state values (isLoading, error, ...) and more 🙂

@FKolwa
Copy link
Member

FKolwa commented Apr 16, 2023

Seems like even though they announced to remove the --experimental-fetch flag with release of v18, this was not the case. I guess the easiest way to fix this now would be to use platform agnostic cross-fetch. Another option for the future might be to use something like react-query as it ships some more features like caching, state values (isLoading, error, ...) and more 🙂

I like it! I'd say we go with cross-fetch for now to keep within the scope of the issue and create a new issue to transition to react-query. That'll be a great replacement for the fetch calls we use to create the tables in our browser views.

@frzifus
Copy link
Contributor Author

frzifus commented Apr 16, 2023

Ok, i will try to change it once iam home :)

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
Copy link
Member

@FKolwa FKolwa left a comment

Choose a reason for hiding this comment

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

@frzifus @schogges Amazing work everyone, thanks for the collaboration on this.
(created two follow up issues #83 and #84 )

src/app/components/Search.tsx Outdated Show resolved Hide resolved
@FKolwa FKolwa merged commit c88c76d into redhatcloudx:main Apr 17, 2023
@frzifus frzifus deleted the poc_search branch April 17, 2023 05:32
@frzifus
Copy link
Contributor Author

frzifus commented Apr 17, 2023

oh i guess it would have been better to squash all this back and forth. 😵‍💫 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add search functionality within image names
3 participants