refactor: convert Control Room views to DataGrid pattern
- Refactor containers_list_page to use shared DataGrid component - Refactor proxy_hosts_page to use shared DataGrid component - Add ContainerStatusBadge.fromString() factory for string state values - Extend CoreApiDataSource to handle raw array API responses - Simplify data classes (no freezed, just fromJson factories) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
a5a8e7ba88
commit
88e8848953
@@ -88,28 +88,37 @@ class CoreApiDataSource<T> extends DataGridSource<T> {
|
||||
queryParams[limitParam] = limit;
|
||||
}
|
||||
|
||||
final response = await dio.get<Map<String, dynamic>>(
|
||||
final response = await dio.get<dynamic>(
|
||||
endpoint,
|
||||
queryParameters: queryParams,
|
||||
);
|
||||
|
||||
final data = response.data!;
|
||||
final responseData = response.data!;
|
||||
|
||||
// Handle both paginated and wrapped responses
|
||||
List<dynamic> itemsJson;
|
||||
int totalCount;
|
||||
|
||||
if (data.containsKey(itemsKey)) {
|
||||
// Paginated response: { items: [...], total: N }
|
||||
itemsJson = data[itemsKey] as List<dynamic>;
|
||||
totalCount = data[totalCountKey] as int? ?? itemsJson.length;
|
||||
if (responseData is List) {
|
||||
// Direct array response: [...]
|
||||
itemsJson = responseData;
|
||||
totalCount = itemsJson.length;
|
||||
} else if (responseData is Map<String, dynamic>) {
|
||||
final data = responseData;
|
||||
if (data.containsKey(itemsKey)) {
|
||||
// Paginated response: { items: [...], total: N }
|
||||
itemsJson = data[itemsKey] as List<dynamic>;
|
||||
totalCount = data[totalCountKey] as int? ?? itemsJson.length;
|
||||
} else {
|
||||
// Try common wrapper patterns: { data: [...] } or { results: [...] }
|
||||
itemsJson = (data['data'] ?? data['results'] ?? []) as List<dynamic>;
|
||||
totalCount = data['count'] as int? ??
|
||||
data['total'] as int? ??
|
||||
data['totalCount'] as int? ??
|
||||
itemsJson.length;
|
||||
}
|
||||
} else {
|
||||
// Try common wrapper patterns: { data: [...] } or { results: [...] }
|
||||
itemsJson = (data['data'] ?? data['results'] ?? []) as List<dynamic>;
|
||||
totalCount = data['count'] as int? ??
|
||||
data['total'] as int? ??
|
||||
data['totalCount'] as int? ??
|
||||
itemsJson.length;
|
||||
throw FormatException('Unexpected response type: ${responseData.runtimeType}');
|
||||
}
|
||||
|
||||
final items = itemsJson
|
||||
|
||||
Reference in New Issue
Block a user