mirror of
https://github.com/Unleash/unleash.git
synced 2025-05-03 01:18:43 +02:00
feat: Plausible search (#4625)
This commit is contained in:
parent
31ed96d8f3
commit
15015f78f3
@ -21,10 +21,7 @@ const testDisplayComponent = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
test('should read saved query from local storage', async () => {
|
test('should read saved query from local storage', async () => {
|
||||||
const { value, setValue } = createLocalStorage(
|
const { setValue } = createLocalStorage('Search:localStorageId:v1', {});
|
||||||
'Search:localStorageId:v1',
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
setValue({
|
setValue({
|
||||||
query: 'oldquery',
|
query: 'oldquery',
|
||||||
});
|
});
|
||||||
|
@ -58,7 +58,9 @@ export const SearchDescription: VFC<ISearchDescriptionProps> = ({
|
|||||||
{filter.values.join(',')}
|
{filter.values.join(',')}
|
||||||
</StyledCode>{' '}
|
</StyledCode>{' '}
|
||||||
in {filter.header}. Options:{' '}
|
in {filter.header}. Options:{' '}
|
||||||
{filter.options.slice(0, 10).join(', ')}
|
{[...new Set(filter.options)]
|
||||||
|
.slice(0, 10)
|
||||||
|
.join(', ')}
|
||||||
</p>
|
</p>
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
|
@ -13,6 +13,7 @@ import {
|
|||||||
SearchInstructions,
|
SearchInstructions,
|
||||||
StyledCode,
|
StyledCode,
|
||||||
} from './SearchInstructions/SearchInstructions';
|
} from './SearchInstructions/SearchInstructions';
|
||||||
|
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
|
||||||
|
|
||||||
const StyledPaper = styled(Paper)(({ theme }) => ({
|
const StyledPaper = styled(Paper)(({ theme }) => ({
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
@ -55,13 +56,12 @@ interface SearchSuggestionsProps {
|
|||||||
|
|
||||||
const quote = (item: string) => (item.includes(' ') ? `"${item}"` : item);
|
const quote = (item: string) => (item.includes(' ') ? `"${item}"` : item);
|
||||||
|
|
||||||
const randomIndex = (arr: any[]) => Math.floor(Math.random() * arr.length);
|
|
||||||
|
|
||||||
export const SearchSuggestions: VFC<SearchSuggestionsProps> = ({
|
export const SearchSuggestions: VFC<SearchSuggestionsProps> = ({
|
||||||
getSearchContext,
|
getSearchContext,
|
||||||
onSuggestion,
|
onSuggestion,
|
||||||
savedQuery,
|
savedQuery,
|
||||||
}) => {
|
}) => {
|
||||||
|
const { trackEvent } = usePlausibleTracker();
|
||||||
const searchContext = getSearchContext();
|
const searchContext = getSearchContext();
|
||||||
|
|
||||||
const filters = getFilterableColumns(searchContext.columns)
|
const filters = getFilterableColumns(searchContext.columns)
|
||||||
@ -116,7 +116,14 @@ export const SearchSuggestions: VFC<SearchSuggestionsProps> = ({
|
|||||||
<StyledBox>
|
<StyledBox>
|
||||||
<StyledHistory />
|
<StyledHistory />
|
||||||
<StyledCode
|
<StyledCode
|
||||||
onClick={() => onSuggestion(savedQuery || '')}
|
onClick={() => {
|
||||||
|
onSuggestion(savedQuery || '');
|
||||||
|
trackEvent('search-filter-suggestions', {
|
||||||
|
props: {
|
||||||
|
eventType: 'saved query',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<span>{savedQuery}</span>
|
<span>{savedQuery}</span>
|
||||||
</StyledCode>
|
</StyledCode>
|
||||||
@ -146,7 +153,14 @@ export const SearchSuggestions: VFC<SearchSuggestionsProps> = ({
|
|||||||
searchableColumnsString={
|
searchableColumnsString={
|
||||||
searchableColumnsString
|
searchableColumnsString
|
||||||
}
|
}
|
||||||
onClick={onSuggestion}
|
onClick={suggestion => {
|
||||||
|
onSuggestion(suggestion);
|
||||||
|
trackEvent('search-filter-suggestions', {
|
||||||
|
props: {
|
||||||
|
eventType: 'filter',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
@ -159,9 +173,16 @@ export const SearchSuggestions: VFC<SearchSuggestionsProps> = ({
|
|||||||
show="Combine filters and search: "
|
show="Combine filters and search: "
|
||||||
/>
|
/>
|
||||||
<StyledCode
|
<StyledCode
|
||||||
onClick={() =>
|
onClick={() => {
|
||||||
onSuggestion(selectedFilter + ' ' + suggestedTextSearch)
|
onSuggestion(
|
||||||
}
|
selectedFilter + ' ' + suggestedTextSearch
|
||||||
|
);
|
||||||
|
trackEvent('search-filter-suggestions', {
|
||||||
|
props: {
|
||||||
|
eventType: 'search and filter',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<span key={selectedFilter}>{selectedFilter}</span>{' '}
|
<span key={selectedFilter}>{selectedFilter}</span>{' '}
|
||||||
<span>{suggestedTextSearch}</span>
|
<span>{suggestedTextSearch}</span>
|
||||||
|
@ -43,7 +43,8 @@ export type CustomEvents =
|
|||||||
| 'strategy-add'
|
| 'strategy-add'
|
||||||
| 'playground'
|
| 'playground'
|
||||||
| 'feature-type-edit'
|
| 'feature-type-edit'
|
||||||
| 'strategy-variants';
|
| 'strategy-variants'
|
||||||
|
| 'search-filter-suggestions';
|
||||||
|
|
||||||
export const usePlausibleTracker = () => {
|
export const usePlausibleTracker = () => {
|
||||||
const plausible = useContext(PlausibleContext);
|
const plausible = useContext(PlausibleContext);
|
||||||
|
Loading…
Reference in New Issue
Block a user