Files
grafana/public/app/features/datasources/components/DataSourcesListHeader.tsx
Syerikjan Kh 2f965a07ab Ref: datasource picker rudderstack events (#95074)
* ref: ds picker events added

* ref: track opendropdown only on click

* ref: update/update all payload added to the event

* ref: configure more ds button event path to from path

* ref: result count fix, enable/disable track

* ref: debounce search tracks

* ref: track connections_plugin_card_clicked

* ref: call tracking from the child comp with result count

* ref: change event names, add creator_team and schema version
2024-10-24 12:03:17 -04:00

59 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { debounce } from 'lodash';
import { useCallback, useMemo } from 'react';
import { SelectableValue } from '@grafana/data';
import PageActionBar from 'app/core/components/PageActionBar/PageActionBar';
import { StoreState, useSelector, useDispatch } from 'app/types';
import { getDataSourcesSearchQuery, getDataSourcesSort, setDataSourcesSearchQuery, setIsSortAscending } from '../state';
import { trackDsSearched } from '../tracking';
const ascendingSortValue = 'alpha-asc';
const descendingSortValue = 'alpha-desc';
const sortOptions = [
// We use this unicode 'en dash' character (U+2013), because it looks nicer
// than simple dash in this context. This is also used in the response of
// the `sorting` endpoint, which is used in the search dashboard page.
{ label: 'Sort by AZ', value: ascendingSortValue },
{ label: 'Sort by ZA', value: descendingSortValue },
];
export function DataSourcesListHeader() {
const dispatch = useDispatch();
const debouncedTrackSearch = useMemo(
() =>
debounce((q) => {
trackDsSearched({ query: q });
}, 300),
[]
);
const setSearchQuery = useCallback(
(q: string) => {
dispatch(setDataSourcesSearchQuery(q));
if (q) {
debouncedTrackSearch(q);
}
},
[dispatch, debouncedTrackSearch]
);
const searchQuery = useSelector(({ dataSources }: StoreState) => getDataSourcesSearchQuery(dataSources));
const setSort = useCallback(
(sort: SelectableValue) => dispatch(setIsSortAscending(sort.value === ascendingSortValue)),
[dispatch]
);
const isSortAscending = useSelector(({ dataSources }: StoreState) => getDataSourcesSort(dataSources));
const sortPicker = {
onChange: setSort,
value: isSortAscending ? ascendingSortValue : descendingSortValue,
getSortOptions: () => Promise.resolve(sortOptions),
};
return (
<PageActionBar searchQuery={searchQuery} setSearchQuery={setSearchQuery} key="action-bar" sortPicker={sortPicker} />
);
}