mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -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>
75 lines
2.0 KiB
TypeScript
75 lines
2.0 KiB
TypeScript
// Libraries
|
|
import React, { useState } from 'react';
|
|
import { connect, ConnectedProps } from 'react-redux';
|
|
|
|
// Services & Utils
|
|
import store from 'app/core/store';
|
|
import { RICH_HISTORY_SETTING_KEYS } from 'app/core/history/richHistoryLocalStorageUtils';
|
|
|
|
// Types
|
|
import { ExploreItemState, StoreState } from 'app/types';
|
|
import { ExploreId } from 'app/types/explore';
|
|
|
|
// Components, enums
|
|
import { RichHistory, Tabs } from './RichHistory';
|
|
|
|
//Actions
|
|
import { deleteRichHistory } from '../state/history';
|
|
import { ExploreDrawer } from '../ExploreDrawer';
|
|
|
|
function mapStateToProps(state: StoreState, { exploreId }: { exploreId: ExploreId }) {
|
|
const explore = state.explore;
|
|
// @ts-ignore
|
|
const item: ExploreItemState = explore[exploreId];
|
|
const { datasourceInstance } = item;
|
|
const firstTab = store.getBool(RICH_HISTORY_SETTING_KEYS.starredTabAsFirstTab, false)
|
|
? Tabs.Starred
|
|
: Tabs.RichHistory;
|
|
const { richHistory } = explore;
|
|
return {
|
|
richHistory,
|
|
firstTab,
|
|
activeDatasourceInstance: datasourceInstance?.name,
|
|
};
|
|
}
|
|
|
|
const mapDispatchToProps = {
|
|
deleteRichHistory,
|
|
};
|
|
|
|
const connector = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
interface OwnProps {
|
|
width: number;
|
|
exploreId: ExploreId;
|
|
onClose: () => void;
|
|
}
|
|
export type Props = ConnectedProps<typeof connector> & OwnProps;
|
|
|
|
export function RichHistoryContainer(props: Props) {
|
|
const [height, setHeight] = useState(400);
|
|
|
|
const { richHistory, width, firstTab, activeDatasourceInstance, exploreId, deleteRichHistory, onClose } = props;
|
|
|
|
return (
|
|
<ExploreDrawer
|
|
width={width}
|
|
onResize={(_e, _dir, ref) => {
|
|
setHeight(Number(ref.style.height.slice(0, -2)));
|
|
}}
|
|
>
|
|
<RichHistory
|
|
richHistory={richHistory}
|
|
firstTab={firstTab}
|
|
activeDatasourceInstance={activeDatasourceInstance}
|
|
exploreId={exploreId}
|
|
deleteRichHistory={deleteRichHistory}
|
|
onClose={onClose}
|
|
height={height}
|
|
/>
|
|
</ExploreDrawer>
|
|
);
|
|
}
|
|
|
|
export default connector(RichHistoryContainer);
|