Skip to content
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

[Console] Handle zero row count in appendRow() for Table #35676

Merged
merged 1 commit into from Feb 13, 2020
Merged

[Console] Handle zero row count in appendRow() for Table #35676

merged 1 commit into from Feb 13, 2020

Conversation

adam-prickett
Copy link

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets n/a
License MIT
Doc PR n/a

When a Table is created and rendered with no rows (headers only) and subsequently rows are added using appendRow(), the first call to appendRow() clears back one line too far., thus removing the last run

This is caused by calculateRowCount() not accounting for the fact that the footer separator is also the header separator when no rows are present.

This PR works around the issue by checking to ensure that at least 1 row exists before including the footer separator in the row count.

Example

Command:

<?php

namespace App\Command;

class TableTestCommand extends Command
{
    // ...

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('My table');

        $table = new Table($output->section());
        $table->setHeaders(['Column', 'Another column']);
        $table->render();
        
        $table->appendRow(['Value', 'Another Value']);
        $table->appendRow(['Value', 'Another Value']);
    }
}

Before fix:

+--------+----------------+
| Column | Another column |
+--------+----------------+
| Value  | Another Value  |
| Value  | Another Value  |
+--------+----------------+

After fix:

My table
+--------+----------------+
| Column | Another column |
+--------+----------------+
| Value  | Another Value  |
| Value  | Another Value  |
+--------+----------------+

@nicolas-grekas nicolas-grekas added this to the 4.4 milestone Feb 11, 2020
@nicolas-grekas nicolas-grekas changed the title Handle zero row count in appendRow() for Table [Console] Handle zero row count in appendRow() for Table Feb 11, 2020
@nicolas-grekas
Copy link
Member

Thanks for the PR.
Does this issue exist on 3.4?
Please add a test case also.

@adam-prickett
Copy link
Author

@nicolas-grekas Furthest back this issue goes is to 4.1. Test case incoming.

@fabpot
Copy link
Member

fabpot commented Feb 13, 2020

Thank you @adam-prickett.

fabpot added a commit that referenced this pull request Feb 13, 2020
…Adam Prickett)

This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[Console] Handle zero row count in appendRow() for Table

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | n/a
| License       | MIT
| Doc PR        | n/a

When a `Table` is created and rendered with no rows (headers only) and subsequently rows are added using `appendRow()`, the first call to `appendRow()` clears back one line too far., thus removing the last run

This is caused by `calculateRowCount()` not accounting for the fact that the footer separator is also the header separator when no rows are present.

This PR works around the issue by checking to ensure that at least 1 row exists before including the footer separator in the row count.

## Example

Command:
```php
<?php

namespace App\Command;

class TableTestCommand extends Command
{
    // ...

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('My table');

        $table = new Table($output->section());
        $table->setHeaders(['Column', 'Another column']);
        $table->render();

        $table->appendRow(['Value', 'Another Value']);
        $table->appendRow(['Value', 'Another Value']);
    }
}
```

Before fix:
```
+--------+----------------+
| Column | Another column |
+--------+----------------+
| Value  | Another Value  |
| Value  | Another Value  |
+--------+----------------+
```

After fix:
```
My table
+--------+----------------+
| Column | Another column |
+--------+----------------+
| Value  | Another Value  |
| Value  | Another Value  |
+--------+----------------+
```

Commits
-------

9b38259 [Console] Handle zero row count in appendRow() for Table
@fabpot fabpot merged commit 9b38259 into symfony:4.4 Feb 13, 2020
This was referenced Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants