All files / src/utils/playbook/changeEvents/nrDashboard widgetNRQLExpressionChange.ts

0% Statements 0/19
0% Branches 0/3
0% Functions 0/4
0% Lines 0/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43                                                                                     
import { Task } from "../../../../types/index.ts";
import { updateCardById } from "../../../execution/updateCardById.ts";
import { getCurrentAsset } from "../../getCurrentAsset.ts";
import { Key } from "../../key.ts";
 
export const widgetNRQLExpressionChange = (task: Task) => {
  const source = task.source;
  const taskType = (task as any)[source.toLowerCase()]?.type;
  const taskKey = `${[source.toLowerCase()]}.${taskType.toLowerCase()}`;
 
  const widgetOptions = getCurrentAsset(
    task,
    Key.DASHBOARD_GUID,
    "dashboard_guid",
    undefined,
    "pages",
  )?.[0]?.widgets?.map((e: any) => {
    return {
      id: e.widget_id,
      label: e.widget_title || e.widget_nrql_expression,
      widget: e,
    };
  });
 
  const handleChange = (value: any) => {
    updateCardById(`${taskKey}.${Key.WIDGET_ID}`, value, task.id);
    const widget = widgetOptions?.find((op: any) => op.id === value)?.widget;
    Iif (!widget) return;
    updateCardById(
      `${taskKey}.${Key.WIDGET_TITLE}`,
      widget.widget_title,
      task.id,
    );
    updateCardById(
      `${taskKey}.${Key.WIDGET_NRQL_EXPRESSION}`,
      widget.widget_nrql_expression,
      task.id,
    );
  };
 
  return handleChange;
};