Skip to content

Commit ad0dba5

Browse files
authored
Feat/#178 (#180)
* update: sort workflows alphabetically * Refactor workflow_page_controller.dart to order workflows by name * feat: deletion alert for workflow
1 parent 4eb5701 commit ad0dba5

File tree

3 files changed

+53
-27
lines changed

3 files changed

+53
-27
lines changed

apps/dashboard/lib/src/common_widgets/dialogs.dart

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,37 @@ Future<void> showErrorDialog(BuildContext context, String errorMessage) {
2020
),
2121
);
2222
}
23+
24+
Future<void> showDeleteDialog({
25+
required String title,
26+
required BuildContext context,
27+
required void Function() onDelete,
28+
}) {
29+
return showAdaptiveDialog<void>(
30+
context: context,
31+
builder: (context) => AlertDialog(
32+
title: Text(title),
33+
content: const Text(
34+
'Are you sure you want to delete this item?',
35+
),
36+
actions: [
37+
TextButton(
38+
onPressed: () {
39+
Navigator.of(context).pop();
40+
},
41+
child: const Text('Cancel'),
42+
),
43+
TextButton(
44+
onPressed: () {
45+
onDelete();
46+
Navigator.of(context).pop();
47+
},
48+
child: const Text(
49+
'Delete',
50+
style: TextStyle(color: Colors.red),
51+
),
52+
),
53+
],
54+
),
55+
);
56+
}

apps/dashboard/lib/src/features/secrets/presentation/secret_page.dart

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:convert';
22

33
import 'package:cloud_firestore/cloud_firestore.dart';
4+
import 'package:dashboard/src/common_widgets/dialogs.dart';
45
import 'package:dashboard/src/features/secrets/presentation/secret_page_controller.dart';
56
import 'package:file_picker/file_picker.dart';
67
import 'package:firebase_auth/firebase_auth.dart';
@@ -71,32 +72,15 @@ class SecretPage extends ConsumerWidget {
7172
),
7273
IconButton(
7374
onPressed: () {
74-
showAdaptiveDialog<void>(
75+
showDeleteDialog(
76+
title: 'Delete Secret',
7577
context: context,
76-
builder: (context) => AlertDialog(
77-
title: const Text('Delete Secret'),
78-
content: const Text(
79-
'Are you sure you want to delete this secret?',
80-
),
81-
actions: [
82-
TextButton(
83-
onPressed: () {
84-
Navigator.of(context).pop();
85-
},
86-
child: const Text('Cancel'),
87-
),
88-
TextButton(
89-
onPressed: () {
90-
FirebaseFirestore.instance
91-
.collection(secretsCollectionPath)
92-
.doc(data.docs[index].id)
93-
.delete();
94-
Navigator.of(context).pop();
95-
},
96-
child: const Text('Delete'),
97-
),
98-
],
99-
),
78+
onDelete: () {
79+
FirebaseFirestore.instance
80+
.collection(secretsCollectionPath)
81+
.doc(data.docs[index].id)
82+
.delete();
83+
},
10084
);
10185
},
10286
icon: const Icon(Icons.delete),

apps/dashboard/lib/src/features/workflow/presentation/workflow_page.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:dashboard/src/common_widgets/dialogs.dart';
12
import 'package:dashboard/src/features/workflow/presentation/workflow_editor/presentation/workflow_editor.dart';
23
import 'package:dashboard/src/features/workflow/presentation/workflow_page_controller.dart';
34
import 'package:flutter/material.dart';
@@ -128,8 +129,15 @@ class _WorkflowListItem extends ConsumerWidget {
128129
SizedBox(
129130
width: iconWidth,
130131
child: IconButton(
131-
onPressed: () =>
132-
controller.deleteWorkflow(workflowModel.id),
132+
onPressed: () {
133+
showDeleteDialog(
134+
title: 'Delete Workflow',
135+
context: context,
136+
onDelete: () {
137+
controller.deleteWorkflow(workflowModel.id);
138+
},
139+
);
140+
},
133141
icon: const Icon(
134142
Icons.delete,
135143
),

0 commit comments

Comments
 (0)