Skip to content

Commit

Permalink
review I
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierM committed Aug 1, 2022
1 parent 1c96337 commit 1fca5af
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,11 @@ export async function fetchRuleAlertsAggByTimeRange({
status: alert.key,
});
});
if (totalAlerts - countOfRecoveredActiveAlerts > 0) {
const deltaAlertsCount = totalAlerts - countOfRecoveredActiveAlerts;
if (deltaAlertsCount > 0) {
localAlertChartData.push({
date: dayAlerts.key,
count: totalAlerts - countOfRecoveredActiveAlerts,
count: deltaAlertsCount,
status: 'total',
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ export const getColorSeries = ({ seriesKeys }: XYChartSeriesIdentifier) => {
return null;
}
};

/**
* This function may be passed to `Array.find()` to locate the `P1DT`
* configuration (sub) setting, a string array that contains two entries
* like the following example: `['P1DT', 'YYYY-MM-DD']`.
*/
export const isP1DTFormatterSetting = (formatNameFormatterPair?: string[]) =>
Array.isArray(formatNameFormatterPair) &&
formatNameFormatterPair[0] === 'P1DT' &&
formatNameFormatterPair.length === 2;
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,25 @@ import { useLoadRuleAlertsAggs } from '../../../../hooks/use_load_rule_alerts_ag
import { useLoadRuleTypes } from '../../../../hooks/use_load_rule_types';
import { formatChartAlertData, getColorSeries } from '.';
import { RuleAlertsSummaryProps } from '.';
import { isP1DTFormatterSetting } from './helpers';

const Y_ACCESSORS = ['y'];
const X_ACCESSORS = ['x'];
const G_ACCESSORS = ['g'];

const FALLBACK_DATE_FORMAT_SCALED_P1DT = 'YYYY-MM-DD';
export const RuleAlertsSummary = ({ rule, filteredRuleTypes }: RuleAlertsSummaryProps) => {
const [features, setFeatures] = useState<string>('');
const isDarkMode = useUiSetting<boolean>('theme:darkMode');
const dateFormat = useUiSetting<string>('dateFormat');

const scaledDateFormatPreference = useUiSetting<string[][]>('dateFormat:scaled');
const maybeP1DTFormatter = Array.isArray(scaledDateFormatPreference)
? scaledDateFormatPreference.find(isP1DTFormatterSetting)
: null;
const p1dtFormat =
Array.isArray(maybeP1DTFormatter) && maybeP1DTFormatter.length === 2
? maybeP1DTFormatter[1]
: FALLBACK_DATE_FORMAT_SCALED_P1DT;

const theme = useMemo(
() => [
EUI_SPARKLINE_THEME_PARTIAL,
Expand All @@ -70,10 +80,10 @@ export const RuleAlertsSummary = ({ rule, filteredRuleTypes }: RuleAlertsSummary
() => ({
type: TooltipType.VerticalCursor,
headerFormatter: ({ value }: { value: number }) => {
return <>{moment(value).format(dateFormat)}</>;
return <>{moment(value).format(p1dtFormat)}</>;
},
}),
[dateFormat]
[p1dtFormat]
);

useEffect(() => {
Expand Down

0 comments on commit 1fca5af

Please sign in to comment.