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:
Piotr Jamróz
2021-03-15 15:11:52 +01:00
committed by GitHub
parent 3507c1d188
commit f97384c2f9
8 changed files with 50 additions and 33 deletions

View File

@@ -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;
}
}

View File

@@ -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')));
}
};