Skip to content

Commit

Permalink
Fix table column tooltip typecast (#2076)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Voříšek <[email protected]>
  • Loading branch information
mkrecek234 and mvorisek authored Jan 14, 2025
1 parent 235416b commit 5442ec1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Table/Column/Tooltip.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getDataCellHtml(?Field $field = null, array $attr = []): string
public function getHtmlTags(Model $row, ?Field $field): array
{
// @TODO remove popup tooltip when null
$tooltip = $row->get($this->tooltipField);
$tooltip = $this->getApp()->uiPersistence->typecastSaveField($row->getField($this->tooltipField), $row->get($this->tooltipField));

if ($tooltip === null || $tooltip === '') {
return [
Expand Down
16 changes: 9 additions & 7 deletions tests/Table/Column/LinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class LinkTest extends TestCase
use CreateAppTrait;
use TableTestTrait;

private const NBSP = "\u{00a0}";

/** @var Table */
protected $table;

Expand All @@ -26,14 +28,14 @@ protected function setUp(): void

$arr = [
'table' => [
1 => ['id' => 1, 'name' => 'bar', 'ref' => 'ref123', 'salary' => -123],
1 => ['id' => 1, 'name' => 'bar', 'ref' => 'ref123', 'salary' => -1234],
],
];
$db = new Persistence\Array_($arr);
$m = new Model($db, ['table' => 'table']);
$m->addField('name');
$m->addField('ref');
$m->addField('salary');
$m->addField('salary', ['type' => 'integer']);
$this->table = new Table();
$this->table->setApp($this->createApp());
$this->table->invokeInit();
Expand Down Expand Up @@ -72,7 +74,7 @@ public function testTdLast(): void
);

self::assertSame(
'<tr data-id="1"><td>bar</td><td>ref123</td><td class="right aligned single line negative">-123</td></tr>',
'<tr data-id="1"><td>bar</td><td>ref123</td><td class="right aligned single line negative">-1' . self::NBSP . '234</td></tr>',
$this->extractTableRow($this->table)
);
}
Expand All @@ -88,7 +90,7 @@ public function testTdNotLast(): void
);

self::assertSame(
'<tr data-id="1"><td>bar</td><td>ref123</td><td class="right aligned single line negative"><b>-123</b></td></tr>',
'<tr data-id="1"><td>bar</td><td>ref123</td><td class="right aligned single line negative"><b>-1' . self::NBSP . '234</b></td></tr>',
$this->extractTableRow($this->table)
);
}
Expand All @@ -105,7 +107,7 @@ public function testTwoMoneys(): void
);

self::assertSame(
'<tr data-id="1"><td class="right aligned single line ">bar</td><td>ref123</td><td class="right aligned single line negative"><b>-123</b></td></tr>',
'<tr data-id="1"><td class="right aligned single line ">bar</td><td>ref123</td><td class="right aligned single line negative"><b>-1' . self::NBSP . '234</b></td></tr>',
$this->extractTableRow($this->table)
);
}
Expand Down Expand Up @@ -278,10 +280,10 @@ public function testNoValue(): void

public function testTooltip(): void
{
$this->table->addDecorator('name', [Table\Column\Tooltip::class, ['tooltipField' => 'ref']]);
$this->table->addDecorator('name', [Table\Column\Tooltip::class, ['tooltipField' => 'salary']]);

self::assertSame(
'<tr data-id="1"><td class=""> bar<span class="ui icon link " data-tooltip="ref123"><i class="ui icon info circle"></span></td><td>ref123</td></tr>',
'<tr data-id="1"><td class=""> bar<span class="ui icon link " data-tooltip="-1' . self::NBSP . '234"><i class="ui icon info circle"></span></td><td>ref123</td></tr>',
$this->extractTableRow($this->table)
);
}
Expand Down

0 comments on commit 5442ec1

Please sign in to comment.