diff options
author | ljungster <parkerljung@gmail.com> | 2022-04-07 16:27:38 -0400 |
---|---|---|
committer | ljungster <parkerljung@gmail.com> | 2022-04-07 16:27:38 -0400 |
commit | 5476f6160a357fe697314e6171ff560260c1d301 (patch) | |
tree | 08ba3f28a6141c0f1817cfef2c320e4efd99db61 /src | |
parent | e40ca22ef314cb34a8a48b1ff815bc50e9cb363a (diff) |
Fixed column bug
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); } } |