Skip to content

Commit 941cf25

Browse files
Fix Header::can method (#1774)
1 parent ac29ea8 commit 941cf25

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/Components/Filters/Builders/InputText.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function collection(Collection $collection, string $field, int|array|stri
117117
'is_empty' => $collection->filter(function ($row) use ($field) {
118118
$row = (object) $row;
119119

120-
return $row->{$field} == '' || is_null($row->{$field});
120+
return $row->{$field} == '' || is_null($row->{$field}); // @phpstan-ignore-line
121121
}),
122122
'is_not_empty' => $collection->filter(function ($row) use ($field) {
123123
$row = (object) $row;

src/Concerns/HasActions.php

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ public function storeActionsHeaderInJSWindow(): void
8282

8383
$actionsHtml = collect($this->header())
8484
->transform(function (Button $action) {
85+
$can = data_get($action, 'can');
86+
8587
return [
8688
'action' => $action->action,
8789
'slot' => $action->slot,
@@ -90,6 +92,7 @@ public function storeActionsHeaderInJSWindow(): void
9092
'iconAttributes' => $action->iconAttributes,
9193
'attributes' => $action->attributes,
9294
'rules' => [],
95+
'can' => $can instanceof \Closure ? $can() : $can,
9396
];
9497
});
9598

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
describe('Header can (show/hide)', () => {
2+
[
3+
'/header-can?powerGridTheme=tailwind',
4+
'/header-can?powerGridTheme=bootstrap'
5+
].forEach((route) => {
6+
beforeEach(() => {
7+
cy.visit(route);
8+
});
9+
10+
it('can se only visible header button', () => {
11+
cy.get('[data-cy="btn-header-visible"]').should("be.visible");
12+
13+
cy.get('body').should('contain.text', 'Visible');
14+
15+
cy.get('body').should('not.contain.text', 'Invisible');
16+
})
17+
})
18+
});

0 commit comments

Comments
 (0)