Skip to content

Commit

Permalink
feat: Add PostgreSQL section to default page with namespace selection…
Browse files Browse the repository at this point in the history
… and listing
  • Loading branch information
Tycale committed Dec 31, 2024
1 parent 0299753 commit ba6618b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ui/lib/app/controller/badge_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class BadgeController extends GetxController {

final selectedKustomizationNamespace = Rxn<KubeBadge>();

final _postgresqlNamespaceList = <KubeBadge, List<KubeBadge>>{}.obs;
Map<KubeBadge, List<KubeBadge>> get postgresqlNamespaceList => _postgresqlNamespaceList;
set postgresqlNamespaceList(Map<KubeBadge, List<KubeBadge>> value) =>
_postgresqlNamespaceList.value = value;

final selectedPostgresqlNamespace = Rxn<KubeBadge>();

void refreshNamespaceList() {
_namespaceList.refresh();
}
Expand All @@ -32,6 +39,10 @@ class BadgeController extends GetxController {
_kustomizationNamespaceList.refresh();
}

void refreshPostgresqlNamespaceList() {
_postgresqlNamespaceList.refresh();
}

BadgeController() {
loadData(false);
}
Expand All @@ -53,11 +64,13 @@ class BadgeController extends GetxController {
EasyLoading.show(status: 'Loading...');
namespaceList.clear();
kustomizationNamespaceList.clear();
postgresqlNamespaceList.clear();
var namespaces = await appService.listNamespace(force);
if (!namespaces.status.hasError) {
for (var namespace in namespaces.body!) {
namespaceList[namespace] = [];
kustomizationNamespaceList[namespace] = [];
postgresqlNamespaceList[namespace] = [];
}
}
EasyLoading.dismiss();
Expand Down
43 changes: 43 additions & 0 deletions ui/lib/app/ui/pages/default/default_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,49 @@ class DefaultPage extends GetView<BadgeController> {
},
)
: const SizedBox()),
const CardTitle(title: "PostgreSQL"),
Obx(() => Row(
children: [
const Text("Select Namespace: "),
const SizedBox(width: 8),
DropdownButton<String>(
value: controller.selectedPostgresqlNamespace.value?.name,
items: controller.postgresqlNamespaceList.keys.map((namespace) {
return DropdownMenuItem<String>(
value: namespace.name,
child: Text(namespace.name),
);
}).toList(),
onChanged: (val) async {
if (val != null) {
final selectedBadge = controller.postgresqlNamespaceList.keys
.firstWhere((badge) => badge.name == val);
controller.selectedPostgresqlNamespace.value = selectedBadge;
var postgresqls = await controller.appService.listPostgresqls(val, false);
if (!postgresqls.status.hasError && postgresqls.body!.isNotEmpty) {
controller.postgresqlNamespaceList[selectedBadge] = postgresqls.body!;
controller.refreshPostgresqlNamespaceList();
}
}
},
hint: const Text("Choose a namespace"),
),
],
)),
Obx(() => controller.selectedPostgresqlNamespace.value != null
? BadgeCard(
items: controller.postgresqlNamespaceList[controller.selectedPostgresqlNamespace.value] ?? [],
kubeBadge: controller.selectedPostgresqlNamespace.value,
onTap: (e) {
showDialog(
context: context,
builder: (BuildContext context) {
return BadgeSettingDialog(kubeBadge: e);
},
);
},
)
: const SizedBox()),
],
),
);
Expand Down

0 comments on commit ba6618b

Please sign in to comment.