This reverts commit 7c1993604c.
This commit is contained in:
parent
7c1993604c
commit
b498dd9867
1 changed files with 13 additions and 12 deletions
|
|
@ -29,19 +29,20 @@ export const TagsField = ({ onInput, defaultValue, switchHelpContext }) => {
|
|||
// Fetching further tag data allows us to display a richer UI
|
||||
// This fetch only happens once on first component load
|
||||
if (defaultValue && defaultValue !== '' && !defaultsLoaded) {
|
||||
const tagNamesQueryString = defaultValue
|
||||
.split(', ')
|
||||
.reduce((queryString, nextTagName) => {
|
||||
if (nextTagName) {
|
||||
return queryString
|
||||
? `${queryString}&tag_names[]=${nextTagName}`
|
||||
: `tag_names[]=${nextTagName}`;
|
||||
}
|
||||
}, '');
|
||||
const tagNames = defaultValue.split(', ');
|
||||
|
||||
fetch(`/tags/bulk?${tagNamesQueryString}`)
|
||||
.then((res) => res.json())
|
||||
.then((data) => setDefaultSelections(data));
|
||||
const tagRequests = tagNames.map((tagName) =>
|
||||
fetchSearch('tags', { name: tagName }).then(({ result = [] }) => {
|
||||
const [potentialMatch = {}] = result;
|
||||
return potentialMatch.name === tagName
|
||||
? potentialMatch
|
||||
: { name: tagName };
|
||||
}),
|
||||
);
|
||||
|
||||
Promise.all(tagRequests).then((data) => {
|
||||
setDefaultSelections(data);
|
||||
});
|
||||
}
|
||||
setDefaultsLoaded(true);
|
||||
}, [defaultValue, defaultsLoaded]);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue