From fb91c83b05a5615b2c47b5f44b67a3d8cda5d307 Mon Sep 17 00:00:00 2001 From: Alf Drollinger Date: Wed, 4 Dec 2024 02:36:23 +0100 Subject: [PATCH] Builder wip --- packages/builder/DEVLOG.md | 112 +++++++----------- .../builder/src/Blocks/MarkdownEditor.php | 1 + packages/builder/src/Blocks/Publish.php | 1 + packages/builder/src/Blocks/Simple.php | 2 +- packages/builder/src/Blocks/SimpleStatus.php | 74 ++++++++++++ packages/builder/src/Blocks/Taxonomy.php | 4 +- .../Generators/Entity/ResourceGenerator.php | 1 + .../builder/src/Presets/FullItemPreset.php | 2 - .../src/Presets/PublishableItemPreset.php | 8 ++ .../builder/src/Presets/SimpleItemPreset.php | 2 + .../src/Services/Entity/SectionManager.php | 3 +- 11 files changed, 134 insertions(+), 76 deletions(-) create mode 100644 packages/builder/src/Blocks/SimpleStatus.php diff --git a/packages/builder/DEVLOG.md b/packages/builder/DEVLOG.md index f31e052b4..7605488aa 100644 --- a/packages/builder/DEVLOG.md +++ b/packages/builder/DEVLOG.md @@ -4,71 +4,41 @@ We work on these tasks in order from top to bottom: ## Tasks -### Sections (CURRENTLY WIP) +### General (WIP) -Current issues with section implementation: +From publishable item we learn that TitleWithSlug should implement it's own section, it currently seems to add a comma, why? +Another issue is that the List page is missing the eloquent builder use statement, why? +After fixing that, the list page has other issues too. +Tabs are not generated from the Publish block, should overwrite Tabs block -1. ✓ Code Generation Format +We need to document the new section API and section classes. - - [x] Generated code is now properly formatted line by line - - [x] Pint can handle the formatting - -2. ✓ Section Structure - - - [x] Taxonomy section appears only once - - [x] Taxonomy in meta grid with actions - - [x] Array brackets fixed for taxonomy fields - - [x] Sections in correct grids based on meta flag - -3. Page Actions - - - [ ] Page generators need section-based API implementation - - [ ] Add section support to AbstractPageGenerator - - [ ] Update page templates to handle sections - - [ ] Review action placement in templates: - - ListPage: getHeaderActions() - - ViewPage: getHeaderActions() - - CreatePage: getHeaderActions() - - EditPage: getHeaderActions() - -4. Section Order - - - [ ] Order determined by preset block order - - [ ] Individual blocks can suggest order but preset has final say - - [ ] No need for explicit order in simple blocks - -5. Section Headers - - [ ] Empty section name for actions (currently shows 'resource_actions') - - [ ] Consistent capitalization (e.g., 'Address' vs 'address') - - [ ] Option to hide section header entirely - -Next steps: - -1. Implement section support in AbstractPageGenerator -2. Update page templates for section handling -3. Review section ordering approach -4. Implement flexible section headers +And we need to fix the issue with the FullItem, maybe we need a new way to handle relations like author, user, etc. +Failed to create entity: SQLSTATE[HY000]: General error: 1824 Failed to open the referenced table 'authors' (Connection: mysql, SQL: alter table `preview_preview_full_items` add constraint `preview_preview_full_items_author_id_foreign` foreign key (`author_id`) references `authors` (`id`) on delete cascade) ### Entity - [WIP] We currently work on generating Presets in Preview Context and optimize the generated resources - - [WIP] PreviewSimItem is working like a charm including filters and bulk actions - - [WIP] Need to generate Taxonomy and Relations partials, may already work partially - - [WIP] Taxonomy block needs to be finished. Does not show the taxonomy fields in form or table - - [ ] Config is generated with wrong class names and wrong table names, I prepared the SimpleItemPreset for that, so all information needed should be used from there - - [ ] Resource is hardcoded with comment, that is maybe fixed in the Taxonomy block, see comment there - - [ ] Now taxonomies should be shown, just columns andfilters are missing - - [ ] Relations needs - - [ ] to be implemented first, because relations is a bit different to taxonomies - - [ ] to be generated in the Resource - - [ ] to be generated in the Config - - [ ] Polish Simple Resource with a filterable date field, maybe add a status field too - - [ ] PreviewPubItem + - [WIP] PreviewSimItem is working like a charm including actions, filters, bulk actions and taxonomies + - [ ] Delete does not delete the record + - [ ] Status field is not working as expected, completely weird behavior + - [ ] Uniqueness is not implemented or not used? + - [ ] Taxonomies needs to be tested, TaxonomyInPages has issues + - [ ] Page / AbstractPage generators need section-based API implementation? + - [ ] Relations needs + - [ ] to be implemented first, because relations is a bit different to taxonomies + - [ ] to be generated in the Resource + - [ ] to be generated in the Config + - [WIP] PreviewPubItem - [ ] We need to bring this on the Simple Item level first - - [ ] We need to add Tabs and Taxonomies here + - [ ] Tabs needs to be implemented and should replace the simple tabs + - [ ] Taxonomies needs to be tested, TaxonomyInPages has issues + - [ ] TitleWithSlug should implement it's own section + - [ ] Relations + - [ ] Actions need to work as expected - [ ] We need to work on the publish feature with custom actions, see https://youtu.be/bjv_RiBUtNs?si=cellheQYyxhiHxRg&t=167 - [ ] Then we need to implement the relation feature - - [ ] PreviewFullItem + - [WIP] PreviewFullItem - [ ] We need to bring this on the Publish Item level first - [ ] We need to work on all existing blocks and generate theme here - [ ] Maybe add the three widgets here, needs wiget-generator and template? @@ -92,12 +62,13 @@ Next steps: - [ ] TaxonomyInPages - needs that mount method in ViewPage - [ ] Refactor DeleteCommand to use new services - [ ] Add --migration option to create command -- [ ] Would Builder now be able to generate itself? +- [ ] Would Builder now be able to generate itself based on the current migrations? - [ ] How would we generate a complete different type of resource, like a Media Manager? The only thing we need is a different table, switching to a grid. -- All Blocks need to be updated: +- All Blocks need to be updated - [ ] Toggleable option like in Text - [ ] Filterable option like in Text, and filterable needs to be implemented in ResourceGenerator (only generate filters if filterable is true) + - [ ] The new section API ### Merge and Release @@ -151,11 +122,19 @@ Missing: - Relations configuration - Validation rules - Config entries +- Sections After adding the missing data, we need to implement the RestoreService and use it in the UI. -### Extras +### Ideas +- [ ] Tests + - [ ] Write tests for all services + - [ ] Write tests for all generators + - [ ] Write tests for all commands + - [ ] Write build tests using presets, blocks and contexts + - [ ] Generate Factories from Blocks + - [ ] Generate Tests from Blocks - [ ] Implement App Generator command - [ ] Add (Moox) Packages to composer.json - [ ] Create PanelProvider @@ -169,18 +148,6 @@ After adding the missing data, we need to implement the RestoreService and use i - [ ] Dashboard Widgets https://github.com/Flowframe/laravel-trend and https://github.com/leandrocfe/filament-apex-charts - [ ] Im and Export, see https://github.com/pxlrbt/filament-excel and https://github.com/eighty9nine/filament-excel-import or https://github.com/konnco/filament-import - [ ] PDF see https://laraveldaily.com/post/filament-export-record-to-pdf-two-ways or https://tapansharma.dev/blog/a-guide-to-work-with-pdf-generation-in-filamentphp - -### Tests - -- [ ] Write tests for all services -- [ ] Write tests for all generators -- [ ] Write tests for all commands -- [ ] Write build tests using presets, blocks and contexts -- [ ] Generate Factories from Blocks -- [ ] Generate Tests from Blocks - -### Ideas - - [ ] Option to generate from Blueprint - [ ] Create BlueprintValidator service - [ ] --blueprint option for CreateCommand @@ -195,7 +162,10 @@ After adding the missing data, we need to implement the RestoreService and use i - [ ] Add more Blocks - [ ] https://github.com/lucasgiovanny/filament-multiselect-two-sides - for Builder - [ ] ResourceLinkTable - https://www.youtube.com/watch?v=bjv_RiBUtNs - - [ ] Most wanted like Phone, Address etc. + - [ ] TipTap Editor + - [ ] Code Editor + - [ ] Languages, Currency, Country, Timezone, etc. + - [ ] Phone, Address with validation ## Packages diff --git a/packages/builder/src/Blocks/MarkdownEditor.php b/packages/builder/src/Blocks/MarkdownEditor.php index 2000a5e0f..141143799 100644 --- a/packages/builder/src/Blocks/MarkdownEditor.php +++ b/packages/builder/src/Blocks/MarkdownEditor.php @@ -12,6 +12,7 @@ public function __construct( string $description, bool $nullable = false, protected bool $searchable = false, + // push into section, so that preset can use sections ) { parent::__construct($name, $label, $description, $nullable); diff --git a/packages/builder/src/Blocks/Publish.php b/packages/builder/src/Blocks/Publish.php index 11d4b2942..c30aece22 100644 --- a/packages/builder/src/Blocks/Publish.php +++ b/packages/builder/src/Blocks/Publish.php @@ -34,6 +34,7 @@ public function __construct( 'pages' => [ 'list' => [ 'use Moox\Core\Traits\SinglePublishInListPage;', + // This is missing in the generated list page, why? 'use Illuminate\Database\Eloquent\Builder;', ], ], diff --git a/packages/builder/src/Blocks/Simple.php b/packages/builder/src/Blocks/Simple.php index b72989cf3..88973f05d 100644 --- a/packages/builder/src/Blocks/Simple.php +++ b/packages/builder/src/Blocks/Simple.php @@ -30,7 +30,7 @@ public function __construct( $this->traits['pages']['create'] = ['Moox\Core\Traits\SingleSimpleInCreatePage']; $this->traits['pages']['edit'] = ['Moox\Core\Traits\SingleSimpleInEditPage']; - $this->addSection('resource_actions', 100) + $this->addSection('meta') ->asMeta() ->withFields([ 'static::getSimpleFormActions()', diff --git a/packages/builder/src/Blocks/SimpleStatus.php b/packages/builder/src/Blocks/SimpleStatus.php new file mode 100644 index 000000000..bb4c64536 --- /dev/null +++ b/packages/builder/src/Blocks/SimpleStatus.php @@ -0,0 +1,74 @@ +sortable = $sortable; + $this->searchable = $searchable; + $this->toggleable = $toggleable; + + $this->useStatements['resource'] = [ + 'forms' => ['use Filament\Forms\Components\Select;'], + 'columns' => ['use Filament\Tables\Columns\TextColumn;'], + 'filters' => [ + 'use Filament\Tables\Filters\Filter;', + 'use Illuminate\Database\Eloquent\Builder;', + ], + ]; + + $options = '["'.implode('", "', $enum).'"]'; + + $this->addSection('status') + ->asMeta() + ->hideHeader() + ->withFields([ + 'Select::make(\''.$this->name.'\') + ->label(\''.$this->label.'\') + ->placeholder(__(\'core::core.status\')) + ->options('.$options.')', + ]); + + $this->tableColumns['resource'] = [ + "TextColumn::make('{$this->name}')" + .($this->sortable ? '->sortable()' : '') + .($this->searchable ? '->searchable()' : '') + .($this->toggleable ? '->toggleable()' : ''), + ]; + + $this->migrations['fields'] = [ + "\$table->enum('{$this->name}', ['".implode("', '", $enum)."'])" + .($this->nullable ? '->nullable()' : ''), + ]; + + $this->filters['resource'] = [ + "Filter::make('{$this->name}') + ->form([ + Select::make('{$this->name}') + ->label('{$this->label}') + ->placeholder(__('core::core.search')) + ->options({$options}) + ])", + ]; + } +} diff --git a/packages/builder/src/Blocks/Taxonomy.php b/packages/builder/src/Blocks/Taxonomy.php index c205658b0..7f5957480 100644 --- a/packages/builder/src/Blocks/Taxonomy.php +++ b/packages/builder/src/Blocks/Taxonomy.php @@ -27,7 +27,9 @@ public function __construct( ) { parent::__construct($name, $label, $description, $nullable); - $this->addSection('taxonomy', 20) + $this->addSection('taxonomy') + ->asMeta() + ->hideHeader() ->withFields([ 'static::getTaxonomyFields()', ]); diff --git a/packages/builder/src/Generators/Entity/ResourceGenerator.php b/packages/builder/src/Generators/Entity/ResourceGenerator.php index 8b47c650d..bf521f6f1 100644 --- a/packages/builder/src/Generators/Entity/ResourceGenerator.php +++ b/packages/builder/src/Generators/Entity/ResourceGenerator.php @@ -225,6 +225,7 @@ protected function generateFormSchema(): array 'isMeta' => true, 'fields' => ['static::getTaxonomyFields()'], 'order' => 20, + 'hideHeader' => true, ]; } diff --git a/packages/builder/src/Presets/FullItemPreset.php b/packages/builder/src/Presets/FullItemPreset.php index a6b886cbd..846676190 100644 --- a/packages/builder/src/Presets/FullItemPreset.php +++ b/packages/builder/src/Presets/FullItemPreset.php @@ -7,7 +7,6 @@ use Moox\Builder\Blocks\Author; use Moox\Builder\Blocks\FileUpload; use Moox\Builder\Blocks\Publish; -use Moox\Builder\Blocks\SoftDelete; use Moox\Builder\Blocks\Text; use Moox\Builder\Blocks\TextArea; @@ -48,7 +47,6 @@ protected function initializePreset(): void ), new Author, new Publish, - new SoftDelete, ]; } } diff --git a/packages/builder/src/Presets/PublishableItemPreset.php b/packages/builder/src/Presets/PublishableItemPreset.php index c6fde944e..0836b2f1b 100644 --- a/packages/builder/src/Presets/PublishableItemPreset.php +++ b/packages/builder/src/Presets/PublishableItemPreset.php @@ -4,7 +4,9 @@ namespace Moox\Builder\Presets; +use Moox\Builder\Blocks\MarkdownEditor; use Moox\Builder\Blocks\Publish; +use Moox\Builder\Blocks\Tabs; use Moox\Builder\Blocks\TitleWithSlug; class PublishableItemPreset extends AbstractPreset @@ -20,6 +22,12 @@ protected function initializePreset(): void nullable: false ), new Publish, + new Tabs, + new MarkdownEditor( + name: 'content', + label: 'Content', + description: 'The content of the item', + ), ]; } } diff --git a/packages/builder/src/Presets/SimpleItemPreset.php b/packages/builder/src/Presets/SimpleItemPreset.php index 2fdf694c8..6d87a816c 100644 --- a/packages/builder/src/Presets/SimpleItemPreset.php +++ b/packages/builder/src/Presets/SimpleItemPreset.php @@ -6,6 +6,7 @@ use Moox\Builder\Blocks\Sections\AddressSection; use Moox\Builder\Blocks\Simple; +use Moox\Builder\Blocks\SimpleStatus; use Moox\Builder\Blocks\Tabs; use Moox\Builder\Blocks\Taxonomy; use Moox\Builder\Blocks\Text; @@ -57,6 +58,7 @@ protected function initializePreset(): void createForm: '\Moox\Tag\Forms\TaxonomyCreateForm::class', ), new AddressSection, + new SimpleStatus, ]; } } diff --git a/packages/builder/src/Services/Entity/SectionManager.php b/packages/builder/src/Services/Entity/SectionManager.php index 9e17f38b6..5c03b9f48 100644 --- a/packages/builder/src/Services/Entity/SectionManager.php +++ b/packages/builder/src/Services/Entity/SectionManager.php @@ -65,7 +65,8 @@ public function formatSections(array $sections): string $output = []; foreach ($sections as $section) { if ($section['name'] === 'taxonomy') { - $output[] = " Section::make('Taxonomy') + $sectionTitle = $section['hideHeader'] ?? false ? "''" : "'Taxonomy'"; + $output[] = " Section::make({$sectionTitle}) ->schema(static::getTaxonomyFields())"; continue;