Sha256: c6f53c2ddde499715086838b0c9390ab95e43c226a4163214facd4a823cfff68

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

import React from 'react';

function AssociationPickerResults(props) {
  let items

  const shouldAllowCreate = _.isString(props.value) && props.value.length > 0
    && props.allowCreate && props.items.length === 0

  const selectedIds = _.map(props.selectedItems, 'id')
  const isSelected = (item) => {
    return _.includes(selectedIds, item.id)
  }

  if (shouldAllowCreate) {
    let newItem = { id: props.value, name: props.value, _create: true }
    items = [(
      <tr key={newItem.id}>
        <td onClick={() => props.onSelectItem(newItem)}>
          {props.value}
          <span className="o-assocpicker-create">(Create)</span>
        </td>
      </tr>
    )]
  } else {
    items = props.items.map(item => {
      let newItem = { id: item.id, name: item.name, _create: false, _selected: isSelected(item) }
      return (
        <tr key={newItem.id} className={newItem._selected ? 'active' : ''}>
          <td onClick={() => props.onSelectItem(newItem)}>{newItem.name}</td>
        </tr>
      )
    })
  }

  return (
    <table className="c-admcur-items">
      <thead>
        <tr>
          <th>Name</th>
        </tr>
      </thead>
      <tbody>
        {items.length ? items : <tr><td>Nothing to select</td></tr> }
      </tbody>
    </table>
  )
}

export default AssociationPickerResults

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lcms-engine-0.3.0 app/javascript/components/admin/association-picker/AssociationPickerResults.jsx
lcms-engine-0.2.0 app/javascript/components/admin/association-picker/AssociationPickerResults.jsx