Files

72 lines
2.7 KiB
Dart

import 'package:flutter/widgets.dart';
import '../../../core/api_gateway.dart';
import '../settings_group.dart';
import 'storage_controls.dart';
import 'storage_models.dart';
class StorageCleanup extends StatelessWidget {
const StorageCleanup({super.key, required this.data, this.onApply});
final JsonMap data;
final VoidCallback? onApply;
@override
Widget build(BuildContext context) {
final applied = data['applied'] == true;
final items = storageRows(data['items']);
return SettingsGroup(
title: applied ? 'Cleanup result' : 'Cleanup preview',
children: [
storagePadding(
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
applied
? '${storageInt(data['removed_count'])} items removed · ${storageBytes(storageInt(data['removed_bytes']))} reclaimed'
: '${storageInt(data['candidate_count'])} items · ${storageBytes(storageInt(data['reclaimable_bytes']))} reclaimable',
),
Text('${storageInt(data['protected_count'])} items protected'),
if (data['target_reached'] == false &&
storageInt(data['target_bytes']) > 0)
const Text(
'Protected or retained data prevents reaching the size limit.',
),
if (!applied)
const Text(
'Review the items below. Cleanup permanently removes eligible run history, artifacts and selected worktrees.',
),
if (data['errors'] case final List errors when errors.isNotEmpty)
Text(errors.join('\n')),
],
),
),
for (final item in items)
storagePadding(
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${item['protected'] == true
? 'Protected'
: applied
? 'Selected'
: 'Remove'} · ${item['kind']} ${item['id'] ?? ''} · ${storageBytes(storageInt(item['bytes']))}',
),
if (item['path'] case final String path when path.isNotEmpty)
Text(path),
if (item['reason'] case final String reason
when reason.isNotEmpty)
Text(reason),
],
),
),
if (!applied && storageInt(data['candidate_count']) > 0)
StorageAction(
label: 'Apply cleanup',
onPressed: onApply,
destructive: true,
),
],
);
}
}