All files / src/pages/flowsheet-page ProjectPage.tsx

83.78% Statements 62/74
62.5% Branches 20/32
100% Functions 4/4
85.45% Lines 47/55

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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162                                                                        103x     20659x 20659x       1007x 1007x 33x   974x 974x 1948x 974x 1948x       1033x 1033x 1033x 1033x 1033x   1033x   1137x   1033x 4x                       5x                       13x               111x             1299x     999x     104x 2066x 2032x   104x 104x 3099x   1033x   133x           104x   1033x 1137x 1033x 104x   1033x 1137x     1166x   1698x     1299x   3031x       104x   104x       104x          
import { Tabs, TabsContent } from "@radix-ui/react-tabs";
import {
  AnimatePresence,
  motion,
  type Transition,
  useReducedMotion,
} from "motion/react";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
import { FlowsheetAccessProvider } from "@/ahuora-design-system/ui/accessControlled";
import { Separator } from "@/ahuora-design-system/ui/separator";
import { useFlowsheetRevisionPreview } from "@/hooks/flowsheetRevisionPreview";
import { useFlowsheetSubscriptions } from "@/hooks/notifications/useFlowsheetSubscriptions.ts";
import { FeatureFlagCommands } from "../../commands/FeatureFlagCommands";
import { useSearchParam } from "../../hooks/searchParams";
import EconomicsPage from "./economics/EconomicsPage";
import FlowsheetPage from "./FlowsheetPage";
import { DuplicateFlowsheetCommand } from "./flowsheet/DuplicateFlowsheetCommand";
import { GlobalShortcutInputBlocker } from "./flowsheet/GlobalShortcutInputBlocker";
import {
  CONTENT_MAP,
  ContentTypes,
  ViewTypes,
} from "./flowsheet/LeftSideBar/LeftSideBarTabDefinitions";
import LeftSideBarTabs from "./flowsheet/LeftSideBar/LeftSideBarTabs";
import SwitchViewCommands from "./flowsheet/LeftSideBar/SwitchViewCommands";
import { ResizableGroup } from "./flowsheet/Resizables";
import { FlowsheetReadStateBoundary } from "./flowsheet/revisions/FlowsheetReadStateBoundary";
import { FlowsheetRevisionPreviewBanner } from "./flowsheet/revisions/FlowsheetRevisionPreviewBanner";
import { FlowsheetRevisionPreviewGate } from "./flowsheet/revisions/FlowsheetRevisionPreviewGate";
import { FlowsheetRevisionPreviewProvider } from "./flowsheet/revisions/FlowsheetRevisionPreviewProvider";
import { FlowsheetRevisionSaveProvider } from "./flowsheet/revisions/FlowsheetRevisionSaveProvider";
import Summary from "./flowsheet/Summary/Summary";
import { MenuBar } from "./menuBar/MenuBar";
import PinchAnalysis from "./pinch-analysis/PinchAnalysis";
 
const MotionTabsContent = motion.create(TabsContent);
 
function RevisionAwareSubscriptions() {
  const { isPreview } = useFlowsheetRevisionPreview();
  useFlowsheetSubscriptions(!isPreview);
  return null;
}
 
function WorkingStateCommands({ onNavTabChange }) {
  const { isPreview } = useFlowsheetRevisionPreview();
  Iif (isPreview) return null;
  return (
    <>
      <DuplicateFlowsheetCommand />
      <SwitchViewCommands onNavTabChange={onNavTabChange} />
      <FeatureFlagCommands />
    </>
  );
}
 
const ProjectPageContent = () => {
  const [tab, setTab] = useSearchParam("content", ContentTypes.unitOps);
  const { isPreview } = useFlowsheetRevisionPreview();
  const view = CONTENT_MAP[tab as ContentTypes] || ViewTypes.flowsheet;
  const shouldReduceMotion = useReducedMotion();
 
  const transition: Transition = shouldReduceMotion
    ? { duration: 0 }
    : { duration: 0.16, ease: [0.4, 0, 0.2, 1] };
 
  const renderPage = () => {
    if (view === ViewTypes.pinch) {
      return (
        <FlowsheetReadStateBoundary>
          <FlowsheetRevisionPreviewGate>
            <ResizableGroup>
              <PinchAnalysis />
            </ResizableGroup>
          </FlowsheetRevisionPreviewGate>
        </FlowsheetReadStateBoundary>
      );
    }
 
    if (view === ViewTypes.summary) {
      return (
        <FlowsheetReadStateBoundary>
          <FlowsheetRevisionPreviewGate>
            <ResizableGroup>
              <Summary />
            </ResizableGroup>
          </FlowsheetRevisionPreviewGate>
        </FlowsheetReadStateBoundary>
      );
    }
 
    if (view === ViewTypes.economics) {
      return (
        <FlowsheetReadStateBoundary>
          <FlowsheetRevisionPreviewGate>
            <EconomicsPage isRevisionPreview={isPreview} />
          </FlowsheetRevisionPreviewGate>
        </FlowsheetReadStateBoundary>
      );
    }
 
    return (
      <ResizableGroup>
        <FlowsheetPage />
      </ResizableGroup>
    );
  };
 
  return (
    <FlowsheetAccessProvider>
      {/* Share one pending save guard between the toolbar and revisions panel. */}
      <FlowsheetRevisionSaveProvider>
        <RevisionAwareSubscriptions />
        <GlobalShortcutInputBlocker />
        <WorkingStateCommands onNavTabChange={setTab} />
        <div className="fixed inset-0 flex min-w-0 flex-col overflow-clip">
          <MenuBar />
          <Separator />
          <FlowsheetRevisionPreviewBanner />
          <div className="flex flex-1 overflow-hidden">
            <LeftSideBarTabs />
            <Tabs value={view} className="relative flex-1 overflow-hidden">
              <AnimatePresence initial={false} mode="wait">
                <MotionTabsContent
                  key={view}
                  value={view}
                  forceMount
                  className="absolute inset-0 h-full overflow-hidden"
                  initial={{
                    opacity: 0,
                    x: shouldReduceMotion ? 0 : 8,
                  }}
                  animate={{ opacity: 1, x: 0 }}
                  exit={{
                    opacity: 0,
                    x: shouldReduceMotion ? 0 : -8,
                  }}
                  transition={transition}
                >
                  {renderPage()}
                </MotionTabsContent>
              </AnimatePresence>
            </Tabs>
          </div>
        </div>
      </FlowsheetRevisionSaveProvider>
    </FlowsheetAccessProvider>
  );
};
 
const ProjectPage = () => {
  return (
    <DndProvider backend={HTML5Backend}>
      <FlowsheetRevisionPreviewProvider>
        <ProjectPageContent />
      </FlowsheetRevisionPreviewProvider>
    </DndProvider>
  );
};
 
export default ProjectPage;