import type { LunaticComponentProps } from '../type'; import { Fragment } from 'react'; import { LunaticComponents } from '../LunaticComponents'; import { PairwiseMirror } from './PairwiseMirror'; import { filterCombinations, getCombinations } from './combinations'; export const PairwiseLinks = ( props: LunaticComponentProps<'PairwiseLinks'> ) => { const { iteration, size, getComponents } = props; // We only need to display a pairwise if there are at least 2 guys if (size < 2) { return; } const combinations = getCombinations(size); return ( <> {combinations .filter((combination) => filterCombinations({ combination, iteration })) .map(([x, y]) => ( ({ ...props, id: `${props.id}-${x + 1}-${y + 1} `, })} /> ))} {combinations .filter((combination) => filterCombinations({ combination, iteration, isSymLink: true }) ) .map(([x, y]) => { const components = getComponents(x, y); const firstComponent = components[0]; // Display nothing if there is no component (due to filter) if (firstComponent === undefined || firstComponent === null) return; if (firstComponent?.componentType !== 'Dropdown') { return (
First child component of a pairwise link must be a dropdown
); } return ( ); })} ); };