mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Extract Rich History storage into two separate implementations Implement getting all entries and adding a new entry * Add deleting rich history items * Add editing rich history * Simplify RichHistoryStorage API * Reorganize methods * Rename variable * Remove feature toggle * Fix TS errors * Fix tests * Clean up * Clean up only when adding new entry * Fix showing a warning message * Use enum instead of a string * Update public/app/core/history/richHistoryLocalStorage.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Update public/app/core/history/richHistoryLocalStorage.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Improve readability * Rename files and remove inferred return types * Use const over a var * Remove unsed files * Remove redundant null check * Update public/app/core/history/richHistoryLocalStorageUtils.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Fix linting issues Co-authored-by: Giordano Ricci <me@giordanoricci.com>
127 lines
3.9 KiB
TypeScript
127 lines
3.9 KiB
TypeScript
import React from 'react';
|
|
import { css } from '@emotion/css';
|
|
import { stylesFactory, useTheme, Select, Button, Switch, Field } from '@grafana/ui';
|
|
import { GrafanaTheme, SelectableValue } from '@grafana/data';
|
|
import appEvents from 'app/core/app_events';
|
|
import { ShowConfirmModalEvent } from '../../../types/events';
|
|
import { dispatch } from 'app/store/store';
|
|
import { notifyApp } from 'app/core/actions';
|
|
import { createSuccessNotification } from 'app/core/copy/appNotification';
|
|
import { MAX_HISTORY_ITEMS } from 'app/core/history/RichHistoryLocalStorage';
|
|
|
|
export interface RichHistorySettingsProps {
|
|
retentionPeriod: number;
|
|
starredTabAsFirstTab: boolean;
|
|
activeDatasourceOnly: boolean;
|
|
onChangeRetentionPeriod: (option: SelectableValue<number>) => void;
|
|
toggleStarredTabAsFirstTab: () => void;
|
|
toggleactiveDatasourceOnly: () => void;
|
|
deleteRichHistory: () => void;
|
|
}
|
|
|
|
const getStyles = stylesFactory((theme: GrafanaTheme) => {
|
|
return {
|
|
container: css`
|
|
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.publish(
|
|
new ShowConfirmModalEvent({
|
|
title: 'Delete',
|
|
text: 'Are you sure you want to permanently delete your query history?',
|
|
yesText: 'Delete',
|
|
icon: 'trash-alt',
|
|
onConfirm: () => {
|
|
deleteRichHistory();
|
|
dispatch(notifyApp(createSuccessNotification('Query history deleted')));
|
|
},
|
|
})
|
|
);
|
|
};
|
|
|
|
return (
|
|
<div className={styles.container}>
|
|
<Field
|
|
label="History time span"
|
|
description={`Select the period of time for which Grafana will save your query history. Up to ${MAX_HISTORY_ITEMS} entries will be stored.`}
|
|
className="space-between"
|
|
>
|
|
<div className={styles.input}>
|
|
<Select
|
|
menuShouldPortal
|
|
value={selectedOption}
|
|
options={retentionPeriodOptions}
|
|
onChange={onChangeRetentionPeriod}
|
|
></Select>
|
|
</div>
|
|
</Field>
|
|
<Field label="Default active tab" description=" " className="space-between">
|
|
<div className={styles.switch}>
|
|
<Switch value={starredTabAsFirstTab} onChange={toggleStarredTabAsFirstTab}></Switch>
|
|
<div className={styles.label}>Change the default active tab from “Query history” to “Starred”</div>
|
|
</div>
|
|
</Field>
|
|
<Field label="Data source behaviour" description=" " className="space-between">
|
|
<div className={styles.switch}>
|
|
<Switch value={activeDatasourceOnly} onChange={toggleactiveDatasourceOnly}></Switch>
|
|
<div className={styles.label}>Only show queries for data source currently active in Explore</div>
|
|
</div>
|
|
</Field>
|
|
<div
|
|
className={css`
|
|
font-weight: ${theme.typography.weight.bold};
|
|
`}
|
|
>
|
|
Clear query history
|
|
</div>
|
|
<div
|
|
className={css`
|
|
margin-bottom: ${theme.spacing.sm};
|
|
`}
|
|
>
|
|
Delete all of your query history, permanently.
|
|
</div>
|
|
<Button variant="destructive" onClick={onDelete}>
|
|
Clear query history
|
|
</Button>
|
|
</div>
|
|
);
|
|
}
|