diff options
author | ljungster <parkerljung@gmail.com> | 2022-08-19 06:48:46 -0500 |
---|---|---|
committer | ljungster <parkerljung@gmail.com> | 2022-08-19 06:48:46 -0500 |
commit | 5655589d46c01af74c959c2d365d3eeb15feb407 (patch) | |
tree | a79952087f8d51023b8d5da1caa6103117cb2673 | |
parent | 6f7a94b0fa65729f03b49e8aecf9eb3c8a2461ff (diff) |
persistent resizing undo/redo issues
-rw-r--r-- | src/client/views/collections/CollectionNoteTakingView.tsx | 30 | ||||
-rw-r--r-- | src/client/views/collections/CollectionNoteTakingViewColumn.tsx | 6 |
2 files changed, 23 insertions, 13 deletions
diff --git a/src/client/views/collections/CollectionNoteTakingView.tsx b/src/client/views/collections/CollectionNoteTakingView.tsx index 0aa1b6839..447e1f0c8 100644 --- a/src/client/views/collections/CollectionNoteTakingView.tsx +++ b/src/client/views/collections/CollectionNoteTakingView.tsx @@ -368,18 +368,27 @@ export class CollectionNoteTakingView extends CollectionSubView<Partial<collecti return Math.min(childHeight, maxHeight, panelHeight); } - // called when a column is either added or deleted. This function creates n evenly spaced columns + // called when a column is either added or deleted. + // TODO: this needs help still @action - resizeColumns = (n: number, isAdd: boolean) => { + resizeColumns = (isAdd: boolean, colWidth: number, colIndex: number) => { + const n = this.columnHeaders.length; if (n == 1) { - this.columnHeaders[0].setWidth(1); - return; + this.columnHeaders[0].setWidth(1); + return true; } - let scaleFactor = isAdd ? (n - 1) / n : (n + 1) / n; - // if (isAdd && n == 1) scaleFactor = 1; - this.columnHeaders.forEach(h => { - h.width < 0 ? h.setWidth(1 / n) : h.setWidth(h.width * scaleFactor); + const scaleFactor = isAdd ? 1 - colWidth : 1 / (1 - colWidth); + this.columnHeaders.forEach((h, i) => { + if (!(isAdd && i == colIndex)) { + h.width < 0 ? h.setWidth(1 / n) : h.setWidth(h.width * scaleFactor); + } }); + return true; + // let scaleFactor = isAdd ? (n - 1) / n : (n + 1) / n; + // // if (isAdd && n == 1) scaleFactor = 1; + // this.columnHeaders.forEach(h => { + // h.width < 0 ? h.setWidth(1 / n) : h.setWidth(h.width * scaleFactor); + // }); // if we're adding, need to // const newColXCoords: number[] = []; @@ -638,9 +647,8 @@ export class CollectionNoteTakingView extends CollectionSubView<Partial<collecti @undoBatch addGroup = (value: string) => { const columnHeaders = Cast(this.props.Document.columnHeaders, listSpec(SchemaHeaderField), null); - // const colWidth = (this.PanelWidth - this.numGroupColumns * this.dividerWidth) / (this.numGroupColumns + 1); - this.resizeColumns(this.numGroupColumns + 1, true); - return value && columnHeaders?.push(new SchemaHeaderField(value, undefined, undefined, 1 / (this.numGroupColumns + 1))) ? true : false; + const newColWidth = 1 / (this.numGroupColumns + 1); + return value && columnHeaders?.push(new SchemaHeaderField(value, undefined, undefined, newColWidth)) && this.resizeColumns(true, newColWidth, this.columnHeaders.length - 1) ? true : false; }; sortFunc = (a: [SchemaHeaderField, Doc[]], b: [SchemaHeaderField, Doc[]]): 1 | -1 => { diff --git a/src/client/views/collections/CollectionNoteTakingViewColumn.tsx b/src/client/views/collections/CollectionNoteTakingViewColumn.tsx index 8ad684cec..11a0e69ac 100644 --- a/src/client/views/collections/CollectionNoteTakingViewColumn.tsx +++ b/src/client/views/collections/CollectionNoteTakingViewColumn.tsx @@ -51,7 +51,7 @@ interface CSVFieldColumnProps { unobserveHeight: (myref: any) => void; //setDraggedCol:(clonedDiv:any, header:SchemaHeaderField, xycoors: ) editableViewProps: () => any; - resizeColumns: (n: number, isAdd: boolean) => void; + resizeColumns: (isAdd: boolean, colWidth: number, colIndex: number) => boolean; // columnStartXCoords: number[]; PanelWidth: number; maxColWidth: number; @@ -165,8 +165,10 @@ export class CollectionNoteTakingViewColumn extends React.Component<CSVFieldColu if (columnHeaders && this.props.headingObject) { const index = columnHeaders.indexOf(this.props.headingObject); this.props.docList.forEach(d => (d[this.props.pivotField] = 'unset')); - this.props.resizeColumns(columnHeaders.length - 1, false) + // should never be 0, currently placeholder + const colWidth = this.props.columnHeaders ? this.props.columnHeaders[index].width : 0; columnHeaders.splice(index, 1); + this.props.resizeColumns(false, colWidth, index); } }; |