From 255afd020b0f73148af2acf845356376288ec47c Mon Sep 17 00:00:00 2001 From: Alex Popa Date: Wed, 8 Jan 2025 14:50:45 +0200 Subject: [PATCH] change RepeatableEntry with TableEntry --- .../BenefitResource/Pages/ViewBenefit.php | 31 ++++-- .../Widgets/BenefitTypesWidget.php | 27 ------ .../Admin/Resources/ServiceResource.php | 96 ++++++++++--------- .../ServiceResource/Pages/ViewService.php | 37 ++++--- .../Widgets/InterventionsWidget.php | 40 -------- .../ViewDetailedEvaluation.php | 15 ++- .../ServiceResource/Pages/ViewService.php | 43 ++++++--- .../Widgets/ListServiceInterventions.php | 47 --------- .../components/table-entry.blade.php | 61 +++++------- 9 files changed, 164 insertions(+), 233 deletions(-) delete mode 100644 app/Filament/Admin/Resources/BenefitResource/Widgets/BenefitTypesWidget.php delete mode 100644 app/Filament/Admin/Resources/ServiceResource/Widgets/InterventionsWidget.php delete mode 100644 app/Filament/Organizations/Resources/ServiceResource/Widgets/ListServiceInterventions.php diff --git a/app/Filament/Admin/Resources/BenefitResource/Pages/ViewBenefit.php b/app/Filament/Admin/Resources/BenefitResource/Pages/ViewBenefit.php index a4d4aa78..7fe93ff4 100644 --- a/app/Filament/Admin/Resources/BenefitResource/Pages/ViewBenefit.php +++ b/app/Filament/Admin/Resources/BenefitResource/Pages/ViewBenefit.php @@ -6,9 +6,11 @@ use App\Actions\BackAction; use App\Filament\Admin\Resources\BenefitResource; -use App\Filament\Admin\Resources\BenefitResource\Widgets\BenefitTypesWidget; +use App\Infolists\Components\TableEntry; use Filament\Actions\EditAction; -use Filament\Forms\Form; +use Filament\Infolists\Components\Section; +use Filament\Infolists\Components\TextEntry; +use Filament\Infolists\Infolist; use Filament\Resources\Pages\ViewRecord; use Illuminate\Contracts\Support\Htmlable; @@ -45,15 +47,24 @@ public function getTitle(): string|Htmlable return $this->record->name; } - public function form(Form $form): Form + public function infolist(Infolist $infolist): Infolist { - return $form->schema([]); - } + return $infolist->schema([ + Section::make() + ->maxWidth('3xl') + ->schema([ + TableEntry::make('benefitTypes') + ->hiddenLabel() + ->schema([ + TextEntry::make('name') + ->label(__('nomenclature.labels.benefit_type_name')) + ->hiddenLabel(), - protected function getFooterWidgets(): array - { - return [ - BenefitTypesWidget::class, - ]; + TextEntry::make('status') + ->label(__('nomenclature.labels.status')) + ->hiddenLabel(), + ]), + ]), + ]); } } diff --git a/app/Filament/Admin/Resources/BenefitResource/Widgets/BenefitTypesWidget.php b/app/Filament/Admin/Resources/BenefitResource/Widgets/BenefitTypesWidget.php deleted file mode 100644 index bbdfbe3c..00000000 --- a/app/Filament/Admin/Resources/BenefitResource/Widgets/BenefitTypesWidget.php +++ /dev/null @@ -1,27 +0,0 @@ -query(fn () => $this->record->benefitTypes()) - ->heading('') - ->columns([ - TextColumn::make('name') - ->label(__('nomenclature.labels.benefit_type_name')), - TextColumn::make('status'), - ]); - } -} diff --git a/app/Filament/Admin/Resources/ServiceResource.php b/app/Filament/Admin/Resources/ServiceResource.php index 7156c4c3..c4eb6513 100644 --- a/app/Filament/Admin/Resources/ServiceResource.php +++ b/app/Filament/Admin/Resources/ServiceResource.php @@ -71,54 +71,58 @@ public static function form(Form $form): Form ->options(CounselingSheet::options()), ]), - TableRepeater::make('serviceInterventions') - ->relationship('serviceInterventions') - ->label(__('nomenclature.headings.service_intervention')) - ->columnSpanFull() - ->addActionLabel(__('nomenclature.actions.add_intervention')) - ->schema([ - Placeholder::make('id') - ->label(__('nomenclature.labels.nr')) - ->content(function () { - static $index = 1; - - return $index++; - }) - ->hiddenLabel(), - TextInput::make('name') - ->columnSpanFull() - ->hiddenLabel() - ->maxLength(200) - ->label(__('nomenclature.labels.intervention_name')), - Toggle::make('status') + Section::make() + ->schema([ + TableRepeater::make('serviceInterventions') + ->relationship('serviceInterventions') + ->label(__('nomenclature.headings.service_intervention')) ->columnSpanFull() - ->live() - ->default(true) - ->afterStateUpdated(function (bool $state) { - if (! $state) { - dd('Modal cu inactivare de hard confirmation'); - } - }) - ->label(fn (Get $get) => $get('status') ? __('nomenclature.labels.active') : __('nomenclature.labels.inactive')), - ]) - ->deleteAction( - fn (Action $action) => $action - ->disabled(function (array $arguments, TableRepeater $component): bool { - $items = $component->getState(); - $currentItem = $items[$arguments['item']]; - - $serviceIntervention = ServiceIntervention::where('id', $currentItem['id']) - ->withCount('organizationIntervention') - ->first(); - - if (! $serviceIntervention) { - return false; - } - - return $serviceIntervention->organization_intervention_count > 0; - }) - ), + ->addActionLabel(__('nomenclature.actions.add_intervention')) + ->schema([ + Placeholder::make('id') + ->label(__('nomenclature.labels.nr')) + ->content(function () { + static $index = 1; + + return $index++; + }) + ->hiddenLabel(), + TextInput::make('name') + ->columnSpanFull() + ->hiddenLabel() + ->maxLength(200) + ->label(__('nomenclature.labels.intervention_name')), + + Toggle::make('status') + ->columnSpanFull() + ->live() + ->default(true) + ->afterStateUpdated(function (bool $state) { + if (! $state) { + dd('Modal cu inactivare de hard confirmation'); + } + }) + ->label(fn (Get $get) => $get('status') ? __('nomenclature.labels.active') : __('nomenclature.labels.inactive')), + ]) + ->deleteAction( + fn (Action $action) => $action + ->disabled(function (array $arguments, TableRepeater $component): bool { + $items = $component->getState(); + $currentItem = $items[$arguments['item']]; + + $serviceIntervention = ServiceIntervention::where('id', $currentItem['id']) + ->withCount('organizationIntervention') + ->first(); + + if (! $serviceIntervention) { + return false; + } + + return $serviceIntervention->organization_intervention_count > 0; + }) + ), + ]), ]); } diff --git a/app/Filament/Admin/Resources/ServiceResource/Pages/ViewService.php b/app/Filament/Admin/Resources/ServiceResource/Pages/ViewService.php index 6faeabbf..54e3ded7 100644 --- a/app/Filament/Admin/Resources/ServiceResource/Pages/ViewService.php +++ b/app/Filament/Admin/Resources/ServiceResource/Pages/ViewService.php @@ -7,13 +7,14 @@ use App\Actions\BackAction; use App\Enums\CounselingSheet; use App\Filament\Admin\Resources\ServiceResource; -use App\Filament\Admin\Resources\ServiceResource\Widgets\InterventionsWidget; use App\Filament\Organizations\Resources\InterventionServiceResource\Pages\EditCounselingSheet; use App\Infolists\Components\Notice; +use App\Infolists\Components\TableEntry; use Filament\Actions; use Filament\Actions\StaticAction; use Filament\Infolists\Components\Actions\Action; use Filament\Infolists\Components\Section; +use Filament\Infolists\Components\TextEntry; use Filament\Infolists\Infolist; use Filament\Resources\Pages\ViewRecord; use Illuminate\Contracts\Support\Htmlable; @@ -87,18 +88,30 @@ public function infolist(Infolist $infolist): Infolist ->link(), ), ]), - ]); - } - protected function hasInfolist(): bool - { - return true; - } + Section::make() + ->schema([ + TableEntry::make('serviceInterventions') + ->hiddenLabel() + ->schema([ + TextEntry::make('name') + ->label(__('nomenclature.labels.intervention_name')) + ->hiddenLabel(), - protected function getFooterWidgets(): array - { - return [ - InterventionsWidget::class, - ]; + TextEntry::make('institutions_count') + ->label(__('nomenclature.labels.institutions')) + ->hiddenLabel(), + + TextEntry::make('organizations_count') + ->label(__('nomenclature.labels.centers')) + ->hiddenLabel(), + + TextEntry::make('status') + ->label(__('nomenclature.labels.status')) + ->hiddenLabel(), + + ]), + ]), + ]); } } diff --git a/app/Filament/Admin/Resources/ServiceResource/Widgets/InterventionsWidget.php b/app/Filament/Admin/Resources/ServiceResource/Widgets/InterventionsWidget.php deleted file mode 100644 index d1b12264..00000000 --- a/app/Filament/Admin/Resources/ServiceResource/Widgets/InterventionsWidget.php +++ /dev/null @@ -1,40 +0,0 @@ -query( - fn () => $this->record->serviceInterventions() - ) - ->heading(null) - ->columns([ - TextColumn::make('name') - ->label(__('nomenclature.labels.intervention_name')), - - TextColumn::make('institutions_count') - ->label(__('nomenclature.labels.institutions')), - - TextColumn::make('organizations_count') - ->label(__('nomenclature.labels.centers')), - - TextColumn::make('status') - ->label(__('nomenclature.labels.status')), - - ]); - } -} diff --git a/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/DetailedEvaluation/ViewDetailedEvaluation.php b/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/DetailedEvaluation/ViewDetailedEvaluation.php index d14176c9..5e4bbeb7 100644 --- a/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/DetailedEvaluation/ViewDetailedEvaluation.php +++ b/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/DetailedEvaluation/ViewDetailedEvaluation.php @@ -13,6 +13,7 @@ use App\Infolists\Components\Actions\Edit; use App\Infolists\Components\DateEntry; use App\Infolists\Components\Location; +use App\Infolists\Components\TableEntry; use App\Services\Breadcrumb\BeneficiaryBreadcrumb; use Filament\Infolists\Components\Group; use Filament\Infolists\Components\RepeatableEntry; @@ -295,21 +296,25 @@ public function getPartnerSchema(): array public function getDetailedEvaluationSchema(): array { return [ - RepeatableEntry::make('detailedEvaluationSpecialists') + TableEntry::make('detailedEvaluationSpecialists') ->columns(4) ->label(__('beneficiary.section.detailed_evaluation.labels.specialists')) ->schema([ TextEntry::make('full_name') - ->label(__('beneficiary.section.detailed_evaluation.labels.full_name')), + ->label(__('beneficiary.section.detailed_evaluation.labels.full_name')) + ->hiddenLabel(), TextEntry::make('institution') - ->label(__('beneficiary.section.detailed_evaluation.labels.institution')), + ->label(__('beneficiary.section.detailed_evaluation.labels.institution')) + ->hiddenLabel(), TextEntry::make('relationship') - ->label(__('beneficiary.section.detailed_evaluation.labels.relationship')), + ->label(__('beneficiary.section.detailed_evaluation.labels.relationship')) + ->hiddenLabel(), DateEntry::make('date') - ->label(__('beneficiary.section.detailed_evaluation.labels.contact_date')), + ->label(__('beneficiary.section.detailed_evaluation.labels.contact_date')) + ->hiddenLabel(), ]), RepeatableEntry::make('meetings') diff --git a/app/Filament/Organizations/Resources/ServiceResource/Pages/ViewService.php b/app/Filament/Organizations/Resources/ServiceResource/Pages/ViewService.php index 0977e0d1..08fe7490 100644 --- a/app/Filament/Organizations/Resources/ServiceResource/Pages/ViewService.php +++ b/app/Filament/Organizations/Resources/ServiceResource/Pages/ViewService.php @@ -9,10 +9,13 @@ use App\Filament\Organizations\Resources\InterventionServiceResource\Pages\EditCounselingSheet; use App\Filament\Organizations\Resources\ServiceResource; use App\Infolists\Components\Notice; +use App\Infolists\Components\TableEntry; +use App\Models\BeneficiaryIntervention; use Filament\Actions\EditAction; use Filament\Actions\StaticAction; use Filament\Infolists\Components\Actions\Action; use Filament\Infolists\Components\Section; +use Filament\Infolists\Components\TextEntry; use Filament\Infolists\Infolist; use Filament\Resources\Pages\ViewRecord; use Illuminate\Contracts\Support\Htmlable; @@ -47,6 +50,12 @@ protected function getHeaderActions(): array public function infolist(Infolist $infolist): Infolist { + $this->getRecord() + ->load([ + 'interventions.serviceInterventionWithoutStatusCondition', + 'interventions.beneficiaryInterventions.interventionPlan', + ]); + return $infolist->schema([ Section::make() ->visible(fn () => $this->getRecord()->serviceWithoutStatusCondition->counseling_sheet) @@ -87,18 +96,30 @@ public function infolist(Infolist $infolist): Infolist ->modalAutofocus(false), ), ]), - ]); - } - protected function hasInfolist(): bool - { - return true; - } + TableEntry::make('interventions') + ->columnSpanFull() + ->hiddenLabel() + ->schema([ + TextEntry::make('serviceInterventionWithoutStatusCondition.name') + ->hiddenLabel() + ->label(__('service.labels.interventions')), - protected function getHeaderWidgets(): array - { - return [ - ServiceResource\Widgets\ListServiceInterventions::class, - ]; + TextEntry::make('cases') + ->hiddenLabel() + ->label(__('service.labels.cases')) + ->default( + fn ($record) => $record->beneficiaryInterventions + ?->map(fn (BeneficiaryIntervention $beneficiaryIntervention) => $beneficiaryIntervention->interventionPlan->beneficiary_id) + ->unique() + ->count() + ), + + TextEntry::make('status') + ->hiddenLabel() + ->label(__('service.labels.status')), + ]), + + ]); } } diff --git a/app/Filament/Organizations/Resources/ServiceResource/Widgets/ListServiceInterventions.php b/app/Filament/Organizations/Resources/ServiceResource/Widgets/ListServiceInterventions.php deleted file mode 100644 index 4fa0d72e..00000000 --- a/app/Filament/Organizations/Resources/ServiceResource/Widgets/ListServiceInterventions.php +++ /dev/null @@ -1,47 +0,0 @@ -query( - fn () => $this->record->interventions() - ->with([ - 'serviceInterventionWithoutStatusCondition', - 'beneficiaryInterventions.interventionPlan', - ]) - ) - ->columns([ - TextColumn::make('serviceInterventionWithoutStatusCondition.name') - ->label(__('service.labels.interventions')), - - TextColumn::make('cases') - ->label(__('service.labels.cases')) - ->default( - fn ($record) => $record->beneficiaryInterventions - ?->map(fn (BeneficiaryIntervention $beneficiaryIntervention) => $beneficiaryIntervention->interventionPlan->beneficiary_id) - ->unique() - ->count() - ), - - TextColumn::make('status') - ->label(__('service.labels.status')), - ]) - ->heading(null); - } -} diff --git a/resources/views/infolists/components/table-entry.blade.php b/resources/views/infolists/components/table-entry.blade.php index 20e921e5..44af421e 100644 --- a/resources/views/infolists/components/table-entry.blade.php +++ b/resources/views/infolists/components/table-entry.blade.php @@ -14,7 +14,7 @@ @endphp - +
merge($getExtraAttributes())->class([ @@ -37,14 +37,14 @@ 'xl:ring-gray-950/5 dark:xl:ring-white/20' => ! $hasContainers && $breakPoint === 'xl', '2xl:ring-gray-950/5 dark:2xl:ring-white/20' => ! $hasContainers && $breakPoint === '2xl', ])> - - + $hasHiddenHeader, 'filament-table-repeater-header rounded-t-xl overflow-hidden border-b border-gray-950/5 dark:border-white/20' => ! $hasHiddenHeader, ])> - + @foreach ($headers as $key => $header) - + @endforeach - - + + + @foreach($row->getComponents() as $cell) @if(! $cell instanceof \Filament\Forms\Components\Hidden && ! $cell->isHidden()) + @php + $cellKey = method_exists($cell, 'getName') ? $cell->getName() : $cell->getId(); +// if (!$cell->getState()) +// debug($cell->getState(), $cell->getStatePath()); + @endphp + @endforeach @else - - - + + @endif -
$loop->first, @@ -55,20 +55,15 @@ default => 'text-left rtl:text-right' } ]) - @if ($header['width']) - style="width: {{ $header['width'] }}" - @endif + @style([ + 'width: ' . $header['width'] => $header['width'], + ]) > {{ $header['label'] }} - @if ($header['required']) - - * - - @endif -
$cell->isLabelHidden(), - ]) - @php - $cellKey = method_exists($cell, 'getName') ? $cell->getName() : $cell->getId(); - @endphp - @if ( - $columnWidths && - isset($columnWidths[$cellKey]) - ) - style="width: {{ $columnWidths[$cellKey] }}" + class="filament-table-repeater-column p-2" + @if ($columnWidths && isset($columnWidths[$cellKey])) + style="width: {{$columnWidths[$cellKey]}}" @endif > {{ $cell }} @@ -101,17 +92,17 @@ class="filament-table-repeater-rows-wrapper divide-y divide-gray-950/5 dark:divi @endif @endforeach -
+ + {{ $emptyLabel ?: __('filament-table-repeater::components.repeater.empty.label') }} -
+
@endif