"use client"; import { FC, useMemo } from "react"; import useAttributesList from "@/app/module-editor/[moduleId]/hooks/useAttributesList"; import ObjectSelect, { ObjectSelectProps, } from "@/components/selects/ObjectSelect/ObjectSelect"; import { AttributeSchema } from "@/lib/client"; type Props = Omit< ObjectSelectProps, "data" | "getLabelFn" | "getValueFn" > & { attributesToExclude?: AttributeSchema[]; }; const AttributeSelect: FC = ({ attributesToExclude, ...props }) => { const { attributes } = useAttributesList(); const availableAttributes = useMemo(() => { const attrIdsToExcludeSet = new Set( attributesToExclude?.map(a => a.id) ); return attributes.filter(a => !attrIdsToExcludeSet.has(a.id)); }, [attributes, attributesToExclude]); return ( props.onChange(null)} getLabelFn={(option: AttributeSchema) => option.label} data={availableAttributes} {...props} /> ); }; export default AttributeSelect;