How to use the @microsoft/sp-lodash-subset.findIndex function in @microsoft/sp-lodash-subset

To help you get started, we’ve selected a few @microsoft/sp-lodash-subset examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SharePoint / sp-dev-fx-controls-react / src / controls / listView / ListView.tsx View on Github external
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;
github SharePoint / sp-dev-fx-controls-react / src / controls / fileTypeIcon / FileTypeIcon.tsx View on Github external
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];
        }
github SharePoint / sp-dev-fx-controls-react / src / controls / fileTypeIcon / FileTypeIcon.tsx View on Github external
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;
  }
github SharePoint / sp-dev-fx-controls-react / src / services / PeopleSearchService.ts View on Github external
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;
      }
github SharePoint / sp-dev-fx-webparts / samples / vuejs-todo-single-file-component / src / dataProviders / MockDataProvider.ts View on Github external
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.`));
    }
  }
github SharePoint / sp-dev-fx-webparts / samples / react-todo / src / webparts / todo-step-3 / TodoWebPart.tsx View on Github external
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
      );
  }
github SharePoint / sp-dev-fx-webparts / samples / react-todo / src / webparts / todo-step-4 / dataProviders / MockTodoDataProvider.ts View on Github external
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;
github SharePoint / sp-dev-fx-webparts / samples / react-todo / src / webparts / todo-step-2 / TodoWebPart.tsx View on Github external
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
      );
  }