mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alert list panel: Add view mode "Stat" (#53281)
* add stat mode * remove unused import
This commit is contained in:
parent
196b781c70
commit
509e34cfe7
@ -4,7 +4,17 @@ import React, { useEffect, useMemo } from 'react';
|
|||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
|
|
||||||
import { GrafanaTheme2, PanelProps } from '@grafana/data';
|
import { GrafanaTheme2, PanelProps } from '@grafana/data';
|
||||||
import { Alert, CustomScrollbar, LoadingPlaceholder, useStyles2 } from '@grafana/ui';
|
import {
|
||||||
|
Alert,
|
||||||
|
BigValue,
|
||||||
|
BigValueGraphMode,
|
||||||
|
BigValueJustifyMode,
|
||||||
|
BigValueTextMode,
|
||||||
|
CustomScrollbar,
|
||||||
|
LoadingPlaceholder,
|
||||||
|
useStyles2,
|
||||||
|
} from '@grafana/ui';
|
||||||
|
import { config } from 'app/core/config';
|
||||||
import { contextSrv } from 'app/core/services/context_srv';
|
import { contextSrv } from 'app/core/services/context_srv';
|
||||||
import alertDef from 'app/features/alerting/state/alertDef';
|
import alertDef from 'app/features/alerting/state/alertDef';
|
||||||
import { useUnifiedAlertingSelector } from 'app/features/alerting/unified/hooks/useUnifiedAlertingSelector';
|
import { useUnifiedAlertingSelector } from 'app/features/alerting/unified/hooks/useUnifiedAlertingSelector';
|
||||||
@ -22,7 +32,7 @@ import { AccessControlAction } from 'app/types';
|
|||||||
import { PromRuleWithLocation } from 'app/types/unified-alerting';
|
import { PromRuleWithLocation } from 'app/types/unified-alerting';
|
||||||
import { PromAlertingRuleState } from 'app/types/unified-alerting-dto';
|
import { PromAlertingRuleState } from 'app/types/unified-alerting-dto';
|
||||||
|
|
||||||
import { GroupMode, SortOrder, UnifiedAlertListOptions } from './types';
|
import { GroupMode, SortOrder, UnifiedAlertListOptions, ViewMode } from './types';
|
||||||
import GroupedModeView from './unified-alerting/GroupedView';
|
import GroupedModeView from './unified-alerting/GroupedView';
|
||||||
import UngroupedModeView from './unified-alerting/UngroupedView';
|
import UngroupedModeView from './unified-alerting/UngroupedView';
|
||||||
import { filterAlerts } from './util';
|
import { filterAlerts } from './util';
|
||||||
@ -86,10 +96,21 @@ export function UnifiedAlertList(props: PanelProps<UnifiedAlertListOptions>) {
|
|||||||
{dispatched && loading && !haveResults && <LoadingPlaceholder text="Loading..." />}
|
{dispatched && loading && !haveResults && <LoadingPlaceholder text="Loading..." />}
|
||||||
{noAlertsMessage && <div className={styles.noAlertsMessage}>{noAlertsMessage}</div>}
|
{noAlertsMessage && <div className={styles.noAlertsMessage}>{noAlertsMessage}</div>}
|
||||||
<section>
|
<section>
|
||||||
{props.options.groupMode === GroupMode.Custom && haveResults && (
|
{props.options.viewMode === ViewMode.Stat && haveResults && (
|
||||||
|
<BigValue
|
||||||
|
width={props.width}
|
||||||
|
height={props.height}
|
||||||
|
graphMode={BigValueGraphMode.None}
|
||||||
|
textMode={BigValueTextMode.Auto}
|
||||||
|
justifyMode={BigValueJustifyMode.Auto}
|
||||||
|
theme={config.theme2}
|
||||||
|
value={{ text: `${rules.length}`, numeric: rules.length }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{props.options.viewMode === ViewMode.List && props.options.groupMode === GroupMode.Custom && haveResults && (
|
||||||
<GroupedModeView rules={rules} options={props.options} />
|
<GroupedModeView rules={rules} options={props.options} />
|
||||||
)}
|
)}
|
||||||
{props.options.groupMode === GroupMode.Default && haveResults && (
|
{props.options.viewMode === ViewMode.List && props.options.groupMode === GroupMode.Default && haveResults && (
|
||||||
<UngroupedModeView rules={rules} options={props.options} />
|
<UngroupedModeView rules={rules} options={props.options} />
|
||||||
)}
|
)}
|
||||||
</section>
|
</section>
|
||||||
|
@ -16,7 +16,7 @@ import { alertListPanelMigrationHandler } from './AlertListMigrationHandler';
|
|||||||
import { GroupBy } from './GroupByWithLoading';
|
import { GroupBy } from './GroupByWithLoading';
|
||||||
import { UnifiedAlertList } from './UnifiedAlertList';
|
import { UnifiedAlertList } from './UnifiedAlertList';
|
||||||
import { AlertListSuggestionsSupplier } from './suggestions';
|
import { AlertListSuggestionsSupplier } from './suggestions';
|
||||||
import { AlertListOptions, GroupMode, ShowOption, SortOrder, UnifiedAlertListOptions } from './types';
|
import { AlertListOptions, GroupMode, ShowOption, SortOrder, UnifiedAlertListOptions, ViewMode } from './types';
|
||||||
|
|
||||||
function showIfCurrentState(options: AlertListOptions) {
|
function showIfCurrentState(options: AlertListOptions) {
|
||||||
return options.showOptions === ShowOption.Current;
|
return options.showOptions === ShowOption.Current;
|
||||||
@ -155,6 +155,19 @@ const alertList = new PanelPlugin<AlertListOptions>(AlertList)
|
|||||||
|
|
||||||
const unifiedAlertList = new PanelPlugin<UnifiedAlertListOptions>(UnifiedAlertList).setPanelOptions((builder) => {
|
const unifiedAlertList = new PanelPlugin<UnifiedAlertListOptions>(UnifiedAlertList).setPanelOptions((builder) => {
|
||||||
builder
|
builder
|
||||||
|
.addRadio({
|
||||||
|
path: 'viewMode',
|
||||||
|
name: 'View mode',
|
||||||
|
description: 'Toggle between list view and stat view',
|
||||||
|
defaultValue: ViewMode.List,
|
||||||
|
settings: {
|
||||||
|
options: [
|
||||||
|
{ label: 'List', value: ViewMode.List },
|
||||||
|
{ label: 'Stat', value: ViewMode.Stat },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
category: ['Options'],
|
||||||
|
})
|
||||||
.addRadio({
|
.addRadio({
|
||||||
path: 'groupMode',
|
path: 'groupMode',
|
||||||
name: 'Group mode',
|
name: 'Group mode',
|
||||||
|
@ -18,6 +18,11 @@ export enum GroupMode {
|
|||||||
Custom = 'custom',
|
Custom = 'custom',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ViewMode {
|
||||||
|
List = 'list',
|
||||||
|
Stat = 'stat',
|
||||||
|
}
|
||||||
|
|
||||||
export interface AlertListOptions {
|
export interface AlertListOptions {
|
||||||
showOptions: ShowOption;
|
showOptions: ShowOption;
|
||||||
maxItems: number;
|
maxItems: number;
|
||||||
@ -58,6 +63,7 @@ export interface UnifiedAlertListOptions {
|
|||||||
stateFilter: StateFilter;
|
stateFilter: StateFilter;
|
||||||
alertInstanceLabelFilter: string;
|
alertInstanceLabelFilter: string;
|
||||||
datasource: string;
|
datasource: string;
|
||||||
|
viewMode: ViewMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type GroupedRules = Map<string, Alert[]>;
|
export type GroupedRules = Map<string, Alert[]>;
|
||||||
|
Loading…
Reference in New Issue
Block a user