-
Notifications
You must be signed in to change notification settings - Fork 4
IBX-12039: Added table component extension api #29
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
Open
ciastektk
wants to merge
8
commits into
5.0
Choose a base branch
from
ibx-12039-table-component-extension-api
base: 5.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ed7b405
Extended ibexa.Table with identity props, headline, table class and cβ¦
ciastektk 37f55ab
[Tests] Added coverage for table extensions and form widget cell rendβ¦
ciastektk f54a10a
Changed table full data to explicit nullable and simplified class prop
ciastektk 00af091
[Tests] Adjusted table coverage to nullable full data and exposed tesβ¦
ciastektk 436364c
Improved table component output whitespace
ciastektk cb0b724
[Tests] Refactored table component test scaffolding
ciastektk 58ee183
Reused Column options phpstan type as single source of truth in Table
ciastektk 031ed76
Fixed trailing whitespace in table cell class attributes
ciastektk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 42 additions & 25 deletions
67
src/bundle/Resources/views/themes/admin/twig_components/table.html.twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,47 +1,64 @@ | ||
| {% trans_default_domain 'ibexa_admin_ui' %} | ||
|
|
||
| {%~ block header %} | ||
| {%~ if headline is not null %} | ||
| <div class="ibexa-table-header"> | ||
| <div class="ibexa-table-header__headline">{{ headline }}</div> | ||
| {%~ block header_actions %}{% endblock %} | ||
| </div> | ||
| {%~ endif %} | ||
| {%~ endblock %} | ||
| <div class="ibexa-scrollable-wrapper"> | ||
| <table class="ibexa-table table ibexa-table--last-column-sticky"> | ||
| {%~ block before_table %}{% endblock %} | ||
| <table class="{{ table_class }}"> | ||
| <thead> | ||
| <tr class="ibexa-table__row ibexa-table__row--header"> | ||
| {% for column in columns %} | ||
| <th class="ibexa-table__header-cell {{ loop.last ? 'ibexa-table__header-cell--no-min-width' }}"> | ||
| {%~ for column in columns %} | ||
| <th class="{{ [ | ||
| 'ibexa-table__header-cell', | ||
| loop.last ? 'ibexa-table__header-cell--no-min-width', | ||
| column.options.header_class ?? '', | ||
| ]|filter(class => class)|join(' ') }}"> | ||
| <span class="ibexa-table__header-cell-content"> | ||
| {{ this.renderLabel(column)|raw }} | ||
| </span> | ||
| </th> | ||
| {% endfor %} | ||
| {%~ endfor %} | ||
| </tr> | ||
| </thead> | ||
| <tbody class="ibexa-table__body"> | ||
| {% for item in data %} | ||
| {%~ for item in data %} | ||
| <tr class="ibexa-table__row"> | ||
| {% for column in columns %} | ||
| <td class="ibexa-table__cell {{ loop.last ? 'ibexa-table__cell--has-action-btns' }}"> | ||
| {%~ for column in columns %} | ||
| <td class="{{ [ | ||
| 'ibexa-table__cell', | ||
| loop.last ? 'ibexa-table__cell--has-action-btns', | ||
| column.options.cell_class ?? '', | ||
| ]|filter(class => class)|join(' ') }}"> | ||
| {{ this.renderCell(column, item)|raw }} | ||
| </td> | ||
| {% endfor %} | ||
| {%~ endfor %} | ||
| </tr> | ||
| {% else %} | ||
| {% block empty_state_row %} | ||
| {%~ else %} | ||
| {%~ block empty_state_row %} | ||
| <tr class="ibexa-table__row"> | ||
| <td class="ibexa-table__empty-table-cell"> | ||
| {% block empty_state_content %} | ||
| {% block empty_state_image %} | ||
| <img class="ibexa-table__empty_table-image" src="{{ asset('/bundles/ibexaadminui/img/ibexa-empty-table.svg') }}" alt=""> | ||
| {% endblock empty_state_image %} | ||
| {% block empty_state_text %} | ||
| <div class="ibexa-table__empty-table-text"> | ||
| {% block empty_state_title %}{% endblock empty_state_title %} | ||
| {% block empty_state_description %}{% endblock empty_state_description %} | ||
| {% block empty_state_extra_actions %}{% endblock empty_state_extra_actions %} | ||
| </div> | ||
| {% endblock empty_state_text %} | ||
| {% endblock empty_state_content %} | ||
| {%~ block empty_state_content %} | ||
| {%~ block empty_state_image %} | ||
| <img class="ibexa-table__empty_table-image" src="{{ asset('/bundles/ibexaadminui/img/ibexa-empty-table.svg') }}" alt=""> | ||
| {%~ endblock empty_state_image %} | ||
| {%~ block empty_state_text %} | ||
| <div class="ibexa-table__empty-table-text"> | ||
| {%~ block empty_state_title %}{% endblock empty_state_title %} | ||
| {%~ block empty_state_description %}{% endblock empty_state_description %} | ||
| {%~ block empty_state_extra_actions %}{% endblock empty_state_extra_actions %} | ||
| </div> | ||
| {%~ endblock empty_state_text %} | ||
| {%~ endblock empty_state_content %} | ||
| </td> | ||
| </tr> | ||
| {% endblock empty_state_row %} | ||
| {% endfor %} | ||
| {%~ endblock empty_state_row %} | ||
| {%~ endfor %} | ||
| </tbody> | ||
| </table> | ||
| {%~ block after_table %}{% endblock %} | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Tests\Bundle\TwigComponents\Templating\Twig\Components; | ||
|
|
||
| use Ibexa\Bundle\TwigComponents\Templating\Twig\Components\Table; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| final class TableTest extends TestCase | ||
| { | ||
| /** | ||
| * @dataProvider provideTableClass | ||
| */ | ||
| public function testTableClassAppliesModifierToBaseClasses( | ||
| ?string $classProp, | ||
| string $expectedTableClass | ||
| ): void { | ||
| $table = new Table(); | ||
| if ($classProp !== null) { | ||
| $table->class = $classProp; | ||
| } | ||
|
|
||
| self::assertSame($expectedTableClass, $table->getTableClass()); | ||
| } | ||
|
|
||
| /** | ||
| * @return iterable<string, array{?string, string}> | ||
| */ | ||
| public static function provideTableClass(): iterable | ||
| { | ||
| yield 'default modifier' => [ | ||
| null, | ||
| 'ibexa-table table ibexa-table--last-column-sticky', | ||
| ]; | ||
|
|
||
| yield 'custom modifier replaces the default' => [ | ||
| 'ibexa-table--draft-conflict mb-3', | ||
| 'ibexa-table table ibexa-table--draft-conflict mb-3', | ||
| ]; | ||
|
|
||
| yield 'empty string clears the modifier' => [ | ||
| '', | ||
| 'ibexa-table table', | ||
| ]; | ||
| } | ||
|
|
||
| public function testFullDataIsNullWhenMountSiteDoesNotProvideIt(): void | ||
| { | ||
| $table = new Table(); | ||
| $table->mount([new \stdClass()]); | ||
|
|
||
| self::assertNull($table->getFullData()); | ||
| } | ||
|
|
||
| public function testFullDataIsExposedIndependentlyOfRenderedData(): void | ||
| { | ||
| $renderedPage = [new \stdClass()]; | ||
| $wholeDataset = [...$renderedPage, new \stdClass(), new \stdClass()]; | ||
|
|
||
| $table = new Table(); | ||
| $table->mount($renderedPage, $wholeDataset); | ||
|
|
||
| self::assertSame($renderedPage, $table->getData()); | ||
| self::assertSame($wholeDataset, $table->getFullData()); | ||
| } | ||
|
|
||
| public function testIdentityPropsDefaultToNull(): void | ||
| { | ||
| $table = new Table(); | ||
|
|
||
| self::assertNull($table->type); | ||
| self::assertNull($table->variant); | ||
| self::assertNull($table->headline); | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider provideColumnOptions | ||
| * | ||
| * @param array{header_class?: string, cell_class?: string}|null $options null = argument omitted | ||
| * @param array{header_class?: string, cell_class?: string} $expectedOptions | ||
| */ | ||
| public function testAddColumnCarriesOptionsToColumn(?array $options, array $expectedOptions): void | ||
| { | ||
| $table = new Table(); | ||
| if ($options === null) { | ||
| $table->addColumn( | ||
| 'checkbox', | ||
| static fn (): string => 'Label', | ||
| static fn (): string => 'Cell' | ||
| ); | ||
| } else { | ||
| $table->addColumn( | ||
| 'checkbox', | ||
| static fn (): string => 'Label', | ||
| static fn (): string => 'Cell', | ||
| 110, | ||
| $options | ||
| ); | ||
| } | ||
|
|
||
| self::assertSame($expectedOptions, $table->getColumns()['checkbox']->options); | ||
| } | ||
|
|
||
| /** | ||
| * @return iterable<string, array{?array{header_class?: string, cell_class?: string}, array{header_class?: string, cell_class?: string}}> | ||
| */ | ||
| public static function provideColumnOptions(): iterable | ||
| { | ||
| yield 'passed options land on the column' => [ | ||
| ['header_class' => 'custom-header', 'cell_class' => 'custom-cell'], | ||
| ['header_class' => 'custom-header', 'cell_class' => 'custom-cell'], | ||
| ]; | ||
|
|
||
| yield 'omitted options default to an empty set' => [ | ||
| null, | ||
| [], | ||
| ]; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.