-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AdminUI: Manage quotas on Identity details page (#676)
* feat: manage identity quotas * chore: remove buttons and trigger update on tier change * refactor: extract add quota dialog into a core modal * chore: add a tooltip and grey out the disabled rows * chore: wrap a column widget in a card widget * fix: revert allow empty response * refactor: proper codeshare * refactor: undo other stuff * fix. undo strange translation * fix: add assert to make sure _addQuota is not mis-called * refactor: undo even more stuff * chore: make one function call the dialog * chore: remove late keyword * chore: use bool getter * chore: move identity quota into a separate file * refactor: extract quota buttons into separate widget * refactor: endpoint call * refactor: rename the folder * fix: change imports * fix: move identity quota list to correct folder * fix: imports * fix: import * fix: move quota button group out of the core * fix: import * fix: move quotas button group * fix: revert changes * refactor: rename a file * fix: import * chore: simplify stuff * refactor: this defenitely was no "button" --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Julian König <[email protected]>
- Loading branch information
1 parent
e6747e6
commit 7c96ffd
Showing
10 changed files
with
326 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export 'add_quota_dialog.dart'; | ||
export 'confirmation_dialog.dart'; | ||
export 'settings_dialog.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
AdminUi/apps/admin_ui/lib/core/widgets/quotas_button_group.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import 'package:admin_api_sdk/admin_api_sdk.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
|
||
import '../constants.dart'; | ||
import '../modals/modals.dart'; | ||
|
||
class QuotasButtonGroup extends StatefulWidget { | ||
final List<String> selectedQuotas; | ||
final VoidCallback onQuotasChanged; | ||
final String? identityAddress; | ||
final String? tierId; | ||
|
||
const QuotasButtonGroup({ | ||
required this.selectedQuotas, | ||
required this.onQuotasChanged, | ||
this.identityAddress, | ||
this.tierId, | ||
super.key, | ||
}) : assert(identityAddress != null || tierId != null, 'Either identityAddress or tierId must be provided'), | ||
assert(identityAddress == null || tierId == null, 'Only one of identityAddress or tierId can be provided'); | ||
|
||
@override | ||
State<QuotasButtonGroup> createState() => _QuotasButtonGroupState(); | ||
} | ||
|
||
class _QuotasButtonGroupState extends State<QuotasButtonGroup> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Padding( | ||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), | ||
child: Row( | ||
mainAxisAlignment: MainAxisAlignment.end, | ||
children: [ | ||
IconButton( | ||
icon: Icon( | ||
Icons.delete, | ||
color: widget.selectedQuotas.isNotEmpty ? Theme.of(context).colorScheme.onError : null, | ||
), | ||
style: ButtonStyle( | ||
backgroundColor: WidgetStateProperty.resolveWith((states) { | ||
return widget.selectedQuotas.isNotEmpty ? Theme.of(context).colorScheme.error : null; | ||
}), | ||
), | ||
onPressed: widget.selectedQuotas.isNotEmpty ? _removeSelectedQuotas : null, | ||
), | ||
Gaps.w8, | ||
IconButton.filled( | ||
icon: const Icon(Icons.add), | ||
onPressed: () => showAddQuotaDialog( | ||
context: context, | ||
identityAddress: widget.identityAddress, | ||
tierId: widget.tierId, | ||
onQuotaAdded: widget.onQuotasChanged, | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
|
||
Future<void> _removeSelectedQuotas() async { | ||
final confirmed = await showConfirmationDialog( | ||
context: context, | ||
title: 'Remove Quotas', | ||
message: | ||
'Are you sure you want to remove the selected quotas from ${widget.identityAddress != null ? 'the identity "${widget.identityAddress}"' : 'the tier "${widget.tierId}"'}?', | ||
); | ||
|
||
if (!confirmed) return; | ||
|
||
for (final quota in widget.selectedQuotas) { | ||
final result = await _deleteQuota(quota); | ||
if (result.hasError && mounted) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar( | ||
content: Text('An error occurred while deleting the quota(s). Please try again.'), | ||
showCloseIcon: true, | ||
), | ||
); | ||
|
||
return; | ||
} | ||
} | ||
|
||
widget.onQuotasChanged(); | ||
widget.selectedQuotas.clear(); | ||
if (mounted) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar( | ||
content: Text('Selected quota(s) have been removed.'), | ||
showCloseIcon: true, | ||
), | ||
); | ||
} | ||
} | ||
|
||
Future<ApiResponse<void>> _deleteQuota(String quota) { | ||
final client = GetIt.I.get<AdminApiClient>(); | ||
|
||
if (widget.identityAddress != null) return client.quotas.deleteIdentityQuota(address: widget.identityAddress!, individualQuotaId: quota); | ||
return client.quotas.deleteTierQuota(tierId: widget.tierId!, tierQuotaDefinitionId: quota); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.