From 7e2e16165e608859019f422dfaa88e3dc3e97306 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 12 Nov 2025 08:39:23 +0100 Subject: [PATCH 1/2] ContinueWith: Disable button if the query with filter returns no results --- src/Widget/ContinueWith.php | 42 ++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/src/Widget/ContinueWith.php b/src/Widget/ContinueWith.php index 6c3fd693..4d2694e9 100644 --- a/src/Widget/ContinueWith.php +++ b/src/Widget/ContinueWith.php @@ -27,10 +27,38 @@ class ContinueWith extends BaseHtmlElement /** @var string */ protected $title; - public function __construct(Url $url, $filter) + /** @var ?bool Whether the current query has results */ + protected ?bool $hasResults; + + /** + * Whether the current query has results + * + * @return bool + */ + public function hasResults(): bool + { + return $this->hasResults; + } + + /** + * Set whether the current query has results + * + * @param bool $hasResults + * + * @return ContinueWith + */ + public function setHasResults(bool $hasResults): ContinueWith + { + $this->hasResults = $hasResults; + + return $this; + } + + public function __construct(Url $url, $filter, bool $hasResults) { $this->url = $url; $this->filter = $filter; + $this->hasResults = $hasResults; } /** @@ -54,18 +82,18 @@ public function assemble() $filter = $filter(); /** @var Filter\Rule $filter */ } - $baseFilter = $this->url->getFilter(); - if ($baseFilter && ((! $baseFilter instanceof Filter\Chain) || ! $baseFilter->isEmpty())) { - $filter = Filter::all($baseFilter, $filter); - } - - if ($filter instanceof Filter\Chain && $filter->isEmpty()) { + if (! $this->hasResults || ($filter instanceof Filter\Chain && $filter->isEmpty())) { $this->addHtml(new HtmlElement( 'span', Attributes::create(['class' => ['control-button', 'disabled']]), new Icon('share') )); } else { + $baseFilter = $this->url->getFilter(); + if ($baseFilter && ((! $baseFilter instanceof Filter\Chain) || ! $baseFilter->isEmpty())) { + $filter = Filter::all($baseFilter, $filter); + } + $this->addHtml(new ActionLink( null, $this->url->setFilter($filter), From 52103b1460c9ed0e5da524e9a5097bcc28736198 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 19 Nov 2025 11:20:29 +0100 Subject: [PATCH 2/2] ContinueWith: Add property type and return type --- src/Widget/ContinueWith.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Widget/ContinueWith.php b/src/Widget/ContinueWith.php index 4d2694e9..902521b6 100644 --- a/src/Widget/ContinueWith.php +++ b/src/Widget/ContinueWith.php @@ -19,13 +19,13 @@ class ContinueWith extends BaseHtmlElement protected $defaultAttributes = ['class' => 'continue-with']; /** @var Url */ - protected $url; + protected Url $url; /** @var Filter\Rule|callable */ protected $filter; - /** @var string */ - protected $title; + /** @var ?string */ + protected ?string $title; /** @var ?bool Whether the current query has results */ protected ?bool $hasResults; @@ -68,14 +68,14 @@ public function __construct(Url $url, $filter, bool $hasResults) * * @return $this */ - public function setTitle($title) + public function setTitle(string $title): static { $this->title = $title; return $this; } - public function assemble() + public function assemble(): void { $filter = $this->filter; if (is_callable($filter)) {