-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix/3279
- Loading branch information
Showing
27 changed files
with
2,441 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"title": "Facet by Meta Range (ElasticPress)", | ||
"textdomain": "elasticpress", | ||
"name": "elasticpress/facet-meta-range", | ||
"icon": "feedback", | ||
"category": "widgets", | ||
"attributes": { | ||
"facet": { | ||
"type": "string", | ||
"default": "" | ||
} | ||
}, | ||
"supports": { | ||
"html": false | ||
}, | ||
"editorScript": "ep-facets-meta-range-block-script", | ||
"style": "file:/../../../../../dist/css/facets-styles.css" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* global facetMetaBlock */ | ||
|
||
import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; | ||
import { PanelBody, Spinner, Placeholder, SelectControl } from '@wordpress/components'; | ||
import { | ||
Fragment, | ||
useEffect, | ||
useState, | ||
useCallback, | ||
createInterpolateElement, | ||
} from '@wordpress/element'; | ||
import apiFetch from '@wordpress/api-fetch'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
const FacetBlockEdit = (props) => { | ||
const { attributes, setAttributes } = props; | ||
const [metaKeys, setMetaKeys] = useState([]); | ||
const [preview, setPreview] = useState(''); | ||
const [loading, setLoading] = useState(false); | ||
const { facet, min, max } = attributes; | ||
|
||
const blockProps = useBlockProps(); | ||
|
||
const load = useCallback(async () => { | ||
const metaKeys = await apiFetch({ | ||
path: '/elasticpress/v1/facets/meta-range/keys', | ||
}); | ||
setMetaKeys(metaKeys); | ||
}, [setMetaKeys]); | ||
|
||
useEffect(load, [load]); | ||
|
||
useEffect(() => { | ||
setLoading(true); | ||
const params = new URLSearchParams({ facet }); | ||
apiFetch({ | ||
path: `/elasticpress/v1/facets/meta-range/block-preview?${params}`, | ||
}) | ||
.then((preview) => setPreview(preview)) | ||
.finally(() => setLoading(false)); | ||
}, [facet, min, max]); | ||
|
||
return ( | ||
<Fragment> | ||
<InspectorControls> | ||
<PanelBody title={__('Facet Settings', 'elasticpress')}> | ||
<SelectControl | ||
label={__('Meta Field Key', 'elasticpress')} | ||
help={createInterpolateElement( | ||
__( | ||
'This is the list of meta fields indexed in Elasticsearch. If your desired field does not appear in this list please try to <a>sync your content</a>', | ||
'elasticpress', | ||
), | ||
// eslint-disable-next-line jsx-a11y/anchor-has-content, jsx-a11y/control-has-associated-label | ||
{ a: <a href={facetMetaBlock.syncUrl} /> }, | ||
)} | ||
value={facet} | ||
options={[ | ||
...metaKeys.map((metaKey) => ({ | ||
label: metaKey, | ||
value: metaKey, | ||
})), | ||
]} | ||
onChange={(value) => setAttributes({ facet: value })} | ||
/> | ||
</PanelBody> | ||
</InspectorControls> | ||
|
||
<div {...blockProps}> | ||
{loading && ( | ||
<Placeholder> | ||
<Spinner /> | ||
</Placeholder> | ||
)} | ||
{/* eslint-disable-next-line react/no-danger */} | ||
{!loading && <div dangerouslySetInnerHTML={{ __html: preview }} />} | ||
</div> | ||
</Fragment> | ||
); | ||
}; | ||
export default FacetBlockEdit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* WordPress dependencies. | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies. | ||
*/ | ||
import edit from './edit'; | ||
import block from './block.json'; | ||
|
||
registerBlockType(block, { | ||
edit, | ||
save: () => {}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.