Skip to content

Commit

Permalink
replace queryProperty to field
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Apr 3, 2024
1 parent bddf765 commit 7184b82
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 40 deletions.
10 changes: 1 addition & 9 deletions src/Column/DataColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
*/
final class DataColumn implements ColumnInterface
{
public readonly ?QueryProperty $queryProperty;

/**
* @var bool|callable|null
* @psalm-var bool|FilterEmptyCallable|null
Expand All @@ -39,8 +37,7 @@ final class DataColumn implements ColumnInterface
*/
public function __construct(
public readonly ?string $property = null,
?string $queryProperty = null,
?string $queryField = null,
public readonly ?string $field = null,
public readonly ?string $header = null,
public readonly bool $encodeHeader = true,
public readonly ?string $footer = null,
Expand All @@ -56,11 +53,6 @@ public function __construct(
bool|callable|null $filterEmpty = null,
private readonly bool $visible = true,
) {
$queryProperty ??= $property;
$this->queryProperty = $queryProperty === null
? null
: new QueryProperty($queryProperty, $queryField ?? $queryProperty);

$this->filterEmpty = $filterEmpty;
}

Expand Down
27 changes: 15 additions & 12 deletions src/Column/DataColumnRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ public function renderHeader(ColumnInterface $column, Cell $cell, HeaderContext
}
$cell = $cell->content($label);

if (!$column->withSorting || $column->queryProperty === null) {
if (!$column->withSorting || $column->property === null) {
return $cell;
}

[$cell, $link, $prepend, $append] = $context->prepareSortable($cell, $column->queryProperty->property);
[$cell, $link, $prepend, $append] = $context->prepareSortable($cell, $column->property);
if ($link !== null) {
$link = $link->content($label)->encode(false);
}
Expand All @@ -88,7 +88,7 @@ public function renderFilter(ColumnInterface $column, Cell $cell, FilterContext
{
$this->checkColumn($column);

if ($column->queryProperty === null || $column->filter === false) {
if ($column->property === null || $column->filter === false) {
return null;
}

Expand All @@ -103,14 +103,14 @@ public function renderFilter(ColumnInterface $column, Cell $cell, FilterContext
$content = [
$widget->withContext(
new Context(
$column->queryProperty->property,
$context->getQueryValue($column->queryProperty->property),
$column->property,
$context->getQueryValue($column->property),

Check warning on line 107 in src/Column/DataColumnRenderer.php

View check run for this annotation

Codecov / codecov/patch

src/Column/DataColumnRenderer.php#L106-L107

Added lines #L106 - L107 were not covered by tests
$context->formId
)
),
];

$errors = $context->validationResult->getAttributeErrorMessages($column->queryProperty->property);
$errors = $context->validationResult->getAttributeErrorMessages($column->property);

Check warning on line 113 in src/Column/DataColumnRenderer.php

View check run for this annotation

Codecov / codecov/patch

src/Column/DataColumnRenderer.php#L113

Added line #L113 was not covered by tests
if (!empty($errors)) {
$cell = $cell->addClass($context->cellInvalidClass);
$content[] = Html::div(attributes: $context->errorsContainerAttributes)
Expand All @@ -123,11 +123,11 @@ public function renderFilter(ColumnInterface $column, Cell $cell, FilterContext
public function makeFilter(ColumnInterface $column, MakeFilterContext $context): ?FilterInterface
{
$this->checkColumn($column);
if ($column->queryProperty === null) {
if ($column->property === null) {
return null;
}

$value = $context->getQueryValue($column->queryProperty->property);
$value = $context->getQueryValue($column->property);
if ($value === null) {
return null;
}
Expand All @@ -144,7 +144,7 @@ public function makeFilter(ColumnInterface $column, MakeFilterContext $context):
$context->validationResult->addError(
$error->getMessage(),
$error->getParameters(),
[$column->queryProperty->property]
[$column->property]

Check warning on line 147 in src/Column/DataColumnRenderer.php

View check run for this annotation

Codecov / codecov/patch

src/Column/DataColumnRenderer.php#L147

Added line #L147 was not covered by tests
);
}
return null;
Expand All @@ -163,7 +163,7 @@ public function makeFilter(ColumnInterface $column, MakeFilterContext $context):
$factory = $column->filterFactory;
}

return $factory->create($column->queryProperty->field, $value);
return $factory->create($column->field ?? $column->property, $value);

Check warning on line 166 in src/Column/DataColumnRenderer.php

View check run for this annotation

Codecov / codecov/patch

src/Column/DataColumnRenderer.php#L166

Added line #L166 was not covered by tests
}

public function renderBody(ColumnInterface $column, Cell $cell, DataContext $context): Cell
Expand Down Expand Up @@ -249,10 +249,13 @@ public function getOverrideOrderFields(ColumnInterface $column): array
{
$this->checkColumn($column);

if ($column->queryProperty === null || $column->queryProperty->hasEqualField()) {
if ($column->property === null
|| $column->field === null
|| $column->property === $column->field
) {
return [];
}

return [$column->queryProperty->property => $column->queryProperty->field];
return [$column->property => $column->field];

Check warning on line 259 in src/Column/DataColumnRenderer.php

View check run for this annotation

Codecov / codecov/patch

src/Column/DataColumnRenderer.php#L259

Added line #L259 was not covered by tests
}
}
19 changes: 0 additions & 19 deletions src/Column/QueryProperty.php

This file was deleted.

0 comments on commit 7184b82

Please sign in to comment.