Skip to content

Commit

Permalink
Merge branch '6.x' of github.com:Power-Components/livewire-powergrid …
Browse files Browse the repository at this point in the history
…into add-cypress-test
  • Loading branch information
luanfreitasdev committed Sep 8, 2024
2 parents 02dedf8 + 25cbe18 commit 17595e8
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 26 deletions.
2 changes: 1 addition & 1 deletion dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/powergrid.js": "/powergrid.js?id=05c5f62ec274e8fcf8d83856987538fe",
"/powergrid.js": "/powergrid.js?id=434af38e193e4b54d647faede6b8b74f",
"/bootstrap5.css": "/bootstrap5.css?id=a27af22343149104b2aa3283d8fd502b",
"/tailwind.css": "/tailwind.css?id=924477e2afcb2cb56aa392e266ee56ca"
}
2 changes: 1 addition & 1 deletion dist/powergrid.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions resources/js/components/pg-render-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export default (params) => ({
},

shouldHideAction(action) {

if (action.can === false) {
return true;
}

let hideAction = false;
if (action.rules && Object.values(action.rules).length > 0) {
Object.values(action.rules).forEach((ruleObj) => {
Expand Down
75 changes: 75 additions & 0 deletions resources/lang/pt/datatable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

return [
'buttons' => [
'filter' => 'Filtrar',
'clear_all_filters' => 'Limpar Todos',
],
'labels' => [
'action' => 'Ações',
'results_per_page' => 'Registos por página',
'clear_filter' => 'Limpar filtro',
'no_data' => 'Nenhum registo encontrado',
'all' => 'Todos',
'selected' => 'Selecionados',
'filtered' => 'Filtrados',
],
'placeholders' => [
'search' => 'Pesquisar ...',
'select' => 'Selecione um período',
],
'pagination' => [
'showing' => 'A mostrar',
'to' => 'até',
'of' => 'de',
'results' => 'resultados',
'all' => 'Todos',
],
'multi_select' => [
'select' => 'Selecione',
'all' => 'Todos',
],
'select' => [
'select' => 'Selecione',
'all' => 'Todos',
],
'boolean_filter' => [
'all' => 'Todos',
],
'input_text_options' => [
'is' => 'É exatamente',
'is_not' => 'É diferente de',
'contains' => 'Contém',
'contains_not' => 'Não contém',
'starts_with' => 'Começa com',
'ends_with' => 'Termina com',
'is_null' => 'É nulo',
'is_not_null' => 'Não é núlo',
'is_blank' => 'Está em branco',
'is_not_blank' => 'Não está em branco',
'is_empty' => 'Não está preenchido',
'is_not_empty' => 'Está preenchido',
],
'export' => [
'exporting' => 'Por favor, aguarde!',
'completed' => 'Exportação concluída! Os seus ficheiros estão prontos para download',
],
'soft_deletes' => [
'message_with_trashed' => 'A mostrar todos os registos, incluindo os excluídos.',
'message_only_trashed' => 'A mostrar apenas os registos excluídos.',
'without_trashed' => 'Sem excluídos',
'with_trashed' => 'Com excluídos',
'only_trashed' => 'Apenas excluídos',
],
'multi_sort' => [
'message' => 'A classificação múltipla está ativa',
],
'buttons_macros' => [
'confirm' => [
'message' => 'Tem a certeza que pretende executar esta ação?',
],
'confirm_prompt' => [
'message' => "Tem a certeza que pretende executar esta ação? \n\n Escreva :confirmValue para confirmar.",
],
],
];
4 changes: 2 additions & 2 deletions resources/lang/pt_BR/datatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@
],
'buttons_macros' => [
'confirm' => [
'message' => 'Are you sure you want to perform this action?',
'message' => 'Tem a certeza que pretende executar esta ação?',
],
'confirm_prompt' => [
'message' => "Are you sure you want to perform this action? \n\n Enter :confirmValue to confirm.",
'message' => "Tem a certeza que pretende executar esta ação? \n\n Escreva :confirmValue para confirmar.",
],
],
];
2 changes: 1 addition & 1 deletion src/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class Button implements Wireable

public ?\Closure $hideWhen = null;

public ?\Closure $can = null;
public bool | \Closure $can = true;

public function __construct(public string $action)
{
Expand Down
20 changes: 10 additions & 10 deletions src/Concerns/HasActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ public function storeActionsHeaderInJSWindow(): void
}

$actionsHtml = collect($this->header())
->transform(function (Button $action) {
return [
'slot' => $action->slot,
'tag' => $action->tag,
'icon' => $action->icon,
'iconAttributes' => $action->iconAttributes,
'attributes' => $action->attributes,
'rules' => [],
];
});
->transform(function (Button $action) {
return [
'slot' => $action->slot,
'tag' => $action->tag,
'icon' => $action->icon,
'iconAttributes' => $action->iconAttributes,
'attributes' => $action->attributes,
'rules' => [],
];
});

$actionsHtml = json_encode($actionsHtml);

Expand Down
28 changes: 18 additions & 10 deletions src/DataSource/Processors/DataSourceBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,24 @@ private static function processRows(BaseCollection $results, PowerGridComponent
if ($renderActions && !$hasCookieActionsForRow) {
try {
$actions = collect($component->actions((object) $row)) // @phpstan-ignore-line
->transform(function (Button|array $action) use ($row, $component) {
return [
'slot' => data_get($action, 'slot'),
'tag' => data_get($action, 'tag'),
'icon' => data_get($action, 'icon'),
'iconAttributes' => data_get($action, 'iconAttributes'),
'attributes' => data_get($action, 'attributes'),
'rules' => $component->resolveActionRules($row),
];
});
->transform(function (Button|array $action) use ($row, $component) {
/** @var bool|\Closure $can */
$can = data_get($action, 'can');

if ($can instanceof \Closure) {
$allowed = $can($row);
}

return [
'can' => $allowed ?? $can,
'slot' => data_get($action, 'slot'),
'tag' => data_get($action, 'tag'),
'icon' => data_get($action, 'icon'),
'iconAttributes' => data_get($action, 'iconAttributes'),
'attributes' => data_get($action, 'attributes'),
'rules' => $component->resolveActionRules($row),
];
});

static::$actionsHtml[$rowId] = $actions->toArray();
} catch (\ArgumentCountError $exception) {
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/Macros.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static function actions(): void
return $this;
});

Button::macro('can', function (\Closure $closure) {
Button::macro('can', function (bool|\Closure $closure) {
$this->can = $closure;

return $this;
Expand Down

0 comments on commit 17595e8

Please sign in to comment.