|
|
|
@ -4,6 +4,7 @@ import { useLocalStorage } from 'react-use'; |
|
|
|
|
|
|
|
|
|
import { GrafanaTheme2, PanelData, SelectableValue } from '@grafana/data'; |
|
|
|
|
import { selectors } from '@grafana/e2e-selectors'; |
|
|
|
|
import { reportInteraction } from '@grafana/runtime'; |
|
|
|
|
import { VizPanel } from '@grafana/scenes'; |
|
|
|
|
import { Button, CustomScrollbar, Field, FilterInput, RadioButtonGroup, useStyles2 } from '@grafana/ui'; |
|
|
|
|
import { LS_VISUALIZATION_SELECT_TAB_KEY, LS_WIDGET_SELECT_TAB_KEY } from 'app/core/constants'; |
|
|
|
@ -14,6 +15,8 @@ import { VizTypeChangeDetails } from 'app/features/panel/components/VizTypePicke |
|
|
|
|
|
|
|
|
|
import { PanelModelCompatibilityWrapper } from '../utils/PanelModelCompatibilityWrapper'; |
|
|
|
|
|
|
|
|
|
import { INTERACTION_EVENT_NAME, INTERACTION_ITEM } from './interaction'; |
|
|
|
|
|
|
|
|
|
export interface Props { |
|
|
|
|
data?: PanelData; |
|
|
|
|
panel: VizPanel; |
|
|
|
@ -25,6 +28,13 @@ export function PanelVizTypePicker({ panel, data, onChange, onClose }: Props) { |
|
|
|
|
const styles = useStyles2(getStyles); |
|
|
|
|
const [searchQuery, setSearchQuery] = useState(''); |
|
|
|
|
|
|
|
|
|
const handleSearchChange = (value: string) => { |
|
|
|
|
if (value) { |
|
|
|
|
reportInteraction(INTERACTION_EVENT_NAME, { item: INTERACTION_ITEM.SEARCH, query: value }); |
|
|
|
|
} |
|
|
|
|
setSearchQuery(value); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const isWidgetEnabled = false; |
|
|
|
|
const tabKey = isWidgetEnabled ? LS_WIDGET_SELECT_TAB_KEY : LS_VISUALIZATION_SELECT_TAB_KEY; |
|
|
|
|
const defaultTab = isWidgetEnabled ? VisualizationSelectPaneTab.Widgets : VisualizationSelectPaneTab.Visualizations; |
|
|
|
@ -40,6 +50,14 @@ export function PanelVizTypePicker({ panel, data, onChange, onClose }: Props) { |
|
|
|
|
[] |
|
|
|
|
); |
|
|
|
|
const [listMode, setListMode] = useLocalStorage(tabKey, defaultTab); |
|
|
|
|
const handleListModeChange = (value: VisualizationSelectPaneTab) => { |
|
|
|
|
reportInteraction(INTERACTION_EVENT_NAME, { |
|
|
|
|
item: INTERACTION_ITEM.CHANGE_TAB, |
|
|
|
|
tab: VisualizationSelectPaneTab[value], |
|
|
|
|
}); |
|
|
|
|
setListMode(value); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (listMode && !supportedListModes.has(listMode)) { |
|
|
|
|
setListMode(defaultTab); |
|
|
|
@ -57,7 +75,7 @@ export function PanelVizTypePicker({ panel, data, onChange, onClose }: Props) { |
|
|
|
|
<FilterInput |
|
|
|
|
className={styles.filter} |
|
|
|
|
value={searchQuery} |
|
|
|
|
onChange={setSearchQuery} |
|
|
|
|
onChange={handleSearchChange} |
|
|
|
|
autoFocus={true} |
|
|
|
|
placeholder="Search for..." |
|
|
|
|
/> |
|
|
|
@ -71,7 +89,7 @@ export function PanelVizTypePicker({ panel, data, onChange, onClose }: Props) { |
|
|
|
|
/> |
|
|
|
|
</div> |
|
|
|
|
<Field className={styles.customFieldMargin}> |
|
|
|
|
<RadioButtonGroup options={radioOptions} value={listMode} onChange={setListMode} fullWidth /> |
|
|
|
|
<RadioButtonGroup options={radioOptions} value={listMode} onChange={handleListModeChange} fullWidth /> |
|
|
|
|
</Field> |
|
|
|
|
<CustomScrollbar> |
|
|
|
|
{listMode === VisualizationSelectPaneTab.Visualizations && ( |
|
|
|
|