Skip to content

Commit

Permalink
Builder wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adrolli committed Dec 4, 2024
1 parent 7b56e32 commit fb91c83
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 76 deletions.
112 changes: 41 additions & 71 deletions packages/builder/DEVLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions packages/builder/src/Blocks/MarkdownEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions packages/builder/src/Blocks/Publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;',
],
],
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/src/Blocks/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()',
Expand Down
74 changes: 74 additions & 0 deletions packages/builder/src/Blocks/SimpleStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

namespace Moox\Builder\Blocks;

class SimpleStatus extends AbstractBlock
{
private bool $sortable;

private bool $searchable;

private bool $toggleable;

public function __construct(
string $name = 'status',
string $label = 'Status',
string $description = 'Adds a simple status field based on an enum to a resource',
array $enum = ['New', 'Open', 'Pending', 'Closed', 'Rejected', 'Cancelled'],
bool $nullable = false,
bool $sortable = true,
bool $searchable = true,
bool $toggleable = true,
) {
parent::__construct($name, $label, $description, $nullable);

$this->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})
])",
];
}
}
4 changes: 3 additions & 1 deletion packages/builder/src/Blocks/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()',
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ protected function generateFormSchema(): array
'isMeta' => true,
'fields' => ['static::getTaxonomyFields()'],
'order' => 20,
'hideHeader' => true,
];
}

Expand Down
2 changes: 0 additions & 2 deletions packages/builder/src/Presets/FullItemPreset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -48,7 +47,6 @@ protected function initializePreset(): void
),
new Author,
new Publish,
new SoftDelete,
];
}
}
8 changes: 8 additions & 0 deletions packages/builder/src/Presets/PublishableItemPreset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
),
];
}
}
2 changes: 2 additions & 0 deletions packages/builder/src/Presets/SimpleItemPreset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,6 +58,7 @@ protected function initializePreset(): void
createForm: '\Moox\Tag\Forms\TaxonomyCreateForm::class',
),
new AddressSection,
new SimpleStatus,
];
}
}
3 changes: 2 additions & 1 deletion packages/builder/src/Services/Entity/SectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fb91c83

Please sign in to comment.