# all files / src/ transforms.js

100% Statements 51/51
95.83% Branches 23/24
83.33% Functions 15/18
100% Lines 25/25
2 branches Ignored

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    727×

    7×

    4×
    4×
    4×

    4×
    3×

    2×

    1×
    1×

    4×

    4×

    7×
    1×

    2×
    2×
    2×
    2×

    2×
    1×

    2×

    1×

    2×

    2×

     import React from 'react';

    const edit = ({
      getEditId = () => {},
      getEditProperty = () => {},
      onActivate = () => {},
      onValue = () => {}
    }) => editor => {
      const Edit = (value, extraParameters) => {
        const idx = getEditId(extraParameters);
        const editedCell = getEditProperty();

        if (editedCell === idx) {
          return {
            children: React.createElement(
              editor,
              {
                value,
                onValue: v => onValue(
                  { value: v, ...extraParameters }
                )
              }
            )
          };
        }

        return {
          onClick: () => onActivate(idx)
        };
      };
      Edit.propTypes = {
        value: React.PropTypes.any,
        extraParameters: React.PropTypes.shape({
          cellData: React.PropTypes.object.isRequired,
          property: React.PropTypes.string.isRequired
        })
      };

      return Edit;
    };

    const sort = ({
      getSortingColumns = () => [],
      onSort = () => {}
    }) => property => {
      const Sort = () => {
        const columns = getSortingColumns();
        const index = columns.map(c => c.property).indexOf(property);
        let headerClass = '';

        if (index >= 0) {
          headerClass = `sort-${columns[index].sort}`;
        }

        return {
          className: headerClass,
          onClick: () => onSort(property)
        };
      };
      Sort.propTypes = {
        property: React.PropTypes.string.isRequired
      };

      return Sort;
    };

    export default {
      edit,
      sort
    };