2022-02-04 05:46:27 -06:00
|
|
|
import { omit } from 'lodash';
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
|
2022-02-04 05:46:27 -06:00
|
|
|
import { DataQuery, DataSourceApi, dateTimeFormat, ExploreUrlState, urlUtil } from '@grafana/data';
|
2020-06-30 07:51:04 -05:00
|
|
|
import { serializeStateToUrlParam } from '@grafana/data/src/utils/url';
|
2020-12-04 07:24:55 -06:00
|
|
|
import { getDataSourceSrv } from '@grafana/runtime';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { notifyApp } from 'app/core/actions';
|
2022-05-19 06:45:32 -05:00
|
|
|
import {
|
|
|
|
createErrorNotification,
|
|
|
|
createSuccessNotification,
|
|
|
|
createWarningNotification,
|
|
|
|
} from 'app/core/copy/appNotification';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { dispatch } from 'app/store/store';
|
|
|
|
import { RichHistoryQuery } from 'app/types/explore';
|
|
|
|
|
2022-05-19 06:45:32 -05:00
|
|
|
import RichHistoryLocalStorage from '../history/RichHistoryLocalStorage';
|
|
|
|
import RichHistoryRemoteStorage from '../history/RichHistoryRemoteStorage';
|
2022-04-22 08:33:13 -05:00
|
|
|
import {
|
|
|
|
RichHistoryServiceError,
|
|
|
|
RichHistoryStorageWarning,
|
|
|
|
RichHistoryStorageWarningDetails,
|
|
|
|
} from '../history/RichHistoryStorage';
|
|
|
|
import { getRichHistoryStorage } from '../history/richHistoryStorageProvider';
|
|
|
|
|
2022-04-27 08:07:44 -05:00
|
|
|
import { RichHistorySearchFilters, RichHistorySettings, SortOrder } from './richHistoryTypes';
|
2022-02-04 05:46:27 -06:00
|
|
|
|
2022-04-27 08:07:44 -05:00
|
|
|
export { RichHistorySearchFilters, RichHistorySettings, SortOrder };
|
2020-08-06 11:35:49 -05:00
|
|
|
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
/*
|
|
|
|
* Add queries to rich history. Save only queries within the retention period, or that are starred.
|
|
|
|
* Side-effect: store history in local storage
|
|
|
|
*/
|
|
|
|
|
2022-02-04 05:46:27 -06:00
|
|
|
export async function addToRichHistory(
|
2022-02-10 06:59:43 -06:00
|
|
|
datasourceUid: string,
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
datasourceName: string | null,
|
2020-04-24 11:23:31 -05:00
|
|
|
queries: DataQuery[],
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
starred: boolean,
|
|
|
|
comment: string | null,
|
2021-10-11 02:48:25 -05:00
|
|
|
showQuotaExceededError: boolean,
|
|
|
|
showLimitExceededWarning: boolean
|
2022-04-06 06:49:25 -05:00
|
|
|
): Promise<{ richHistoryStorageFull?: boolean; limitExceeded?: boolean }> {
|
2020-04-24 11:23:31 -05:00
|
|
|
/* Save only queries, that are not falsy (e.g. empty object, null, ...) */
|
2021-01-20 00:59:48 -06:00
|
|
|
const newQueriesToSave: DataQuery[] = queries && queries.filter((query) => notEmptyQuery(query));
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
|
2020-04-24 11:23:31 -05:00
|
|
|
if (newQueriesToSave.length > 0) {
|
2022-02-04 05:46:27 -06:00
|
|
|
let richHistoryStorageFull = false;
|
2021-10-11 02:48:25 -05:00
|
|
|
let limitExceeded = false;
|
2022-02-04 05:46:27 -06:00
|
|
|
let warning: RichHistoryStorageWarningDetails | undefined;
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
|
2020-04-20 08:13:02 -05:00
|
|
|
try {
|
2022-02-10 06:59:43 -06:00
|
|
|
const result = await getRichHistoryStorage().addToRichHistory({
|
|
|
|
datasourceUid: datasourceUid,
|
|
|
|
datasourceName: datasourceName ?? '',
|
|
|
|
queries: newQueriesToSave,
|
|
|
|
starred,
|
|
|
|
comment: comment ?? '',
|
|
|
|
});
|
|
|
|
warning = result.warning;
|
2020-04-20 08:13:02 -05:00
|
|
|
} catch (error) {
|
2022-02-04 05:46:27 -06:00
|
|
|
if (error.name === RichHistoryServiceError.StorageFull) {
|
|
|
|
richHistoryStorageFull = true;
|
|
|
|
showQuotaExceededError && dispatch(notifyApp(createErrorNotification(error.message)));
|
|
|
|
} else if (error.name !== RichHistoryServiceError.DuplicatedEntry) {
|
|
|
|
dispatch(notifyApp(createErrorNotification('Rich History update failed', error.message)));
|
|
|
|
}
|
|
|
|
// Saving failed. Do not add new entry.
|
2022-04-06 06:49:25 -05:00
|
|
|
return { richHistoryStorageFull, limitExceeded };
|
2022-02-04 05:46:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Limit exceeded but new entry was added. Notify that old entries have been removed.
|
|
|
|
if (warning && warning.type === RichHistoryStorageWarning.LimitExceeded) {
|
|
|
|
limitExceeded = true;
|
|
|
|
showLimitExceededWarning && dispatch(notifyApp(createWarningNotification(warning.message)));
|
2020-03-17 10:06:02 -05:00
|
|
|
}
|
2022-02-04 05:46:27 -06:00
|
|
|
|
2022-04-06 06:49:25 -05:00
|
|
|
return { richHistoryStorageFull, limitExceeded };
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
}
|
|
|
|
|
2022-04-06 06:49:25 -05:00
|
|
|
// Nothing to change
|
|
|
|
return {};
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
}
|
|
|
|
|
2022-04-27 08:07:44 -05:00
|
|
|
export async function getRichHistory(filters: RichHistorySearchFilters): Promise<RichHistoryQuery[]> {
|
|
|
|
return await getRichHistoryStorage().getRichHistory(filters);
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
}
|
|
|
|
|
2022-04-12 11:55:39 -05:00
|
|
|
export async function updateRichHistorySettings(settings: RichHistorySettings): Promise<void> {
|
|
|
|
await getRichHistoryStorage().updateSettings(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getRichHistorySettings(): Promise<RichHistorySettings> {
|
|
|
|
return await getRichHistoryStorage().getSettings();
|
|
|
|
}
|
|
|
|
|
2022-02-04 05:46:27 -06:00
|
|
|
export async function deleteAllFromRichHistory(): Promise<void> {
|
|
|
|
return getRichHistoryStorage().deleteAll();
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
}
|
|
|
|
|
2022-04-06 06:49:25 -05:00
|
|
|
export async function updateStarredInRichHistory(id: string, starred: boolean) {
|
2020-04-20 08:13:02 -05:00
|
|
|
try {
|
2022-04-06 06:49:25 -05:00
|
|
|
return await getRichHistoryStorage().updateStarred(id, starred);
|
2020-04-20 08:13:02 -05:00
|
|
|
} catch (error) {
|
2021-09-30 02:22:57 -05:00
|
|
|
dispatch(notifyApp(createErrorNotification('Saving rich history failed', error.message)));
|
2022-04-06 06:49:25 -05:00
|
|
|
return undefined;
|
2020-04-20 08:13:02 -05:00
|
|
|
}
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
}
|
|
|
|
|
2022-04-06 06:49:25 -05:00
|
|
|
export async function updateCommentInRichHistory(id: string, newComment: string | undefined) {
|
2020-04-20 08:13:02 -05:00
|
|
|
try {
|
2022-04-06 06:49:25 -05:00
|
|
|
return await getRichHistoryStorage().updateComment(id, newComment);
|
2020-04-20 08:13:02 -05:00
|
|
|
} catch (error) {
|
2021-09-30 02:22:57 -05:00
|
|
|
dispatch(notifyApp(createErrorNotification('Saving rich history failed', error.message)));
|
2022-04-06 06:49:25 -05:00
|
|
|
return undefined;
|
2020-04-20 08:13:02 -05:00
|
|
|
}
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
}
|
|
|
|
|
2022-04-06 06:49:25 -05:00
|
|
|
export async function deleteQueryInRichHistory(id: string) {
|
2020-04-20 08:13:02 -05:00
|
|
|
try {
|
2022-02-10 06:59:43 -06:00
|
|
|
await getRichHistoryStorage().deleteRichHistory(id);
|
2022-04-06 06:49:25 -05:00
|
|
|
return id;
|
2020-04-20 08:13:02 -05:00
|
|
|
} catch (error) {
|
2021-09-30 02:22:57 -05:00
|
|
|
dispatch(notifyApp(createErrorNotification('Saving rich history failed', error.message)));
|
2022-04-06 06:49:25 -05:00
|
|
|
return undefined;
|
2020-04-20 08:13:02 -05:00
|
|
|
}
|
2020-03-19 02:47:27 -05:00
|
|
|
}
|
|
|
|
|
2022-05-19 06:45:32 -05:00
|
|
|
export enum LocalStorageMigrationStatus {
|
|
|
|
Successful = 'successful',
|
|
|
|
Failed = 'failed',
|
|
|
|
NotNeeded = 'not-needed',
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function migrateQueryHistoryFromLocalStorage(): Promise<LocalStorageMigrationStatus> {
|
|
|
|
const richHistoryLocalStorage = new RichHistoryLocalStorage();
|
|
|
|
const richHistoryRemoteStorage = new RichHistoryRemoteStorage();
|
|
|
|
|
|
|
|
try {
|
|
|
|
const richHistory: RichHistoryQuery[] = await richHistoryLocalStorage.getRichHistory({
|
|
|
|
datasourceFilters: [],
|
|
|
|
from: 0,
|
|
|
|
search: '',
|
|
|
|
sortOrder: SortOrder.Descending,
|
|
|
|
starred: false,
|
|
|
|
to: 14,
|
|
|
|
});
|
|
|
|
if (richHistory.length === 0) {
|
|
|
|
return LocalStorageMigrationStatus.NotNeeded;
|
|
|
|
}
|
|
|
|
await richHistoryRemoteStorage.migrate(richHistory);
|
|
|
|
dispatch(notifyApp(createSuccessNotification('Query history successfully migrated from local storage')));
|
|
|
|
return LocalStorageMigrationStatus.Successful;
|
|
|
|
} catch (error) {
|
|
|
|
dispatch(notifyApp(createWarningNotification(`Query history migration failed. ${error.message}`)));
|
|
|
|
return LocalStorageMigrationStatus.Failed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
export const createUrlFromRichHistory = (query: RichHistoryQuery) => {
|
|
|
|
const exploreState: ExploreUrlState = {
|
|
|
|
/* Default range, as we are not saving timerange in rich history */
|
|
|
|
range: { from: 'now-1h', to: 'now' },
|
|
|
|
datasource: query.datasourceName,
|
2020-04-24 11:23:31 -05:00
|
|
|
queries: query.queries,
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
context: 'explore',
|
|
|
|
};
|
|
|
|
|
2022-01-27 05:23:56 -06:00
|
|
|
const serializedState = serializeStateToUrlParam(exploreState);
|
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 05:46:59 -05:00
|
|
|
const baseUrl = /.*(?=\/explore)/.exec(`${window.location.href}`)![0];
|
2020-04-20 00:37:38 -05:00
|
|
|
const url = urlUtil.renderUrl(`${baseUrl}/explore`, { left: serializedState });
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
return url;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Needed for slider in Rich history to map numerical values to meaningful strings */
|
|
|
|
export const mapNumbertoTimeInSlider = (num: number) => {
|
|
|
|
let str;
|
|
|
|
switch (num) {
|
|
|
|
case 0:
|
|
|
|
str = 'today';
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
str = 'yesterday';
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
str = 'a week ago';
|
|
|
|
break;
|
|
|
|
case 14:
|
|
|
|
str = 'two weeks ago';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = `${num} days ago`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
};
|
|
|
|
|
|
|
|
export function createDateStringFromTs(ts: number) {
|
2020-04-27 08:28:06 -05:00
|
|
|
return dateTimeFormat(ts, {
|
|
|
|
format: 'MMMM D',
|
|
|
|
});
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getQueryDisplayText(query: DataQuery): string {
|
2020-04-24 11:23:31 -05:00
|
|
|
/* If datasource doesn't have getQueryDisplayText, create query display text by
|
|
|
|
* stringifying query that was stripped of key, refId and datasource for nicer
|
|
|
|
* formatting and improved readability
|
|
|
|
*/
|
2021-04-21 02:38:00 -05:00
|
|
|
const strippedQuery = omit(query, ['key', 'refId', 'datasource']);
|
2020-04-24 11:23:31 -05:00
|
|
|
return JSON.stringify(strippedQuery);
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export function createQueryHeading(query: RichHistoryQuery, sortOrder: SortOrder) {
|
|
|
|
let heading = '';
|
|
|
|
if (sortOrder === SortOrder.DatasourceAZ || sortOrder === SortOrder.DatasourceZA) {
|
|
|
|
heading = query.datasourceName;
|
|
|
|
} else {
|
2022-02-10 06:59:43 -06:00
|
|
|
heading = createDateStringFromTs(query.createdAt);
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
}
|
|
|
|
return heading;
|
|
|
|
}
|
|
|
|
|
2020-06-30 09:15:46 -05:00
|
|
|
export function createQueryText(query: DataQuery, queryDsInstance: DataSourceApi | undefined) {
|
2020-04-24 11:23:31 -05:00
|
|
|
/* query DatasourceInstance is necessary because we use its getQueryDisplayText method
|
|
|
|
* to format query text
|
|
|
|
*/
|
|
|
|
if (queryDsInstance?.getQueryDisplayText) {
|
|
|
|
return queryDsInstance.getQueryDisplayText(query);
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
}
|
|
|
|
|
2020-04-24 11:23:31 -05:00
|
|
|
return getQueryDisplayText(query);
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export function mapQueriesToHeadings(query: RichHistoryQuery[], sortOrder: SortOrder) {
|
|
|
|
let mappedQueriesToHeadings: any = {};
|
|
|
|
|
2021-01-20 00:59:48 -06:00
|
|
|
query.forEach((q) => {
|
Explore: Rich History (#22570)
* Explore: Refactor active buttons css
* Explore: Add query history button
* WIP: Creating drawer
* WIP: Create custom drawer (for now)
* Revert changes to Drawer.tsx
* WIP: Layout finished
* Rich History: Set up boilerplate for Settings
* WIP: Query history cards
* Refactor, split components
* Add resizability, interactivity
* Save history to local storage
* Visualise queries from queryhistory local storage
* Set up query history settings
* Refactor
* Create link, un-refactored verison
* Copyable url
* WIP: Add slider
* Commenting feature
* Slider filtration
* Add headings
* Hide Rich history behind feature toggle
* Cleaning up, refactors
* Update tests
* Implement getQueryDisplayText
* Update lockfile for new dependencies
* Update heading based on sorting
* Fix typescript strinctNullCheck errors
* Fix Forms, new forms
* Fixes based on provided feedback
* Fixes, splitting component into two
* Add tooltips, add delete history button
* Clicking on card adds queries to query rows
* Delete history, width of drawers
* UI/UX changes, updates
* Add number of queries to headings, box shadows
* Fix slider, remove feature toggle
* Fix typo in the beta announcement
* Fix how the rich history state is rendered when initialization
* Move updateFilters when activeDatasourceFilter onlyto RichHistory, remove duplicated code
* Fix typescript strictnull errors, not used variables errors
2020-03-10 09:08:15 -05:00
|
|
|
let heading = createQueryHeading(q, sortOrder);
|
|
|
|
if (!(heading in mappedQueriesToHeadings)) {
|
|
|
|
mappedQueriesToHeadings[heading] = [q];
|
|
|
|
} else {
|
|
|
|
mappedQueriesToHeadings[heading] = [...mappedQueriesToHeadings[heading], q];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return mappedQueriesToHeadings;
|
|
|
|
}
|
2020-03-19 02:47:27 -05:00
|
|
|
|
2022-04-27 08:07:44 -05:00
|
|
|
/*
|
|
|
|
* Create a list of all available data sources
|
2020-03-19 02:47:27 -05:00
|
|
|
*/
|
2022-04-27 08:07:44 -05:00
|
|
|
export function createDatasourcesList() {
|
|
|
|
return getDataSourceSrv()
|
|
|
|
.getList()
|
|
|
|
.map((dsSettings) => {
|
|
|
|
return {
|
|
|
|
name: dsSettings.name,
|
|
|
|
uid: dsSettings.uid,
|
2020-12-04 07:24:55 -06:00
|
|
|
imgUrl: dsSettings.meta.info.logos.small,
|
2022-04-27 08:07:44 -05:00
|
|
|
};
|
|
|
|
});
|
2020-03-19 02:47:27 -05:00
|
|
|
}
|
2020-04-24 11:23:31 -05:00
|
|
|
|
|
|
|
export function notEmptyQuery(query: DataQuery) {
|
|
|
|
/* Check if query has any other properties besides key, refId and datasource.
|
|
|
|
* If not, then we consider it empty query.
|
|
|
|
*/
|
2021-04-21 02:38:00 -05:00
|
|
|
const strippedQuery = omit(query, ['key', 'refId', 'datasource']);
|
2020-04-24 11:23:31 -05:00
|
|
|
const queryKeys = Object.keys(strippedQuery);
|
|
|
|
|
|
|
|
if (queryKeys.length > 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|