feat(studio): module-store manager (list / add / remove)
Some checks failed
Security / Security check (push) Failing after 2s
Some checks failed
Security / Security check (push) Failing after 2s
A store icon in the Store app bar opens a dialog that lists the configured module stores + the bundled seed (with per-source module counts), lets the operator add a store by index URL (the hub fetches + merges it live so its modules appear immediately), and remove a store. Backed by the new ListStores/AddStore/RemoveStore RPCs + SDK methods. This is how a domain app's published modules (e.g. reclaim's) become visible in the Store without touching the CLI. Signed-off-by: flemming-it <stefan.a.flemming@googlemail.com>
This commit is contained in:
parent
cb130b2f03
commit
57dac3d999
4 changed files with 217 additions and 0 deletions
|
|
@ -212,6 +212,21 @@ class HubService {
|
||||||
|
|
||||||
Future<bool> healthy() => _client.healthy();
|
Future<bool> healthy() => _client.healthy();
|
||||||
|
|
||||||
|
/// Configured module stores (+ the bundled seed) for the store manager.
|
||||||
|
Future<List<StoreSource>> listStores() => _client.listStores();
|
||||||
|
|
||||||
|
/// Register a new module store; the hub fetches + merges it live.
|
||||||
|
Future<AddStoreResponse> addStore({
|
||||||
|
required String name,
|
||||||
|
required String url,
|
||||||
|
String bearerEnv = '',
|
||||||
|
}) =>
|
||||||
|
_client.addStore(name: name, url: url, bearerEnv: bearerEnv);
|
||||||
|
|
||||||
|
/// Drop a configured store by name (the bundled seed cannot be removed).
|
||||||
|
Future<RemoveStoreResponse> removeStore(String name) =>
|
||||||
|
_client.removeStore(name);
|
||||||
|
|
||||||
/// List of installed WASM modules, grouped by `module_name`.
|
/// List of installed WASM modules, grouped by `module_name`.
|
||||||
/// Built-in and federated capabilities are excluded — they
|
/// Built-in and federated capabilities are excluded — they
|
||||||
/// don't correspond to a bundle on disk and would confuse the
|
/// don't correspond to a bundle on disk and would confuse the
|
||||||
|
|
|
||||||
|
|
@ -234,6 +234,11 @@ class _StorePageState extends State<StorePage> {
|
||||||
onPressed: _openFilterDialog,
|
onPressed: _openFilterDialog,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.storefront_outlined, size: 18),
|
||||||
|
tooltip: 'Module stores',
|
||||||
|
onPressed: () => ChainStoresDialog.show(context),
|
||||||
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.refresh, size: 18),
|
icon: const Icon(Icons.refresh, size: 18),
|
||||||
tooltip: l.storeReloadTooltip,
|
tooltip: l.storeReloadTooltip,
|
||||||
|
|
|
||||||
196
lib/widgets/chain_stores_dialog.dart
Normal file
196
lib/widgets/chain_stores_dialog.dart
Normal file
|
|
@ -0,0 +1,196 @@
|
||||||
|
// Module-store manager — list the configured module stores (+ the
|
||||||
|
// bundled seed), add a store by index URL, or remove one. The hub merges
|
||||||
|
// every store's modules into one searchable index, so adding a store
|
||||||
|
// (e.g. a domain app's published modules) makes them appear in the Store.
|
||||||
|
|
||||||
|
import 'package:chain_client_sdk/chain_client_sdk.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../data/error_presentation.dart';
|
||||||
|
import '../data/hub.dart';
|
||||||
|
import '../theme/tokens.dart';
|
||||||
|
|
||||||
|
class ChainStoresDialog extends StatefulWidget {
|
||||||
|
const ChainStoresDialog._();
|
||||||
|
|
||||||
|
static Future<void> show(BuildContext context) => showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => const ChainStoresDialog._(),
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ChainStoresDialog> createState() => _ChainStoresDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ChainStoresDialogState extends State<ChainStoresDialog> {
|
||||||
|
late Future<List<StoreSource>> _future;
|
||||||
|
final _name = TextEditingController();
|
||||||
|
final _url = TextEditingController();
|
||||||
|
bool _busy = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _reload() =>
|
||||||
|
setState(() => _future = HubService.instance.listStores());
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_name.dispose();
|
||||||
|
_url.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _add() async {
|
||||||
|
final name = _name.text.trim();
|
||||||
|
final url = _url.text.trim();
|
||||||
|
if (name.isEmpty || url.isEmpty) return;
|
||||||
|
setState(() => _busy = true);
|
||||||
|
try {
|
||||||
|
final r = await HubService.instance.addStore(name: name, url: url);
|
||||||
|
if (!mounted) return;
|
||||||
|
_name.clear();
|
||||||
|
_url.clear();
|
||||||
|
ScaffoldMessenger.of(context)
|
||||||
|
.showSnackBar(SnackBar(content: Text(r.message)));
|
||||||
|
_reload();
|
||||||
|
} catch (e) {
|
||||||
|
if (mounted) {
|
||||||
|
showFaiErrorSnack(context, 'store.add', e,
|
||||||
|
title: 'Could not add store');
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (mounted) setState(() => _busy = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _remove(String name) async {
|
||||||
|
try {
|
||||||
|
final r = await HubService.instance.removeStore(name);
|
||||||
|
if (!mounted) return;
|
||||||
|
ScaffoldMessenger.of(context)
|
||||||
|
.showSnackBar(SnackBar(content: Text(r.message)));
|
||||||
|
_reload();
|
||||||
|
} catch (e) {
|
||||||
|
if (mounted) {
|
||||||
|
showFaiErrorSnack(context, 'store.remove', e,
|
||||||
|
title: 'Could not remove store');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Module stores'),
|
||||||
|
content: SizedBox(
|
||||||
|
width: 540,
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'The hub merges modules from every store below into one index. '
|
||||||
|
'Add a store index URL to make its modules installable here.',
|
||||||
|
style: theme.textTheme.bodySmall
|
||||||
|
?.copyWith(color: theme.colorScheme.onSurfaceVariant),
|
||||||
|
),
|
||||||
|
const SizedBox(height: ChainSpace.md),
|
||||||
|
Flexible(
|
||||||
|
child: FutureBuilder<List<StoreSource>>(
|
||||||
|
future: _future,
|
||||||
|
builder: (c, snap) {
|
||||||
|
if (snap.connectionState == ConnectionState.waiting) {
|
||||||
|
return const Padding(
|
||||||
|
padding: EdgeInsets.all(16),
|
||||||
|
child: Center(child: CircularProgressIndicator()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final stores = snap.data ?? const <StoreSource>[];
|
||||||
|
return ListView(
|
||||||
|
shrinkWrap: true,
|
||||||
|
children: [
|
||||||
|
for (final s in stores)
|
||||||
|
ListTile(
|
||||||
|
dense: true,
|
||||||
|
leading: Icon(
|
||||||
|
s.removable
|
||||||
|
? Icons.cloud_outlined
|
||||||
|
: Icons.inventory_2_outlined,
|
||||||
|
size: 18,
|
||||||
|
),
|
||||||
|
title: Text(s.name),
|
||||||
|
subtitle: Text(
|
||||||
|
s.url.isEmpty
|
||||||
|
? '${s.moduleCount} modules · bundled'
|
||||||
|
: '${s.url}\n${s.moduleCount} modules',
|
||||||
|
),
|
||||||
|
isThreeLine: s.url.isNotEmpty,
|
||||||
|
trailing: s.removable
|
||||||
|
? IconButton(
|
||||||
|
icon: const Icon(Icons.delete_outline),
|
||||||
|
tooltip: 'Remove',
|
||||||
|
onPressed: () => _remove(s.name),
|
||||||
|
)
|
||||||
|
: const Icon(Icons.lock_outline, size: 16),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Divider(),
|
||||||
|
Text('Add a store', style: theme.textTheme.titleSmall),
|
||||||
|
const SizedBox(height: ChainSpace.sm),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
flex: 2,
|
||||||
|
child: TextField(
|
||||||
|
controller: _name,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText: 'Name',
|
||||||
|
isDense: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: ChainSpace.sm),
|
||||||
|
Expanded(
|
||||||
|
flex: 4,
|
||||||
|
child: TextField(
|
||||||
|
controller: _url,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText: 'Index URL (https:// or file://)',
|
||||||
|
isDense: true,
|
||||||
|
),
|
||||||
|
onSubmitted: (_) => _add(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
|
child: const Text('Close'),
|
||||||
|
),
|
||||||
|
FilledButton(
|
||||||
|
onPressed: _busy ? null : _add,
|
||||||
|
child: _busy
|
||||||
|
? const SizedBox(
|
||||||
|
width: 16,
|
||||||
|
height: 16,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
)
|
||||||
|
: const Text('Add store'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -16,5 +16,6 @@ export 'chain_log_viewer.dart';
|
||||||
export 'chain_module_sheet.dart';
|
export 'chain_module_sheet.dart';
|
||||||
export 'chain_pill.dart';
|
export 'chain_pill.dart';
|
||||||
export 'chain_settings_dialog.dart';
|
export 'chain_settings_dialog.dart';
|
||||||
|
export 'chain_stores_dialog.dart';
|
||||||
export 'chain_status_dot.dart';
|
export 'chain_status_dot.dart';
|
||||||
export 'chain_system_ai_editor.dart';
|
export 'chain_system_ai_editor.dart';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue