feat(settings): multi-version uninstall picker + default_scope editor
Some checks failed
Security / Security check (push) Failing after 2s
Some checks failed
Security / Security check (push) Failing after 2s
Two operator surfaces shipped together:
**Multi-version uninstall picker** — when more than one version
of a `(provider, name)` is installed side-by-side, both the
module-sheet "Uninstall" affordance and the store-detail
"Uninstall" affordance now ask the operator which version to
remove before calling the RPC. The hub's wire-level support for
this (UninstallModuleRequest.version) was already there; Studio
just wasn't using it. Picker pre-selects the highest version so
single-version flows still take one click.
- `HubService.installedVersions(name)` enumerates the installed
versions via the capabilities list.
- `HubService.uninstallModule(name, version: ...)` forwards
the version into the RPC.
- `_UninstallVersionPickerDialog` (module sheet) and
`_StoreUninstallVersionPickerDialog` (store) host the
picker — separate widgets so each surface can evolve copy
independently. Uses `RadioGroup<String>` for Flutter
3.32+ deprecation compliance.
**Default scope editor** — new DEFAULT SCOPE panel in Settings
that calls the freshly-added HubAdmin RPCs
`GetDefaultScope` / `SetDefaultScope`. Operators can:
- reorder publisher segments with up/down buttons
(first match wins in the bare-form resolver),
- delete entries (hub still rejects empty list — Studio
surfaces the constraint inline),
- add arbitrary entries via the text field,
- add catalog-known publishers via suggestion chips
(sorted alphabetically, populated from the catalog).
Every change persists to `~/.fai/config.yaml` via the hub
and hot-swaps the in-memory copy without a daemon restart.
Bumped pubspec to 0.48.0. dart analyze clean (No issues
found!); flutter test green (11 tests).
Signed-off-by: flemming-it <stefan.a.flemming@googlemail.com>
This commit is contained in:
parent
327bc0fea2
commit
1903babc5a
10 changed files with 750 additions and 7 deletions
|
|
@ -570,6 +570,8 @@ class _FaiSettingsDialogState extends State<FaiSettingsDialog> {
|
|||
onClear: _clearHubAuthToken,
|
||||
),
|
||||
const SizedBox(height: FaiSpace.lg),
|
||||
const _DefaultScopePanel(),
|
||||
const SizedBox(height: FaiSpace.lg),
|
||||
const _ThemePluginPanel(),
|
||||
const SizedBox(height: FaiSpace.lg),
|
||||
_MaintenancePanel(
|
||||
|
|
@ -2227,3 +2229,315 @@ const _kMcpSuggestions = <_McpSuggestion>[
|
|||
apiKeyEnv: '',
|
||||
),
|
||||
];
|
||||
|
||||
/// Operator panel for `default_scope:` — the ordered list of
|
||||
/// publisher segments the bare-form capability resolver consults
|
||||
/// when a flow names a capability without an explicit
|
||||
/// `<provider>/` prefix (e.g. `text.extract@^1` resolves to
|
||||
/// `fai/text.extract@^1` when `default_scope: [fai]`).
|
||||
///
|
||||
/// The hub returns the live list plus a catalog-known shortlist
|
||||
/// (`knownProviders`) — the panel renders the shortlist as
|
||||
/// suggestion chips and lets operators paste arbitrary entries
|
||||
/// for private publisher segments.
|
||||
///
|
||||
/// The order matters: when more than one segment matches a bare
|
||||
/// capability name, the first match wins. The panel surfaces the
|
||||
/// order with simple up/down buttons so operators can reorder
|
||||
/// without dragging.
|
||||
class _DefaultScopePanel extends StatefulWidget {
|
||||
const _DefaultScopePanel();
|
||||
|
||||
@override
|
||||
State<_DefaultScopePanel> createState() => _DefaultScopePanelState();
|
||||
}
|
||||
|
||||
class _DefaultScopePanelState extends State<_DefaultScopePanel> {
|
||||
List<String>? _scope;
|
||||
List<String> _knownProviders = const [];
|
||||
bool _loading = true;
|
||||
bool _saving = false;
|
||||
String? _error;
|
||||
final _addController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_load();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_addController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
try {
|
||||
final r = await HubService.instance.getDefaultScope();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_scope = r.scope;
|
||||
_knownProviders = r.knownProviders;
|
||||
_loading = false;
|
||||
_error = null;
|
||||
});
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_loading = false;
|
||||
_error = e.toString();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _save(List<String> next) async {
|
||||
setState(() {
|
||||
_saving = true;
|
||||
_error = null;
|
||||
});
|
||||
try {
|
||||
final r = await HubService.instance.setDefaultScope(next);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_scope = r.scope;
|
||||
_knownProviders = r.knownProviders;
|
||||
_saving = false;
|
||||
});
|
||||
final l = AppLocalizations.of(context)!;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(l.defaultScopeSavedToast)),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_saving = false;
|
||||
_error = e.toString();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _addEntry(String raw) {
|
||||
final entry = raw.trim();
|
||||
if (entry.isEmpty) return;
|
||||
final current = List<String>.from(_scope ?? const []);
|
||||
if (current.contains(entry)) return;
|
||||
current.add(entry);
|
||||
_addController.clear();
|
||||
_save(current);
|
||||
}
|
||||
|
||||
void _removeAt(int i) {
|
||||
final current = List<String>.from(_scope ?? const []);
|
||||
if (i < 0 || i >= current.length) return;
|
||||
if (current.length == 1) {
|
||||
// Hub rejects empty; surface the constraint inline rather
|
||||
// than letting the RPC fail.
|
||||
setState(() => _error = AppLocalizations.of(context)!
|
||||
.defaultScopeNonEmptyError);
|
||||
return;
|
||||
}
|
||||
current.removeAt(i);
|
||||
_save(current);
|
||||
}
|
||||
|
||||
void _moveUp(int i) {
|
||||
if (i <= 0) return;
|
||||
final current = List<String>.from(_scope ?? const []);
|
||||
final item = current.removeAt(i);
|
||||
current.insert(i - 1, item);
|
||||
_save(current);
|
||||
}
|
||||
|
||||
void _moveDown(int i) {
|
||||
final current = List<String>.from(_scope ?? const []);
|
||||
if (i >= current.length - 1) return;
|
||||
final item = current.removeAt(i);
|
||||
current.insert(i + 1, item);
|
||||
_save(current);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final l = AppLocalizations.of(context)!;
|
||||
final scope = _scope;
|
||||
final unusedSuggestions = _knownProviders
|
||||
.where((p) => !(scope ?? const []).contains(p))
|
||||
.toList();
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
l.defaultScopeHeader,
|
||||
style: theme.textTheme.labelSmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
letterSpacing: 0.6,
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
l.defaultScopeBlurb,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: FaiSpace.sm),
|
||||
if (_loading)
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: FaiSpace.sm),
|
||||
child: SizedBox(
|
||||
height: 16,
|
||||
width: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
)
|
||||
else if (scope == null)
|
||||
Text(
|
||||
_error ?? l.defaultScopeLoadFailed,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.error,
|
||||
),
|
||||
)
|
||||
else ...[
|
||||
for (var i = 0; i < scope.length; i++)
|
||||
_ScopeRow(
|
||||
index: i,
|
||||
total: scope.length,
|
||||
entry: scope[i],
|
||||
busy: _saving,
|
||||
onUp: () => _moveUp(i),
|
||||
onDown: () => _moveDown(i),
|
||||
onRemove: () => _removeAt(i),
|
||||
),
|
||||
const SizedBox(height: FaiSpace.sm),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _addController,
|
||||
decoration: InputDecoration(
|
||||
labelText: l.defaultScopeAddLabel,
|
||||
hintText: l.defaultScopeAddHint,
|
||||
border: const OutlineInputBorder(),
|
||||
isDense: true,
|
||||
),
|
||||
onSubmitted: _saving ? null : _addEntry,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: FaiSpace.sm),
|
||||
FilledButton.icon(
|
||||
icon: const Icon(Icons.add, size: 14),
|
||||
label: Text(l.defaultScopeAddButton),
|
||||
onPressed: _saving
|
||||
? null
|
||||
: () => _addEntry(_addController.text),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (unusedSuggestions.isNotEmpty) ...[
|
||||
const SizedBox(height: FaiSpace.sm),
|
||||
Text(
|
||||
l.defaultScopeSuggestions,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Wrap(
|
||||
spacing: FaiSpace.xs,
|
||||
runSpacing: 4,
|
||||
children: [
|
||||
for (final s in unusedSuggestions)
|
||||
ActionChip(
|
||||
label: Text(
|
||||
s,
|
||||
style: const TextStyle(fontFamily: 'monospace'),
|
||||
),
|
||||
onPressed: _saving ? null : () => _addEntry(s),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
if (_error != null) ...[
|
||||
const SizedBox(height: FaiSpace.sm),
|
||||
Text(
|
||||
_error!,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.error,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ScopeRow extends StatelessWidget {
|
||||
final int index;
|
||||
final int total;
|
||||
final String entry;
|
||||
final bool busy;
|
||||
final VoidCallback onUp;
|
||||
final VoidCallback onDown;
|
||||
final VoidCallback onRemove;
|
||||
|
||||
const _ScopeRow({
|
||||
required this.index,
|
||||
required this.total,
|
||||
required this.entry,
|
||||
required this.busy,
|
||||
required this.onUp,
|
||||
required this.onDown,
|
||||
required this.onRemove,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 2),
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 24,
|
||||
child: Text(
|
||||
'${index + 1}.',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
entry,
|
||||
style: const TextStyle(fontFamily: 'monospace'),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.arrow_upward, size: 16),
|
||||
tooltip: 'Move up',
|
||||
onPressed: busy || index == 0 ? null : onUp,
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.arrow_downward, size: 16),
|
||||
tooltip: 'Move down',
|
||||
onPressed: busy || index == total - 1 ? null : onDown,
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete_outline, size: 16),
|
||||
tooltip: 'Remove',
|
||||
onPressed: busy ? null : onRemove,
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue