Skip to content

Commit

Permalink
Merge pull request #5559 from gooddata/SHA_master
Browse files Browse the repository at this point in the history
fix: repairs related to operator and comparison
  • Loading branch information
hackerstanislav authored Nov 14, 2024
2 parents 59285dc + e8dfb98 commit 7cd9a1b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// (C) 2022-2024 GoodData Corporation
import React, { useMemo } from "react";
import { IAutomationMetadataObject } from "@gooddata/sdk-model";
import { DateGranularity, IAutomationMetadataObject } from "@gooddata/sdk-model";
import { Button, Dropdown, List, OverlayPositionType, SingleSelectListItem } from "@gooddata/sdk-ui-kit";
import { FormattedMessage, useIntl } from "react-intl";
import cx from "classnames";
Expand Down Expand Up @@ -44,7 +44,7 @@ export const AlertComparisonPeriodSelect = (props: IAlertComparisonPeriodSelectP
);

return [
sp?.granularity
sp?.granularity && pp?.granularity !== DateGranularity.year
? {
title: intl.formatMessage(
{ id: "insightAlert.config.compare_with_sp_granularity" },
Expand Down Expand Up @@ -151,7 +151,7 @@ const DropdownButtonLabel = (props: DropdownButtonLabelProps) => {
return (
<div className="gd-edit-alert__measure-info">
<FormattedMessage id="insightAlert.config.compare_with" />{" "}
{selectedOperator.granularity ? (
{selectedOperator.granularity && selectedOperator.granularity !== DateGranularity.year ? (
<FormattedMessage
id="insightAlert.config.compare_with_sp_granularity"
values={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,10 @@ function fillComparators(simpleMetrics: AlertMetric[], datasets: ICatalogDateDat
}

simpleMetrics.forEach((metric) => {
const prev = metric.comparators.find(
const previousPeriod = metric.comparators.find(
(c) => c.comparator === AlertMetricComparatorType.PreviousPeriod,
);
if (!prev) {
if (!previousPeriod) {
//PP
metric.comparators.push({
measure: newPreviousPeriodMeasure(
Expand All @@ -452,7 +452,12 @@ function fillComparators(simpleMetrics: AlertMetric[], datasets: ICatalogDateDat
dataset: undefined,
granularity: undefined,
});
}

const samePeriodPrevYear = metric.comparators.find(
(c) => c.comparator === AlertMetricComparatorType.SamePeriodPreviousYear,
);
if (!samePeriodPrevYear) {
//PoP
metric.comparators.push({
measure: newPopMeasure(
Expand Down Expand Up @@ -483,14 +488,11 @@ function fillGranularity(simpleMetrics: AlertMetric[], datasets: ICatalogDateDat
const dataset = datasets.find((d) => {
return d.dateAttributes.some((a) => areObjRefsEqual(a.attribute.ref, attr));
});
const dateAttribute = dataset?.dateAttributes.find((a) =>
areObjRefsEqual(a.attribute.ref, attr),
);

if (dataset) {
const lowest = sortDateAttributes(dataset)[0];
comparator.dataset = dataset.dataSet;
//comparator.dateAttribute = dateAttribute?.attribute;
comparator.granularity = dateAttribute?.granularity;
comparator.granularity = lowest?.granularity;
}
}
if (isPreviousPeriodMeasureDefinition(def)) {
Expand All @@ -501,13 +503,7 @@ function fillGranularity(simpleMetrics: AlertMetric[], datasets: ICatalogDateDat
});

if (dataset) {
const sorted = dataset.dateAttributes.slice().sort((a, b) => {
return (
SortedGranularities.indexOf(b.granularity) -
SortedGranularities.indexOf(a.granularity)
);
});
const lowest = sorted[0];
const lowest = sortDateAttributes(dataset)[0];
comparator.dataset = dataset.dataSet;
comparator.granularity = lowest?.granularity;
}
Expand All @@ -516,6 +512,12 @@ function fillGranularity(simpleMetrics: AlertMetric[], datasets: ICatalogDateDat
});
}

function sortDateAttributes(dataset: ICatalogDateDataset) {
return dataset.dateAttributes.slice().sort((a, b) => {
return SortedGranularities.indexOf(b.granularity) - SortedGranularities.indexOf(a.granularity);
});
}

function removeInvalidComparators(simpleMetrics: AlertMetric[], insightFilters: IFilter[]) {
const dateFilters = insightFilters.filter((filter) =>
isRelativeDateFilter(filter),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export function transformAlertByRelativeOperator(
comparatorType?: AlertMetricComparatorType,
): IAutomationMetadataObject {
const periodMeasure = measure.comparators.filter((c) =>
comparatorType ? c.comparator === comparatorType : true,
comparatorType !== undefined ? c.comparator === comparatorType : true,
);

const cond = transformToRelativeCondition(alert.alert!.condition);
Expand Down

0 comments on commit 7cd9a1b

Please sign in to comment.