mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 08:35:43 -06:00
* Initial commit * Progress * Update * Progress * updates * Minor fix * fixed ts issue * fixed e2e tests * More explorations * Making progress * Panel options and field options unified * With nested categories * Starting to find something * fix paddings * Progress * Breakthrough ux layout * Progress * Updates * New way of composing options with search * added regex search * Refactoring to react note tree * Show overrides * Adding overrides radio button support * Added popular view * Separate stat/gauge/bargauge options into value options and display options * Initial work on getting library panels into viz picker flow * Fixed issues switching to panel library panel * Move search input put of LibraryPanelsView * Changing design again to have content inside boxes * Style updates * Refactoring to fix scroll issue * Option category naming * Fixed FilterInput issue * Updated snapshots * Fix padding * Updated viz picker design * Unify library panel an viz picker card * Updated card with delete action * Major refactoring back to an object model instead of searching and filtering react node tree * More refactoring * Show option category in label when searching * Nice logic for categories rendering when searching or when only child * Make getSuggestions more lazy for DataLinksEditor * Add missing repeat options and handle conditional options * Prepping options category to be more flexibly and control state from outside * Added option count to search result * Minor style tweak * Added button to close viz picker * Rewrote overrides to enable searching overrides * New search engine and tests * Searching overrides works * Hide radio buttons while searching * Added angular options back * Added memoize for all options so they are not rebuilt for every search key stroke * Added back support for category counters * Started unit test work * Refactoring and base popular options list * Initial update to e2e test, more coming to add e2e test for search features * Minor fix * Review updates * Fixing category open states * Unit test progress * Do not show visualization list mode radio button if library panels is not enabled * Use boolean * More unit tests * Increase library panels per page count and give search focus when switching list mode * field config change test and search test * Feedback updates * Minor tweaks * Minor refactorings * More minimal override collapse state
261 lines
8.1 KiB
TypeScript
261 lines
8.1 KiB
TypeScript
import React, { useState, useEffect, useCallback } from 'react';
|
|
import { css } from 'emotion';
|
|
import { uniqBy, debounce } from 'lodash';
|
|
|
|
// Types
|
|
import { RichHistoryQuery, ExploreId } from 'app/types/explore';
|
|
|
|
// Utils
|
|
import { stylesFactory, useTheme, RangeSlider, Select } from '@grafana/ui';
|
|
import { GrafanaTheme, SelectableValue } from '@grafana/data';
|
|
|
|
import {
|
|
SortOrder,
|
|
mapNumbertoTimeInSlider,
|
|
mapQueriesToHeadings,
|
|
createDatasourcesList,
|
|
filterAndSortQueries,
|
|
} from 'app/core/utils/richHistory';
|
|
|
|
// Components
|
|
import RichHistoryCard from './RichHistoryCard';
|
|
import { sortOrderOptions } from './RichHistory';
|
|
import { FilterInput } from 'app/core/components/FilterInput/FilterInput';
|
|
|
|
export interface Props {
|
|
queries: RichHistoryQuery[];
|
|
sortOrder: SortOrder;
|
|
activeDatasourceOnly: boolean;
|
|
datasourceFilters: SelectableValue[] | null;
|
|
retentionPeriod: number;
|
|
exploreId: ExploreId;
|
|
height: number;
|
|
onChangeSortOrder: (sortOrder: SortOrder) => void;
|
|
onSelectDatasourceFilters: (value: SelectableValue[]) => void;
|
|
}
|
|
|
|
const getStyles = stylesFactory((theme: GrafanaTheme, height: number) => {
|
|
const bgColor = theme.isLight ? theme.palette.gray5 : theme.palette.dark4;
|
|
|
|
/* 134px is based on the width of the Query history tabs bar, so the content is aligned to right side of the tab */
|
|
const cardWidth = '100% - 134px';
|
|
const sliderHeight = `${height - 180}px`;
|
|
return {
|
|
container: css`
|
|
display: flex;
|
|
.label-slider {
|
|
font-size: ${theme.typography.size.sm};
|
|
&:last-of-type {
|
|
margin-top: ${theme.spacing.lg};
|
|
}
|
|
&:first-of-type {
|
|
font-weight: ${theme.typography.weight.semibold};
|
|
margin-bottom: ${theme.spacing.md};
|
|
}
|
|
}
|
|
`,
|
|
containerContent: css`
|
|
width: calc(${cardWidth});
|
|
`,
|
|
containerSlider: css`
|
|
width: 129px;
|
|
margin-right: ${theme.spacing.sm};
|
|
.slider {
|
|
bottom: 10px;
|
|
height: ${sliderHeight};
|
|
width: 129px;
|
|
padding: ${theme.spacing.sm} 0;
|
|
}
|
|
`,
|
|
slider: css`
|
|
position: fixed;
|
|
`,
|
|
selectors: css`
|
|
display: flex;
|
|
justify-content: space-between;
|
|
flex-wrap: wrap;
|
|
`,
|
|
filterInput: css`
|
|
margin-bottom: ${theme.spacing.sm};
|
|
`,
|
|
multiselect: css`
|
|
width: 100%;
|
|
margin-bottom: ${theme.spacing.sm};
|
|
.gf-form-select-box__multi-value {
|
|
background-color: ${bgColor};
|
|
padding: ${theme.spacing.xxs} ${theme.spacing.xs} ${theme.spacing.xxs} ${theme.spacing.sm};
|
|
border-radius: ${theme.border.radius.sm};
|
|
}
|
|
`,
|
|
sort: css`
|
|
width: 170px;
|
|
`,
|
|
sessionName: css`
|
|
display: flex;
|
|
align-items: flex-start;
|
|
justify-content: flex-start;
|
|
margin-top: ${theme.spacing.lg};
|
|
h4 {
|
|
margin: 0 10px 0 0;
|
|
}
|
|
`,
|
|
heading: css`
|
|
font-size: ${theme.typography.heading.h4};
|
|
margin: ${theme.spacing.md} ${theme.spacing.xxs} ${theme.spacing.sm} ${theme.spacing.xxs};
|
|
`,
|
|
footer: css`
|
|
height: 60px;
|
|
margin-top: ${theme.spacing.lg};
|
|
display: flex;
|
|
justify-content: center;
|
|
font-weight: ${theme.typography.weight.light};
|
|
font-size: ${theme.typography.size.sm};
|
|
a {
|
|
font-weight: ${theme.typography.weight.semibold};
|
|
margin-left: ${theme.spacing.xxs};
|
|
}
|
|
`,
|
|
queries: css`
|
|
font-size: ${theme.typography.size.sm};
|
|
font-weight: ${theme.typography.weight.regular};
|
|
margin-left: ${theme.spacing.xs};
|
|
`,
|
|
};
|
|
});
|
|
|
|
export function RichHistoryQueriesTab(props: Props) {
|
|
const {
|
|
datasourceFilters,
|
|
onSelectDatasourceFilters,
|
|
queries,
|
|
onChangeSortOrder,
|
|
sortOrder,
|
|
activeDatasourceOnly,
|
|
retentionPeriod,
|
|
exploreId,
|
|
height,
|
|
} = props;
|
|
|
|
const [timeFilter, setTimeFilter] = useState<[number, number]>([0, retentionPeriod]);
|
|
const [filteredQueries, setFilteredQueries] = useState<RichHistoryQuery[]>([]);
|
|
const [searchInput, setSearchInput] = useState('');
|
|
|
|
const theme = useTheme();
|
|
const styles = getStyles(theme, height);
|
|
|
|
const datasourcesRetrievedFromQueryHistory = uniqBy(queries, 'datasourceName').map((d) => d.datasourceName);
|
|
const listOfDatasources = createDatasourcesList(datasourcesRetrievedFromQueryHistory);
|
|
|
|
const filterAndSortQueriesDebounced = useCallback(
|
|
debounce((searchValue: string) => {
|
|
setFilteredQueries(
|
|
filterAndSortQueries(
|
|
queries,
|
|
sortOrder,
|
|
datasourceFilters?.map((d) => d.value) as string[] | null,
|
|
searchValue,
|
|
timeFilter
|
|
)
|
|
);
|
|
}, 300),
|
|
[timeFilter, queries, sortOrder, datasourceFilters]
|
|
);
|
|
|
|
useEffect(() => {
|
|
setFilteredQueries(
|
|
filterAndSortQueries(
|
|
queries,
|
|
sortOrder,
|
|
datasourceFilters?.map((d) => d.value) as string[] | null,
|
|
searchInput,
|
|
timeFilter
|
|
)
|
|
);
|
|
}, [timeFilter, queries, sortOrder, datasourceFilters]);
|
|
|
|
/* mappedQueriesToHeadings is an object where query headings (stringified dates/data sources)
|
|
* are keys and arrays with queries that belong to that headings are values.
|
|
*/
|
|
const mappedQueriesToHeadings = mapQueriesToHeadings(filteredQueries, sortOrder);
|
|
|
|
return (
|
|
<div className={styles.container}>
|
|
<div className={styles.containerSlider}>
|
|
<div className={styles.slider}>
|
|
<div className="label-slider">Filter history</div>
|
|
<div className="label-slider">{mapNumbertoTimeInSlider(timeFilter[0])}</div>
|
|
<div className="slider">
|
|
<RangeSlider
|
|
tooltipAlwaysVisible={false}
|
|
min={0}
|
|
max={retentionPeriod}
|
|
value={timeFilter}
|
|
orientation="vertical"
|
|
formatTooltipResult={mapNumbertoTimeInSlider}
|
|
reverse={true}
|
|
onAfterChange={setTimeFilter as () => number[]}
|
|
/>
|
|
</div>
|
|
<div className="label-slider">{mapNumbertoTimeInSlider(timeFilter[1])}</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className={styles.containerContent}>
|
|
<div className={styles.selectors}>
|
|
{!activeDatasourceOnly && (
|
|
<div aria-label="Filter datasources" className={styles.multiselect}>
|
|
<Select
|
|
isMulti={true}
|
|
options={listOfDatasources}
|
|
value={datasourceFilters}
|
|
placeholder="Filter queries for data sources(s)"
|
|
onChange={onSelectDatasourceFilters}
|
|
/>
|
|
</div>
|
|
)}
|
|
<div className={styles.filterInput}>
|
|
<FilterInput
|
|
placeholder="Search queries"
|
|
value={searchInput}
|
|
onChange={(value: string) => {
|
|
setSearchInput(value);
|
|
filterAndSortQueriesDebounced(value);
|
|
}}
|
|
/>
|
|
</div>
|
|
<div aria-label="Sort queries" className={styles.sort}>
|
|
<Select
|
|
value={sortOrderOptions.filter((order) => order.value === sortOrder)}
|
|
options={sortOrderOptions}
|
|
placeholder="Sort queries by"
|
|
onChange={(e) => onChangeSortOrder(e.value as SortOrder)}
|
|
/>
|
|
</div>
|
|
</div>
|
|
{Object.keys(mappedQueriesToHeadings).map((heading) => {
|
|
return (
|
|
<div key={heading}>
|
|
<div className={styles.heading}>
|
|
{heading} <span className={styles.queries}>{mappedQueriesToHeadings[heading].length} queries</span>
|
|
</div>
|
|
{mappedQueriesToHeadings[heading].map((q: RichHistoryQuery) => {
|
|
const idx = listOfDatasources.findIndex((d) => d.label === q.datasourceName);
|
|
return (
|
|
<RichHistoryCard
|
|
query={q}
|
|
key={q.ts}
|
|
exploreId={exploreId}
|
|
dsImg={listOfDatasources[idx].imgUrl}
|
|
isRemoved={listOfDatasources[idx].isRemoved}
|
|
/>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
})}
|
|
<div className={styles.footer}>The history is local to your browser and is not shared with others.</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|