Skip to content

Commit

Permalink
Added ability to delete rows and columns
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep committed May 24, 2024
1 parent e6a6648 commit 59c0da7
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,9 @@ extension CommandsExampleViewController: TableViewDelegate {
handler: { (_) in
tableView.insertColumn(at: cell.columnSpan.min()!, configuration: GridColumnConfiguration(width: .fixed(100)))
}),
// UIAction(title: "Delete Column", image: UIImage(systemName: "trash"), attributes: columnCount > 1 ? .destructive : .disabled, handler: { (_) in
// gridView.deleteColumn(at: cell.columnSpan.max()!)
// }),
UIAction(title: "Delete Column", image: UIImage(systemName: "trash"), attributes: columnCount > 1 ? .destructive : .disabled, handler: { (_) in
tableView.deleteColumn(at: cell.columnSpan.max()!)
}),
// UIAction(title: "Freeze Columns", image: UIImage(systemName: "arrow.up"), handler: { (_) in
// gridView.freezeColumns(upTo: cell.columnSpan.max()!)
// }),
Expand Down
2 changes: 1 addition & 1 deletion ExampleApp/ExampleApp/Commands/TableViewCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class TableViewCommand: EditorCommand {
text.append(NSAttributedString(string: "Text before Grid"))
timeEvent(label: "Create")
for i in 1..<2 {
text.append(makeGridViewAttachment(id: i, numRows: 200, numColumns: 10).string)
text.append(makeGridViewAttachment(id: i, numRows: 10, numColumns: 10).string)
// text.append(makePanelAttachment(id: i).string)
text.append(NSAttributedString(string: "\ntest middle\n"))
}
Expand Down
3 changes: 1 addition & 2 deletions Proton/Sources/Swift/Table/Core/TableCellStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ class TableCellStore {
}

func deleteCells(_ cellsToDelete: [TableCell]) {
//TODO: fix
// cells = cells.filter({ !cellsToDelete.contains($0) })
cells = cells.filter({ !cellsToDelete.contains($0) })
}

func moveCellRowIndex(from index: Int, by step: Int) {
Expand Down
78 changes: 78 additions & 0 deletions Proton/Tests/Table/TableViewAttachmentSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,45 @@ class TableViewAttachmentSnapshotTests: SnapshotTestCase {
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
}

func testDeletesRow() throws {
let config = GridConfiguration(
columnsConfiguration: [
GridColumnConfiguration(width: .fixed(50)),
GridColumnConfiguration(width: .fixed(50)),
GridColumnConfiguration(width: .fixed(50)),
],
rowsConfiguration: [
GridRowConfiguration(initialHeight: 40),
GridRowConfiguration(initialHeight: 40),
GridRowConfiguration(initialHeight: 40),
],
ignoresOptimizedInit: true
)
let attachment = TableViewAttachment(config: config)
let table = attachment.view
attachment.view.delegate = delegate

editor.replaceCharacters(in: .zero, with: "Some text in editor")
editor.insertAttachment(in: editor.textEndRange, attachment: attachment)
editor.replaceCharacters(in: editor.textEndRange, with: "Text after grid")

let cell00 = try XCTUnwrap(table.cellAt(rowIndex: 0, columnIndex: 0))
let cell10 = try XCTUnwrap(table.cellAt(rowIndex: 1, columnIndex: 0))
let cell20 = try XCTUnwrap(table.cellAt(rowIndex: 2, columnIndex: 0))

cell00.attributedText = NSAttributedString(string: "R1")
cell10.attributedText = NSAttributedString(string: "R2")
cell20.attributedText = NSAttributedString(string: "R3")

viewController.render(size: CGSize(width: 201, height: 300))
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)

table.deleteRow(at: 1)

viewController.render(size: CGSize(width: 201, height: 300))
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
}

func testInsertsColumnInMiddle() throws {
let config = GridConfiguration(
columnsConfiguration: [
Expand Down Expand Up @@ -1246,6 +1285,45 @@ class TableViewAttachmentSnapshotTests: SnapshotTestCase {
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)
}

func testDeletesColumn() throws {
recordMode = true
let config = GridConfiguration(
columnsConfiguration: [
GridColumnConfiguration(width: .fixed(30)),
GridColumnConfiguration(width: .fractional(0.35)),
GridColumnConfiguration(width: .fractional(0.35)),
],
rowsConfiguration: [
GridRowConfiguration(initialHeight: 40),
GridRowConfiguration(initialHeight: 40),
],
ignoresOptimizedInit: true
)
let attachment = TableViewAttachment(config: config)
let table = attachment.view
attachment.view.delegate = delegate

editor.replaceCharacters(in: .zero, with: "Some text in editor")
editor.insertAttachment(in: editor.textEndRange, attachment: attachment)
editor.replaceCharacters(in: editor.textEndRange, with: "Text after grid")

let gridView = attachment.view

let cell11 = try XCTUnwrap(table.cellAt(rowIndex: 1, columnIndex: 1))
let cell12 = try XCTUnwrap(table.cellAt(rowIndex: 1, columnIndex: 2))

cell11.attributedText = NSAttributedString(string: "C1")
cell12.attributedText = NSAttributedString(string: "C2")

viewController.render(size: CGSize(width: 200, height: 300))
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)

Check failure on line 1319 in Proton/Tests/Table/TableViewAttachmentSnapshotTests.swift

View workflow job for this annotation

GitHub Actions / Xcode test results

Assertion Failure

failed - Record mode is on. Turn record mode off and re-run "testDeletesColumn" to test against the newly-recorded snapshot. open "/Users/runner/work/proton/proton/Proton/Tests/Table/__Snapshots__/TableViewAttachmentSnapshotTests/testDeletesColumn.1.png" Recorded snapshot: …

table.deleteColumn(at: 1)

viewController.render(size: CGSize(width: 200, height: 300))
assertSnapshot(matching: viewController.view, as: .image, record: recordMode)

Check failure on line 1324 in Proton/Tests/Table/TableViewAttachmentSnapshotTests.swift

View workflow job for this annotation

GitHub Actions / Xcode test results

Assertion Failure

failed - Record mode is on. Turn record mode off and re-run "testDeletesColumn" to test against the newly-recorded snapshot. open "/Users/runner/work/proton/proton/Proton/Tests/Table/__Snapshots__/TableViewAttachmentSnapshotTests/testDeletesColumn.2.png" Recorded snapshot: …
}


private func makeTableViewAttachment(config: GridConfiguration, cells: [TableCell] = []) -> TableViewAttachment {
let attachment: TableViewAttachment
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 59c0da7

Please sign in to comment.