All files / src/pages/flowsheet-page/pinch-analysis PinchTargetDashboard.tsx

82.14% Statements 23/28
87.5% Branches 14/16
66.66% Functions 6/9
82.14% Lines 23/28

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107                        16x         16x   16x 4x             12x       12x       12x 12x 27x   12x 27x     12x 36x     12x 48x     12x 72x   12x           12x               12x           12x           12x   12x                                                
import { RowTypeEnum, TargetSummaryRead } from "@/api/apiStore.gen";
import { DataTable } from "@/ahuora-design-system/ui/data-table";
import { getTargetColumns } from "./TableColumns/TargetOutputColumns";
import { ColumnDef } from "@tanstack/react-table";
import { Spinner } from "@/ahuora-design-system/ui/spinner";
import { Separator } from "@/ahuora-design-system/ui/separator";
import {
  useCurrentPinchOptions,
  useCurrentPinchOutputs,
} from "@/hooks/PinchHooks";
 
export default function PinchTargetDashboard() {
  const { outputs, isLoading, isError } = useCurrentPinchOutputs();
  const {
    options,
    isLoading: isOptionsLoading,
    isError: isOptionsError,
  } = useCurrentPinchOptions();
 
  if (isLoading || isOptionsLoading) {
    return (
      <div className="flex justify-center items-center h-screen">
        <Spinner />
      </div>
    );
  }
 
  Iif (isError || !outputs) {
    return <div>Error loading target data.</div>;
  }
 
  Iif (isOptionsError || !outputs || !options) {
    return <div>Error loading target data.</div>;
  }
 
  const targets: TargetSummaryRead[] = outputs[0]!.targets!;
  const contentRows: TargetSummaryRead[] = targets.filter(
    (row) => row.row_type == RowTypeEnum.Content,
  );
  const footerRows: TargetSummaryRead[] = targets.filter(
    (row) => row.row_type == RowTypeEnum.Footer,
  );
  const turbineSelected: boolean =
    options[0].selections?.ContainedProperties?.find(
      (prop) => prop.key == "PROP_MOP_2",
    )?.values.value ?? false;
  const areaSelected: boolean =
    options[0].selections?.ContainedProperties?.find(
      (prop) => prop.key == "PROP_MOP_3",
    )?.values.value ?? false;
  const exergySelected: boolean =
    options[0].selections?.ContainedProperties?.find(
      (prop) => prop.key == "PROP_MOP_5",
    )?.values.value ?? false;
  const mainColumns: ColumnDef<TargetSummaryRead>[] = getTargetColumns(
    targets,
    turbineSelected,
    areaSelected,
    exergySelected,
  );
  const utilityColumns: ColumnDef<TargetSummaryRead>[] = getTargetColumns(
    targets,
    turbineSelected,
    areaSelected,
    exergySelected,
    true,
  );
 
    const sortOrder = [
        "Total Integrated Target",
        "Total Site Target",
        "Total Process Target",
    ];
 
  footerRows.sort((a, b) => {
    const indexA = sortOrder.indexOf(a.name);
    const indexB = sortOrder.indexOf(b.name);
    return indexA - indexB;
  });
 
  const combinedRows: TargetSummaryRead[] = [...footerRows, ...contentRows];
 
  return (
    <div>
      <div className="flex flex-col gap-8">
        <div className="overflow-x-auto">
          <DataTable
            columns={mainColumns}
            data={combinedRows}
            rowSelection={() => {}}
            withBorder={false}
          />
        </div>
        <Separator />
        <div className="overflow-x-auto">
          <DataTable
            columns={utilityColumns}
            data={combinedRows}
            rowSelection={() => {}}
            withBorder={false}
          />
        </div>
      </div>
    </div>
  );
}