import React from 'react'; import { css } from 'emotion'; import { stylesFactory, useTheme, Select, Button, Switch, Field } from '@grafana/ui'; import { GrafanaTheme, AppEvents } from '@grafana/data'; import appEvents from 'app/core/app_events'; import { CoreEvents } from 'app/types'; export interface RichHistorySettingsProps { retentionPeriod: number; starredTabAsFirstTab: boolean; activeDatasourceOnly: boolean; onChangeRetentionPeriod: (option: { label: string; value: number }) => void; toggleStarredTabAsFirstTab: () => void; toggleactiveDatasourceOnly: () => void; deleteRichHistory: () => void; } const getStyles = stylesFactory((theme: GrafanaTheme) => { return { container: css` padding-left: ${theme.spacing.sm}; font-size: ${theme.typography.size.sm}; .space-between { margin-bottom: ${theme.spacing.lg}; } `, input: css` max-width: 200px; `, switch: css` display: flex; align-items: center; `, label: css` margin-left: ${theme.spacing.md}; `, }; }); const retentionPeriodOptions = [ { value: 2, label: '2 days' }, { value: 5, label: '5 days' }, { value: 7, label: '1 week' }, { value: 14, label: '2 weeks' }, ]; export function RichHistorySettings(props: RichHistorySettingsProps) { const { retentionPeriod, starredTabAsFirstTab, activeDatasourceOnly, onChangeRetentionPeriod, toggleStarredTabAsFirstTab, toggleactiveDatasourceOnly, deleteRichHistory, } = props; const theme = useTheme(); const styles = getStyles(theme); const selectedOption = retentionPeriodOptions.find(v => v.value === retentionPeriod); const onDelete = () => { appEvents.emit(CoreEvents.showConfirmModal, { title: 'Delete', text: 'Are you sure you want to permanently delete your query history?', yesText: 'Delete', icon: 'trash-alt', onConfirm: () => { deleteRichHistory(); appEvents.emit(AppEvents.alertSuccess, ['Query history deleted']); }, }); }; return (