chore: remove addition of numberOfResults from PgSearchEngine
Signed-off-by: Phil Berryman <phil@berryman.org.uk>
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
'@backstage/plugin-search-backend': minor
|
||||
'@backstage/plugin-search-backend-module-elasticsearch': minor
|
||||
'@backstage/plugin-search-backend-node': minor
|
||||
'@backstage/plugin-search-backend-module-pg': minor
|
||||
---
|
||||
|
||||
numberOfResults is now provided alongside the query result
|
||||
|
||||
@@ -231,7 +231,6 @@ describe('PgSearchEngine', () => {
|
||||
},
|
||||
],
|
||||
nextPageCursor: undefined,
|
||||
numberOfResults: 1,
|
||||
});
|
||||
expect(database.transaction).toHaveBeenCalledTimes(1);
|
||||
expect(database.query).toHaveBeenCalledWith(tx, {
|
||||
@@ -289,7 +288,6 @@ describe('PgSearchEngine', () => {
|
||||
},
|
||||
})),
|
||||
nextPageCursor: 'MQ==',
|
||||
numberOfResults: 30,
|
||||
});
|
||||
expect(database.transaction).toHaveBeenCalledTimes(1);
|
||||
expect(database.query).toHaveBeenCalledWith(tx, {
|
||||
@@ -350,7 +348,6 @@ describe('PgSearchEngine', () => {
|
||||
}))
|
||||
.slice(25),
|
||||
previousPageCursor: 'MA==',
|
||||
numberOfResults: 5,
|
||||
});
|
||||
expect(database.transaction).toHaveBeenCalledTimes(1);
|
||||
expect(database.query).toHaveBeenCalledWith(tx, {
|
||||
|
||||
@@ -194,7 +194,6 @@ export class PgSearchEngine implements SearchEngine {
|
||||
const previousPageCursor = hasPreviousPage
|
||||
? encodePageCursor({ page: page - 1 })
|
||||
: undefined;
|
||||
const numberOfResults = rows.length;
|
||||
|
||||
const results = pageRows.map(
|
||||
({ type, document, highlight }, index): IndexableResult => ({
|
||||
@@ -216,7 +215,7 @@ export class PgSearchEngine implements SearchEngine {
|
||||
}),
|
||||
);
|
||||
|
||||
return { results, nextPageCursor, previousPageCursor, numberOfResults };
|
||||
return { results, nextPageCursor, previousPageCursor };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,24 +17,34 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import { useAnalytics } from '@backstage/core-plugin-api';
|
||||
import { useSearch } from '../../context';
|
||||
import usePrevious from 'react-use/lib/usePrevious';
|
||||
|
||||
/**
|
||||
* Capture search event on term change.
|
||||
*/
|
||||
export const TrackSearch = ({ children }: { children: React.ReactChild }) => {
|
||||
const useHasChanged = (value: any) => {
|
||||
const previousVal = usePrevious(value);
|
||||
return previousVal !== value;
|
||||
};
|
||||
|
||||
const analytics = useAnalytics();
|
||||
const { term, result } = useSearch();
|
||||
|
||||
const numberOfResults = result.value?.numberOfResults ?? undefined;
|
||||
|
||||
// Stops the analtyics event from firing before the new search engine response is returned
|
||||
const hasStartedLoading = useHasChanged(result.loading);
|
||||
const hasFinishedLoading = hasStartedLoading && !result.loading;
|
||||
|
||||
useEffect(() => {
|
||||
if (term) {
|
||||
// Capture analytics search event with search term provided as value
|
||||
if (term && hasFinishedLoading) {
|
||||
// Capture analytics search event with search term and numberOfResults (provided as value)
|
||||
analytics.captureEvent('search', term, {
|
||||
value: numberOfResults,
|
||||
});
|
||||
}
|
||||
}, [analytics, term, numberOfResults]);
|
||||
}, [analytics, term, numberOfResults, hasFinishedLoading]);
|
||||
|
||||
return <>{children}</>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user