Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENHANCEMENT/FIX] Fix hideToggleable, add Action Rules editOnClick(), toggleable(), unless()` condition and others... #1559

Merged
merged 11 commits into from
May 22, 2024

Conversation

dansysanalyst
Copy link
Member

@dansysanalyst dansysanalyst commented May 19, 2024

⚡ PowerGrid - Pull Request

Welcome and thank you for your interest in contributing to our project!. You must use this template to submit a Pull Request or it will not be accepted.


Motivation

  • Bug fix
  • Enhancement
  • New feature
  • Breaking change

Description

This Pull Request fixes the bug of hideToggleable not being applied and adds new Action Rules as documented below.

As a minor detail, I have also linked the README screenshot to the "Demo Dish" table.

New Rules

  • unless() conditition
  • Rule::rows()->alternating()
  • Rule::rows()->hideToggleDetail()
  • Rule::rows()->disableEditOnClick()
  • Rule::toggleable($column)
  • Rule::editOnClick($column)
  • Rule::rows()->hideToggleable() (fixed)
Screenshot

CleanShot 2024-05-20 at 00 36 28@2x

Example using alternating() to produce a zebra-striped table, Rule::editOnClick('name')->enable() forces inline editing on dish ID # 10, Rule::rows()->hideToggleable() hiding the toggleable on dishes ID # 5,6,10

📜 New Rules Action Rules Summary

🚀 ACTION RULES
ROW RULE
Method Description
setAttribute(string $attribute = null, string $value = null)
Sets a value to the Rule target attribute.
detailView(string $detailView = null, array $options = []) Sets a view for the Detail Row
showToggleable() / hideToggleable()
Show / Hide toggleable switches in the row
enableEditOnClick() /disableEditOnClick() Show / Hide edit on click in the row
showToggleDetail() / hideToggleDetail() Show / Hide detail row toggleable in the row
loop() Interact with the row loop
firstOnPage() / lastOnPage() / alternating() Alias to the loop modifier. Each alias will override the loop modifier, so combining them is not possible.
CHECKBOX RULE
Method Description
setAttribute(string $attribute = null, string $value = null) Sets a value to the Rule target attribute.
hide() Hide the checkboxes
disable() Disable the checkboxes
applyRowClasses(string $attrClass = '') Apply Classes in a row
RADIO BUTTON RULE
Method Description
setAttribute(string $attribute = null, string $value = null) Sets a value to the Rule target attribute.
hide() Hide the radio buttons
disable() Disable the radio buttons
applyRowClasses(string $attrClass = '') Apply Classes in a row
BUTTON RULES
Method Description
dispatch(string $event = '', array $params = []) Sets the event to be emitted by the Rule target
dispatchTo(string $to = '', string $event = '', array $params = []) Sets the target component and the event name to be emitted by the Rule target
setAttribute(string $attribute = null, string|array $value = null) Sets a value to the Rule target attribute. Buttons accept multiple usages of this modifier.
show() / hide() Show or hide a button
enable() / disable() Enable or disable a button
redirect(Closure $closure = null, string $target = '_blank') Sets Rule target's redirect URL
slot(string $slot) Sets the Rule target slot content
bladeComponent(string $component, array $params) Changes the Blade Component in the Rule target.
EDIT ON CLICK RULE
enable() / disable() Forcefully enable or disable a edit on click, regardless of column configuration or its permission.
TOGGLEABLE RULE
show() / hide() Forcefully show or hide a toggleable switch, regardless of column configuration or its permission.
Usage/Examples

Specific target rules have precedence over column and row rules. That is, if a column is configured to NOT have permission to display a toggleable switch, but a rule is targeting that column with the show() modifier, this toggle will be rendered.

In the next example, the column doesn't have permission to show toggleables. However, the dish with ID 1 will forcefully display a toggle, while all other rows will have the fallback badge.

            Column::make('Active', 'active')
                ->toggleable(hasPermission: false),

            Rule::toggleable('active')
                ->when(fn ($dish) => $dish->id == 1)
                ->show(),

In a similar case, now the column active has permission to display toggles. In this column, we will hide toggles when active is false. So, when a user switches it to false, he cannot switch to true again. However, for the dish #1, the checkbox will always be shown.

            Column::make('Active', 'active')
                ->toggleable(hasPermission: true),

            Rule::rows()
                ->when(fn ($dish) => $dish->active == false)
                ->hideToggleable()

            Rule::toggleable('active')
                ->when(fn ($dish) => $dish->id == 1)
                ->show(),

The alternating() modifier is a convenient way to produce a zebra-stripped table.

           Rule::rows()
                ->alternating()
                ->setAttribute('class', '!bg-indigo-100'),

For more details, see the tests associated with the tests/Concerns/Components/ComponentsForTestRule.php component.

POSSIBLE BREAKING CHANGES

The following views were altered and will cause breaking changes in users who published/customized the views.

  • resources/views/components/row.blade.php
  • resources/views/components/frameworks/bootstrap5/toggleable.blade.php
  • resources/views/components/frameworks/tailwind/toggleable.blade.php

Related Issue(s): #1539

Documentation

This PR requires Documentation update?

  • Yes
  • No
  • I have already submitted a Documentation pull request.

@dansysanalyst dansysanalyst changed the title [ENHANCEMENT/FIX] Fix `hideToggleable, add new Action Rules [ENHANCEMENT/FIX] Fix hideToggleable, add Action Rules editOnClick(), toggleable(), unless()` condition and others... May 19, 2024
@luanfreitasdev
Copy link
Collaborator

Thanks @dansysanalyst ! I believe this refactoring was very well done.

@luanfreitasdev luanfreitasdev merged commit 61b4c44 into Power-Components:5.x May 22, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants