Skip to content

Commit

Permalink
feat: add localization to forms and tables (cachethq#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
swoga authored Oct 13, 2024
1 parent 2b069f7 commit bd2bc81
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 8 deletions.
8 changes: 8 additions & 0 deletions src/Filament/Resources/ComponentGroupResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ public static function form(Form $form): Form
->schema([
Forms\Components\Section::make()->columns(2)->schema([
Forms\Components\TextInput::make('name')
->label(__('Name'))
->required()
->maxLength(255)
->columnSpanFull(),
Forms\Components\ToggleButtons::make('visible')
->label(__('Visible'))
->inline()
->options(ResourceVisibilityEnum::class)
->default(ResourceVisibilityEnum::guest)
->required()
->columnSpanFull(),
Forms\Components\ToggleButtons::make('collapsed')
->label(__('Collapsed'))
->required()
->inline()
->options(ComponentGroupVisibilityEnum::class)
Expand All @@ -49,17 +52,22 @@ public static function table(Table $table): Table
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->label(__('Name'))
->searchable(),
Tables\Columns\TextColumn::make('visible')
->label(__('Visible'))
->badge()
->sortable(),
Tables\Columns\TextColumn::make('collapsed')
->label(__('Collapsed'))
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->label(__('Created at'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->label(__('Updated at'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Expand Down
12 changes: 12 additions & 0 deletions src/Filament/Resources/ComponentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ public static function form(Form $form): Form
->schema([
Forms\Components\Section::make()->columns(2)->schema([
Forms\Components\TextInput::make('name')
->label(__('Name'))
->required()
->maxLength(255),
Forms\Components\ToggleButtons::make('status')
->label(__('Status'))
->inline()
->columnSpanFull()
->options(ComponentStatusEnum::class)
->required(),
Forms\Components\MarkdownEditor::make('description')
->label(__('Description'))
->maxLength(255)
->columnSpanFull(),
Forms\Components\Select::make('component_group_id')
Expand All @@ -39,6 +42,7 @@ public static function form(Form $form): Form
->preload()
->label(__('Component Group')),
Forms\Components\TextInput::make('link')
->label(__('Link'))
->url()
->hint(__('An optional link to the component.')),
]),
Expand All @@ -57,28 +61,36 @@ public static function table(Table $table): Table
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->label(__('Name'))
->searchable(),
Tables\Columns\TextColumn::make('status')
->label(__('Status'))
->badge()
->sortable(),
Tables\Columns\TextColumn::make('order')
->label(__('Order'))
->numeric()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('group.name')
->label(__('Group'))
->sortable(),
Tables\Columns\IconColumn::make('enabled')
->label(__('Enabled'))
->boolean()
->toggleable(isToggledHiddenByDefault: false),
Tables\Columns\TextColumn::make('created_at')
->label(__('Created at'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->label(__('Updated at'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('deleted_at')
->label(__('Deleted at'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,37 @@
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;

class ComponentsRelationManager extends RelationManager
{
protected static string $relationship = 'components';

public static function getTitle(Model $ownerRecord, string $pageClass): string
{
return __('Components');
}

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->label(__('Name'))
->required()
->maxLength(255),
Forms\Components\ToggleButtons::make('status')
->label(__('Status'))
->inline()
->columnSpanFull()
->options(ComponentStatusEnum::class)
->required(),
Forms\Components\MarkdownEditor::make('description')
->label(__('Description'))
->maxLength(255)
->columnSpanFull(),
Forms\Components\TextInput::make('link')
->label(__('Link'))
->url()
->hint(__('An optional link to the component.')),
]);
Expand All @@ -38,12 +48,17 @@ public function table(Table $table): Table
{
return $table
->recordTitleAttribute('name')
->modelLabel(__('Component'))
->pluralModelLabel(__('Components'))
->columns([
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('name')
->label(__('Name')),
Tables\Columns\TextColumn::make('status')
->label(__('Status'))
->badge()
->sortable(),
Tables\Columns\IconColumn::make('enabled')
->label(__('Enabled'))
->boolean()
->toggleable(isToggledHiddenByDefault: false),
])
Expand Down
19 changes: 18 additions & 1 deletion src/Filament/Resources/IncidentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,24 @@ public static function form(Form $form): Form
->schema([
Section::make()->schema([
Forms\Components\TextInput::make('name')
->label(__('Name'))
->required()
->maxLength(255),
Forms\Components\ToggleButtons::make('status')
->label(__('Status'))
->inline()
->columnSpanFull()
->options(IncidentStatusEnum::class)
->required(),
Forms\Components\MarkdownEditor::make('message')
->label(__('Message'))
->required()
->columnSpanFull(),
Forms\Components\DateTimePicker::make('occurred_at')
->label(__('Occurred at'))
->helperText(__('The incident\'s created timestamp will be used if left empty.')),
Forms\Components\ToggleButtons::make('visible')
->label(__('Visible'))
->inline()
->options(ResourceVisibilityEnum::class)
->default(ResourceVisibilityEnum::guest)
Expand Down Expand Up @@ -85,39 +90,48 @@ public static function table(Table $table): Table
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->label(__('Name'))
->searchable(),
Tables\Columns\TextColumn::make('status')
->label(__('Status'))
->sortable()
->badge(),
Tables\Columns\TextColumn::make('visible')
->label(__('Visible'))
->sortable()
->badge(),
Tables\Columns\IconColumn::make('stickied')
->label(__('Stickied'))
->toggleable(isToggledHiddenByDefault: true)
->boolean(),
Tables\Columns\TextColumn::make('occurred_at')
->label(__('Occurred at'))
->dateTime()
->sortable(),
Tables\Columns\IconColumn::make('notifications')
->label(__('Notified Subscribers'))
->boolean()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('created_at')
->label(__('Created at'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: false),
Tables\Columns\TextColumn::make('updated_at')
->label(__('Updated at'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('deleted_at')
->label(__('Deleted at'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
Tables\Filters\TrashedFilter::make(),
Tables\Filters\SelectFilter::make('status')
->label(__('Status'))
->options(IncidentStatusEnum::class),
])
->actions([
Expand All @@ -135,8 +149,11 @@ public static function table(Table $table): Table
->send();
})
->form([
Forms\Components\MarkdownEditor::make('message')->required(),
Forms\Components\MarkdownEditor::make('message')
->label(__('Message'))
->required(),
Forms\Components\ToggleButtons::make('status')
->label(__('Status'))
->options(IncidentStatusEnum::class)
->inline()
->required(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;

class ComponentsRelationManager extends RelationManager
{
protected static string $relationship = 'components';

public static function getTitle(Model $ownerRecord, string $pageClass): string
{
return __('Components');
}

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->label(__('Name'))
->searchable(),
Forms\Components\ToggleButtons::make('status')
->label(__('Status'))
->inline()
->options(ComponentStatusEnum::class)
->required(),
Expand All @@ -31,9 +39,13 @@ public function table(Table $table): Table
{
return $table
->recordTitleAttribute('name')
->modelLabel(__('Component'))
->pluralModelLabel(__('Components'))
->columns([
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('name')
->label(__('Name')),
Tables\Columns\TextColumn::make('status')
->label(__('Status'))
->badge()
->sortable(),
])
Expand All @@ -45,6 +57,7 @@ public function table(Table $table): Table
->form(fn (Tables\Actions\AttachAction $action): array => [
$action->getRecordSelect(),
Forms\Components\ToggleButtons::make('status')
->label(__('Status'))
->inline()
->columnSpanFull()
->options(ComponentStatusEnum::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,50 @@
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;

class IncidentUpdatesRelationManager extends RelationManager
{
protected static string $relationship = 'incidentUpdates';

public static function getTitle(Model $ownerRecord, string $pageClass): string
{
return __('Incident Updates');
}

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\MarkdownEditor::make('message')
->label(__('Message'))
->required()
->columnSpanFull(),
Forms\Components\Select::make('user_id')
->label(__('User'))
->hint(__('The user who reported the incident.'))
->relationship('user', 'name')
->searchable()
->preload()
->createOptionForm([
Forms\Components\TextInput::make('name')
->label(__('Name'))
->required()
->maxLength(255),
Forms\Components\TextInput::make('email')
->label(__('Email'))
->required()
->email()
->maxLength(255),
Forms\Components\TextInput::make('password')
->label(__('Password'))
->required()
->password()
->confirmed()
->minLength(8),
]),
Forms\Components\ToggleButtons::make('status')
->label(__('Status'))
->inline()
->columnSpanFull()
->options(IncidentStatusEnum::class)
Expand All @@ -51,26 +63,34 @@ public function table(Table $table): Table
{
return $table
->recordTitleAttribute('title')
->modelLabel(__('Incident Update'))
->pluralModelLabel(__('Incident Updates'))
->columns([
Tables\Columns\TextColumn::make('incident.name')
->label(__('Incident'))
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('status')
->label(__('Status'))
->badge()
->sortable(),
Tables\Columns\TextColumn::make('user.name')
->label(__('User'))
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->label(__('Created at'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->label(__('Updated at'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
Tables\Filters\SelectFilter::make('status')
->label(__('Status'))
->options(IncidentStatusEnum::class),
])
->headerActions([
Expand Down
Loading

0 comments on commit bd2bc81

Please sign in to comment.