diff --git a/.github/workflows/run-phpstan.yml b/.github/workflows/run-phpstan.yml index 094841e2c..a94ed2a24 100644 --- a/.github/workflows/run-phpstan.yml +++ b/.github/workflows/run-phpstan.yml @@ -9,7 +9,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: [8.2] + php: [8.3] laravel: [10] stability: [prefer-dist] diff --git a/.github/workflows/run-tests-pcov-pull.yml b/.github/workflows/run-tests-pcov-pull.yml index fbfdb8af2..387cc75f3 100644 --- a/.github/workflows/run-tests-pcov-pull.yml +++ b/.github/workflows/run-tests-pcov-pull.yml @@ -9,21 +9,32 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: [8.2] + php: [8.3] laravel: [10] stability: [prefer-dist] - name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + name: PCOV-PULL - ${{ matrix.os }} - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} + env: + extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }}-withpcov + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pcov,pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo steps: - name: Checkout code uses: actions/checkout@v3 + + - name: Setup cache environment + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ matrix.php }} + extensions: ${{ env.extensions }} + key: ${{ env.extensionKey }} - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, iconv, fileinfo + extensions: ${{ env.extensions }} tools: phpunit:latest ini-values: memory_limit=512M coverage: pcov @@ -41,8 +52,8 @@ jobs: - uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer- + key: ${{ runner.os }}-PCOV-PULL-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-PCOV-PULL-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer- - name: Add token run: | diff --git a/.github/workflows/run-tests-pcov.yml b/.github/workflows/run-tests-pcov.yml index 1456d1cf1..08f1ec574 100644 --- a/.github/workflows/run-tests-pcov.yml +++ b/.github/workflows/run-tests-pcov.yml @@ -9,21 +9,39 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: [8.2] + php: [8.3] laravel: [10] stability: [prefer-dist] - name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + name: PCOV-PUSH - ${{ matrix.os }} - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} + env: + extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }}-withpcov + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pcov,pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, :psr steps: - name: Checkout code uses: actions/checkout@v3 - + + - name: Setup cache environment + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ matrix.php }} + extensions: ${{ env.extensions }} + key: ${{ env.extensionKey }} + + - name: Cache extensions + uses: actions/cache@v3 + with: + path: ${{ steps.extcache.outputs.dir }} + key: ${{ steps.extcache.outputs.key }} + restore-keys: ${{ steps.extcache.outputs.key }} + - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, iconv, fileinfo + extensions: ${{ env.extensions }} tools: phpunit:latest ini-values: memory_limit=512M coverage: pcov @@ -41,8 +59,8 @@ jobs: - uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer- + key: ${{ runner.os }}-PCOV-PUSH-PHP-${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-PCOV-PUSH-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer- - name: Add token run: | diff --git a/.github/workflows/run-tests-pull.yml b/.github/workflows/run-tests-pull.yml index 9c28ca24b..0b53b11f8 100644 --- a/.github/workflows/run-tests-pull.yml +++ b/.github/workflows/run-tests-pull.yml @@ -9,21 +9,39 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: [8.1, 8.2] + php: [8.1, 8.2, 8.3] laravel: [10] stability: [prefer-dist] - name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + name: STD-PULL - ${{ matrix.os }} - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} + env: + extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pcov, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, :psr steps: - name: Checkout code uses: actions/checkout@v3 - + + - name: Setup cache environment + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ matrix.php }} + extensions: ${{ env.extensions }} + key: ${{ runner.os }}-${{ env.extensionKey }} + + - name: Cache extensions + uses: actions/cache@v3 + with: + path: ${{ steps.extcache.outputs.dir }} + key: ${{ steps.extcache.outputs.key }} + restore-keys: ${{ steps.extcache.outputs.key }} + - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, iconv, fileinfo + extensions: ${{ env.extensions }} tools: phpunit:latest ini-values: memory_limit=512M coverage: none @@ -41,8 +59,8 @@ jobs: - uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer- + key: ${{ runner.os }}-STDPULL-PHP-${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-STDPULL-PHP-${{ matrix.php }}-L${{ matrix.laravel }}-composer- - name: Add token run: | @@ -53,11 +71,7 @@ jobs: run: composer require "laravel/framework:${{ matrix.laravel }}.*" --no-interaction --no-update - name: Update dependencies - if: steps.composer-cache.outputs.cache-hit != 'true' run: composer update --${{ matrix.stability }} --no-interaction - - name: Setup problem matchers for PHPUnit - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - name: Run Unit Tests run: php ./vendor/bin/paratest --no-coverage --processes=4 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 5fb8a4359..073bbe9c5 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -9,21 +9,39 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: [8.1, 8.2] + php: [8.1, 8.2, 8.3] laravel: [10] stability: [prefer-dist] - name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + name: STD-PUSH - ${{ matrix.os }} - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} + env: + extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pcov, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, :psr steps: - name: Checkout code uses: actions/checkout@v3 - + + - name: Setup cache environment + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ matrix.php }} + extensions: ${{ env.extensions }} + key: ${{ env.extensionKey }} + + - name: Cache extensions + uses: actions/cache@v3 + with: + path: ${{ steps.extcache.outputs.dir }} + key: ${{ runner.os }}-${{ steps.extcache.outputs.key }} + restore-keys: ${{ runner.os }}-${{ steps.extcache.outputs.key }} + - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, iconv, fileinfo + extensions: ${{ env.extensions }} tools: phpunit:latest ini-values: memory_limit=512M coverage: none @@ -41,8 +59,8 @@ jobs: - uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer- + key: ${{ runner.os }}-STDPUSH-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-STDPUSH-PHP${{ matrix.php }}-L${{ matrix.laravel }}-composer- - name: Add token run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index 174f2a550..b4cd109ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ All notable changes to `laravel-livewire-tables` will be documented in this file +## UNRELEASED +### New Features +- Add capability to use as a Full Page Component + +### Tweaks +- Internal - modify GitHub workflows to improve caching, but use unique caches per workflow matrix +- Internal - remove superfluous PHPStan ignoreErrors +- Internal - update Test Suite to also test at PHP 8.3 + ## [v3.1.4] - 2023-12-04 ### New Features - Add capability to hide Column Label by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1512 diff --git a/composer.json b/composer.json index 512a01e8e..10ae9c63e 100644 --- a/composer.json +++ b/composer.json @@ -18,15 +18,17 @@ } ], "require": { - "php": "^8.1|^8.2", + "php": "^8.1|^8.2|^8.3", "blade-ui-kit/blade-heroicons": "^2.1", "illuminate/contracts": "^10.0|^11.0", + "illuminate/support": "^10.0|^11.0", "livewire/livewire": "^3.0|dev-main" }, "require-dev": { "ext-sqlite3": "*", "brianium/paratest": "^5.0|^6.0|^7.0|^8.0", "laravel/pint": "^1.10", + "monolog/monolog": "*", "nunomaduro/collision": "^6.0|^7.0|^8.0", "nunomaduro/larastan": "^2.6", "orchestra/testbench": "^7.0|^8.0|^9.0", diff --git a/docs/usage/creating-components.md b/docs/usage/creating-components.md index b5173e2ca..a8e094ae0 100644 --- a/docs/usage/creating-components.md +++ b/docs/usage/creating-components.md @@ -3,6 +3,7 @@ title: Creating Components weight: 1 --- +### In-Line Component You can create components by using the [command](../start/commands) or copying from one of the [examples](../examples/basic-example). This is what a bare bones component looks like before your customization: @@ -38,3 +39,63 @@ class UsersTable extends DataTableComponent ``` Your component will extend the `Rappasoft\LaravelLivewireTables\DataTableComponent` class and at minimum implement 2 methods called [configure](./configuration) and [columns](../columns/creating-columns). + +### Full Page Component +To use a Table as a Full Page Component, there are a few options that you must set in your configure() method. + +#### setLayout +To use a Custom Layout (as a Full Page Component), use the setLayout() method, which expects to be passed a string which is the path to the layout. +```php + public function configure(): void + { + $this->setLayout('path-to-layout'); + } + +``` + +#### setSlot +To use a Custom Slot (as a Full Page Component), use setSlot() method, which expects to be passed a string which is the name of the slot. +```php + public function configure(): void + { + $this->setSlot('slot-name-here'); + } + +``` + +#### setSection +To use a Custom Section (as a Full Page Component), use setSection() method, which expects to be passed a string which is the name of the section. + + +#### Full Page Component Example +```php +setPrimaryKey('id') + ->setLayout('path-to-layout') + ->setSlot('slot-name-here'); + } + + public function columns(): array + { + return [ + Column::make('ID', 'id') + ->sortable(), + Column::make('Name') + ->sortable(), + ]; + } +} +``` diff --git a/phpstan.neon b/phpstan.neon index 7366c08f3..5f80ea639 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -16,12 +16,8 @@ parameters: checkGenericClassInNonGenericObjectType: false ignoreErrors: - "#Unsafe usage of new static#" - - "#Called 'count' on Laravel collection, but could have been retrieved as a query.#" - - '#Attribute class Rappasoft\\LaravelLivewireTables\\Traits\\Url does not exist.#' - - '#Attribute class Rappasoft\\LaravelLivewireTables\\Traits\\Helpers\\On does not exist.#' - '#on array\, mixed\>\> in empty\(\) does not exist.#' - '#on array, mixed>> in isset\(\) does not exist#' - - '#on array\, mixed\>\> in isset\(\) does not exist#' - '#on non-empty-array<1|string, array, mixed>> in isset\(\) does not exist.#' - '#\$callback of method Illuminate\\Support\\Collection::filter\(\) expects \(callable\(string, int\): bool\)\|null, Closure\(mixed\): int<0, max> given.#' - '#Property Illuminate\\Database\\Query\\Builder\:\:\$joins \(array\) on left side of \?\? is not nullable.#' diff --git a/src/Traits/Configuration/CustomisationsConfiguration.php b/src/Traits/Configuration/CustomisationsConfiguration.php index f16cf682a..745ecdc9f 100644 --- a/src/Traits/Configuration/CustomisationsConfiguration.php +++ b/src/Traits/Configuration/CustomisationsConfiguration.php @@ -4,4 +4,43 @@ trait CustomisationsConfiguration { + /** + * Used to set a Custom Layout if using a Full Page Component approach. + */ + public function setLayout(string $layout): self + { + $this->layout = $layout; + + return $this; + } + + /** + * Used to set a Custom Slot if using a Full Page Component approach + */ + public function setSlot(string $slot): self + { + $this->slot = $slot; + + return $this; + } + + /** + * Used to set a Custom Extends Layout if using a Full Page Component approach + */ + public function setExtends(string $extends): self + { + $this->extends = $extends; + + return $this; + } + + /** + * Used to set a Custom Layout Section if using a Full Page Component approach + */ + public function setSection(string $section): self + { + $this->section = $section; + + return $this; + } } diff --git a/src/Traits/Helpers/CustomisationsHelpers.php b/src/Traits/Helpers/CustomisationsHelpers.php index 5520ae5c7..05795fc1c 100644 --- a/src/Traits/Helpers/CustomisationsHelpers.php +++ b/src/Traits/Helpers/CustomisationsHelpers.php @@ -4,4 +4,55 @@ trait CustomisationsHelpers { + /** + * Used to determine if a Layout Extends has been defined - used when using as a Full Page Component + */ + public function hasExtends(): bool + { + return isset($this->extends) && $this->extends !== null; + } + + public function getExtends() + { + return $this->extends; + } + + /** + * Used to determine if a Layout Section has been defined - used when using as a Full Page Component + */ + public function hasSection(): bool + { + return isset($this->section) && $this->section !== null; + } + + public function getSection() + { + return $this->section; + } + + /** + * Used to determine if a Layout Slot has been defined - used when using as a Full Page Component + */ + public function hasSlot(): bool + { + return isset($this->slot) && $this->slot !== null; + } + + public function getSlot() + { + return $this->slot; + } + + /** + * Used to determine if a $layout has been defined - used when using as a Full Page Component + */ + public function hasLayout(): bool + { + return isset($this->layout) && $this->layout !== null; + } + + public function getLayout() + { + return $this->layout; + } } diff --git a/src/Traits/WithCustomisations.php b/src/Traits/WithCustomisations.php index 556b5982d..d8b9c3d24 100644 --- a/src/Traits/WithCustomisations.php +++ b/src/Traits/WithCustomisations.php @@ -10,6 +10,14 @@ trait WithCustomisations use CustomisationsConfiguration, CustomisationsHelpers; + protected ?string $layout = null; + + protected ?string $slot = null; + + protected ?string $extends = null; + + protected ?string $section = null; + /** * The view to add any modals for the table, could also be used for any non-visible html */ @@ -23,6 +31,22 @@ public function customView(): string */ public function renderingWithCustomisations(\Illuminate\View\View $view, array $data = []): void { + if ($this->hasLayout()) { + $view->layout($this->getLayout()); + } + + if ($this->hasExtends()) { + $view->extends($this->getExtends()); + } + + if ($this->hasSection()) { + $view->section($this->getSection()); + } + + if ($this->hasSlot()) { + $view->slot($this->getSlot()); + } + $view = $view->with([ 'customView' => $this->customView(), ]); diff --git a/tests/Traits/Configuration/CustomisationsConfigurationTest.php b/tests/Traits/Configuration/CustomisationsConfigurationTest.php new file mode 100644 index 000000000..6ee063fd0 --- /dev/null +++ b/tests/Traits/Configuration/CustomisationsConfigurationTest.php @@ -0,0 +1,40 @@ +assertNull($this->basicTable->getExtends()); + $this->basicTable->setExtends('app.layout'); + $this->assertEquals('app.layout', $this->basicTable->getExtends()); + } + + /** @test */ + public function can_set_layout(): void + { + $this->assertNull($this->basicTable->getLayout()); + $this->basicTable->setLayout('app.layout'); + $this->assertEquals('app.layout', $this->basicTable->getLayout()); + } + + /** @test */ + public function can_set_section(): void + { + $this->assertNull($this->basicTable->getSection()); + $this->basicTable->setSection('content'); + $this->assertEquals('content', $this->basicTable->getSection()); + } + + /** @test */ + public function can_set_slot(): void + { + $this->assertNull($this->basicTable->getSlot()); + $this->basicTable->setSlot('my_slot'); + $this->assertEquals('my_slot', $this->basicTable->getSlot()); + } +}