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

@@ -1,8 +1,7 @@
import React, { useState } from 'react';
import { Button, JSONFormatter, LoadingPlaceholder, TabbedContainer, TabConfig } from '@grafana/ui';
import { AppEvents, PanelData, TimeZone } from '@grafana/data';
import { PanelData, TimeZone } from '@grafana/data';
import appEvents from 'app/core/app_events';
import { CopyToClipboard } from 'app/core/components/CopyToClipboard/CopyToClipboard';
import { StoreState, ExploreItemState, ExploreId } from 'app/types';
import { hot } from 'react-hot-loader';
@@ -12,6 +11,9 @@ import { useEffectOnce } from 'react-use';
import { getBackendSrv } from 'app/core/services/backend_srv';
import { InspectStatsTab } from '../dashboard/components/Inspector/InspectStatsTab';
import { getPanelInspectorStyles } from '../dashboard/components/Inspector/styles';
import { dispatch } from 'app/store/store';
import { notifyApp } from 'app/core/actions';
import { createSuccessNotification } from 'app/core/copy/appNotification';
function stripPropsFromResponse(response: any) {
// ignore silent requests and return early
@@ -73,7 +75,7 @@ export function ExploreQueryInspector(props: Props) {
};
const onClipboardSuccess = () => {
appEvents.emit(AppEvents.alertSuccess, ['Content copied to clipboard']);
dispatch(notifyApp(createSuccessNotification('Content copied to clipboard')));
};
const [allNodesExpanded, setAllNodesExpanded] = useState(false);

View File

@@ -4,12 +4,15 @@ import { hot } from 'react-hot-loader';
import { css, cx } from 'emotion';
import { stylesFactory, useTheme, TextArea, Button, IconButton } from '@grafana/ui';
import { getDataSourceSrv } from '@grafana/runtime';
import { GrafanaTheme, AppEvents, DataSourceApi } from '@grafana/data';
import { GrafanaTheme, DataSourceApi } from '@grafana/data';
import { RichHistoryQuery, ExploreId } from 'app/types/explore';
import { createUrlFromRichHistory, createQueryText } from 'app/core/utils/richHistory';
import { createAndCopyShortLink } from 'app/core/utils/shortLinks';
import { copyStringToClipboard } from 'app/core/utils/explore';
import appEvents from 'app/core/app_events';
import { dispatch } from 'app/store/store';
import { notifyApp } from 'app/core/actions';
import { createSuccessNotification } from 'app/core/copy/appNotification';
import { StoreState } from 'app/types';
import { updateRichHistory } from '../state/history';
@@ -179,7 +182,7 @@ export function RichHistoryCard(props: Props) {
const onCopyQuery = () => {
const queriesToCopy = query.queries.map((q) => createQueryText(q, queryDsInstance)).join('\n');
copyStringToClipboard(queriesToCopy);
appEvents.emit(AppEvents.alertSuccess, ['Query copied to clipboard']);
dispatch(notifyApp(createSuccessNotification('Query copied to clipboard')));
};
const onCreateShortLink = async () => {
@@ -198,13 +201,13 @@ export function RichHistoryCard(props: Props) {
icon: 'trash-alt',
onConfirm: () => {
updateRichHistory(query.ts, 'delete');
appEvents.emit(AppEvents.alertSuccess, ['Query deleted']);
dispatch(notifyApp(createSuccessNotification('Query deleted')));
},
})
);
} else {
updateRichHistory(query.ts, 'delete');
appEvents.emit(AppEvents.alertSuccess, ['Query deleted']);
dispatch(notifyApp(createSuccessNotification('Query deleted')));
}
};

View File

@@ -1,9 +1,12 @@
import React from 'react';
import { css } from 'emotion';
import { stylesFactory, useTheme, Select, Button, Switch, Field } from '@grafana/ui';
import { GrafanaTheme, AppEvents } from '@grafana/data';
import { GrafanaTheme } from '@grafana/data';
import appEvents from 'app/core/app_events';
import { ShowConfirmModalEvent } from '../../../types/events';
import { dispatch } from 'app/store/store';
import { notifyApp } from 'app/core/actions';
import { createSuccessNotification } from 'app/core/copy/appNotification';
export interface RichHistorySettingsProps {
retentionPeriod: number;
@@ -67,7 +70,7 @@ export function RichHistorySettings(props: RichHistorySettingsProps) {
icon: 'trash-alt',
onConfirm: () => {
deleteRichHistory();
appEvents.emit(AppEvents.alertSuccess, ['Query history deleted']);
dispatch(notifyApp(createSuccessNotification('Query history deleted')));
},
})
);