import { useState } from '@wordpress/element';
import { CheckboxControl, TextControl } from '@wordpress/components';
function PerPageMaxInput( { value, onCommit } ) {
const [ draft, setDraft ] = useState( String( value ) );
function handleBlur() {
const clamped = Math.min( 50, Math.max( 1, parseInt( draft, 10 ) || 50 ) );
setDraft( String( clamped ) );
onCommit( clamped );
}
return (
);
}
export default function FilterSelector( { available, selected, onChange } ) {
function toggleFilter( key ) {
const updated = { ...selected };
if ( updated[ key ] ) {
delete updated[ key ];
} else {
updated[ key ] = { enabled: true, description: available[ key ]?.description || '' };
}
onChange( updated );
}
function updateFilterConfig( key, partial ) {
const updated = {
...selected,
[ key ]: { ...selected[ key ], ...partial },
};
onChange( updated );
}
return (
Select which query filters the AI can use when calling this tool.
{ Object.entries( available ).map( ( [ key, filterDef ] ) => {
const isEnabled = !! selected[ key ]?.enabled;
return (
toggleFilter( key ) }
/>
{ isEnabled && (
updateFilterConfig( key, { description: val } ) }
placeholder={ filterDef.description }
/>
{ key === 'per_page' && (
updateFilterConfig( key, { max: val } ) }
/>
) }
) }
);
} ) }
);
}