import { useState } from '@wordpress/element'; import { SelectControl } from '@wordpress/components'; import FieldSelector from '../FieldSelector'; import MetaKeySelector from '../MetaKeySelector'; import TaxonomySelector from '../TaxonomySelector'; import FilterSelector from '../FilterSelector'; import JoinSelector from '../JoinSelector'; const TABS = [ { key: 'fields', label: 'Fields' }, { key: 'meta', label: 'Custom Fields' }, { key: 'taxonomies', label: 'Taxonomies' }, { key: 'filters', label: 'Filters' }, { key: 'joins', label: 'Joins' }, ]; export default function PostsConfigurator( { block, definition, dispatch } ) { const postTypes = window.wlconduitData?.postTypes || []; const [ activeTab, setActiveTab ] = useState( 'fields' ); function updateConfig( partial ) { dispatch( { type: 'UPDATE_BLOCK_CONFIG', payload: { id: block.id, config: partial }, } ); } return (
( { label: pt.internal ? `${ pt.label } (internal)` : pt.label, value: pt.name, } ) ) } onChange={ ( val ) => updateConfig( { post_type: val, taxonomies: {}, meta_keys: {}, } ) } />
{ TABS.map( ( tab ) => ( ) ) }
{ activeTab === 'fields' && ( updateConfig( { fields } ) } /> ) } { activeTab === 'meta' && ( updateConfig( { meta_keys } ) } /> ) } { activeTab === 'taxonomies' && ( updateConfig( { taxonomies } ) } /> ) } { activeTab === 'filters' && ( updateConfig( { filters } ) } /> ) } { activeTab === 'joins' && ( updateConfig( { joins } ) } /> ) }
); }