mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Replace AppEvents with notifyApp in Explore (#31864)
* Replace AppEvents with notifyApp in Explore * Replace AppEvents with notifyApp in Explore-related components
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
// Services & Utils
|
||||
import { DataQuery, DataSourceApi, dateTimeFormat, AppEvents, urlUtil, ExploreUrlState } from '@grafana/data';
|
||||
import appEvents from 'app/core/app_events';
|
||||
import { DataQuery, DataSourceApi, dateTimeFormat, urlUtil, ExploreUrlState } from '@grafana/data';
|
||||
import store from 'app/core/store';
|
||||
import { dispatch } from 'app/store/store';
|
||||
import { notifyApp } from 'app/core/actions';
|
||||
import { createErrorNotification } from 'app/core/copy/appNotification';
|
||||
|
||||
// Types
|
||||
import { RichHistoryQuery } from 'app/types/explore';
|
||||
@@ -76,7 +78,7 @@ export function addToRichHistory(
|
||||
store.setObject(RICH_HISTORY_KEY, updatedHistory);
|
||||
return updatedHistory;
|
||||
} catch (error) {
|
||||
appEvents.emit(AppEvents.alertError, [error]);
|
||||
dispatch(notifyApp(createErrorNotification(error)));
|
||||
return richHistory;
|
||||
}
|
||||
}
|
||||
@@ -109,7 +111,7 @@ export function updateStarredInRichHistory(richHistory: RichHistoryQuery[], ts:
|
||||
store.setObject(RICH_HISTORY_KEY, updatedHistory);
|
||||
return updatedHistory;
|
||||
} catch (error) {
|
||||
appEvents.emit(AppEvents.alertError, [error]);
|
||||
dispatch(notifyApp(createErrorNotification(error)));
|
||||
return richHistory;
|
||||
}
|
||||
}
|
||||
@@ -131,7 +133,7 @@ export function updateCommentInRichHistory(
|
||||
store.setObject(RICH_HISTORY_KEY, updatedHistory);
|
||||
return updatedHistory;
|
||||
} catch (error) {
|
||||
appEvents.emit(AppEvents.alertError, [error]);
|
||||
dispatch(notifyApp(createErrorNotification(error)));
|
||||
return richHistory;
|
||||
}
|
||||
}
|
||||
@@ -142,7 +144,7 @@ export function deleteQueryInRichHistory(richHistory: RichHistoryQuery[], ts: nu
|
||||
store.setObject(RICH_HISTORY_KEY, updatedHistory);
|
||||
return updatedHistory;
|
||||
} catch (error) {
|
||||
appEvents.emit(AppEvents.alertError, [error]);
|
||||
dispatch(notifyApp(createErrorNotification(error)));
|
||||
return richHistory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import memoizeOne from 'memoize-one';
|
||||
import { getBackendSrv, config } from '@grafana/runtime';
|
||||
import { AppEvents } from '@grafana/data';
|
||||
import appEvents from 'app/core/app_events';
|
||||
import { copyStringToClipboard } from './explore';
|
||||
import { dispatch } from 'app/store/store';
|
||||
import { notifyApp } from 'app/core/actions';
|
||||
import { createErrorNotification, createSuccessNotification } from 'app/core/copy/appNotification';
|
||||
|
||||
function buildHostUrl() {
|
||||
return `${window.location.protocol}//${window.location.host}${config.appSubUrl}`;
|
||||
@@ -21,7 +22,7 @@ export const createShortLink = memoizeOne(async function (path: string) {
|
||||
return shortLink.url;
|
||||
} catch (err) {
|
||||
console.error('Error when creating shortened link: ', err);
|
||||
appEvents.emit(AppEvents.alertError, ['Error generating shortened link']);
|
||||
dispatch(notifyApp(createErrorNotification('Error generating shortened link')));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -29,8 +30,8 @@ export const createAndCopyShortLink = async (path: string) => {
|
||||
const shortLink = await createShortLink(path);
|
||||
if (shortLink) {
|
||||
copyStringToClipboard(shortLink);
|
||||
appEvents.emit(AppEvents.alertSuccess, ['Shortened link copied to clipboard']);
|
||||
dispatch(notifyApp(createSuccessNotification('Shortened link copied to clipboard')));
|
||||
} else {
|
||||
appEvents.emit(AppEvents.alertError, ['Error generating shortened link']);
|
||||
dispatch(notifyApp(createErrorNotification('Error generating shortened link')));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user