Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Term item to add to the active nodes array
const termItem = {
name: term.Name,
key: term.Id,
path: term.PathOfTerm,
termSet: term.TermSet.Id
};
// Check if the term is checked or unchecked
if (checked) {
// Check if it is allowed to select multiple terms
if (this.props.allowMultipleSelections) {
// Add the checked term
activeNodes.push(termItem);
// Filter out the duplicate terms
activeNodes = uniqBy(activeNodes, 'key');
} else {
// Only store the current selected item
activeNodes = [termItem];
}
} else {
// Remove the term from the list of active nodes
activeNodes = activeNodes.filter(item => item.key !== term.Id);
}
// Sort all active nodes
activeNodes = sortBy(activeNodes, 'path');
// Update the current state
this.setState({
activeNodes: activeNodes
});
}
name: term.Name,
key: term.Id,
path: term.PathOfTerm,
termSet: term.TermSet.Id,
termGroup: termGroup,
labels: term.Labels
};
// Check if the term is checked or unchecked
if (checked) {
// Check if it is allowed to select multiple terms
if (this.props.allowMultipleSelections) {
// Add the checked term
activeNodes.push(termItem);
// Filter out the duplicate terms
activeNodes = uniqBy(activeNodes, 'key');
} else {
// Only store the current selected item
activeNodes = [termItem];
}
} else {
// Remove the term from the list of active nodes
activeNodes = activeNodes.filter(item => item.key !== term.Id);
}
// Sort all active nodes
activeNodes = sortBy(activeNodes, 'path');
// Update the current state
this.setState({
activeNodes: activeNodes
});
}
private onSearchFieldChanged = async (searchText: string, currentSelected: IPersonaProps[]): Promise => {
if (searchText.length > 2) {
const results = await this.peopleSearchService.searchPeople(searchText, this.suggestionsLimit, this.props.principalTypes, this.props.webAbsoluteUrl, this.groupId, this.props.ensureUser);
// Remove duplicates
const { selectedPersons, mostRecentlyUsedPersons } = this.state;
const filteredPersons = this.removeDuplicates(results, selectedPersons);
// Add the users to the most recently used ones
let recentlyUsed = [...filteredPersons, ...mostRecentlyUsedPersons];
recentlyUsed = uniqBy(recentlyUsed, "text");
this.setState({
mostRecentlyUsedPersons: recentlyUsed.slice(0, this.suggestionsLimit)
});
return filteredPersons;
} else {
return [];
}
}