Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7264ca9acf | |||
| 99acd3766d | |||
| 77ccbeb543 | |||
| 11835de49f | |||
| 41168594f3 | |||
| 3a1f19bdf3 | |||
| f395a749a4 |
@@ -1392,11 +1392,6 @@
|
|||||||
"count": 2
|
"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": {
|
"public/app/features/alerting/unified/components/mute-timings/MuteTimingTimeInterval.tsx": {
|
||||||
"no-restricted-syntax": {
|
"no-restricted-syntax": {
|
||||||
"count": 5
|
"count": 5
|
||||||
@@ -1521,11 +1516,6 @@
|
|||||||
"count": 1
|
"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": {
|
"public/app/features/alerting/unified/components/rule-editor/alert-rule-form/simplifiedRouting/route-settings/RouteSettings.tsx": {
|
||||||
"no-restricted-syntax": {
|
"no-restricted-syntax": {
|
||||||
"count": 1
|
"count": 1
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import { getBarColorByDiff, getBarColorByPackage, getBarColorByValue } from './c
|
|||||||
import { CollapseConfig, CollapsedMap, FlameGraphDataContainer, LevelItem } from './dataTransform';
|
import { CollapseConfig, CollapsedMap, FlameGraphDataContainer, LevelItem } from './dataTransform';
|
||||||
|
|
||||||
type RenderOptions = {
|
type RenderOptions = {
|
||||||
canvasRef: RefObject<HTMLCanvasElement | null>;
|
canvasRef: RefObject<HTMLCanvasElement>;
|
||||||
data: FlameGraphDataContainer;
|
data: FlameGraphDataContainer;
|
||||||
root: LevelItem;
|
root: LevelItem;
|
||||||
direction: 'children' | 'parents';
|
direction: 'children' | 'parents';
|
||||||
@@ -373,7 +373,7 @@ function useColorFunction(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function useSetupCanvas(canvasRef: RefObject<HTMLCanvasElement | null>, wrapperWidth: number, numberOfLevels: number) {
|
function useSetupCanvas(canvasRef: RefObject<HTMLCanvasElement>, wrapperWidth: number, numberOfLevels: number) {
|
||||||
const [ctx, setCtx] = useState<CanvasRenderingContext2D>();
|
const [ctx, setCtx] = useState<CanvasRenderingContext2D>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const CAUGHT_KEYS = ['ArrowUp', 'ArrowDown', 'Home', 'End', 'Enter', 'Tab'];
|
|||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export interface UseListFocusProps {
|
export interface UseListFocusProps {
|
||||||
localRef: RefObject<HTMLUListElement | null>;
|
localRef: RefObject<HTMLUListElement>;
|
||||||
options: TimeOption[];
|
options: TimeOption[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { RefObject, useRef } from 'react';
|
import { RefObject, useRef } from 'react';
|
||||||
|
|
||||||
export function useFocus(): [RefObject<HTMLInputElement | null>, () => void] {
|
export function useFocus(): [RefObject<HTMLInputElement>, () => void] {
|
||||||
const ref = useRef<HTMLInputElement | null>(null);
|
const ref = useRef<HTMLInputElement>(null);
|
||||||
const setFocus = () => {
|
const setFocus = () => {
|
||||||
ref.current && ref.current.focus();
|
ref.current && ref.current.focus();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const UNFOCUSED = -1;
|
|||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export interface UseMenuFocusProps {
|
export interface UseMenuFocusProps {
|
||||||
localRef: RefObject<HTMLDivElement | null>;
|
localRef: RefObject<HTMLDivElement>;
|
||||||
isMenuOpen?: boolean;
|
isMenuOpen?: boolean;
|
||||||
close?: () => void;
|
close?: () => void;
|
||||||
onOpen?: (focusOnItem: (itemId: number) => void) => void;
|
onOpen?: (focusOnItem: (itemId: number) => void) => void;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ interface Props extends Omit<BoxProps, 'display' | 'direction' | 'element' | 'fl
|
|||||||
*
|
*
|
||||||
* https://developers.grafana.com/ui/latest/index.html?path=/docs/layout-scrollcontainer--docs
|
* https://developers.grafana.com/ui/latest/index.html?path=/docs/layout-scrollcontainer--docs
|
||||||
*/
|
*/
|
||||||
export const ScrollContainer = forwardRef<HTMLDivElement | null, PropsWithChildren<Props>>(
|
export const ScrollContainer = forwardRef<HTMLDivElement, PropsWithChildren<Props>>(
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
children,
|
children,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export interface TableCellTooltipProps {
|
|||||||
field: Field;
|
field: Field;
|
||||||
getActions: (field: Field, rowIdx: number) => ActionModel[];
|
getActions: (field: Field, rowIdx: number) => ActionModel[];
|
||||||
getTextColorForBackground: (bgColor: string) => string;
|
getTextColorForBackground: (bgColor: string) => string;
|
||||||
gridRef: RefObject<DataGridHandle | null>;
|
gridRef: RefObject<DataGridHandle>;
|
||||||
height: number;
|
height: number;
|
||||||
placement?: TableCellTooltipPlacement;
|
placement?: TableCellTooltipPlacement;
|
||||||
renderer: TableCellRenderer;
|
renderer: TableCellRenderer;
|
||||||
|
|||||||
@@ -463,7 +463,7 @@ export function useColumnResize(
|
|||||||
return dataGridResizeHandler;
|
return dataGridResizeHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useScrollbarWidth(ref: RefObject<DataGridHandle | null>, height: number) {
|
export function useScrollbarWidth(ref: RefObject<DataGridHandle>, height: number) {
|
||||||
const [scrollbarWidth, setScrollbarWidth] = useState(0);
|
const [scrollbarWidth, setScrollbarWidth] = useState(0);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ export const Table = memo((props: Props) => {
|
|||||||
// `useTableStateReducer`, which is needed to construct options for `useTable` (the hook that returns
|
// `useTableStateReducer`, which is needed to construct options for `useTable` (the hook that returns
|
||||||
// `toggleAllRowsExpanded`), and if we used a variable, that variable would be undefined at the time
|
// `toggleAllRowsExpanded`), and if we used a variable, that variable would be undefined at the time
|
||||||
// we initialize `useTableStateReducer`.
|
// we initialize `useTableStateReducer`.
|
||||||
const toggleAllRowsExpandedRef = useRef<((value?: boolean) => void) | null>(null);
|
const toggleAllRowsExpandedRef = useRef<(value?: boolean) => void>();
|
||||||
|
|
||||||
// Internal react table state reducer
|
// Internal react table state reducer
|
||||||
const stateReducer = useTableStateReducer({
|
const stateReducer = useTableStateReducer({
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import { GrafanaTableState } from './types';
|
|||||||
Select the scrollbar element from the VariableSizeList scope
|
Select the scrollbar element from the VariableSizeList scope
|
||||||
*/
|
*/
|
||||||
export function useFixScrollbarContainer(
|
export function useFixScrollbarContainer(
|
||||||
variableSizeListScrollbarRef: React.RefObject<HTMLDivElement | null>,
|
variableSizeListScrollbarRef: React.RefObject<HTMLDivElement>,
|
||||||
tableDivRef: React.RefObject<HTMLDivElement | null>
|
tableDivRef: React.RefObject<HTMLDivElement>
|
||||||
) {
|
) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (variableSizeListScrollbarRef.current && tableDivRef.current) {
|
if (variableSizeListScrollbarRef.current && tableDivRef.current) {
|
||||||
@@ -43,7 +43,7 @@ export function useFixScrollbarContainer(
|
|||||||
*/
|
*/
|
||||||
export function useResetVariableListSizeCache(
|
export function useResetVariableListSizeCache(
|
||||||
extendedState: GrafanaTableState,
|
extendedState: GrafanaTableState,
|
||||||
listRef: React.RefObject<VariableSizeList | null>,
|
listRef: React.RefObject<VariableSizeList>,
|
||||||
data: DataFrame,
|
data: DataFrame,
|
||||||
hasUniqueId: boolean
|
hasUniqueId: boolean
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ interface EventsCanvasProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function EventsCanvas({ id, events, renderEventMarker, mapEventToXYCoords, config }: EventsCanvasProps) {
|
export function EventsCanvas({ id, events, renderEventMarker, mapEventToXYCoords, config }: EventsCanvasProps) {
|
||||||
const plotInstance = useRef<uPlot | null>(null);
|
const plotInstance = useRef<uPlot>();
|
||||||
// render token required to re-render annotation markers. Rendering lines happens in uPlot and the props do not change
|
// render token required to re-render annotation markers. Rendering lines happens in uPlot and the props do not change
|
||||||
// so we need to force the re-render when the draw hook was performed by uPlot
|
// so we need to force the re-render when the draw hook was performed by uPlot
|
||||||
const [renderToken, setRenderToken] = useState(0);
|
const [renderToken, setRenderToken] = useState(0);
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ export const TooltipPlugin2 = ({
|
|||||||
|
|
||||||
const [{ plot, isHovering, isPinned, contents, style, dismiss }, setState] = useReducer(mergeState, null, initState);
|
const [{ plot, isHovering, isPinned, contents, style, dismiss }, setState] = useReducer(mergeState, null, initState);
|
||||||
|
|
||||||
const sizeRef = useRef<TooltipContainerSize | null>(null);
|
const sizeRef = useRef<TooltipContainerSize>();
|
||||||
const styles = useStyles2(getStyles, maxWidth);
|
const styles = useStyles2(getStyles, maxWidth);
|
||||||
|
|
||||||
const renderRef = useRef(render);
|
const renderRef = useRef(render);
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ export interface GraphNGState {
|
|||||||
export class GraphNG extends Component<GraphNGProps, GraphNGState> {
|
export class GraphNG extends Component<GraphNGProps, GraphNGState> {
|
||||||
static contextType = PanelContextRoot;
|
static contextType = PanelContextRoot;
|
||||||
panelContext: PanelContext = {} as PanelContext;
|
panelContext: PanelContext = {} as PanelContext;
|
||||||
private plotInstance: React.RefObject<uPlot | null>;
|
private plotInstance: React.RefObject<uPlot>;
|
||||||
|
|
||||||
private subscription = new Subscription();
|
private subscription = new Subscription();
|
||||||
|
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ const defaultMatchers = {
|
|||||||
* "Time as X" core component, expects ascending x
|
* "Time as X" core component, expects ascending x
|
||||||
*/
|
*/
|
||||||
export class GraphNG extends Component<GraphNGProps, GraphNGState> {
|
export class GraphNG extends Component<GraphNGProps, GraphNGState> {
|
||||||
private plotInstance: React.RefObject<uPlot | null>;
|
private plotInstance: React.RefObject<uPlot>;
|
||||||
|
|
||||||
constructor(props: GraphNGProps) {
|
constructor(props: GraphNGProps) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|||||||
@@ -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 = ({
|
export const ProvisioningBadge = ({
|
||||||
tooltip,
|
tooltip,
|
||||||
provenance,
|
provenance,
|
||||||
|
|||||||
+130
@@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
+13
-4
@@ -1,17 +1,24 @@
|
|||||||
import { SelectableValue } from '@grafana/data';
|
import { SelectableValue } from '@grafana/data';
|
||||||
import { t } from '@grafana/i18n';
|
import { t } from '@grafana/i18n';
|
||||||
import { MultiSelect, MultiSelectCommonProps } from '@grafana/ui';
|
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 { BaseAlertmanagerArgs } from 'app/features/alerting/unified/types/hooks';
|
||||||
import { timeIntervalToString } from 'app/features/alerting/unified/utils/alertmanager';
|
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,
|
value: name,
|
||||||
label: name,
|
label: name,
|
||||||
description: time_intervals.map((interval) => timeIntervalToString(interval)).join(', AND '),
|
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 */
|
/** Provides a MultiSelect with available time intervals for the given alertmanager */
|
||||||
const TimeIntervalSelector = ({
|
const TimeIntervalSelector = ({
|
||||||
alertmanager,
|
alertmanager,
|
||||||
@@ -19,7 +26,9 @@ const TimeIntervalSelector = ({
|
|||||||
}: BaseAlertmanagerArgs & { selectProps: MultiSelectCommonProps<string> }) => {
|
}: BaseAlertmanagerArgs & { selectProps: MultiSelectCommonProps<string> }) => {
|
||||||
const { data } = useMuteTimings({ alertmanager, skip: selectProps.disabled });
|
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 (
|
return (
|
||||||
<MultiSelect
|
<MultiSelect
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Navigate } from 'react-router-dom-v5-compat';
|
|||||||
import { t } from '@grafana/i18n';
|
import { t } from '@grafana/i18n';
|
||||||
import { useGetMuteTiming } from 'app/features/alerting/unified/components/mute-timings/useMuteTimings';
|
import { useGetMuteTiming } from 'app/features/alerting/unified/components/mute-timings/useMuteTimings';
|
||||||
import { useURLSearchParams } from 'app/features/alerting/unified/hooks/useURLSearchParams';
|
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 { useAlertmanager } from '../../state/AlertmanagerContext';
|
||||||
import { withPageErrorBoundary } from '../../withPageErrorBoundary';
|
import { withPageErrorBoundary } from '../../withPageErrorBoundary';
|
||||||
@@ -28,13 +29,15 @@ const EditTimingRoute = () => {
|
|||||||
return <Navigate replace to="/alerting/routes" />;
|
return <Navigate replace to="/alerting/routes" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const provenance = timeInterval?.metadata?.annotations?.[K8sAnnotations.Provenance];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MuteTimingForm
|
<MuteTimingForm
|
||||||
editMode
|
editMode
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
showError={isError}
|
showError={isError}
|
||||||
muteTiming={timeInterval}
|
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 { useAlertmanager } from '../../state/AlertmanagerContext';
|
||||||
import { MuteTimingFields } from '../../types/mute-timing-form';
|
import { MuteTimingFields } from '../../types/mute-timing-form';
|
||||||
|
import { isImportedResource, isProvisionedResource } from '../../utils/k8s/utils';
|
||||||
import { makeAMLink } from '../../utils/misc';
|
import { makeAMLink } from '../../utils/misc';
|
||||||
import { createMuteTiming, defaultTimeInterval, isTimeIntervalDisabled } from '../../utils/mute-timings';
|
import { createMuteTiming, defaultTimeInterval, isTimeIntervalDisabled } from '../../utils/mute-timings';
|
||||||
import { ProvisionedResource, ProvisioningAlert } from '../Provisioning';
|
import { ImportedTimeIntervalAlert, ProvisionedResource, ProvisioningAlert } from '../Provisioning';
|
||||||
|
|
||||||
import { MuteTimingTimeInterval } from './MuteTimingTimeInterval';
|
import { MuteTimingTimeInterval } from './MuteTimingTimeInterval';
|
||||||
|
|
||||||
@@ -24,8 +25,8 @@ interface Props {
|
|||||||
muteTiming?: MuteTiming;
|
muteTiming?: MuteTiming;
|
||||||
showError?: boolean;
|
showError?: boolean;
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
/** Is the current mute timing provisioned? If so, will disable editing via UI */
|
/** Provenance of the mute timing - indicates how it was created (e.g., 'file', 'prometheus_convert', 'none') */
|
||||||
provisioned?: boolean;
|
provenance?: string;
|
||||||
/** Are we editing an existing time interval? */
|
/** Are we editing an existing time interval? */
|
||||||
editMode?: boolean;
|
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 { selectedAlertmanager } = useAlertmanager();
|
||||||
const hookArgs = { alertmanager: selectedAlertmanager! };
|
const hookArgs = { alertmanager: selectedAlertmanager! };
|
||||||
|
|
||||||
@@ -105,14 +106,19 @@ const MuteTimingForm = ({ muteTiming, showError, loading, provisioned, editMode
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isProvisioned = isProvisionedResource(provenance);
|
||||||
|
const isImported = isImportedResource(provenance);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{provisioned && <ProvisioningAlert resource={ProvisionedResource.MuteTiming} />}
|
{isProvisioned && isImported && <ImportedTimeIntervalAlert />}
|
||||||
|
{isProvisioned && !isImported && <ProvisioningAlert resource={ProvisionedResource.MuteTiming} />}
|
||||||
<FormProvider {...formApi}>
|
<FormProvider {...formApi}>
|
||||||
<form onSubmit={formApi.handleSubmit(onSubmit)} data-testid="mute-timing-form">
|
<form onSubmit={formApi.handleSubmit(onSubmit)} data-testid="mute-timing-form">
|
||||||
<FieldSet disabled={provisioned || updating}>
|
<FieldSet disabled={isProvisioned || updating}>
|
||||||
<Field
|
<Field
|
||||||
required
|
required
|
||||||
|
noMargin
|
||||||
label={t('alerting.mute-timing-form.label-name', 'Name')}
|
label={t('alerting.mute-timing-form.label-name', 'Name')}
|
||||||
description={t(
|
description={t(
|
||||||
'alerting.time-interval-form.description-unique-time-interval',
|
'alerting.time-interval-form.description-unique-time-interval',
|
||||||
|
|||||||
+1
@@ -27,6 +27,7 @@ export function MuteTimingFields({ alertmanager }: BaseAlertmanagerArgs) {
|
|||||||
)}
|
)}
|
||||||
className={styles.muteTimingField}
|
className={styles.muteTimingField}
|
||||||
invalid={!!errors.contactPoints?.[alertmanager]?.muteTimeIntervals}
|
invalid={!!errors.contactPoints?.[alertmanager]?.muteTimeIntervals}
|
||||||
|
noMargin
|
||||||
>
|
>
|
||||||
<Controller
|
<Controller
|
||||||
render={({ field: { onChange, ref, ...field } }) => (
|
render={({ field: { onChange, ref, ...field } }) => (
|
||||||
|
|||||||
@@ -175,6 +175,36 @@ export const setTimeIntervalsListEmpty = () => {
|
|||||||
return handler;
|
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() {
|
export function mimirDataSource() {
|
||||||
const dataSource = mockDataSource(
|
const dataSource = mockDataSource(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -65,3 +65,7 @@ export const stringifyFieldSelector = (fieldSelectors: FieldSelector[]): string
|
|||||||
export function isProvisionedResource(provenance?: string): boolean {
|
export function isProvisionedResource(provenance?: string): boolean {
|
||||||
return Boolean(provenance && provenance !== KnownProvenance.None);
|
return Boolean(provenance && provenance !== KnownProvenance.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isImportedResource(provenance?: string): boolean {
|
||||||
|
return provenance === KnownProvenance.ConvertedPrometheus;
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ global.ResizeObserver = jest.fn().mockImplementation((callback) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Helper function to assign a mock div to a ref
|
// Helper function to assign a mock div to a ref
|
||||||
function assignMockDivToRef(ref: React.RefObject<HTMLDivElement | null>, mockDiv: HTMLDivElement) {
|
function assignMockDivToRef(ref: React.RefObject<HTMLDivElement>, mockDiv: HTMLDivElement) {
|
||||||
// Use type assertion to bypass readonly restriction in tests
|
// Use type assertion to bypass readonly restriction in tests
|
||||||
(ref as { current: HTMLDivElement | null }).current = mockDiv;
|
(ref as { current: HTMLDivElement | null }).current = mockDiv;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import grafanaTextLogoDarkSvg from 'img/grafana_text_logo_dark.svg';
|
|||||||
import grafanaTextLogoLightSvg from 'img/grafana_text_logo_light.svg';
|
import grafanaTextLogoLightSvg from 'img/grafana_text_logo_light.svg';
|
||||||
|
|
||||||
interface SoloPanelPageLogoProps {
|
interface SoloPanelPageLogoProps {
|
||||||
containerRef: React.RefObject<HTMLDivElement | null>;
|
containerRef: React.RefObject<HTMLDivElement>;
|
||||||
isHovered: boolean;
|
isHovered: boolean;
|
||||||
hideLogo?: UrlQueryValue;
|
hideLogo?: UrlQueryValue;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -61,7 +61,7 @@ interface State {
|
|||||||
|
|
||||||
class UnThemedTransformationsEditor extends React.PureComponent<TransformationsEditorProps, State> {
|
class UnThemedTransformationsEditor extends React.PureComponent<TransformationsEditorProps, State> {
|
||||||
subscription?: Unsubscribable;
|
subscription?: Unsubscribable;
|
||||||
ref: RefObject<HTMLDivElement | null>;
|
ref: RefObject<HTMLDivElement>;
|
||||||
|
|
||||||
constructor(props: TransformationsEditorProps) {
|
constructor(props: TransformationsEditorProps) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|||||||
+1
-1
@@ -43,7 +43,7 @@ export const LibraryPanelsView = ({
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
const asyncDispatch = useMemo(() => asyncDispatcher(dispatch), [dispatch]);
|
const asyncDispatch = useMemo(() => asyncDispatcher(dispatch), [dispatch]);
|
||||||
const abortControllerRef = useRef<AbortController | null>(null);
|
const abortControllerRef = useRef<AbortController>();
|
||||||
|
|
||||||
useDebounce(
|
useDebounce(
|
||||||
() => {
|
() => {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export interface Props {}
|
|||||||
|
|
||||||
export const LiveConnectionWarning = memo(function LiveConnectionWarning() {
|
export const LiveConnectionWarning = memo(function LiveConnectionWarning() {
|
||||||
const [show, setShow] = useState<boolean | undefined>(undefined);
|
const [show, setShow] = useState<boolean | undefined>(undefined);
|
||||||
const subscriptionRef = useRef<Unsubscribable | null>(null);
|
const subscriptionRef = useRef<Unsubscribable>();
|
||||||
const styles = useStyles2(getStyle);
|
const styles = useStyles2(getStyle);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ import { render, screen } from '@testing-library/react';
|
|||||||
import { defaultsDeep } from 'lodash';
|
import { defaultsDeep } from 'lodash';
|
||||||
import { Provider } from 'react-redux';
|
import { Provider } from 'react-redux';
|
||||||
|
|
||||||
import { FieldType, getDefaultTimeRange, LoadingState } from '@grafana/data';
|
import { CoreApp, EventBusSrv, FieldType, getDefaultTimeRange, LoadingState } from '@grafana/data';
|
||||||
import { PanelDataErrorViewProps } from '@grafana/runtime';
|
import { config, PanelDataErrorViewProps } from '@grafana/runtime';
|
||||||
|
import { usePanelContext } from '@grafana/ui';
|
||||||
import { configureStore } from 'app/store/configureStore';
|
import { configureStore } from 'app/store/configureStore';
|
||||||
|
|
||||||
import { PanelDataErrorView } from './PanelDataErrorView';
|
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', () => {
|
describe('PanelDataErrorView', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockUsePanelContext.mockReturnValue(panelContextRoot);
|
||||||
|
});
|
||||||
|
|
||||||
it('show No data when there is no data', () => {
|
it('show No data when there is no data', () => {
|
||||||
renderWithProps();
|
renderWithProps();
|
||||||
|
|
||||||
@@ -70,6 +88,45 @@ describe('PanelDataErrorView', () => {
|
|||||||
|
|
||||||
expect(screen.getByText('Query returned nothing')).toBeInTheDocument();
|
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>) {
|
function renderWithProps(overrides?: Partial<PanelDataErrorViewProps>) {
|
||||||
|
|||||||
@@ -5,14 +5,15 @@ import {
|
|||||||
FieldType,
|
FieldType,
|
||||||
getPanelDataSummary,
|
getPanelDataSummary,
|
||||||
GrafanaTheme2,
|
GrafanaTheme2,
|
||||||
|
PanelData,
|
||||||
PanelDataSummary,
|
PanelDataSummary,
|
||||||
PanelPluginVisualizationSuggestion,
|
PanelPluginVisualizationSuggestion,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { selectors } from '@grafana/e2e-selectors';
|
import { selectors } from '@grafana/e2e-selectors';
|
||||||
import { t, Trans } from '@grafana/i18n';
|
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 { 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 { CardButton } from 'app/core/components/CardButton';
|
||||||
import { LS_VISUALIZATION_SELECT_TAB_KEY } from 'app/core/constants';
|
import { LS_VISUALIZATION_SELECT_TAB_KEY } from 'app/core/constants';
|
||||||
import store from 'app/core/store';
|
import store from 'app/core/store';
|
||||||
@@ -24,6 +25,11 @@ import { findVizPanelByKey, getVizPanelKeyForPanelId } from 'app/features/dashbo
|
|||||||
import { useDispatch } from 'app/types/store';
|
import { useDispatch } from 'app/types/store';
|
||||||
|
|
||||||
import { changePanelPlugin } from '../state/actions';
|
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) {
|
export function PanelDataErrorView(props: PanelDataErrorViewProps) {
|
||||||
const styles = useStyles2(getStyles);
|
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 (
|
return (
|
||||||
<div className={styles.wrapper}>
|
<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}>
|
<div className={styles.message} data-testid={selectors.components.Panels.Panel.PanelDataErrorMessage}>
|
||||||
{message}
|
{message}
|
||||||
</div>
|
</div>
|
||||||
@@ -131,7 +143,17 @@ function getMessageFor(
|
|||||||
return message;
|
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');
|
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%',
|
width: '100%',
|
||||||
maxWidth: '600px',
|
maxWidth: '600px',
|
||||||
}),
|
}),
|
||||||
|
emptyStateIcon: css({
|
||||||
|
color: theme.colors.text.secondary,
|
||||||
|
marginBottom: theme.spacing(2),
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export function useSearchKeyboardNavigation(
|
|||||||
): ItemSelection {
|
): ItemSelection {
|
||||||
const highlightIndexRef = useRef<ItemSelection>({ x: 0, y: -1 });
|
const highlightIndexRef = useRef<ItemSelection>({ x: 0, y: -1 });
|
||||||
const [highlightIndex, setHighlightIndex] = useState<ItemSelection>({ x: 0, y: -1 });
|
const [highlightIndex, setHighlightIndex] = useState<ItemSelection>({ x: 0, y: -1 });
|
||||||
const urlsRef = useRef<Field | null>(null);
|
const urlsRef = useRef<Field>();
|
||||||
|
|
||||||
// Clear selection when the search results change
|
// Clear selection when the search results change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export const SuggestionsInput = ({
|
|||||||
const theme = useTheme2();
|
const theme = useTheme2();
|
||||||
const styles = getStyles(theme, inputHeight);
|
const styles = getStyles(theme, inputHeight);
|
||||||
|
|
||||||
const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement | null>(null);
|
const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
scrollRef.current?.scrollTo(0, scrollTop);
|
scrollRef.current?.scrollTo(0, scrollTop);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import checkboxWhitePng from 'img/checkbox_white.png';
|
|||||||
|
|
||||||
import { ALL_VARIABLE_VALUE } from '../../constants';
|
import { ALL_VARIABLE_VALUE } from '../../constants';
|
||||||
|
|
||||||
export interface Props extends Omit<React.HTMLProps<HTMLUListElement>, 'onToggle'>, Themeable2 {
|
export interface Props extends React.HTMLProps<HTMLUListElement>, Themeable2 {
|
||||||
multi: boolean;
|
multi: boolean;
|
||||||
values: VariableOption[];
|
values: VariableOption[];
|
||||||
selectedValues: VariableOption[];
|
selectedValues: VariableOption[];
|
||||||
|
|||||||
+2
-2
@@ -20,8 +20,8 @@ interface CodeEditorProps {
|
|||||||
export const LogsQLCodeEditor = (props: CodeEditorProps) => {
|
export const LogsQLCodeEditor = (props: CodeEditorProps) => {
|
||||||
const { query, datasource, onChange } = props;
|
const { query, datasource, onChange } = props;
|
||||||
|
|
||||||
const monacoRef = useRef<Monaco | null>(null);
|
const monacoRef = useRef<Monaco>();
|
||||||
const disposalRef = useRef<monacoType.IDisposable | undefined>(undefined);
|
const disposalRef = useRef<monacoType.IDisposable>();
|
||||||
|
|
||||||
const onFocus = useCallback(async () => {
|
const onFocus = useCallback(async () => {
|
||||||
disposalRef.current = await reRegisterCompletionProvider(
|
disposalRef.current = await reRegisterCompletionProvider(
|
||||||
|
|||||||
+2
-2
@@ -42,8 +42,8 @@ interface LogsCodeEditorProps {
|
|||||||
export const PPLQueryEditor = (props: LogsCodeEditorProps) => {
|
export const PPLQueryEditor = (props: LogsCodeEditorProps) => {
|
||||||
const { query, datasource, onChange } = props;
|
const { query, datasource, onChange } = props;
|
||||||
|
|
||||||
const monacoRef = useRef<Monaco | null>(null);
|
const monacoRef = useRef<Monaco>();
|
||||||
const disposalRef = useRef<monacoType.IDisposable | undefined>(undefined);
|
const disposalRef = useRef<monacoType.IDisposable>();
|
||||||
|
|
||||||
const onFocus = useCallback(async () => {
|
const onFocus = useCallback(async () => {
|
||||||
disposalRef.current = await reRegisterCompletionProvider(
|
disposalRef.current = await reRegisterCompletionProvider(
|
||||||
|
|||||||
+2
-2
@@ -20,8 +20,8 @@ interface SQLCodeEditorProps {
|
|||||||
export const SQLQueryEditor = (props: SQLCodeEditorProps) => {
|
export const SQLQueryEditor = (props: SQLCodeEditorProps) => {
|
||||||
const { query, datasource, onChange } = props;
|
const { query, datasource, onChange } = props;
|
||||||
|
|
||||||
const monacoRef = useRef<Monaco | null>(null);
|
const monacoRef = useRef<Monaco>();
|
||||||
const disposalRef = useRef<monacoType.IDisposable | undefined>(undefined);
|
const disposalRef = useRef<monacoType.IDisposable>();
|
||||||
|
|
||||||
const onFocus = useCallback(async () => {
|
const onFocus = useCallback(async () => {
|
||||||
disposalRef.current = await reRegisterCompletionProvider(
|
disposalRef.current = await reRegisterCompletionProvider(
|
||||||
|
|||||||
+1
-1
@@ -94,7 +94,7 @@ const EDITOR_HEIGHT_OFFSET = 2;
|
|||||||
* Hook that returns function that will set up monaco autocomplete for the label selector
|
* Hook that returns function that will set up monaco autocomplete for the label selector
|
||||||
*/
|
*/
|
||||||
function useAutocomplete(getLabelValues: (label: string) => Promise<string[]>, labels?: string[]) {
|
function useAutocomplete(getLabelValues: (label: string) => Promise<string[]>, labels?: string[]) {
|
||||||
const providerRef = useRef<CompletionProvider | null>(null);
|
const providerRef = useRef<CompletionProvider>();
|
||||||
if (providerRef.current === undefined) {
|
if (providerRef.current === undefined) {
|
||||||
providerRef.current = new CompletionProvider();
|
providerRef.current = new CompletionProvider();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ export function LokiContextUi(props: LokiContextUiProps) {
|
|||||||
window.localStorage.getItem(SHOULD_INCLUDE_PIPELINE_OPERATIONS) === 'true'
|
window.localStorage.getItem(SHOULD_INCLUDE_PIPELINE_OPERATIONS) === 'true'
|
||||||
);
|
);
|
||||||
|
|
||||||
const timerHandle = useRef<number | null>(null);
|
const timerHandle = useRef<number>();
|
||||||
const previousInitialized = useRef<boolean>(false);
|
const previousInitialized = useRef<boolean>(false);
|
||||||
const previousContextFilters = useRef<ContextFilter[]>([]);
|
const previousContextFilters = useRef<ContextFilter[]>([]);
|
||||||
|
|
||||||
@@ -191,18 +191,14 @@ export function LokiContextUi(props: LokiContextUiProps) {
|
|||||||
}, 1500);
|
}, 1500);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
if (timerHandle.current) {
|
clearTimeout(timerHandle.current);
|
||||||
clearTimeout(timerHandle.current);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [contextFilters, initialized]);
|
}, [contextFilters, initialized]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
if (timerHandle.current) {
|
clearTimeout(timerHandle.current);
|
||||||
clearTimeout(timerHandle.current);
|
|
||||||
}
|
|
||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
}, [onClose]);
|
}, [onClose]);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export function TraceQLEditor(props: Props) {
|
|||||||
const onRunQueryRef = useRef(onRunQuery);
|
const onRunQueryRef = useRef(onRunQuery);
|
||||||
onRunQueryRef.current = onRunQuery;
|
onRunQueryRef.current = onRunQuery;
|
||||||
|
|
||||||
const errorTimeoutId = useRef<number | null>(null);
|
const errorTimeoutId = useRef<number>();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -103,9 +103,7 @@ export function TraceQLEditor(props: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove previous callback if existing, to prevent squiggles from been shown while the user is still typing
|
// Remove previous callback if existing, to prevent squiggles from been shown while the user is still typing
|
||||||
if (errorTimeoutId.current) {
|
window.clearTimeout(errorTimeoutId.current);
|
||||||
window.clearTimeout(errorTimeoutId.current);
|
|
||||||
}
|
|
||||||
|
|
||||||
const errorNodes = getErrorNodes(model.getValue());
|
const errorNodes = getErrorNodes(model.getValue());
|
||||||
const cursorPosition = changeEvent.changes[0].rangeOffset;
|
const cursorPosition = changeEvent.changes[0].rangeOffset;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export function renderHistogram(
|
export function renderHistogram(
|
||||||
can: React.RefObject<HTMLCanvasElement | null>,
|
can: React.RefObject<HTMLCanvasElement>,
|
||||||
histCanWidth: number,
|
histCanWidth: number,
|
||||||
histCanHeight: number,
|
histCanHeight: number,
|
||||||
xVals: number[],
|
xVals: number[],
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ export const LogsPanel = ({
|
|||||||
const dataSourcesMap = useDatasourcesFromTargets(panelData.request?.targets);
|
const dataSourcesMap = useDatasourcesFromTargets(panelData.request?.targets);
|
||||||
// Prevents the scroll position to change when new data from infinite scrolling is received
|
// Prevents the scroll position to change when new data from infinite scrolling is received
|
||||||
const keepScrollPositionRef = useRef<null | 'infinite-scroll' | 'user'>(null);
|
const keepScrollPositionRef = useRef<null | 'infinite-scroll' | 'user'>(null);
|
||||||
const closeCallback = useRef<(() => void) | null>(null);
|
let closeCallback = useRef<() => void>();
|
||||||
const { app, eventBus, onAddAdHocFilter } = usePanelContext();
|
const { app, eventBus, onAddAdHocFilter } = usePanelContext();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ export function useLayout(
|
|||||||
const currentSignature = createDataSignature(rawNodes, rawEdges);
|
const currentSignature = createDataSignature(rawNodes, rawEdges);
|
||||||
|
|
||||||
const isMounted = useMountedState();
|
const isMounted = useMountedState();
|
||||||
const layoutWorkerCancelRef = useRef<(() => void) | null>(null);
|
const layoutWorkerCancelRef = useRef<(() => void) | undefined>();
|
||||||
|
|
||||||
useUnmount(() => {
|
useUnmount(() => {
|
||||||
if (layoutWorkerCancelRef.current) {
|
if (layoutWorkerCancelRef.current) {
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ export const AnnotationsPlugin2 = ({
|
|||||||
const newRangeRef = useRef(newRange);
|
const newRangeRef = useRef(newRange);
|
||||||
newRangeRef.current = newRange;
|
newRangeRef.current = newRange;
|
||||||
|
|
||||||
const xAxisRef = useRef<HTMLDivElement | null>(null);
|
const xAxisRef = useRef<HTMLDivElement>();
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
config.addHook('ready', (u) => {
|
config.addHook('ready', (u) => {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export const ExemplarsPlugin = ({
|
|||||||
maxHeight,
|
maxHeight,
|
||||||
maxWidth,
|
maxWidth,
|
||||||
}: ExemplarsPluginProps) => {
|
}: ExemplarsPluginProps) => {
|
||||||
const plotInstance = useRef<uPlot | null>(null);
|
const plotInstance = useRef<uPlot>();
|
||||||
|
|
||||||
const [lockedExemplarRowIndex, setLockedExemplarRowIndex] = useState<number | undefined>();
|
const [lockedExemplarRowIndex, setLockedExemplarRowIndex] = useState<number | undefined>();
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ interface ThresholdControlsPluginProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const OutsideRangePlugin = ({ config, onChangeTimeRange }: ThresholdControlsPluginProps) => {
|
export const OutsideRangePlugin = ({ config, onChangeTimeRange }: ThresholdControlsPluginProps) => {
|
||||||
const plotInstance = useRef<uPlot | null>(null);
|
const plotInstance = useRef<uPlot>();
|
||||||
const [timevalues, setTimeValues] = useState<number[] | TypedArray>([]);
|
const [timevalues, setTimeValues] = useState<number[] | TypedArray>([]);
|
||||||
const [timeRange, setTimeRange] = useState<Scale | undefined>();
|
const [timeRange, setTimeRange] = useState<Scale | undefined>();
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ interface ThresholdControlsPluginProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const ThresholdControlsPlugin = ({ config, fieldConfig, onThresholdsChange }: ThresholdControlsPluginProps) => {
|
export const ThresholdControlsPlugin = ({ config, fieldConfig, onThresholdsChange }: ThresholdControlsPluginProps) => {
|
||||||
const plotInstance = useRef<uPlot | null>(null);
|
const plotInstance = useRef<uPlot>();
|
||||||
const [renderToken, setRenderToken] = useState(0);
|
const [renderToken, setRenderToken] = useState(0);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
|
|||||||
@@ -2178,8 +2178,10 @@
|
|||||||
"badge-tooltip-provenance": "This resource has been provisioned via {{provenance}} and cannot be edited through the UI",
|
"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",
|
"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": "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}}.",
|
"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": "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"
|
"title-provisioned": "This {{resource}} cannot be edited through the UI"
|
||||||
},
|
},
|
||||||
"provisioning-badge": {
|
"provisioning-badge": {
|
||||||
|
|||||||
Reference in New Issue
Block a user