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

feat(infinite-hits): add top banner to InfiniteHits widget #6243

Merged
merged 10 commits into from
Jun 27, 2024

Conversation

taylorcjohnson
Copy link
Contributor

@taylorcjohnson taylorcjohnson commented Jun 18, 2024

Summary

A series of PRs recently added a top banner to the Hits widget (visibility is controlled by rules that update renderingContent for a given query). This PR implements the same feature, but for the InfiniteHits widget.

This was done by:

  1. updating connectInfiniteHits (previous PR)
  2. updating InfiniteHits JS component
  3. updating infinite-hits JS widget
  4. updating InfiniteHits React component
  5. updating InfiniteHits React widget
  6. updating satellite.scss and algolia.scss

Related tickets:

Result

JS Hits, default banner:
image

JS InfiniteHits, default banner:
image

JS InfiniteHits, default banner, no results:
image

React Hits, default banner:
image

React InfiniteHits, default banner:
image

React InfiniteHits, default banner, no results:
image

Copy link

codesandbox-ci bot commented Jun 18, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 816a51b:

Sandbox Source
example-instantsearch-getting-started Configuration
example-react-instantsearch-getting-started Configuration
example-react-instantsearch-next-app-dir-example Configuration
example-react-instantsearch-next-routing-example Configuration
example-vue-instantsearch-getting-started Configuration

@taylorcjohnson taylorcjohnson changed the title wip(infinite-hits): add banner to js component and widget feat(infinite-hits): add top banner to InfiniteHits widget Jun 21, 2024
Comment on lines +102 to +126
<div
className={cx(cssClasses.root, cssClasses.emptyRoot)}
onClick={handleInsightsClick}
>
{banner &&
(templateProps.templates.banner ? (
<Template
{...templateProps}
templateKey="banner"
rootTagName="fragment"
data={{
banner,
className: cssClasses.bannerRoot,
}}
/>
) : (
<DefaultBanner banner={banner} classNames={cssClasses} />
))}
<Template
{...templateProps}
templateKey="empty"
rootTagName="fragment"
data={results}
/>
</div>
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 empty template fragment is being hoisted above the banner (even though the banner is above it in the DOM here). Any suggestions for forcing the expected layout (see Hits example in image below) without adding additional DOM nodes?

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aymeric-giraudet or @Haroenv - any thoughts on this?

Copy link
Member

Choose a reason for hiding this comment

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

That's odd @taylorcjohnson, is it related to CSS ?
How does it look like without our CSS stylesheets ? Maybe this should just be solved within instantsearch.css

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't believe so, @aymeric-giraudet - I removed the css to verify, but the DOM still shows a difference.

image

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's the right solution, but what happens if you put the no results template in a div or give it a root tag name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then it works as expected 😢 (either wrapping the empty template component in a div or changing the rootTagName to something else (like a div).

Copy link
Member

Choose a reason for hiding this comment

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

Ah I think this may be due to the RawHtml component which is a hack for supporting Hogan with fragments, I'll check for a fix tomorrow morning :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ok, I was hoping I was just missing some background context somewhere. If you can take a look I'd really appreciate it otherwise I can attempt as well.


export type InfiniteHitsComponentCSSClasses =
ComponentCSSClasses<InfiniteHitsCSSClasses>;
export type InfiniteHitsComponentTemplates = Required<InfiniteHitsTemplates>;
export type InfiniteHitsComponentTemplates = InfiniteHitsTemplates;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This reassignment probably isn't needed anymore - unless we really need to keep the Required<> wrapper.

Copy link
Member

Choose a reason for hiding this comment

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

It's fine to keep if other widgets do this I guess

@taylorcjohnson taylorcjohnson self-assigned this Jun 21, 2024
@taylorcjohnson taylorcjohnson requested review from a team, sarahdayan, Haroenv and aymeric-giraudet and removed request for a team June 21, 2024 22:37
@taylorcjohnson taylorcjohnson marked this pull request as ready for review June 21, 2024 22:37
Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

code looks good, but this should be tested in common test suite, not in the flavour specific tests :)

@taylorcjohnson
Copy link
Contributor Author

code looks good, but this should be tested in common test suite, not in the flavour specific tests :)

Hey @Haroenv - sorry, this is the first I am learning about the common test suite. Does that refer to everything in tests/common/widgets/infinite-hits?

If so, do we need to update the tests for hits as well? I did not touch those tests when adding the banner to the hits widget.

And are you saying that I should remove the banner related tests for both hits and infinite-hits in the flavor specific tests? Or that the tests in /common and the flavor specific tests should be updated to test for the banner?

@Haroenv
Copy link
Contributor

Haroenv commented Jun 24, 2024

Ah sorry I didn't notice the tests weren't done in cts for the hits implementation. Ideally yes you'd probably add a new file (suite) inside the common test suite, and also for hits. the flavour specific tests can be removed, unless it's something that exists only in one of the flavours

@taylorcjohnson
Copy link
Contributor Author

taylorcjohnson commented Jun 24, 2024

@Haroenv thanks - I'll work on adding tests here for infinite-hits (and hits, unless you'd prefer that in a separate PR). I think we should leave the additional tests in the specific flavors since the banner feature is only supported in JS and React for right now (though the tentative plan is to add it for Vue as well in the near future). What do you think?

@Haroenv
Copy link
Contributor

Haroenv commented Jun 25, 2024

all tests should go exclusively in CTS when supported in more than one flavour, or planned to be. Thanks! Reach out if you are stuck somewhere

Copy link
Member

@aymeric-giraudet aymeric-giraudet left a comment

Choose a reason for hiding this comment

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

Thanks for the common test suite, looks good to me ! 👍

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

good for me, even though the order on empty isn't right. Not sure that matters much for now, we may even consider leaving it as-is, as I assume the banner on empty won't be that popular together with an empty template.

I'm even tempted to not display the banner on empty at all, although that would be inconsistent with Hits then.

@aymeric-giraudet aymeric-giraudet merged commit 9287532 into master Jun 27, 2024
12 checks passed
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.

3 participants