Skip to content

Commit

Permalink
Add QueryClientProvider to QueryInspectorControls
Browse files Browse the repository at this point in the history
  • Loading branch information
iansvo committed Dec 28, 2024
1 parent ee29cc9 commit 18d89af
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/blocks/query/components/ControlBuilder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function ControlBuilder( props ) {
dependencies,
placeholder,
postType,
queryClient,
} = props;

let controlDescription = description;
Expand Down Expand Up @@ -114,6 +115,7 @@ export function ControlBuilder( props ) {
onChange,
min: isPostsPerPage ? -1 : undefined,
postType,
queryClient,
...dependencies,
};

Expand Down
4 changes: 3 additions & 1 deletion src/blocks/query/components/ParameterControl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useCallback } from '@wordpress/element';

import { ControlBuilder } from './ControlBuilder';

export function ParameterControl( { parameter, query, setParameter, removeParameter } ) {
export function ParameterControl( { parameter, query, setParameter, removeParameter, queryClient } ) {
const { dependencies = {} } = parameter;
const parameterValue = query[ parameter.id ];
const postType = query?.post_type ?? [ 'post' ];
Expand All @@ -21,6 +21,7 @@ export function ParameterControl( { parameter, query, setParameter, removeParame
return (
<ControlBuilder
{ ...parameter }
queryClient={ queryClient }
postType={ postType }
value={ parameterValue }
onChange={ onChangeControl }
Expand All @@ -34,6 +35,7 @@ export function ParameterControl( { parameter, query, setParameter, removeParame
Array.isArray( parameterValue ) && parameterValue.map( ( value, i ) => (
<ControlBuilder
{ ...parameter }
queryClient={ queryClient }
key={ `${ parameter.id }-${ i }` }
postType={ postType }
value={ value }
Expand Down
3 changes: 2 additions & 1 deletion src/blocks/query/components/ParameterList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getParametersList = ( query ) => {
) ).filter( Boolean ) );
};

export function ParameterList( { query, setParameter, removeParameter } ) {
export function ParameterList( { query, setParameter, removeParameter, queryClient } ) {
const parameterList = getParametersList( query );

return (
Expand All @@ -24,6 +24,7 @@ export function ParameterList( { query, setParameter, removeParameter } ) {
query={ query }
setParameter={ setParameter }
removeParameter={ removeParameter }
queryClient={ queryClient }
/>
) ) }
</Stack>
Expand Down
14 changes: 11 additions & 3 deletions src/blocks/query/components/QueryInspectorControls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ import { ToggleControl, SelectControl } from '@wordpress/components';
import { applyFilters } from '@wordpress/hooks';

import { isEqual } from 'lodash';
import {

Check failure on line 7 in src/blocks/query/components/QueryInspectorControls.jsx

View workflow job for this annotation

GitHub Actions / JS Lint

'@tanstack/react-query' should be listed in the project's dependencies. Run 'npm i -S @tanstack/react-query' to add it
QueryClient,
QueryClientProvider,
} from '@tanstack/react-query';

import useQueryReducer from '@hooks/useQueryReducer';
import { SelectQueryParameter } from './SelectQueryParameter';
import { AddQueryParameterButton } from './AddQueryParameterButton';
import { ParameterList } from './ParameterList';
import useQueryReducer from '@hooks/useQueryReducer';
import { getParameters } from '../query-parameters';

const queryClient = new QueryClient();

export function QueryInspectorControls( { attributes, setAttributes, context } ) {
const { queryState, setParameter, removeParameter } = useQueryReducer( attributes.query );
const [ displayParameterSelect, setDisplayParameterSelect ] = useState( false );
Expand Down Expand Up @@ -44,7 +50,7 @@ export function QueryInspectorControls( { attributes, setAttributes, context } )
}, [ queryTypes, attributes.queryType ] );

return (
<>
<QueryClientProvider client={ queryClient }>
{ queryTypes.length > 1 && (
<SelectControl
value={ attributes.queryType }
Expand Down Expand Up @@ -83,6 +89,7 @@ export function QueryInspectorControls( { attributes, setAttributes, context } )
query={ queryState }
setParameter={ setParameter }
removeParameter={ removeParameter }
queryClient={ queryClient }
/>

{ ! displayParameterSelect &&
Expand Down Expand Up @@ -129,9 +136,10 @@ export function QueryInspectorControls( { attributes, setAttributes, context } )
setParameter,
removeParameter,
context,
queryClient,
}
)
}
</>
</QueryClientProvider>
);
}

0 comments on commit 18d89af

Please sign in to comment.