( ctx context.Context, svc *docs.Service, docID, tabID, expectedRevisionID string, tableIndex, rowIndex int, values []string, )
| 500 | } |
| 501 | |
| 502 | func populateDocsTableRow( |
| 503 | ctx context.Context, |
| 504 | svc *docs.Service, |
| 505 | docID, tabID, expectedRevisionID string, |
| 506 | tableIndex, rowIndex int, |
| 507 | values []string, |
| 508 | ) error { |
| 509 | loaded, err := loadDocsTargetDocument(ctx, svc, docID, tabID) |
| 510 | if err != nil { |
| 511 | return fmt.Errorf("reload inserted table row: %w", err) |
| 512 | } |
| 513 | if loaded.full.RevisionId != expectedRevisionID { |
| 514 | return fmt.Errorf( |
| 515 | "populate inserted table row: document revision changed after row insertion (expected %s, got %s)", |
| 516 | expectedRevisionID, loaded.full.RevisionId, |
| 517 | ) |
| 518 | } |
| 519 | target, _, err := resolveDocsTableWithIndex(loaded.target, tableIndex) |
| 520 | if err != nil { |
| 521 | return err |
| 522 | } |
| 523 | if rowIndex < 1 || rowIndex > len(target.table.TableRows) { |
| 524 | return fmt.Errorf("inserted row %d not found after mutation", rowIndex) |
| 525 | } |
| 526 | row := target.table.TableRows[rowIndex-1] |
| 527 | if len(values) != len(row.TableCells) { |
| 528 | return fmt.Errorf("inserted row has %d cells, want %d", len(row.TableCells), len(values)) |
| 529 | } |
| 530 | requests := make([]*docs.Request, 0, len(values)) |
| 531 | for col := len(values) - 1; col >= 0; col-- { |
| 532 | if values[col] == "" { |
| 533 | continue |
| 534 | } |
| 535 | cell := row.TableCells[col] |
| 536 | if len(cell.Content) == 0 { |
| 537 | return fmt.Errorf("inserted row cell %d has no content location", col+1) |
| 538 | } |
| 539 | requests = append(requests, &docs.Request{InsertText: &docs.InsertTextRequest{ |
| 540 | Location: &docs.Location{Index: cell.Content[0].StartIndex, TabId: tabID}, |
| 541 | Text: values[col], |
| 542 | }}) |
| 543 | } |
| 544 | if len(requests) == 0 { |
| 545 | return nil |
| 546 | } |
| 547 | if _, err := executeDocsTableRequests(ctx, svc, docID, loaded.full.RevisionId, requests); err != nil { |
| 548 | return fmt.Errorf("populate inserted table row: %w", err) |
| 549 | } |
| 550 | return nil |
| 551 | } |
| 552 | |
| 553 | func writeDocsTableMutationResult( |
| 554 | ctx context.Context, |
no test coverage detected