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

0% Statements 0/18
0% Branches 0/1
0% Functions 0/4
0% Lines 0/15

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                                                                 
import { Task } from "../../../../types/index.ts";
import { updateCardById } from "../../../execution/updateCardById.ts";
import { getCurrentAsset } from "../../getCurrentAsset.ts";
import { Key } from "../../key.ts";
 
export const pageGuidChange = (task: Task) => {
  const source = task.source;
  const taskType = (task as any)[source.toLowerCase()]?.type;
  const taskKey = `${[source.toLowerCase()]}.${taskType.toLowerCase()}`;
 
  const pageOptions = getCurrentAsset(
    task,
    Key.DASHBOARD_GUID,
    "dashboard_guid",
    undefined,
    "pages",
  ).map((e: any) => {
    return {
      id: e.page_guid,
      label: e.page_name,
    };
  });
 
  const handleChange = (value: any) => {
    updateCardById(`${taskKey}.${Key.PAGE_GUID}`, value, task.id);
    const page = pageOptions?.find((op: any) => op.id === value);
    Iif (!page) return;
    updateCardById(`${taskKey}.${Key.PAGE_NAME}`, page?.label, task.id);
  };
 
  return handleChange;
};