diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/collections/CollectionNoteTakingViewFieldColumn.tsx | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/client/views/collections/CollectionNoteTakingViewFieldColumn.tsx b/src/client/views/collections/CollectionNoteTakingViewFieldColumn.tsx index 4344f08c4..6d95eeb0c 100644 --- a/src/client/views/collections/CollectionNoteTakingViewFieldColumn.tsx +++ b/src/client/views/collections/CollectionNoteTakingViewFieldColumn.tsx @@ -136,16 +136,20 @@ export class CollectionNoteTakingViewFieldColumn extends React.Component<CSVFiel @action deleteColumn = () => { - if (this.props.columnHeaders && this.props.headingObject) { - const index = this.props.columnHeaders.indexOf(this.props.headingObject); - if (index > 0) { - const newHeader = this.props.columnHeaders[index - 1]; - this.props.docList.forEach(d => d[this.props.pivotField] = newHeader.heading.toString()) - } else { - // 1 exists because that ensures that we have at least one column (and not the buggy 0 one) - this.props.docList.forEach(d => d[this.props.pivotField] = "1"); - } - this.props.columnHeaders.splice(index, 1); + if (!this.props.columnHeaders) { + return + } + if (this.props.columnHeaders.length == 1) { + // (1) length is 1, alert user can't delete + alert("You can't delete the last column! Going to remove delete button soon") + return + } + if (this.props.headingObject) { + const index = this.props.columnHeaders.indexOf(this.props.headingObject); + const newIndex = index == 0 ? 1 : index - 1 + const newHeader = this.props.columnHeaders[newIndex]; + this.props.docList.forEach(d => d[this.props.pivotField] = newHeader.heading.toString()) + this.props.columnHeaders.splice(index, 1); } } |