fix(004): align backup item counts with policy version

This commit is contained in:
Ahmed Darrazi 2025-12-23 14:15:51 +01:00
parent 92bf7af017
commit f09967e3ab

View File

@ -51,19 +51,26 @@ public function table(Table $table): Table
->label('Assignments') ->label('Assignments')
->badge() ->badge()
->color('info') ->color('info')
->formatStateUsing(fn ($state) => is_array($state) ? count($state) : 0), ->getStateUsing(function (BackupItem $record): int {
$assignments = $record->policyVersion?->assignments ?? $record->assignments ?? [];
return is_array($assignments) ? count($assignments) : 0;
}),
Tables\Columns\TextColumn::make('scope_tags') Tables\Columns\TextColumn::make('scope_tags')
->label('Scope Tags') ->label('Scope Tags')
->badge()
->separator(',')
->default('—') ->default('—')
->formatStateUsing(function ($state, BackupItem $record) { ->getStateUsing(function (BackupItem $record): array {
// Get scope tags from PolicyVersion if available $tags = $record->policyVersion?->scope_tags['names'] ?? [];
if ($record->policyVersion && ! empty($record->policyVersion->scope_tags)) {
$tags = $record->policyVersion->scope_tags; return is_array($tags) ? $tags : [];
if (is_array($tags) && isset($tags['names'])) { })
return implode(', ', $tags['names']); ->formatStateUsing(function ($state): string {
} if (is_array($state)) {
return $state === [] ? '—' : implode(', ', $state);
}
if (is_string($state) && $state !== '') {
return $state;
} }
return '—'; return '—';