Skip to content

Commit

Permalink
Merge pull request #1535 from rappasoft/develop
Browse files Browse the repository at this point in the history
- Add additional Lifecycle Hook by @lrljoe in #1534
  - SettingColumns/ColumnsSet
- Migrate methods for pre-render out of render by @lrljoe in #1534
- Update tests to reflect hooks by @lrljoe in #1534
- Update tests to add invalid string tests for dates by @lrljoe in #1534
- Remove maps and minimise functions from FrontendAssets by @lrljoe in #1534
  • Loading branch information
lrljoe authored Nov 3, 2023
2 parents f0a32bc + f73b59e commit b554a83
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 9 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

All notable changes to `laravel-livewire-tables` will be documented in this file

## [v3.1.3] - 2023-11-03
- Add additional Lifecycle Hook by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1534
- SettingColumns/ColumnsSet
- Migrate methods for pre-render out of render by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1534
- Update tests to reflect hooks by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1534
- Update tests to add invalid string tests for dates by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1534
- Remove maps and minimise functions from FrontendAssets by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1534

## [v3.1.2] - 2023-11-03
- Add Initial Lifecycle Hooks - Configuring/Configured by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1520
- Configuring/Configured
- Add missing tests for DateFilter and DateTimeFilter by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1527


## [v3.1.1] - 2023-11-02
### New Features
- Add setCustomView for Filters
Expand Down
8 changes: 7 additions & 1 deletion docs/misc/lifecycle-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ With the migration to Livewire 3, there we are implementing several Lifecycle Ho
This is called immediately prior to the configure() method being called

## configured
This is called immediately after the configure() method is called
This is called immediately after the configure() method is called

## settingColumns
This is called prior to setting up the available Columns via the columns() method

## columnsSet
This is called immediately after the Columns are set up
16 changes: 10 additions & 6 deletions src/DataTableComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function boot(): void
*/
public function booted(): void
{
// Configuring
// Fire hook for configuring
$this->callHook('configuring');
$this->callTraitHook('configuring');
Expand All @@ -59,8 +60,17 @@ public function booted(): void
$this->setBuilder($this->builder());

// Sets Columns
// Fire hook for settingColumns
$this->callHook('settingColumns');
$this->callTraitHook('settingColumns');

// Set Columns
$this->setColumns();

// Fire hook for columnsSet
$this->callHook('columnsSet');
$this->callTraitHook('columnsSet');

// Make sure a primary key is set
if (! $this->hasPrimaryKey()) {
throw new DataTableConfigurationException('You must set a primary key using setPrimaryKey in the configure method.');
Expand Down Expand Up @@ -99,12 +109,6 @@ public function customView(): string

public function render(): \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
{
$this->setupColumnSelect();
$this->setupPagination();
$this->setupSecondaryHeader();
$this->setupFooter();
$this->setupReordering();

return view('livewire-tables::datatable')
->with([
'filterGenericData' => $this->getFilterGenericData(),
Expand Down
3 changes: 2 additions & 1 deletion src/Mechanisms/RappasoftFrontendAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ protected function pretendResponseIsCSS(string $file): \Symfony\Component\HttpFo
return response()->file($file, $headers);
}

/*
public function maps(): \Symfony\Component\HttpFoundation\Response
{
return Utils::pretendResponseIsFile(__DIR__.'/../../../resources/js/laravel-livewire-tables.min.js.map');
Expand All @@ -117,5 +118,5 @@ public function maps(): \Symfony\Component\HttpFoundation\Response
protected static function minify(string $subject): array|string|null
{
return preg_replace('~(\v|\t|\s{2,})~m', '', $subject);
}
}*/
}
5 changes: 5 additions & 0 deletions src/Traits/WithColumnSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,9 @@ public function allSelectedColumnsAreVisibleByDefault(): bool
{
return count($this->selectedColumns) === count($this->getDefaultVisibleColumns());
}

public function renderingWithColumnSelect()
{
$this->setupColumnSelect();
}
}
5 changes: 5 additions & 0 deletions src/Traits/WithFooter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public function setupFooter(): void
}
}
}

public function renderingWithFooter()
{
$this->setupFooter();
}
}
5 changes: 5 additions & 0 deletions src/Traits/WithPagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ private function getPerPagePaginationSessionKey(): string
{
return $this->tableName.'-perPage';
}

public function renderingWithPagination()
{
$this->setupPagination();
}
}
5 changes: 5 additions & 0 deletions src/Traits/WithReordering.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,9 @@ public function storeReorder(array $rows = [])
$this->forgetReorderingSession();
$this->getReorderingBackup();
}

public function renderingWithReordering()
{
$this->setupReordering();
}
}
5 changes: 5 additions & 0 deletions src/Traits/WithSecondaryHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ public function setupSecondaryHeader(): void
}
}
}

public function renderingWithSecondaryHeader()
{
$this->setupSecondaryHeader();
}
}
3 changes: 3 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ protected function setUp(): void
$this->basicTable = new PetsTable();
$this->basicTable->boot();
$this->basicTable->booted();
$this->basicTable->callHook('rendering');
$this->basicTable->callTraitHook('rendering');
$this->basicTable->render();
$this->basicTable->callHook('rendered');
}

protected function getPackageProviders($app): array
Expand Down
10 changes: 10 additions & 0 deletions tests/Views/Filters/DateFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,14 @@ public function test_can_get_filter_pills_value(): void

$this->assertSame($dateTime->format('d M Y'), self::$filterInstance->getFilterPillValue($dateTime->format('Y-m-d')));
}

/**
* @test
*/
public function test_can_not_get_filter_pills_invalid_value(): void
{
$dateTime = (new DateTime('now'));

$this->assertNull(self::$filterInstance->getFilterPillValue('2022-2111'));
}
}
10 changes: 10 additions & 0 deletions tests/Views/Filters/DateTimeFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,14 @@ public function test_can_get_filter_pills_value(): void

$this->assertSame($dateTime->format('d M Y - H:i'), self::$filterInstance->getFilterPillValue($dateTime->format('Y-m-d\TH:i')));
}

/**
* @test
*/
public function test_can_not_get_filter_pills_invalid_value(): void
{
$dateTime = (new DateTime('now'));

$this->assertNull(self::$filterInstance->getFilterPillValue('2022-1111'));
}
}

0 comments on commit b554a83

Please sign in to comment.