All files / src/pages/flowsheet-page/flowsheet/PropertiesSidebar/Connections GroupConnectionList.tsx

91.66% Statements 11/12
66.66% Branches 2/3
100% Functions 6/6
91.66% Lines 11/12

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                              1x 1x 11x   1x   3x   1x                 1x 3x     1x       1x       1x                                            
import {
  Accordion,
  AccordionContent,
  AccordionItem,
  AccordionTrigger,
} from "@/ahuora-design-system/ui/accordion";
import {
  useCurrentGroupObjects,
  useCurrentObjectId,
  useGroupGraphicsObjects
} from "@/hooks/flowsheetObjects";
import { isStream } from "../../../../../lib/isStream";
import { ConnectionList } from "./ConnectionList";
 
export function GroupConnectionList() {
  const selectedObjectId = useCurrentObjectId();
  const currentObject = useCurrentGroupObjects().filter(
    (obj) => obj.id == selectedObjectId,
  )[0];
  const currentGroupObjects = useGroupGraphicsObjects(
    currentObject?.groupId,
  )?.map((obj) => obj.simulationObject);
 
  Iif (!currentObject) {
    return (
      <div className="p-4 text-muted-foreground text-sm">
        Select a group to view its connections
      </div>
    );
  }
 
  // Filter out streams and nested groups, only show unit operations
  const displayObjects = currentGroupObjects?.filter(
    (obj) => !isStream(obj) && obj.objectType !== "group",
  );
 
  return (
    <div className="pb-8">
      <Accordion
        type="multiple"
        defaultValue={displayObjects?.map((obj) => obj.id.toString())}
        className="flex flex-col h-full"
      >
        {displayObjects?.map((object) => (
          <AccordionItem
            key={object.id}
            value={object.id.toString()}
            className="p-0"
          >
            <AccordionTrigger
              variant="default"
              aria-label={`objectAccordion-${object?.componentName}`}
            >
              {object.componentName}
            </AccordionTrigger>
            <AccordionContent className="p-2 mt-1.5">
              <div className="px-1.5">
                <ConnectionList selectedObj={object} />
              </div>
            </AccordionContent>
          </AccordionItem>
        ))}
      </Accordion>
    </div>
  );
}