Repository navigation
Clear sheet before removing #1160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ff28485
d106b6f
3cc726f
6c322c7
1fa0236
754109b
6287f76
03657c7
2061dd3
f24726b
bdf3b58
0499db9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -291,28 +291,16 @@ export class DependencyGraph { | |
| } | ||
|
|
||
| public removeSheet(removedSheetId: number) { | ||
| const arrays: Set<ArrayVertex> = new Set() | ||
| this.clearSheet(removedSheetId) | ||
|
|
||
| for (const [adr, vertex] of this.addressMapping.sheetEntries(removedSheetId)) { | ||
| if (vertex instanceof ArrayVertex) { | ||
| if (arrays.has(vertex)) { | ||
| continue | ||
| } else { | ||
| arrays.add(vertex) | ||
| } | ||
| } | ||
| for (const adjacentNode of this.graph.adjacentNodes(vertex)) { | ||
| this.graph.markNodeAsSpecialRecentlyChanged(adjacentNode) | ||
| } | ||
| this.removeVertex(vertex) | ||
| this.addressMapping.removeCell(adr) | ||
| } | ||
|
|
||
| this.stats.measure(StatType.ADJUSTING_ARRAY_MAPPING, () => { | ||
| for (const array of arrays.values()) { | ||
| this.arrayMapping.removeArray(array.getRange()) | ||
| } | ||
| }) | ||
|
|
||
|
Comment on lines
-310
to
-315
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is no longer necessary because |
||
| this.stats.measure(StatType.ADJUSTING_RANGES, () => { | ||
| const rangesToRemove = this.rangeMapping.removeRangesInSheet(removedSheetId) | ||
| for (const range of rangesToRemove) { | ||
|
|
@@ -323,8 +311,6 @@ export class DependencyGraph { | |
| this.addressMapping.removeSheet(removedSheetId) | ||
| }) | ||
| }) | ||
|
|
||
| this.addStructuralNodesToChangeSet() | ||
| } | ||
|
|
||
| public clearSheet(sheetId: number) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,6 +109,38 @@ describe('remove sheet', () => { | |
| expect(engine.sheetMapping.numberOfSheets()).toBe(0) | ||
| expect(Array.from(engine.addressMapping.entries())).toEqual([]) | ||
| }) | ||
|
|
||
| it('should remove a sheet with a cell reference to a value in the same sheet', () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it could be a good idea to check if by removing one sheet, we're not affecting values in another sheet which is referenced. This does not have to be a scope of this PR, but maybe it's worth checking if it makes sense: it('should not remove data from cell referenced in another sheet', () => {
const engine = HyperFormula.buildFromSheets({
Sheet1: [
['=Sheet2!A1)'],
],
Sheet2: [
['1'],
],
})
engine.removeSheet(0)
expect(Array.from(engine.sheetMapping.displayNames())).toEqual(['Sheet2'])
expect(engine.getCellValue(adr('A1', 1))).toBe(1)
})
it('should not remove data from cell range referenced in another sheet', () => {
const engine = HyperFormula.buildFromSheets({
Sheet1: [
['=SUM(Sheet2!A1:A2)'],
],
Sheet2: [
['1'],
['5'],
],
})
engine.removeSheet(0)
expect(Array.from(engine.sheetMapping.displayNames())).toEqual(['Sheet2'])
expect(engine.getCellValue(adr('A1', 1))).toBe(1)
expect(engine.getCellValue(adr('A2', 1))).toBe(5)
})Let me know what you think.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, these test cases are absolutely valid. I added an |
||
| const engine = HyperFormula.buildFromArray([ | ||
| [1, '=A1'], | ||
| ]) | ||
|
|
||
| engine.removeSheet(0) | ||
|
|
||
| expect(engine.sheetMapping.numberOfSheets()).toBe(0) | ||
| expect(Array.from(engine.addressMapping.entries())).toEqual([]) | ||
| }) | ||
|
|
||
| it('should not affect data in the sheets that were referenced by the sheet being removed', () => { | ||
| const engine = HyperFormula.buildFromSheets({ | ||
| Sheet1: [ | ||
| ['=Sheet2!A1)'], | ||
| ['=SUM(Sheet2!A1:A2)'], | ||
| ], | ||
| Sheet2: [ | ||
| [1], | ||
| [2], | ||
| [3], | ||
| ], | ||
| }) | ||
|
|
||
| engine.removeSheet(0) | ||
|
|
||
| expect(Array.from(engine.sheetMapping.displayNames())).toEqual(['Sheet2']) | ||
| expect(engine.getCellValue(adr('A1', 1))).toBe(1) | ||
| expect(engine.getCellValue(adr('A2', 1))).toBe(2) | ||
| expect(engine.getCellValue(adr('A3', 1))).toBe(3) | ||
| }) | ||
| }) | ||
|
|
||
| describe('remove sheet - adjust edges', () => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.