92 lines
2.5 KiB
Markdown
92 lines
2.5 KiB
Markdown
# Clean Code Guidelines for Filament Resources
|
|
|
|
This document outlines the coding standards and structure for Filament Resources in this project.
|
|
|
|
## 1. Class Properties
|
|
|
|
Properties within the Resource class should be ordered alphabetically.
|
|
|
|
**Example:**
|
|
```php
|
|
protected static ?string $model = User::class;
|
|
protected static ?string $navigationGroup = 'Master';
|
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::UserGroup;
|
|
protected static ?string $navigationLabel = 'Pengguna';
|
|
protected static ?string $recordTitleAttribute = 'name';
|
|
protected static ?string $slug = 'master/users';
|
|
```
|
|
|
|
## 2. Form Structure
|
|
|
|
Form components should be structured with method calls in the following order:
|
|
|
|
1. **Basic**: `make`, `label`, `placeholder`
|
|
2. **HTML Attributes**: `autocomplete`, `autofocus`, etc.
|
|
3. **Validation**: `required`, `maxLength`, `email`, `unique`, `regex`, etc.
|
|
4. **Filament/Logic**: `relationship`, `live`, `afterStateUpdated`, etc.
|
|
|
|
**Formatting:**
|
|
- Use a blank line between each component definition.
|
|
|
|
**Example:**
|
|
```php
|
|
TextInput::make('name')
|
|
->label('Nama')
|
|
->placeholder('John Doe')
|
|
->autocomplete(false)
|
|
->autofocus()
|
|
->required()
|
|
->maxLength(100),
|
|
|
|
TextInput::make('email')
|
|
->label('Alamat Surel')
|
|
->placeholder('email@example.com')
|
|
->autocomplete(false)
|
|
->required()
|
|
->email(),
|
|
```
|
|
|
|
## 3. Table Structure
|
|
|
|
### Columns
|
|
Column definitions should be structured in the following order:
|
|
|
|
1. **Basic**: `make`, `label`
|
|
2. **Search & Sort**: `searchable`, `sortable` (These should be present for most fields)
|
|
3. **State & Attributes**: `getStateUsing`, `updateStateUsing`, `badge`, `icon`
|
|
4. **Formatting**: `dateTime`, `money`, etc.
|
|
|
|
**Formatting:**
|
|
- Use a blank line between each column definition.
|
|
|
|
**Example:**
|
|
```php
|
|
TextColumn::make('name')
|
|
->label('Nama')
|
|
->searchable()
|
|
->sortable(),
|
|
|
|
ToggleColumn::make('is_active')
|
|
->label('Status')
|
|
->sortable()
|
|
->updateStateUsing(...),
|
|
```
|
|
|
|
### Table Method Order
|
|
The methods chained to the `$table` object should follow this order:
|
|
|
|
1. `columns([\ ... ])`
|
|
2. `filters([\ ... ])`
|
|
3. `recordActions([\ ... ])` (or `actions`)
|
|
4. `toolbarActions([\ ... ])` (or `headerActions`)
|
|
5. `emptyStateIcon(...)`
|
|
6. `emptyStateDescription(...)`
|
|
7. `defaultSort(...)`
|
|
8. `deferFilters(...)`
|
|
9. Other configuration methods.
|
|
|
|
## 4. General Formatting
|
|
|
|
- Ensure consistent indentation.
|
|
- Always use a blank line to separate distinct logical blocks or component definitions to improve readability.
|