Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public componentDidMount(): void {
let crntItems = this.props.value ? sortBy(cloneDeep(this.props.value), this.SORT_IDX) : [];
crntItems = crntItems.map((item, idx) => {
if (!item[this.SORT_IDX]) {
item[this.SORT_IDX] = idx + 1;
}
return item;
});
// Update the sort propety
crntItems = this.updateSortProperty(crntItems);
this.setState({
crntItems: sortBy(crntItems, this.SORT_IDX)
});
}
// 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
});
}
this.setState((prevState: ICollectionDataViewerState): ICollectionDataViewerState => {
let { crntItems } = prevState;
crntItems.splice(idx, 1);
// Update the sort propety
crntItems = this.updateSortProperty(crntItems);
return {
crntItems: sortBy(crntItems, this.SORT_IDX)
};
});
}
public componentDidMount(): void {
let crntItems = this.props.value ? sortBy(cloneDeep(this.props.value), this.SORT_IDX) : [];
crntItems = crntItems.map((item, idx) => {
if (!item[this.SORT_IDX]) {
item[this.SORT_IDX] = idx + 1;
}
return item;
});
// Update the sort propety
crntItems = this.updateSortProperty(crntItems);
this.setState({
crntItems: sortBy(crntItems, this.SORT_IDX)
});
}
// 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
});
}
Title: result.Title,
Url: result.Url,
Description: result.Description
} as IPromotedResult);
});
}
});
results.PromotedResults = promotedResults;
}
// Resolve all the promises once to get news
const relevantResults: ISearchResult[] = await Promise.all(allItemsPromises);
// Sort refiners according to the property pane value
refinementResults = sortBy(refinementResults, (refinement) => {
// Get the index of the corresponding filter name
return sortedRefiners.indexOf(refinement.FilterName);
});
results.RelevantResults = relevantResults;
results.RefinementResults = refinementResults;
results.TotalRows = this._initialSearchResult.TotalRows;
}
return results;
} catch (error) {
Logger.write('[SharePointDataProvider.search()]: Error: ' + error, LogLevel.Error);
throw error;
}
}
private _sortItems(items: any[], columnName: string, descending = false): any[] {
// Sort the items
const ascItems = sortBy(items, [columnName]);
const sortedItems = descending ? ascItems.reverse() : ascItems;
// Check if selection needs to be updated
if (this._selection) {
const selection = this._selection.getSelection();
if (selection && selection.length > 0) {
// Clear selection
this._selection.setItems([], true);
setTimeout(() => {
// Find new index
let idxs: number[] = selection.map(item => findIndex(sortedItems, item));
idxs.forEach(idx => this._selection.setIndexSelected(idx, true, false));
}, 0);
}
}
}
// If required and message are false, it doesn't need to be added
if (!fieldMsg.message && !fieldMsg.isRequired) {
// Remove the item
if (fieldMsgIdx !== -1) {
errorMsgs.splice(fieldMsgIdx, 1);
}
} else {
if (fieldMsgIdx === -1) {
errorMsgs.push(fieldMsg);
}
}
// Sort based on the index
errorMsgs = sortBy(errorMsgs, ["field"]);
return {
errorMsgs
};
});
}
this.setState((prevState: ICollectionDataViewerState) => {
const { crntItems } = prevState;
let newOrderedItems = cloneDeep(crntItems);
newOrderedItems = this.moveItemTo(newOrderedItems, oldIdx, newIdx - 1);
newOrderedItems = this.updateSortProperty(newOrderedItems);
newOrderedItems = sortBy(newOrderedItems, this.SORT_IDX);
return {
crntItems: newOrderedItems
};
});
}