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 | 33x 190x 190x 4x 186x 954x 954x 179x 775x 33x 791x 16x 16x 791x 791x 791x 791x 791x | import { ScrollArea } from "@/ahuora-design-system/ui/scroll-area";
import {
SimulationObjectRetrieveRead,
useUnitopsSimulationobjectsRetrieveQuery
} from "@/api/apiStore.gen";
import { ObjectType } from "@/data/ObjectTypes.gen";
import objs from "@/data/objects.json";
import { useSearchParam } from "@/hooks/searchParams";
import { memo, useState } from "react";
import GeneralInfo from "./GeneralInfo/GeneralInfo";
import { GroupData } from "./GroupData";
import { UnitOpData } from "./UnitOpData";
import UnitOpContent from "../LeftSideBar/UnitOpContent";
const objects = objs as unknown as Record<string, ObjectType>;
function RightSideBarData() {
const [objectId] = useSearchParam("object");
if (!objectId) {
return ( // Fallback to show unit operations when no object is selected
<UnitOpContent/>
);
}
return <RightSideBarDataByObjectId objectId={+objectId} />;
}
function RightSideBarDataByObjectId({ objectId }: { objectId: number }) {
const { data: object } = useUnitopsSimulationobjectsRetrieveQuery({
id: objectId,
});
if (!object) {
return <></>;
}
return <RightSideBarDataByObject data={object} />;
}
let openAccordions = [
//"connections", // leave connections closed by default, because noone uses it other than the tests
"details",
"properties",
"composition",
"default",
"recycleSettings",
]
function useAccordionState() {
const [state, setState] = useState<string[]>(openAccordions);
function setAccordionState(newState: string[] | ((prevState: string[]) => string[])) {
setState(newState);
// Store the accordion state globally, so when switching between objects, it keeps the same things open.
openAccordions = typeof newState === "function" ? newState(openAccordions) : newState;
}
return [state, setAccordionState] as const;
}
function RightSideBarDataByObject({ data }: { data: SimulationObjectRetrieveRead }) {
const [openAccordions, setOpenAccordions] = useAccordionState();
const objectType = data.objectType;
const schema = objects[objectType];
return (
<div className="h-full w-full flex flex-col">
<div className="bg-background border-b border-border">
<GeneralInfo />
</div>
{data.objectType === "group" ? (
<GroupData
schema={schema}
openAccordions={openAccordions}
setOpenAccordions={setOpenAccordions}
/>
) : (
<ScrollArea className="flex flex-col w-full h-full">
<UnitOpData
schema={schema}
objectType={objectType}
openAccordions={openAccordions}
setOpenAccordions={setOpenAccordions}
/>
</ScrollArea>
)}
</div>
);
}
export interface SelectedPropertyInfo {
unitOpId: number;
propertyId: number;
}
export default memo(RightSideBarData);
|