All files / packages/design-system/ui/components/data-tables/inline-edit index.jsx

85.71% Statements 6/7
85.71% Branches 12/14
0% Functions 0/1
85.71% Lines 6/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160                                    1x         1x               12x   11x                                                                                                                                                                                                                 1x 1x                                        
// Copyright (c) 2015-present, salesforce.com, inc. All rights reserved
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license
 
import React, { useContext } from 'react';
import PropTypes from 'prop-types';
 
import {
  TBodyTr,
  Td,
  RowTh,
  ErrorCell,
  SelectRowCell,
  EditableCell,
  RowActionsCell,
  DataTableContext,
} from '../';
import { IsDependentOn } from '../../../shared/helpers';
 
export const Demo = (props) => (
  <div className="demo-only" {...props}>
    {props.children}
  </div>
);
Demo.propTypes = {
  children: PropTypes.node,
};
 
/**
 * @name InlineEditTr - Common table row for inline edit data grids
 */
export const InlineEditTr = (props) => {
  const { isActionableMode } = useContext(DataTableContext);
 
  return (
    <TBodyTr isSelected={props.isSelected}>
      <Td
        hasFocus={props.focusedCell === 'error'}
        isEditable
        isErrorCell
        type="advanced"
      >
        <ErrorCell hasError={props.showRowError} index={props.index} />
      </Td>
      <Td
        hasFocus={props.focusedCell === 'selectRow'}
        isEditable
        tabIndex={
          !isActionableMode && props.focusableCell === 'selectRow' ? '0' : null
        }
        type="advanced"
      >
        <SelectRowCell
          checked={props.isSelected}
          index={props.index}
          inputTabIndex={isActionableMode ? '0' : '-1'}
        />
      </Td>
      <RowTh
        hasFocus={props.focusedCell === 'recordName'}
        isEditable
        tabIndex={
          !isActionableMode && props.focusableCell === 'recordName' ? '0' : null
        }
      >
        <EditableCell
          buttonText={'Edit Name of ' + props.recordName}
          cellLink
          cellText={props.recordName}
          index={props.index}
        />
      </RowTh>
      <Td
        hasError={props.showCellError}
        hasFocus={props.focusedCell === 'accountName'}
        isEditable
        isEdited={props.showEditedCell}
        isEditing={props.showEdit}
        isLocked={props.isLocked}
        tabIndex={
          !isActionableMode && props.focusableCell === 'accountName'
            ? '0'
            : null
        }
        type="advanced"
      >
        <EditableCell
          buttonText={'Edit Account Name of ' + props.recordName}
          cellText={props.accountName}
          hasError={props.showEditError}
          index={props.index}
          isLocked={props.isLocked}
          isRequired={props.showEditRequired}
          showEdit={props.showEdit}
          isEdited={props.showEditedCell}
        />
      </Td>
      <Td isEditable type="advanced">
        <EditableCell
          buttonText={'Edit Close Date of ' + props.recordName}
          cellText={props.closeDate}
          index={props.index}
        />
      </Td>
      <Td isEditable type="advanced">
        <EditableCell
          buttonText={'Edit Stage of ' + props.recordName}
          cellText={props.stage}
          index={props.index}
        />
      </Td>
      <Td isEditable isLocked type="advanced">
        <EditableCell
          buttonText={'Edit Confidence of ' + props.recordName}
          cellText={props.confidence}
          index={props.index}
          isLocked
        />
      </Td>
      <Td isEditable type="advanced">
        <EditableCell
          buttonText={'Edit Amount of ' + props.recordName}
          cellText={props.amount}
          index={props.index}
        />
      </Td>
      <Td isEditable type="advanced">
        <EditableCell
          buttonText={'Edit Contact of ' + props.recordName}
          cellText={props.contact}
          index={props.index}
        />
      </Td>
      <Td isEditable type="advanced">
        <RowActionsCell isEditable rowName={props.recordName} />
      </Td>
    </TBodyTr>
  );
};
InlineEditTr.displayName = 'InlineEditTr';
InlineEditTr.propTypes = {
  accountName: PropTypes.string.isRequired,
  amount: PropTypes.string.isRequired,
  closeDate: PropTypes.string.isRequired,
  confidence: PropTypes.string.isRequired,
  contact: PropTypes.string.isRequired,
  focusableCell: PropTypes.string,
  focusedCell: PropTypes.string,
  index: PropTypes.number.isRequired,
  isLocked: PropTypes.bool,
  recordName: PropTypes.string.isRequired,
  isSelected: PropTypes.bool,
  showCellError: IsDependentOn('showRowError', PropTypes.bool),
  showEdit: PropTypes.bool,
  showEditError: PropTypes.bool,
  showEditRequired: PropTypes.bool,
  showEditedCell: PropTypes.bool,
  showRowError: PropTypes.bool,
  stage: PropTypes.string.isRequired,
};