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 | 702x 168x 168x 168x 168x 196x 168x 168x 168x 168x 2x 224x 168x 168x 71x 208x 6x 327x 168x 168x 71x 71x 220x 71x 523x 168x 239x | import { Plus } from "lucide-react";
import {
ObjectTypeEnum,
useCoreMlcolumnmappingListQuery,
useUnitopsSimulationobjectsAddExpressionCreateMutation,
useUnitopsSimulationobjectsRetrieveQuery,
} from "@/api/apiStore.gen";
import { useCurrentObjectId, useObjectSchema } from "@/hooks/flowsheetObjects";
import { useSimulationObjectPropertySet } from "@/hooks/properties";
import { AccessControlledButton as Button } from "../../../../../ahuora-design-system/ui/accessControlled";
import { ToolTipCover } from "../../../../../ahuora-design-system/ui/tooltip";
import { isEconomicsProperty } from "../../PropertiesSidebar/PropertyPanel/economicsPropertyMetadata";
import { useEconomicsFormulaMentionGroups } from "./economicsFormulaMentionGroups";
import { FormulaCard } from "./FormulaCard";
import { FormulaTemplates } from "./FormulaTemplates";
import { MLProperties } from "./MLProperties";
export function CustomProperties() {
const currentObjectId = useCurrentObjectId();
const propertySet = useSimulationObjectPropertySet(currentObjectId);
const objectSchema = useObjectSchema(currentObjectId);
const currentObject = useUnitopsSimulationobjectsRetrieveQuery({
id: currentObjectId,
}).data;
const formulaMentionGroups = useEconomicsFormulaMentionGroups();
const { data: columnMappingsSet } = useCoreMlcolumnmappingListQuery();
const [addExpression] =
useUnitopsSimulationobjectsAddExpressionCreateMutation();
const onAddExpression = () => {
Iif (!currentObjectId) return;
addExpression({
id: currentObjectId,
});
};
const isMachineLearningBlock =
currentObject?.objectType === ObjectTypeEnum.MachineLearningBlock;
const mapPropertiesFn = (propertySet) => {
return propertySet.ContainedProperties.filter(
(property) =>
// only show properties that are not defined in the object config
!(
property.key in (objectSchema?.properties || {}) ||
(
columnMappingsSet?.map((mapping) => mapping.propertyKey) || []
).includes(property.key)
) && !isEconomicsProperty(property),
).map((property) => {
return (
<FormulaCard
key={property.id}
property={property}
formulaMentionGroups={formulaMentionGroups}
/>
);
});
};
const invalidObjectTypes = [ObjectTypeEnum.Stream, ObjectTypeEnum.Recycle];
Iif (invalidObjectTypes.includes(currentObject?.objectType as ObjectTypeEnum))
return null;
const isValidForML = () => {
Iif (!currentObject) return false;
const invalidObjectTypes = [
ObjectTypeEnum.Stream,
ObjectTypeEnum.Recycle,
ObjectTypeEnum.MachineLearningBlock,
];
return !invalidObjectTypes.includes(
currentObject.objectType as ObjectTypeEnum,
);
};
return (
// All the padding at the bottom is so that the dropdown for the expressions is not cut off.
<div className="flex flex-col gap-2">
{!isMachineLearningBlock && (
<>
<div className="w-full flex flex-col gap-2 py-2">
{propertySet && mapPropertiesFn(propertySet)}
<ToolTipCover
asChild
content="Add a property defined by a custom formula."
>
<Button variant="secondary" onClick={onAddExpression}>
<Plus aria-label="Add Custom Property" /> Add Custom Property
</Button>
</ToolTipCover>
</div>
{isValidForML() && <MLProperties />}
</>
)}
<FormulaTemplates />
</div>
);
}
|