Skip to content

Commit

Permalink
[Alert Edit] Fix time range reloading and fix where filter (#4205)
Browse files Browse the repository at this point in the history
* Fix time range reloading and fix where filter

* Fix lint
  • Loading branch information
AdityaHegde authored Feb 29, 2024
1 parent e376031 commit d80d9b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
9 changes: 3 additions & 6 deletions web-common/src/features/alerts/extract-alert-form-values.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { AlertFormValues } from "@rilldata/web-common/features/alerts/form-utils";
import { TIME_GRAIN } from "@rilldata/web-common/lib/time/config";
import { createAndExpression } from "@rilldata/web-common/features/dashboards/stores/filter-utils";
import { TimeRangePreset } from "@rilldata/web-common/lib/time/types";
import {
V1Expression,
V1MetricsViewAggregationDimension,
V1MetricsViewAggregationMeasure,
V1MetricsViewAggregationRequest,
Expand Down Expand Up @@ -48,9 +47,7 @@ export function extractAlertFormValues(
return {
measure: measures[0].name as string,
splitByDimension: dimensions[0] ?? "",
splitByTimeGrain: timeDimension[0]?.timeGrain
? (TIME_GRAIN[timeDimension[0].timeGrain].duration as string)
: "",
splitByTimeGrain: queryArgs.timeRange?.isoDuration ?? "",

criteria:
queryArgs.having?.cond?.exprs?.map((e) => ({
Expand All @@ -62,7 +59,7 @@ export function extractAlertFormValues(

// These are not part of the form, but are used to track the state of the form
metricsViewName: queryArgs.metricsView as string,
whereFilter: queryArgs.where as V1Expression,
whereFilter: queryArgs.where ?? createAndExpression([]),
timeRange: (queryArgs.timeRange as V1TimeRange) ?? {
isoDuration: metricsViewSpec.defaultTimeRange ?? TimeRangePreset.ALL_TIME,
},
Expand Down
18 changes: 11 additions & 7 deletions web-common/src/features/alerts/form-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
createAndExpression,
createBinaryExpression,
sanitiseExpression,
} from "@rilldata/web-common/features/dashboards/stores/filter-utils";
import type {
V1Expression,
Expand Down Expand Up @@ -39,13 +40,16 @@ export function getAlertQueryArgsFromFormValues(
dimensions: formValues.splitByDimension
? [{ name: formValues.splitByDimension }]
: [],
where: formValues.whereFilter,
having: createAndExpression(
formValues.criteria.map((c) =>
createBinaryExpression(
c.field,
c.operation as V1Operation,
Number(c.value),
where: sanitiseExpression(formValues.whereFilter, undefined),
having: sanitiseExpression(
undefined,
createAndExpression(
formValues.criteria.map((c) =>
createBinaryExpression(
c.field,
c.operation as V1Operation,
Number(c.value),
),
),
),
),
Expand Down

1 comment on commit d80d9b2

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.