Skip to content

Commit

Permalink
Merge branch 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Voltra authored Dec 24, 2024
2 parents 5b4c30d + 96a4f5a commit 21b4510
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2.1.0
uses: dependabot/fetch-metadata@v2.2.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

All notable changes to `filament-fabricator` will be documented in this file.

## v2.3.0 - 2024-12-22

### What's Changed

* allow layout live switching by @phpsa in https://github.com/Z3d0X/filament-fabricator/pull/188
* Add exception for runningInConsole in FilamentFabricatorServiceProvid… by @yolanmees in https://github.com/Z3d0X/filament-fabricator/pull/160
* Add a hook to allow mass-preload/batch-load of related data when rendering a page's blocks by @Voltra in https://github.com/Z3d0X/filament-fabricator/pull/166

### New Contributors

* @phpsa made their first contribution in https://github.com/Z3d0X/filament-fabricator/pull/188
* @yolanmees made their first contribution in https://github.com/Z3d0X/filament-fabricator/pull/160

**Full Changelog**: https://github.com/Z3d0X/filament-fabricator/compare/v2.2.2...v2.3.0

## v2.2.2 - 2024-05-12

### What's Changed
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Orchestra\Testbench\Foundation\Application;
use Z3d0X\FilamentFabricator\FilamentFabricatorServiceProvider;

$basePathLocator = new class()
$basePathLocator = new class
{
use CreatesApplication;
};
Expand Down
23 changes: 18 additions & 5 deletions resources/views/components/page-blocks.blade.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
@aware(['page'])
@props(['blocks' => []])

@php
$groups = \Z3d0X\FilamentFabricator\Helpers::arrayRefsGroupBy($blocks, 'type');
foreach ($groups as $blockType => &$group) {
/**
* @var class-string<\Z3d0X\FilamentFabricator\PageBlocks\PageBlock> $blockClass
*/
$blockClass = FilamentFabricator::getPageBlockFromName($blockType);
if (!empty($blockClass)) {
$blockClass::preloadRelatedData($page, $group);
}
}
@endphp

@foreach ($blocks as $blockData)
@php
$pageBlock = \Z3d0X\FilamentFabricator\Facades\FilamentFabricator::getPageBlockFromName($blockData['type'])
$pageBlock = \Z3d0X\FilamentFabricator\Facades\FilamentFabricator::getPageBlockFromName($blockData['type']);
@endphp

@isset($pageBlock)
<x-dynamic-component
:component="$pageBlock::getComponent()"
:attributes="new \Illuminate\View\ComponentAttributeBag($pageBlock::mutateData($blockData['data']))"
/>
<x-dynamic-component :component="$pageBlock::getComponent()" :attributes="new \Illuminate\View\ComponentAttributeBag($pageBlock::mutateData($blockData['data']))" />
@endisset
@endforeach
1 change: 0 additions & 1 deletion src/FilamentFabricatorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Closure;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
use Z3d0X\FilamentFabricator\Layouts\Layout;
use Z3d0X\FilamentFabricator\Models\Contracts\Page as PageContract;
Expand Down
44 changes: 23 additions & 21 deletions src/FilamentFabricatorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,30 @@ public function packageRegistered(): void

public function bootingPackage(): void
{
Route::bind('filamentFabricatorPage', function ($value) {
/**
* @var PageRoutesService $routesService
*/
$routesService = resolve(PageRoutesService::class);

return $routesService->findPageOrFail($value);
});

$this->registerComponentsFromDirectory(
Layout::class,
config('filament-fabricator.layouts.register'),
config('filament-fabricator.layouts.path'),
config('filament-fabricator.layouts.namespace')
);
if (! $this->app->runningInConsole()) {
Route::bind('filamentFabricatorPage', function ($value) {
/**
* @var PageRoutesService $routesService
*/
$routesService = resolve(PageRoutesService::class);

return $routesService->findPageOrFail($value);
});

$this->registerComponentsFromDirectory(
PageBlock::class,
config('filament-fabricator.page-blocks.register'),
config('filament-fabricator.page-blocks.path'),
config('filament-fabricator.page-blocks.namespace')
);
$this->registerComponentsFromDirectory(
Layout::class,
config('filament-fabricator.layouts.register'),
config('filament-fabricator.layouts.path'),
config('filament-fabricator.layouts.namespace')
);

$this->registerComponentsFromDirectory(
PageBlock::class,
config('filament-fabricator.page-blocks.register'),
config('filament-fabricator.page-blocks.path'),
config('filament-fabricator.page-blocks.namespace')
);
}
}

public function packageBooted()
Expand Down
23 changes: 23 additions & 0 deletions src/Helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Z3d0X\FilamentFabricator;

abstract class Helpers
{
/**
* Group an array of associative arrays by a given key
*
* @param array[] $arr
* @return array[]
*/
public static function arrayRefsGroupBy(array &$arr, string $key): array
{
$ret = [];

foreach ($arr as &$item) {
$ret[$item[$key]][] = &$item;
}

return $ret;
}
}
3 changes: 1 addition & 2 deletions src/Observers/PageRoutesObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class PageRoutesObserver
{
public function __construct(
protected PageRoutesService $pageRoutesService
) {
}
) {}

/**
* Handle the Page "created" event.
Expand Down
12 changes: 12 additions & 0 deletions src/PageBlocks/PageBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Z3d0X\FilamentFabricator\PageBlocks;

use Filament\Forms\Components\Builder\Block;
use Z3d0X\FilamentFabricator\Models\Contracts\Page;

abstract class PageBlock
{
Expand All @@ -28,4 +29,15 @@ public static function mutateData(array $data): array
{
return $data;
}

/**
* Hook used to mass-preload related data to reduce the number of DB queries.
* For instance, to load model objects/data from their IDs
*
* @param (array{
* type: string,
* data: array,
* })[] $blocks - The array of blocks' data for the given page and the given block type
*/
public static function preloadRelatedData(Page $page, array &$blocks): void {}
}
1 change: 1 addition & 0 deletions src/Resources/PageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public static function form(Form $form): Form
->label(__('filament-fabricator::page-resource.labels.layout'))
->options(FilamentFabricator::getLayouts())
->default(fn () => FilamentFabricator::getDefaultLayoutName())
->live()
->required(),

Select::make('parent_id')
Expand Down

0 comments on commit 21b4510

Please sign in to comment.