-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3068 from 10up/feature/mapping-weighting-dashboar…
…d-refactor New weighting screen with meta support
- Loading branch information
Showing
32 changed files
with
1,781 additions
and
658 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
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,64 @@ | ||
/** | ||
* WordPress dependencies. | ||
*/ | ||
import { Button } from '@wordpress/components'; | ||
import { WPElement } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal Dependencies. | ||
*/ | ||
import { useSettingsScreen } from '../../settings-screen'; | ||
import PostType from '../components/post-type'; | ||
import { useWeightingSettings } from '../provider'; | ||
|
||
/** | ||
* Weighting settings app. | ||
* | ||
* @returns {WPElement} Element. | ||
*/ | ||
export default () => { | ||
const { createNotice } = useSettingsScreen(); | ||
const { isBusy, save, weightableFields } = useWeightingSettings(); | ||
|
||
/** | ||
* Submit event. | ||
* | ||
* @param {Event} event Submit event. | ||
*/ | ||
const onSubmit = async (event) => { | ||
event.preventDefault(); | ||
|
||
try { | ||
await save(); | ||
createNotice('success', __('Settings saved.', 'elasticpress')); | ||
} catch (e) { | ||
createNotice('error', __('Something went wrong. Please try again.', 'elasticpress')); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<p> | ||
{__( | ||
'This dashboard enables you to select which fields ElasticPress should sync, whether to use those fields in searches, and how heavily to weight fields in the search algorithm. In general, increasing the Weight of a field will increase the relevancy score of a post that has matching text in that field.', | ||
'elasticpress', | ||
)} | ||
</p> | ||
<p> | ||
{__( | ||
'For example, adding more weight to the title attribute will cause search matches on the post title to appear more prominently.', | ||
'elasticpress', | ||
)} | ||
</p> | ||
<form className="ep-weighting-screen" onSubmit={onSubmit}> | ||
{weightableFields.map(({ key }) => { | ||
return <PostType key={key} postType={key} />; | ||
})} | ||
<Button disabled={isBusy} isBusy={isBusy} isPrimary type="submit" variant="primary"> | ||
{__('Save changes', 'elasticpress')} | ||
</Button> | ||
</form> | ||
</> | ||
); | ||
}; |
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,78 @@ | ||
/** | ||
* WordPress Dependencies. | ||
*/ | ||
import { Button, CheckboxControl, RangeControl } from '@wordpress/components'; | ||
import { WPElement } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { trash } from '@wordpress/icons'; | ||
|
||
/** | ||
* Field settings component. | ||
* | ||
* @param {object} props Component props. | ||
* @param {string} props.label Property label. | ||
* @param {Function} props.onChange Change handler. | ||
* @param {Function} props.onDelete Delete handler. | ||
* @param {object} props.value Values. | ||
* @returns {WPElement} Component element. | ||
*/ | ||
export default ({ label, onChange, onDelete, value }) => { | ||
const { enabled = false, weight = 0 } = value; | ||
|
||
/** | ||
* Handle change of searchable. | ||
* | ||
* @param {boolean} enabled New searchable value. | ||
* @returns {void} | ||
*/ | ||
const onChangeSearchable = (enabled) => { | ||
onChange({ weight, enabled }); | ||
}; | ||
|
||
/** | ||
* Handle change of weighting. | ||
* | ||
* @param {number} weight New weight value. | ||
* @returns {void} | ||
*/ | ||
const onChangeWeight = (weight) => { | ||
onChange({ enabled: true, weight }); | ||
}; | ||
|
||
/** | ||
* Render. | ||
*/ | ||
return ( | ||
<div className="ep-weighting-field"> | ||
<fieldset> | ||
<legend className="ep-weighting-field__name">{label}</legend> | ||
<div className="ep-weighting-field__searchable"> | ||
<CheckboxControl | ||
checked={enabled} | ||
label={__('Searchable', 'elasticpress')} | ||
onChange={onChangeSearchable} | ||
/> | ||
</div> | ||
<div className="ep-weighting-field__weighting"> | ||
<RangeControl | ||
disabled={!enabled} | ||
label={__('Weight', 'elasticpress')} | ||
max={100} | ||
min={1} | ||
onChange={onChangeWeight} | ||
value={weight} | ||
/> | ||
</div> | ||
<div className="ep-weighting-field__actions"> | ||
<Button | ||
className="ep-weighting-action ep-weighting-action--delete" | ||
disabled={!onDelete} | ||
icon={trash} | ||
label={__('Remove', 'elasticpress')} | ||
onClick={onDelete} | ||
/> | ||
</div> | ||
</fieldset> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.