Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _columnClick = (ev: React.MouseEvent, column: IColumn): void => {
// Find the field in the viewFields list
const columnIdx = findIndex(this.props.viewFields, field => field.name === column.key);
// Check if the field has been found
if (columnIdx !== -1) {
const field = this.props.viewFields[columnIdx];
// Check if the field needs to be sorted
if (has(field, 'sorting')) {
// Check if the sorting option is true
if (field.sorting) {
const sortDescending = typeof column.isSortedDescending === 'undefined' ? false : !column.isSortedDescending;
const sortedItems = this._sortItems(this.state.items, column.key, sortDescending);
// Update the columns
const sortedColumns = this.state.columns.map(c => {
if (c.key === column.key) {
c.isSortedDescending = sortDescending;
c.isSorted = true;
} else {
c.isSorted = false;
private _getIconByExtension(extension: string, iconType: IconType): string {
// Find the application index by the provided extension
const appIdx = findIndex(ApplicationIconList, item => { return item.extensions.indexOf(extension.toLowerCase()) !== -1; });
// Check if an application has found
if (appIdx !== -1) {
// Check the type of icon, the image needs to get checked for the name
if (iconType === IconType.font) {
return ApplicationIconList[appIdx].iconName;
} else {
const knownImgs = ApplicationIconList[appIdx].imageName;
// Check if the file extension is known
const imgIdx = knownImgs.indexOf(extension);
if (imgIdx !== -1) {
return knownImgs[imgIdx];
} else {
// Return the first one if it was not known
return knownImgs[0];
}
private _getFileSizeName(value: ImageSize): string {
// Find the image size index by the image size
const sizeIdx = findIndex(IconSizes, size => size.size === value);
// Check if an icon size has been retrieved
if (sizeIdx !== -1) {
// Return the first icon size
return IconSizes[sizeIdx].name;
}
// Return the default file size if nothing was found
return ICON_DEFAULT_SIZE;
}
private async ensureUser(userId: string): Promise {
const siteUrl = this.context.pageContext.web.absoluteUrl;
if (this.cachedLocalUsers && this.cachedLocalUsers[siteUrl]) {
const users = this.cachedLocalUsers[siteUrl];
const userIdx = findIndex(users, u => u.LoginName === userId);
if (userIdx !== -1) {
return users[userIdx].Id;
}
}
const restApi = `${siteUrl}/_api/web/ensureuser`;
const data = await this.context.spHttpClient.post(restApi, SPHttpClient.configurations.v1, {
body: JSON.stringify({ 'logonName': userId })
});
if (data.ok) {
const user: IUserInfo = await data.json();
if (user && user.Id) {
this.cachedLocalUsers[siteUrl].push(user);
return user.Id;
}
public updateItem(itemUpdated: ITodoItem): Promise {
const index: number =
lodash.findIndex(
this._items[this._selectedList.Id],
(item: ITodoItem) => item.Id === itemUpdated.Id
);
if (index !== -1) {
this._items[this._selectedList.Id][index] = itemUpdated;
return this.getItems();
}
else {
return Promise.reject(new Error(`Item to update doesn't exist.`));
}
}
private _updateItem(newItem: ITodoTask): Promise {
this.clearError();
const updatingIndex: number = lodash.findIndex(this._todoComponentData.selectedListItems,
(item: ITodoTask) => item.Id === newItem.Id
);
this._renderTodoComponent({
selectedListItems: update(this._todoComponentData.selectedListItems, { [updatingIndex]: { $set: newItem } })
});
return this._dataProvider.updateItem(newItem)
.then(
(items: ITodoTask[]) => items && this._renderTodoComponent({ selectedListItems: items }),
this.renderError
);
}
public updateItem(itemUpdated: ITodoTask): Promise {
const index: number =
lodash.findIndex(
this._itemsStore[this._selectedList.Title],
(item: ITodoTask) => item.Id === itemUpdated.Id
);
if (index !== -1) {
const editor: ITodoPerson = itemUpdated.PercentComplete >= 1
? {
Id: 3,
Title: 'Chris Meyer',
Picture: 'http://dev.office.com/Modules/DevOffice.Fabric/Fabric/components/Persona/Persona.Person2.png',
EMail: ''
}
: undefined;
this._itemsStore[this._selectedList.Title][index] = itemUpdated;
this._itemsStore[this._selectedList.Title][index].Editor = editor;
private _updateItem(newItem: ITodoTask): Promise {
this.clearError();
const updatingIndex: number = lodash.findIndex(this._todoComponentData.selectedListItems,
(item: ITodoTask) => item.Id === newItem.Id
);
this._renderTodoComponent({
selectedListItems: update(this._todoComponentData.selectedListItems, { [updatingIndex]: { $set: newItem } })
});
return this._dataProvider.updateItem(newItem)
.then(
(items: ITodoTask[]) => items && this._renderTodoComponent({ selectedListItems: items }),
this.renderError
);
}