import _ from 'lodash'; import { EdgeGroup } from '@/react/edge/edge-groups/types'; import { Select } from '@@/form-components/ReactSelect'; import { FormSection } from '@@/form-components/FormSection'; import { FormError } from '@@/form-components/FormError'; import { Link } from '@@/Link'; import { FormControl } from '@@/form-components/FormControl'; import { useEdgeGroups } from '../../edge-groups/queries/useEdgeGroups'; type SingleValue = EdgeGroup['Id']; interface Props { value: SingleValue[]; onChange: (value: SingleValue[]) => void; error?: string | string[]; horizontal?: boolean; isGroupVisible?(group: EdgeGroup): boolean; } export function EdgeGroupsSelector({ value, onChange, error, horizontal, isGroupVisible = () => true, }: Props) { const selector = ( ); return horizontal ? ( {selector} ) : (
{selector}
{error && (
{error}
)}
); } function InnerSelector({ value, onChange, isGroupVisible, }: { isGroupVisible(group: EdgeGroup): boolean; value: SingleValue[]; onChange: (value: SingleValue[]) => void; }) { const edgeGroupsQuery = useEdgeGroups(); const items = (edgeGroupsQuery.data || []).filter(isGroupVisible); const valueGroups = _.compact( value.map((id) => items.find((item) => item.Id === id)) ); return items.length ? (