mirror of
https://github.com/grafana/grafana.git
synced 2026-01-14 21:25:50 +00:00
Compare commits
7 Commits
ash/react-
...
alerting/U
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7264ca9acf | ||
|
|
99acd3766d | ||
|
|
77ccbeb543 | ||
|
|
11835de49f | ||
|
|
41168594f3 | ||
|
|
3a1f19bdf3 | ||
|
|
f395a749a4 |
@@ -1392,11 +1392,6 @@
|
||||
"count": 2
|
||||
}
|
||||
},
|
||||
"public/app/features/alerting/unified/components/mute-timings/MuteTimingForm.tsx": {
|
||||
"no-restricted-syntax": {
|
||||
"count": 1
|
||||
}
|
||||
},
|
||||
"public/app/features/alerting/unified/components/mute-timings/MuteTimingTimeInterval.tsx": {
|
||||
"no-restricted-syntax": {
|
||||
"count": 5
|
||||
@@ -1521,11 +1516,6 @@
|
||||
"count": 1
|
||||
}
|
||||
},
|
||||
"public/app/features/alerting/unified/components/rule-editor/alert-rule-form/simplifiedRouting/route-settings/MuteTimingFields.tsx": {
|
||||
"no-restricted-syntax": {
|
||||
"count": 1
|
||||
}
|
||||
},
|
||||
"public/app/features/alerting/unified/components/rule-editor/alert-rule-form/simplifiedRouting/route-settings/RouteSettings.tsx": {
|
||||
"no-restricted-syntax": {
|
||||
"count": 1
|
||||
|
||||
@@ -56,6 +56,24 @@ export const ImportedContactPointAlert = (props: ExtraAlertProps) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const ImportedTimeIntervalAlert = (props: ExtraAlertProps) => {
|
||||
return (
|
||||
<Alert
|
||||
title={t(
|
||||
'alerting.provisioning.title-imported-time-interval',
|
||||
'This time interval was imported and cannot be edited through the UI'
|
||||
)}
|
||||
severity="info"
|
||||
{...props}
|
||||
>
|
||||
<Trans i18nKey="alerting.provisioning.body-imported-time-interval">
|
||||
This time interval was imported from an external Alertmanager and is currently read-only. The time interval will
|
||||
become editable after the migration process is complete.
|
||||
</Trans>
|
||||
</Alert>
|
||||
);
|
||||
};
|
||||
|
||||
export const ProvisioningBadge = ({
|
||||
tooltip,
|
||||
provenance,
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
import { render, screen, userEvent } from 'test/test-utils';
|
||||
|
||||
import { setupMswServer } from 'app/features/alerting/unified/mockApi';
|
||||
import { grantUserPermissions } from 'app/features/alerting/unified/mocks';
|
||||
import { setTimeIntervalsList } from 'app/features/alerting/unified/mocks/server/configure';
|
||||
import { AlertmanagerProvider } from 'app/features/alerting/unified/state/AlertmanagerContext';
|
||||
import { GRAFANA_RULES_SOURCE_NAME } from 'app/features/alerting/unified/utils/datasource';
|
||||
import { AccessControlAction } from 'app/types/accessControl';
|
||||
|
||||
import MuteTimingsSelector from './MuteTimingsSelector';
|
||||
|
||||
const renderWithProvider = (alertManagerSource = GRAFANA_RULES_SOURCE_NAME) => {
|
||||
return render(
|
||||
<AlertmanagerProvider accessType={'notification'} alertmanagerSourceName={alertManagerSource}>
|
||||
<MuteTimingsSelector
|
||||
alertmanager={alertManagerSource}
|
||||
selectProps={{
|
||||
onChange: () => {},
|
||||
}}
|
||||
/>
|
||||
</AlertmanagerProvider>
|
||||
);
|
||||
};
|
||||
|
||||
setupMswServer();
|
||||
|
||||
describe('MuteTimingsSelector', () => {
|
||||
beforeEach(() => {
|
||||
grantUserPermissions([
|
||||
AccessControlAction.AlertingNotificationsRead,
|
||||
AccessControlAction.AlertingNotificationsWrite,
|
||||
]);
|
||||
});
|
||||
|
||||
it('should show all non-imported time intervals', async () => {
|
||||
const user = userEvent.setup();
|
||||
setTimeIntervalsList([
|
||||
{ name: 'regular-interval', provenance: 'none' },
|
||||
{ name: 'file-provisioned', provenance: 'file' },
|
||||
{ name: 'another-regular', provenance: 'none' },
|
||||
]);
|
||||
|
||||
renderWithProvider();
|
||||
|
||||
// Click to open the dropdown
|
||||
const selector = await screen.findByRole('combobox', { name: /time intervals/i });
|
||||
await user.click(selector);
|
||||
|
||||
// All non-imported intervals should be visible
|
||||
expect(await screen.findByText('regular-interval')).toBeInTheDocument();
|
||||
expect(screen.getByText('file-provisioned')).toBeInTheDocument();
|
||||
expect(screen.getByText('another-regular')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should filter out imported time intervals (provenance: converted_prometheus)', async () => {
|
||||
const user = userEvent.setup();
|
||||
setTimeIntervalsList([
|
||||
{ name: 'regular-interval', provenance: 'none' },
|
||||
{ name: 'imported-interval', provenance: 'converted_prometheus' },
|
||||
{ name: 'file-provisioned', provenance: 'file' },
|
||||
]);
|
||||
|
||||
renderWithProvider();
|
||||
|
||||
// Click to open the dropdown
|
||||
const selector = await screen.findByRole('combobox', { name: /time intervals/i });
|
||||
await user.click(selector);
|
||||
|
||||
// Regular and file-provisioned should be visible
|
||||
expect(await screen.findByText('regular-interval')).toBeInTheDocument();
|
||||
expect(screen.getByText('file-provisioned')).toBeInTheDocument();
|
||||
|
||||
// Imported interval should NOT be in the list
|
||||
expect(screen.queryByText('imported-interval')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should show only non-imported intervals when all types are present', async () => {
|
||||
const user = userEvent.setup();
|
||||
setTimeIntervalsList([
|
||||
{ name: 'normal-1', provenance: 'none' },
|
||||
{ name: 'imported-1', provenance: 'converted_prometheus' },
|
||||
{ name: 'normal-2', provenance: 'none' },
|
||||
{ name: 'imported-2', provenance: 'converted_prometheus' },
|
||||
{ name: 'file-1', provenance: 'file' },
|
||||
]);
|
||||
|
||||
renderWithProvider();
|
||||
|
||||
// Click to open the dropdown
|
||||
const selector = await screen.findByRole('combobox', { name: /time intervals/i });
|
||||
await user.click(selector);
|
||||
|
||||
// Non-imported intervals should be visible
|
||||
expect(await screen.findByText('normal-1')).toBeInTheDocument();
|
||||
expect(screen.getByText('normal-2')).toBeInTheDocument();
|
||||
expect(screen.getByText('file-1')).toBeInTheDocument();
|
||||
|
||||
// Imported intervals should NOT be visible
|
||||
expect(screen.queryByText('imported-1')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('imported-2')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should handle empty list', async () => {
|
||||
setTimeIntervalsList([]);
|
||||
|
||||
renderWithProvider();
|
||||
|
||||
// Selector should be present but have no options
|
||||
const selector = await screen.findByRole('combobox', { name: /time intervals/i });
|
||||
expect(selector).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should handle list with only imported intervals', async () => {
|
||||
const user = userEvent.setup();
|
||||
setTimeIntervalsList([
|
||||
{ name: 'imported-1', provenance: 'converted_prometheus' },
|
||||
{ name: 'imported-2', provenance: 'converted_prometheus' },
|
||||
]);
|
||||
|
||||
renderWithProvider();
|
||||
|
||||
// Click to open the dropdown
|
||||
const selector = await screen.findByRole('combobox', { name: /time intervals/i });
|
||||
await user.click(selector);
|
||||
|
||||
// No intervals should be visible
|
||||
expect(screen.queryByText('imported-1')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('imported-2')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -1,17 +1,24 @@
|
||||
import { SelectableValue } from '@grafana/data';
|
||||
import { t } from '@grafana/i18n';
|
||||
import { MultiSelect, MultiSelectCommonProps } from '@grafana/ui';
|
||||
import { useMuteTimings } from 'app/features/alerting/unified/components/mute-timings/useMuteTimings';
|
||||
import { MuteTiming, useMuteTimings } from 'app/features/alerting/unified/components/mute-timings/useMuteTimings';
|
||||
import { BaseAlertmanagerArgs } from 'app/features/alerting/unified/types/hooks';
|
||||
import { timeIntervalToString } from 'app/features/alerting/unified/utils/alertmanager';
|
||||
import { MuteTimeInterval } from 'app/plugins/datasource/alertmanager/types';
|
||||
import { K8sAnnotations } from 'app/features/alerting/unified/utils/k8s/constants';
|
||||
import { isImportedResource } from 'app/features/alerting/unified/utils/k8s/utils';
|
||||
|
||||
const mapTimeInterval = ({ name, time_intervals }: MuteTimeInterval): SelectableValue<string> => ({
|
||||
const mapTimeInterval = ({ name, time_intervals }: MuteTiming): SelectableValue<string> => ({
|
||||
value: name,
|
||||
label: name,
|
||||
description: time_intervals.map((interval) => timeIntervalToString(interval)).join(', AND '),
|
||||
});
|
||||
|
||||
/** Check if a time interval was imported from an external Alertmanager */
|
||||
const isImportedTimeInterval = (timing: MuteTiming): boolean => {
|
||||
const provenance = timing.metadata?.annotations?.[K8sAnnotations.Provenance];
|
||||
return isImportedResource(provenance);
|
||||
};
|
||||
|
||||
/** Provides a MultiSelect with available time intervals for the given alertmanager */
|
||||
const TimeIntervalSelector = ({
|
||||
alertmanager,
|
||||
@@ -19,7 +26,9 @@ const TimeIntervalSelector = ({
|
||||
}: BaseAlertmanagerArgs & { selectProps: MultiSelectCommonProps<string> }) => {
|
||||
const { data } = useMuteTimings({ alertmanager, skip: selectProps.disabled });
|
||||
|
||||
const timeIntervalOptions = data?.map((value) => mapTimeInterval(value)) || [];
|
||||
// Filter out imported time intervals (provenance === 'prometheus_convert')
|
||||
const availableTimings = data?.filter((timing) => !isImportedTimeInterval(timing)) || [];
|
||||
const timeIntervalOptions = availableTimings.map((value) => mapTimeInterval(value));
|
||||
|
||||
return (
|
||||
<MultiSelect
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Navigate } from 'react-router-dom-v5-compat';
|
||||
import { t } from '@grafana/i18n';
|
||||
import { useGetMuteTiming } from 'app/features/alerting/unified/components/mute-timings/useMuteTimings';
|
||||
import { useURLSearchParams } from 'app/features/alerting/unified/hooks/useURLSearchParams';
|
||||
import { K8sAnnotations } from 'app/features/alerting/unified/utils/k8s/constants';
|
||||
|
||||
import { useAlertmanager } from '../../state/AlertmanagerContext';
|
||||
import { withPageErrorBoundary } from '../../withPageErrorBoundary';
|
||||
@@ -28,13 +29,15 @@ const EditTimingRoute = () => {
|
||||
return <Navigate replace to="/alerting/routes" />;
|
||||
}
|
||||
|
||||
const provenance = timeInterval?.metadata?.annotations?.[K8sAnnotations.Provenance];
|
||||
|
||||
return (
|
||||
<MuteTimingForm
|
||||
editMode
|
||||
loading={isLoading}
|
||||
showError={isError}
|
||||
muteTiming={timeInterval}
|
||||
provisioned={timeInterval?.provisioned}
|
||||
provenance={provenance}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import { render, screen } from 'test/test-utils';
|
||||
|
||||
import { setupMswServer } from 'app/features/alerting/unified/mockApi';
|
||||
import { grantUserPermissions } from 'app/features/alerting/unified/mocks';
|
||||
import { AlertmanagerProvider } from 'app/features/alerting/unified/state/AlertmanagerContext';
|
||||
import { GRAFANA_RULES_SOURCE_NAME } from 'app/features/alerting/unified/utils/datasource';
|
||||
import { AccessControlAction } from 'app/types/accessControl';
|
||||
|
||||
import MuteTimingForm from './MuteTimingForm';
|
||||
import { muteTimeInterval } from './mocks';
|
||||
|
||||
const renderWithProvider = (provenance?: string, editMode = false) => {
|
||||
return render(
|
||||
<AlertmanagerProvider accessType={'notification'} alertmanagerSourceName={GRAFANA_RULES_SOURCE_NAME}>
|
||||
<MuteTimingForm
|
||||
muteTiming={{ id: 'mock-id', ...muteTimeInterval }}
|
||||
provenance={provenance}
|
||||
editMode={editMode}
|
||||
loading={false}
|
||||
showError={false}
|
||||
/>
|
||||
</AlertmanagerProvider>
|
||||
);
|
||||
};
|
||||
|
||||
setupMswServer();
|
||||
|
||||
describe('MuteTimingForm', () => {
|
||||
beforeEach(() => {
|
||||
grantUserPermissions([
|
||||
AccessControlAction.AlertingNotificationsRead,
|
||||
AccessControlAction.AlertingNotificationsWrite,
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not show any alert when provenance is none', async () => {
|
||||
renderWithProvider('none');
|
||||
|
||||
expect(screen.queryByText(/imported and cannot be edited/i)).not.toBeInTheDocument();
|
||||
expect(screen.queryByText(/provisioned/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should not show any alert when provenance is undefined', async () => {
|
||||
renderWithProvider(undefined);
|
||||
|
||||
expect(screen.queryByText(/imported and cannot be edited/i)).not.toBeInTheDocument();
|
||||
expect(screen.queryByText(/provisioned/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should show imported alert when provenance is converted_prometheus', async () => {
|
||||
renderWithProvider('converted_prometheus');
|
||||
|
||||
expect(
|
||||
await screen.findByText(/This time interval was imported and cannot be edited through the UI/i)
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText(/This time interval was imported from an external Alertmanager and is currently read-only/i)
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should show provisioning alert when provenance is file', async () => {
|
||||
renderWithProvider('file');
|
||||
|
||||
expect(await screen.findByText(/This time interval cannot be edited through the UI/i)).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText(/This time interval has been provisioned, that means it was created by config/i)
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should show provisioning alert for other provenance types', async () => {
|
||||
renderWithProvider('api');
|
||||
|
||||
expect(await screen.findByText(/This time interval cannot be edited through the UI/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should disable form when provenance is converted_prometheus', async () => {
|
||||
renderWithProvider('converted_prometheus', true);
|
||||
|
||||
const nameInput = await screen.findByTestId('mute-timing-name');
|
||||
expect(nameInput).toBeDisabled();
|
||||
});
|
||||
|
||||
it('should disable form when provenance is file', async () => {
|
||||
renderWithProvider('file', true);
|
||||
|
||||
const nameInput = await screen.findByTestId('mute-timing-name');
|
||||
expect(nameInput).toBeDisabled();
|
||||
});
|
||||
|
||||
it('should enable form when provenance is none', async () => {
|
||||
renderWithProvider('none', true);
|
||||
|
||||
const nameInput = await screen.findByTestId('mute-timing-name');
|
||||
expect(nameInput).toBeEnabled();
|
||||
});
|
||||
|
||||
it('should enable form when provenance is undefined', async () => {
|
||||
renderWithProvider(undefined, true);
|
||||
|
||||
const nameInput = await screen.findByTestId('mute-timing-name');
|
||||
expect(nameInput).toBeEnabled();
|
||||
});
|
||||
});
|
||||
@@ -14,9 +14,10 @@ import {
|
||||
|
||||
import { useAlertmanager } from '../../state/AlertmanagerContext';
|
||||
import { MuteTimingFields } from '../../types/mute-timing-form';
|
||||
import { isImportedResource, isProvisionedResource } from '../../utils/k8s/utils';
|
||||
import { makeAMLink } from '../../utils/misc';
|
||||
import { createMuteTiming, defaultTimeInterval, isTimeIntervalDisabled } from '../../utils/mute-timings';
|
||||
import { ProvisionedResource, ProvisioningAlert } from '../Provisioning';
|
||||
import { ImportedTimeIntervalAlert, ProvisionedResource, ProvisioningAlert } from '../Provisioning';
|
||||
|
||||
import { MuteTimingTimeInterval } from './MuteTimingTimeInterval';
|
||||
|
||||
@@ -24,8 +25,8 @@ interface Props {
|
||||
muteTiming?: MuteTiming;
|
||||
showError?: boolean;
|
||||
loading?: boolean;
|
||||
/** Is the current mute timing provisioned? If so, will disable editing via UI */
|
||||
provisioned?: boolean;
|
||||
/** Provenance of the mute timing - indicates how it was created (e.g., 'file', 'prometheus_convert', 'none') */
|
||||
provenance?: string;
|
||||
/** Are we editing an existing time interval? */
|
||||
editMode?: boolean;
|
||||
}
|
||||
@@ -56,7 +57,7 @@ const useDefaultValues = (muteTiming?: MuteTiming): MuteTimingFields => {
|
||||
};
|
||||
};
|
||||
|
||||
const MuteTimingForm = ({ muteTiming, showError, loading, provisioned, editMode }: Props) => {
|
||||
const MuteTimingForm = ({ muteTiming, showError, loading, provenance, editMode }: Props) => {
|
||||
const { selectedAlertmanager } = useAlertmanager();
|
||||
const hookArgs = { alertmanager: selectedAlertmanager! };
|
||||
|
||||
@@ -105,14 +106,19 @@ const MuteTimingForm = ({ muteTiming, showError, loading, provisioned, editMode
|
||||
);
|
||||
}
|
||||
|
||||
const isProvisioned = isProvisionedResource(provenance);
|
||||
const isImported = isImportedResource(provenance);
|
||||
|
||||
return (
|
||||
<>
|
||||
{provisioned && <ProvisioningAlert resource={ProvisionedResource.MuteTiming} />}
|
||||
{isProvisioned && isImported && <ImportedTimeIntervalAlert />}
|
||||
{isProvisioned && !isImported && <ProvisioningAlert resource={ProvisionedResource.MuteTiming} />}
|
||||
<FormProvider {...formApi}>
|
||||
<form onSubmit={formApi.handleSubmit(onSubmit)} data-testid="mute-timing-form">
|
||||
<FieldSet disabled={provisioned || updating}>
|
||||
<FieldSet disabled={isProvisioned || updating}>
|
||||
<Field
|
||||
required
|
||||
noMargin
|
||||
label={t('alerting.mute-timing-form.label-name', 'Name')}
|
||||
description={t(
|
||||
'alerting.time-interval-form.description-unique-time-interval',
|
||||
|
||||
@@ -27,6 +27,7 @@ export function MuteTimingFields({ alertmanager }: BaseAlertmanagerArgs) {
|
||||
)}
|
||||
className={styles.muteTimingField}
|
||||
invalid={!!errors.contactPoints?.[alertmanager]?.muteTimeIntervals}
|
||||
noMargin
|
||||
>
|
||||
<Controller
|
||||
render={({ field: { onChange, ref, ...field } }) => (
|
||||
|
||||
@@ -175,6 +175,36 @@ export const setTimeIntervalsListEmpty = () => {
|
||||
return handler;
|
||||
};
|
||||
|
||||
interface TimeIntervalConfig {
|
||||
name: string;
|
||||
provenance?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the mock server respond with custom time intervals
|
||||
*/
|
||||
export const setTimeIntervalsList = (intervals: TimeIntervalConfig[]) => {
|
||||
const listMuteTimingsPath = listNamespacedTimeIntervalHandler().info.path;
|
||||
const handler = http.get(listMuteTimingsPath, () => {
|
||||
const items = intervals.map((interval) => ({
|
||||
metadata: {
|
||||
annotations: {
|
||||
'grafana.com/provenance': interval.provenance ?? 'none',
|
||||
},
|
||||
name: interval.name,
|
||||
uid: `uid-${interval.name}`,
|
||||
namespace: 'default',
|
||||
resourceVersion: 'e0270bfced786660',
|
||||
},
|
||||
spec: { name: interval.name, time_intervals: [] },
|
||||
}));
|
||||
return HttpResponse.json(getK8sResponse('TimeIntervalList', items));
|
||||
});
|
||||
|
||||
server.use(handler);
|
||||
return handler;
|
||||
};
|
||||
|
||||
export function mimirDataSource() {
|
||||
const dataSource = mockDataSource(
|
||||
{
|
||||
|
||||
@@ -65,3 +65,7 @@ export const stringifyFieldSelector = (fieldSelectors: FieldSelector[]): string
|
||||
export function isProvisionedResource(provenance?: string): boolean {
|
||||
return Boolean(provenance && provenance !== KnownProvenance.None);
|
||||
}
|
||||
|
||||
export function isImportedResource(provenance?: string): boolean {
|
||||
return provenance === KnownProvenance.ConvertedPrometheus;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@ import { render, screen } from '@testing-library/react';
|
||||
import { defaultsDeep } from 'lodash';
|
||||
import { Provider } from 'react-redux';
|
||||
|
||||
import { FieldType, getDefaultTimeRange, LoadingState } from '@grafana/data';
|
||||
import { PanelDataErrorViewProps } from '@grafana/runtime';
|
||||
import { CoreApp, EventBusSrv, FieldType, getDefaultTimeRange, LoadingState } from '@grafana/data';
|
||||
import { config, PanelDataErrorViewProps } from '@grafana/runtime';
|
||||
import { usePanelContext } from '@grafana/ui';
|
||||
import { configureStore } from 'app/store/configureStore';
|
||||
|
||||
import { PanelDataErrorView } from './PanelDataErrorView';
|
||||
@@ -16,7 +17,24 @@ jest.mock('app/features/dashboard/services/DashboardSrv', () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('@grafana/ui', () => ({
|
||||
...jest.requireActual('@grafana/ui'),
|
||||
usePanelContext: jest.fn(),
|
||||
}));
|
||||
|
||||
const mockUsePanelContext = jest.mocked(usePanelContext);
|
||||
const RUN_QUERY_MESSAGE = 'Run a query to visualize it here or go to all visualizations to add other panel types';
|
||||
const panelContextRoot = {
|
||||
app: CoreApp.Dashboard,
|
||||
eventsScope: 'global',
|
||||
eventBus: new EventBusSrv(),
|
||||
};
|
||||
|
||||
describe('PanelDataErrorView', () => {
|
||||
beforeEach(() => {
|
||||
mockUsePanelContext.mockReturnValue(panelContextRoot);
|
||||
});
|
||||
|
||||
it('show No data when there is no data', () => {
|
||||
renderWithProps();
|
||||
|
||||
@@ -70,6 +88,45 @@ describe('PanelDataErrorView', () => {
|
||||
|
||||
expect(screen.getByText('Query returned nothing')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should show "Run a query..." message when no query is configured and feature toggle is enabled', () => {
|
||||
mockUsePanelContext.mockReturnValue(panelContextRoot);
|
||||
|
||||
const originalFeatureToggle = config.featureToggles.newVizSuggestions;
|
||||
config.featureToggles.newVizSuggestions = true;
|
||||
|
||||
renderWithProps({
|
||||
data: {
|
||||
state: LoadingState.Done,
|
||||
series: [],
|
||||
timeRange: getDefaultTimeRange(),
|
||||
},
|
||||
});
|
||||
|
||||
expect(screen.getByText(RUN_QUERY_MESSAGE)).toBeInTheDocument();
|
||||
|
||||
config.featureToggles.newVizSuggestions = originalFeatureToggle;
|
||||
});
|
||||
|
||||
it('should show "No data" message when feature toggle is disabled even without queries', () => {
|
||||
mockUsePanelContext.mockReturnValue(panelContextRoot);
|
||||
|
||||
const originalFeatureToggle = config.featureToggles.newVizSuggestions;
|
||||
config.featureToggles.newVizSuggestions = false;
|
||||
|
||||
renderWithProps({
|
||||
data: {
|
||||
state: LoadingState.Done,
|
||||
series: [],
|
||||
timeRange: getDefaultTimeRange(),
|
||||
},
|
||||
});
|
||||
|
||||
expect(screen.getByText('No data')).toBeInTheDocument();
|
||||
expect(screen.queryByText(RUN_QUERY_MESSAGE)).not.toBeInTheDocument();
|
||||
|
||||
config.featureToggles.newVizSuggestions = originalFeatureToggle;
|
||||
});
|
||||
});
|
||||
|
||||
function renderWithProps(overrides?: Partial<PanelDataErrorViewProps>) {
|
||||
|
||||
@@ -5,14 +5,15 @@ import {
|
||||
FieldType,
|
||||
getPanelDataSummary,
|
||||
GrafanaTheme2,
|
||||
PanelData,
|
||||
PanelDataSummary,
|
||||
PanelPluginVisualizationSuggestion,
|
||||
} from '@grafana/data';
|
||||
import { selectors } from '@grafana/e2e-selectors';
|
||||
import { t, Trans } from '@grafana/i18n';
|
||||
import { PanelDataErrorViewProps, locationService } from '@grafana/runtime';
|
||||
import { PanelDataErrorViewProps, locationService, config } from '@grafana/runtime';
|
||||
import { VizPanel } from '@grafana/scenes';
|
||||
import { usePanelContext, useStyles2 } from '@grafana/ui';
|
||||
import { Icon, usePanelContext, useStyles2 } from '@grafana/ui';
|
||||
import { CardButton } from 'app/core/components/CardButton';
|
||||
import { LS_VISUALIZATION_SELECT_TAB_KEY } from 'app/core/constants';
|
||||
import store from 'app/core/store';
|
||||
@@ -24,6 +25,11 @@ import { findVizPanelByKey, getVizPanelKeyForPanelId } from 'app/features/dashbo
|
||||
import { useDispatch } from 'app/types/store';
|
||||
|
||||
import { changePanelPlugin } from '../state/actions';
|
||||
import { hasData } from '../suggestions/utils';
|
||||
|
||||
function hasNoQueryConfigured(data: PanelData): boolean {
|
||||
return !data.request?.targets || data.request.targets.length === 0;
|
||||
}
|
||||
|
||||
export function PanelDataErrorView(props: PanelDataErrorViewProps) {
|
||||
const styles = useStyles2(getStyles);
|
||||
@@ -93,8 +99,14 @@ export function PanelDataErrorView(props: PanelDataErrorViewProps) {
|
||||
}
|
||||
};
|
||||
|
||||
const noData = !hasData(props.data);
|
||||
const noQueryConfigured = hasNoQueryConfigured(props.data);
|
||||
const showEmptyState =
|
||||
config.featureToggles.newVizSuggestions && context.app === CoreApp.PanelEditor && noQueryConfigured && noData;
|
||||
|
||||
return (
|
||||
<div className={styles.wrapper}>
|
||||
{showEmptyState && <Icon name="chart-line" size="xxxl" className={styles.emptyStateIcon} />}
|
||||
<div className={styles.message} data-testid={selectors.components.Panels.Panel.PanelDataErrorMessage}>
|
||||
{message}
|
||||
</div>
|
||||
@@ -131,7 +143,17 @@ function getMessageFor(
|
||||
return message;
|
||||
}
|
||||
|
||||
if (!data.series || data.series.length === 0 || data.series.every((frame) => frame.length === 0)) {
|
||||
const noData = !hasData(data);
|
||||
const noQueryConfigured = hasNoQueryConfigured(data);
|
||||
|
||||
if (config.featureToggles.newVizSuggestions && noQueryConfigured && noData) {
|
||||
return t(
|
||||
'dashboard.new-panel.empty-state-message',
|
||||
'Run a query to visualize it here or go to all visualizations to add other panel types'
|
||||
);
|
||||
}
|
||||
|
||||
if (noData) {
|
||||
return fieldConfig?.defaults.noValue ?? t('panel.panel-data-error-view.no-value.default', 'No data');
|
||||
}
|
||||
|
||||
@@ -176,5 +198,9 @@ const getStyles = (theme: GrafanaTheme2) => {
|
||||
width: '100%',
|
||||
maxWidth: '600px',
|
||||
}),
|
||||
emptyStateIcon: css({
|
||||
color: theme.colors.text.secondary,
|
||||
marginBottom: theme.spacing(2),
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2178,8 +2178,10 @@
|
||||
"badge-tooltip-provenance": "This resource has been provisioned via {{provenance}} and cannot be edited through the UI",
|
||||
"badge-tooltip-standard": "This resource has been provisioned and cannot be edited through the UI",
|
||||
"body-imported": "This contact point contains integrations that were imported from an external Alertmanager and is currently read-only. The integrations will become editable after the migration process is complete.",
|
||||
"body-imported-time-interval": "This time interval was imported from an external Alertmanager and is currently read-only. The time interval will become editable after the migration process is complete.",
|
||||
"body-provisioned": "This {{resource}} has been provisioned, that means it was created by config. Please contact your server admin to update this {{resource}}.",
|
||||
"title-imported": "This contact point was imported and cannot be edited through the UI",
|
||||
"title-imported-time-interval": "This time interval was imported and cannot be edited through the UI",
|
||||
"title-provisioned": "This {{resource}} cannot be edited through the UI"
|
||||
},
|
||||
"provisioning-badge": {
|
||||
|
||||
Reference in New Issue
Block a user