Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `laravel-livewire-tables` will be documented in this file

## PREVIEW
### Tweaks
- Tidying PHPDocs by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/2246

## [v3.7.1] - 2025-02-28
### Bug Fixes
- Ensure that LinkColumn is included in query if "from" is defined
Expand Down
7 changes: 3 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ parameters:
- src/Traits/Helpers/QueryHelpers.php
- src/Views/Columns/Traits/HasSlot.php
- src/Views/Columns/Traits/Helpers/ArrayColumnHelpers.php
- identifier: instanceof.alwaysTrue
paths:
- src/Views/Columns/Traits/HasFooter.php
- src/Views/Columns/Traits/HasSecondaryHeader.php
- identifier: function.alreadyNarrowedType
paths:
- src/Views/Columns/Traits/Helpers/ArrayColumnHelpers.php
Expand All @@ -41,3 +37,6 @@ parameters:
- src/Views/Filters/Traits/HasOptions.php
- src/Views/Traits/Core/HasTheme.php
- src/Views/Traits/Core/HasView.php
- identifier: unset.possiblyHookedProperty
paths:
- src/Traits/Configuration/CollapsingColumnConfiguration.php
12 changes: 6 additions & 6 deletions src/DataTransferObjects/DebuggableData.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

class DebuggableData
{
public DataTableComponent $component;

public function __construct(DataTableComponent $component)
{
$this->component = $component;
}
public function __construct(public DataTableComponent $component) {}

/**
* Returns data to an array
*
* @return array<mixed>
*/
public function toArray(): array
{
return [
Expand Down
24 changes: 6 additions & 18 deletions src/DataTransferObjects/FilterGenericData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,13 @@

class FilterGenericData
{
public string $tableName;

public string $filterLayout;

public bool $isTailwind = false;

public bool $isBootstrap4 = false;

public bool $isBootstrap5 = false;

public function __construct(string $tableName, string $filterLayout, bool $isTailwind = false, bool $isBootstrap4 = false, bool $isBootstrap5 = false)
{
$this->tableName = $tableName;
$this->filterLayout = $filterLayout;
$this->isTailwind = $isTailwind;
$this->isBootstrap4 = $isBootstrap4;
$this->isBootstrap5 = $isBootstrap5;
}
public function __construct(public string $tableName, public string $filterLayout, public bool $isTailwind = false, public bool $isBootstrap4 = false, public bool $isBootstrap5 = false) {}

/**
* Convert To Array
*
* @return array<mixed>
*/
public function toArray(): array
{
return [
Expand Down
111 changes: 103 additions & 8 deletions src/DataTransferObjects/Filters/FilterPillData.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,61 +31,109 @@ public static function make(string $filterKey, string $filterPillTitle, string|a
return new self($filterKey, $filterPillTitle, $filterPillValue, $separator, $isAnExternalLivewireFilter, $hasCustomPillBlade, $customPillBlade, $filterPillsItemAttributes, $renderPillsAsHtml, $watchForEvents, $customResetButtonAttributes, $renderPillsTitleAsHtml);
}

/**
* Get the Filter Key
*/
public function getFilterKey(): string
{
return $this->filterKey;
}

/**
* Get the title for the Filter Pill
*/
public function getTitle(): string
{
return $this->filterPillTitle;
}

/**
* Get The Filter Pill Value
*
* @return array<mixed>|string|null
*/
public function getPillValue(): array|string|null
{
return $this->filterPillValue;
}

/**
* Determing if there is a Custom Pill blade set
*/
public function getHasCustomPillBlade(): bool
{
return $this->hasCustomPillBlade ?? false;
return $this->hasCustomPillBlade;
}

/**
* Get The Custom Pill Blade (if set)
*/
public function getCustomPillBlade(): ?string
{
return $this->customPillBlade;
}

/**
* Get Custom Reset Button Attributes
*
* @return array<mixed>
*/
public function getCustomResetButtonAttributes(): array
{
return $this->customResetButtonAttributes ?? [];
return $this->customResetButtonAttributes;
}

/**
* Determine of this is an External Livewire Filter
*/
public function getIsAnExternalLivewireFilter(): int
{
return intval($this->isAnExternalLivewireFilter ?? 0);
return intval($this->isAnExternalLivewireFilter);
}

/**
* Get the Separator for Pill Values
*/
public function getSeparator(): string
{
return $this->separator ?? ', ';
return $this->separator;
}

/**
* Determine if Pills should render as HTML
*/
public function shouldUsePillsAsHtml(): int
{
return intval($this->renderPillsAsHtml ?? 0);
return intval($this->renderPillsAsHtml);
}

/**
* Determine if Pill Title should render as HTML
*/
public function shouldUsePillsTitleAsHtml(): int
{
return intval($this->renderPillsTitleAsHtml ?? 0);
return intval($this->renderPillsTitleAsHtml);
}

/**
* Determine if Should watch for Events (i.e. is an External Filter)
*/
public function shouldWatchForEvents(): int
{
return intval($this->watchForEvents ?? 0);
return intval($this->watchForEvents);
}

/**
* Determine if Pill Value is an Array
*/
public function isPillValueAnArray(): bool
{
return ! is_null($this->filterPillValue) && is_array($this->filterPillValue);
}

/**
* Return the separator separated value for the pill
*/
public function getSeparatedPillValue(): ?string
{
if ($this->isPillValueAnArray()) {
Expand All @@ -95,6 +143,9 @@ public function getSeparatedPillValue(): ?string
}
}

/**
* Return the safe, separator separated value for the pill
*/
public function getSafeSeparatedPillValue(): ?string
{
$string = $this->getSeparatedPillValue();
Expand All @@ -103,11 +154,21 @@ public function getSafeSeparatedPillValue(): ?string

}

/**
* Get the attributes for the Filter Pills Item
*
* @return array<mixed>
*/
public function getFilterPillsItemAttributes(): array
{
return array_merge(['default' => true, 'default-colors' => true, 'default-styling' => true, 'default-text' => true], $this->filterPillsItemAttributes);
}

/**
* Get the Display Data for the Filter Pills
*
* @return array<mixed>
*/
public function getFilterPillDisplayDataArray(): array
{
$array = [];
Expand All @@ -118,13 +179,25 @@ public function getFilterPillDisplayDataArray(): array
return $this->getInternalFilterPillDisplayDataArray($array);
}

/**
* Get the Display Data for the Filter Pills
*
* @param array<mixed> $array
* @return array<mixed>
*/
public function getExternalFilterPillDisplayDataArray(array $array = []): array
{
$array[$this->shouldUsePillsAsHtml() ? 'x-html' : 'x-text'] = 'displayString';

return $array;
}

/**
* Get the Display Data for the Filter Pills
*
* @param array<mixed> $array
* @return array<mixed>
*/
public function getInternalFilterPillDisplayDataArray(array $array = []): array
{

Expand All @@ -135,20 +208,37 @@ public function getInternalFilterPillDisplayDataArray(array $array = []): array
return $array;
}

/**
* Get the Display Data for the Filter Pills Title
*
* @param array<mixed> $array
* @return array<mixed>
*/
public function getFilterTitleDisplayDataArray(array $array = []): array
{
$array[$this->shouldUsePillsTitleAsHtml() ? 'x-html' : 'x-text'] = 'localFilterTitle';

return $array;
}

/**
* Get the initial setup data
*
* @return array<mixed>
*/
public function getPillSetupData(string $filterKey = '', bool $shouldWatch = false): array
{
$array = array_merge(['filterKey' => $filterKey, 'watchForEvents' => $shouldWatch], $this->toArray());

return $array;
}

/**
* Calculate Any Reset Button Attributes
*
* @param array<mixed> $filterPillsResetFilterButtonAttributes
* @return array<mixed>
*/
public function getCalculatedCustomResetButtonAttributes(string $filterKey, array $filterPillsResetFilterButtonAttributes): array
{
return array_merge(
Expand All @@ -165,10 +255,15 @@ public function getCalculatedCustomResetButtonAttributes(string $filterKey, arra
);
}

/**
* Returns the data to an array
*
* @return array<mixed>
*/
public function toArray(): array
{
return [
'filterKey' => $this->filterKey,
'filterKey' => $this->getFilterKey(),
'filterPillTitle' => $this->getTitle(),
'filterPillValue' => $this->getPillValue(),
'isAnExternalLivewireFilter' => $this->getIsAnExternalLivewireFilter(),
Expand Down
19 changes: 18 additions & 1 deletion src/DataTransferObjects/Filters/StandardFilterPillData.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,43 @@ public static function make(string $filterPillTitle, string $filterSelectName, s
return new self($filterPillTitle, $filterSelectName, $filterPillValue, $renderPillsAsHtml);
}

/**
* Get the Pill Title
*/
public function getTitle(): string
{
return $this->filterPillTitle;
}

/**
* Get the Filter Select Name
*/
public function getSelectName(): string
{
return $this->filterSelectName;
}

/**
* Get The Pill Value
*/
public function getPillValue(): string
{
return $this->filterPillValue;
}

/**
* Should Use Pills as HTML
*/
public function shouldUsePillsAsHtml(): bool
{
return $this->renderPillsAsHtml ?? false;
return $this->renderPillsAsHtml;
}

/**
* Returns the data to an array
*
* @return array<mixed>
*/
public function toArray(): array
{
return [
Expand Down
15 changes: 12 additions & 3 deletions src/Views/Columns/Traits/HasFooter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,19 @@ public function getFooterCallback()

public function footerCallbackIsString(): bool
{
if (! $this->hasFooterCallback()) {
return false;
}

return is_string($this->getFooterCallback());
}

public function footerCallbackIsFilter(): bool
{
if (! $this->hasFooterCallback()) {
return false;
}

$callback = $this->getFooterCallback();

return $callback instanceof Filter;
Expand All @@ -66,9 +74,10 @@ public function footerCallbackIsFilter(): bool
public function getFooterContents(mixed $rows, array $filterGenericData): \Illuminate\Contracts\Foundation\Application|\Illuminate\View\Factory|\Illuminate\View\View|string|HtmlString
{
$value = null;
$callback = $this->getFooterCallback();

if ($this->hasFooterCallback()) {

$callback = $this->getFooterCallback();

if (is_callable($callback)) {
$value = call_user_func($callback, $rows);

Expand Down Expand Up @@ -111,7 +120,7 @@ public function getNewFooterContents(mixed $rows): string|HtmlString

public function getFooterFilter(?Filter $filter, array $filterGenericData): \Illuminate\Contracts\Foundation\Application|\Illuminate\View\Factory|\Illuminate\View\View|string
{
if ($filter !== null && $filter instanceof Filter) {
if ($filter !== null) {
return $filter->setFilterPosition('footer')->setGenericDisplayData($filterGenericData)->render();
} else {
throw new DataTableConfigurationException('The footer callback must be a closure, filter object, or filter key if using footerFilter().');
Expand Down
Loading