-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the utils file and move a few functions into there.
- Loading branch information
1 parent
6bc3cfc
commit 80c6a34
Showing
2 changed files
with
46 additions
and
23 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,44 @@ | ||
/** | ||
* Helper function to update taxonomy queries. | ||
* | ||
* @param {Array} queries The current queries. | ||
* @param {string} queryId The query ID to update. | ||
* @param {string} item The key to update. | ||
* @param {string} value The value to update. | ||
* | ||
* @return {Array} The updated queries. | ||
*/ | ||
export const updateTaxonomyQuery = ( queries, queryId, item, value ) => { | ||
return queries.map( ( query ) => { | ||
if ( query.id === queryId ) { | ||
return { | ||
...query, | ||
[ item ]: value, | ||
}; | ||
} | ||
return query; | ||
} ); | ||
}; | ||
|
||
/** | ||
* A helper to retrieve the correct items to display or save in the token field | ||
* | ||
* @param {Array} subSet | ||
* @param {Array} fullSet | ||
* @param {string} lookupProperty | ||
* @param {string} returnProperty | ||
* @return {Array} The correct items to display or save in the token field | ||
*/ | ||
export const prepDataFromTokenField = ( | ||
subSet, | ||
fullSet, | ||
lookupProperty, | ||
returnProperty | ||
) => { | ||
const subsetFullObjects = fullSet.filter( ( item ) => | ||
subSet.includes( item[ lookupProperty ] ) | ||
); | ||
return subsetFullObjects.map( | ||
( { [ returnProperty ]: returnVal } ) => returnVal | ||
); | ||
}; |