Skip to content

Commit 5bde60d

Browse files
taylorcjohnsonHaroenvaymeric-giraudet
authored
feat(hits): return banner from connectHits (#6130)
* feat(hits): return banner from connectHits * chore(hits): update bundle size * chore(hits): exclude connectHits-test.ts from v3 tsconfig * chore(hits): temporarily ignore ts error until js client types updated * fix(hits): make the banner image url required * fix(hits): image type is object instead of array * fix(hits): use correct target values Co-authored-by: Haroen Viaene <[email protected]> --------- Co-authored-by: Haroen Viaene <[email protected]> Co-authored-by: Aymeric Giraudet <[email protected]>
1 parent 786f496 commit 5bde60d

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

bundlesize.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
{
2020
"path": "packages/react-instantsearch-core/dist/umd/ReactInstantSearchCore.min.js",
21-
"maxSize": "47.25 kB"
21+
"maxSize": "47.5 kB"
2222
},
2323
{
2424
"path": "packages/react-instantsearch/dist/umd/ReactInstantSearch.min.js",

packages/algoliasearch-helper/index.d.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,49 @@ declare namespace algoliasearchHelper {
13261326
};
13271327
};
13281328
};
1329+
/**
1330+
* Defining UI widget configuration
1331+
*/
1332+
widgets?: {
1333+
/**
1334+
* Configuration for banners
1335+
*/
1336+
banners?: Array<{
1337+
/**
1338+
* Configuration for the banner image
1339+
*/
1340+
image: {
1341+
/**
1342+
* Set of possible URLs of the banner image
1343+
*/
1344+
urls: Array<{
1345+
/**
1346+
* URL of the banner image
1347+
*/
1348+
url: string;
1349+
}>;
1350+
/**
1351+
* Alt text of the banner image
1352+
*/
1353+
title?: string;
1354+
};
1355+
/**
1356+
* Configuration for the banner click navigation
1357+
*/
1358+
link?: {
1359+
/**
1360+
* URL to navigate to when the banner is clicked
1361+
*/
1362+
url?: string;
1363+
/**
1364+
* Target of the navigation
1365+
* - `_blank` opens the URL in a new tab
1366+
* - `_self` opens the URL in the same tab
1367+
*/
1368+
target?: '_blank' | '_self';
1369+
};
1370+
}>;
1371+
};
13291372
};
13301373

13311374
/**

packages/instantsearch.js/src/connectors/hits/__tests__/connectHits-test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,12 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
498498
const helper = algoliasearchHelper(createSearchClient(), 'indexName', {
499499
index: 'indexName',
500500
});
501+
const banner = { image: { urls: [{ url: 'https://example.com' }] } };
502+
const renderingContent = {
503+
widgets: {
504+
banners: [banner],
505+
},
506+
};
501507

502508
const renderState1 = hitsWidget.getRenderState(
503509
{},
@@ -506,6 +512,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
506512

507513
expect(renderState1.hits).toEqual({
508514
hits: [],
515+
banner: undefined,
509516
sendEvent: expect.any(Function),
510517
bindEvent: expect.any(Function),
511518
results: undefined,
@@ -518,7 +525,13 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
518525
];
519526

520527
const results = new SearchResults(helper.state, [
521-
createSingleSearchResponse({ hits, queryID: 'theQueryID' }),
528+
createSingleSearchResponse({
529+
hits,
530+
queryID: 'theQueryID',
531+
// @TODO: remove once algoliasearch js client has been updated
532+
// @ts-expect-error
533+
renderingContent,
534+
}),
522535
]);
523536

524537
const renderState2 = hitsWidget.getRenderState(
@@ -537,6 +550,7 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits/js/#co
537550

538551
expect(renderState2.hits).toEqual({
539552
hits: expectedHits,
553+
banner,
540554
sendEvent: renderState1.hits.sendEvent,
541555
bindEvent: renderState1.hits.bindEvent,
542556
results,

packages/instantsearch.js/src/connectors/hits/connectHits.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ const connectHits: HitsConnector = function connectHits(
146146
return {
147147
hits: [],
148148
results: undefined,
149+
banner: undefined,
149150
sendEvent,
150151
bindEvent,
151152
widgetParams,
@@ -172,9 +173,12 @@ const connectHits: HitsConnector = function connectHits(
172173
{ results }
173174
);
174175

176+
const banner = results.renderingContent?.widgets?.banners?.[0];
177+
175178
return {
176179
hits: transformedHits,
177180
results,
181+
banner,
178182
sendEvent,
179183
bindEvent,
180184
widgetParams,

tsconfig.v3.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// v3 has a wrong definition for optionalWords (only accepts string[])
1717
"packages/instantsearch.js/src/connectors/voice-search/__tests__/connectVoiceSearch-test.ts",
1818
// v3 does not have renderingContent (only errors in the test)
19+
"packages/instantSearch.js/src/connectors/hits/__tests__/connectHits-test.ts",
1920
"packages/instantsearch.js/src/connectors/dynamic-widgets/__tests__/connectDynamicWidgets-test.ts",
2021
"packages/instantsearch.js/src/connectors/hierarchical-menu/__tests__/connectHierarchicalMenu-test.ts",
2122
"packages/instantsearch.js/src/connectors/menu/__tests__/connectMenu-test.ts",

0 commit comments

Comments
 (0)