import { css } from '@emotion/css'; import React, { ReactElement } from 'react'; import { useSelector } from 'react-redux'; import { useLocation } from 'react-router-dom'; import { SelectableValue, GrafanaTheme2 } from '@grafana/data'; import { locationSearchToObject } from '@grafana/runtime'; import { LoadingPlaceholder, Select, RadioButtonGroup, useStyles2, Tooltip } from '@grafana/ui'; import { Page } from 'app/core/components/Page/Page'; import { GrafanaRouteComponentProps } from 'app/core/navigation/types'; import { getNavModel } from 'app/core/selectors/navModel'; import { StoreState } from 'app/types/store'; import { HorizontalGroup } from '../components/HorizontalGroup'; import { PluginList } from '../components/PluginList'; import { SearchField } from '../components/SearchField'; import { Sorters } from '../helpers'; import { useHistory } from '../hooks/useHistory'; import { useGetAllWithFilters, useIsRemotePluginsAvailable, useDisplayMode } from '../state/hooks'; import { PluginAdminRoutes, PluginListDisplayMode } from '../types'; export default function Browse({ route }: GrafanaRouteComponentProps): ReactElement | null { const location = useLocation(); const locationSearch = locationSearchToObject(location.search); const navModelId = getNavModelId(route.routeName); const navModel = useSelector((state: StoreState) => getNavModel(state.navIndex, navModelId)); const { displayMode, setDisplayMode } = useDisplayMode(); const styles = useStyles2(getStyles); const history = useHistory(); const remotePluginsAvailable = useIsRemotePluginsAvailable(); const query = (locationSearch.q as string) || ''; const filterBy = (locationSearch.filterBy as string) || 'installed'; const filterByType = (locationSearch.filterByType as string) || 'all'; const sortBy = (locationSearch.sortBy as Sorters) || Sorters.nameAsc; const { isLoading, error, plugins } = useGetAllWithFilters({ query, filterBy, filterByType, sortBy, }); const filterByOptions = [ { value: 'all', label: 'All' }, { value: 'installed', label: 'Installed' }, ]; const onSortByChange = (value: SelectableValue) => { history.push({ query: { sortBy: value.value } }); }; const onFilterByChange = (value: string) => { history.push({ query: { filterBy: value } }); }; const onFilterByTypeChange = (value: string) => { history.push({ query: { filterByType: value } }); }; const onSearch = (q: any) => { history.push({ query: { filterBy: 'all', filterByType: 'all', q } }); }; // How should we handle errors? if (error) { console.error(error.message); return null; } return ( {/* Filter by type */}
{/* Filter by installed / all */} {remotePluginsAvailable ? (
) : (
)} {/* Sorting */}