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 | 76x 76x 2116x 2116x 2116x 2572x 2116x 2116x 334x 2005x 223x 2228x 2116x 35x 35x 35x 35x | import { useMemo } from "react";
import type { PropertyInfoRead } from "@/api/apiStore.gen";
import { useFlowsheetGroups } from "@/hooks/flowsheetObjects";
import { useProject } from "@/hooks/project";
import { useSimulationObjectPropertySet } from "@/hooks/properties";
import type { FormulaMentionGroup } from "./FormulaInputField";
const ECONOMICS_CAPITAL_LINE_KEY = "economics.capital_line";
const ECONOMICS_OPERATING_LINE_KEY = "economics.operating_line";
export function useEconomicsFormulaMentionGroups(): FormulaMentionGroup[] {
const project = useProject();
const groups = useFlowsheetGroups();
const rootGroup = groups?.find((group) => group.id === project?.rootGrouping);
const rootSimulationObjectId = rootGroup?.simulationObject;
const rootPropertySet = useSimulationObjectPropertySet(
rootSimulationObjectId ?? undefined,
);
return useMemo(() => {
Iif (rootSimulationObjectId == null || !rootPropertySet) return [];
const rootProperties = rootPropertySet.ContainedProperties ?? [];
const mentionGroups: FormulaMentionGroup[] = [];
if (rootProperties.some(isNativeEconomicsProperty)) {
mentionGroups.push({
id: "economics-native",
objectId: rootSimulationObjectId,
display: "Economics: ",
includeProperty: isNativeEconomicsProperty,
hideFromDefaultSuggestions: true,
});
}
if (rootProperties.some(isCapitalLineProperty)) {
mentionGroups.push({
id: "economics-capital-lines",
objectId: rootSimulationObjectId,
display: "Other capital costs: ",
displayPrefix: "Other capital costs: ",
includeProperty: isCapitalLineProperty,
hideFromDefaultSuggestions: true,
});
}
if (rootProperties.some(isOperatingLineProperty)) {
mentionGroups.push({
id: "economics-operating-lines",
objectId: rootSimulationObjectId,
display: "Other operating lines: ",
displayPrefix: "Other operating lines: ",
includeProperty: isOperatingLineProperty,
hideFromDefaultSuggestions: true,
});
}
return mentionGroups;
}, [rootPropertySet, rootSimulationObjectId]);
}
function isEconomicsProperty(propertyInfo: PropertyInfoRead): boolean {
return propertyInfo.key?.startsWith("economics.") === true;
}
function isCapitalLineProperty(propertyInfo: PropertyInfoRead): boolean {
return propertyInfo.key === ECONOMICS_CAPITAL_LINE_KEY;
}
function isOperatingLineProperty(propertyInfo: PropertyInfoRead): boolean {
return propertyInfo.key === ECONOMICS_OPERATING_LINE_KEY;
}
function isNativeEconomicsProperty(propertyInfo: PropertyInfoRead): boolean {
return (
isEconomicsProperty(propertyInfo) &&
!isCapitalLineProperty(propertyInfo) &&
!isOperatingLineProperty(propertyInfo)
);
}
|