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