issue fix- checking if items are defined before performing sort & filter

This commit is contained in:
Maya-Mostafa 2022-05-17 11:28:28 -04:00
parent a93be1a70b
commit f2193b10a2
1 changed files with 20 additions and 13 deletions

View File

@ -65,22 +65,29 @@ export default class FollowDocumentWebPart extends React.Component<IFollowDocume
}
let followDocuments: FollowDocument[] = [];
this.getFollowDocuments(followDocuments).then((Items: FollowDocument[]) => {
//Order by Date
Items = Items.sort((a, b) => {
return b.followedDateTime.getTime() - a.followedDateTime.getTime();
});
let uniq = {};
let group: Array<IDropdownOption> = new Array<IDropdownOption>();
//Remove duplicated from array
let uniqueArray = [];
uniqueArray = Items.filter(obj => !uniq[obj.WebUrl] && (uniq[obj.WebUrl] = true));
group.push({ key: '0', text: 'All Sites' });
uniqueArray.forEach(Item => {
group.push({
key: Item.WebUrl,
text: "Site: " + Item.WebName,
if(Items){ //checking if there are items before performing sort & filter to fix the error of running those functions on undefined
//Order by Date
Items = Items.sort((a, b) => {
return b.followedDateTime.getTime() - a.followedDateTime.getTime();
});
});
let uniq = {};
//Remove duplicated from array
let uniqueArray = [];
uniqueArray = Items.filter(obj => !uniq[obj.WebUrl] && (uniq[obj.WebUrl] = true));
uniqueArray.forEach(Item => {
group.push({
key: Item.WebUrl,
text: "Site: " + Item.WebName,
});
});
}
this.setState({
Items: Items,
ItemsSearch: Items,