[FEAT] Added group hydration
This commit is contained in:
@@ -106,17 +106,6 @@ class AstromicFormController {
|
|||||||
return node<T>(id).value;
|
return node<T>(id).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Safely attempts to retrieve a value, returning `null` if the node is missing or of a different type.
|
|
||||||
// T? tryGet<T>(String id) {
|
|
||||||
// if (_nodes.containsKey(id)) {
|
|
||||||
// final n = _nodes[id];
|
|
||||||
// if (n is AstromicFieldNode<T>) {
|
|
||||||
// return n.value;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
T? tryGet<T>(String id) {
|
T? tryGet<T>(String id) {
|
||||||
final n = _nodes[id];
|
final n = _nodes[id];
|
||||||
if (n == null) return null;
|
if (n == null) return null;
|
||||||
@@ -276,6 +265,38 @@ class AstromicFormController {
|
|||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Hydrates a dynamic group with a list of data maps.
|
||||||
|
///
|
||||||
|
/// Each map in [data] represents one instance of the group.
|
||||||
|
/// This method generates a UUID for each map and populates the fields.
|
||||||
|
void hydrateGroup(String groupId, List<Map<String, dynamic>> data, {String? parentUuid}) {
|
||||||
|
// 1. Clear existing manifest for this group/parent context to prevent duplication
|
||||||
|
final manifest = getManifest(groupId, parentUuid);
|
||||||
|
manifest.value = [];
|
||||||
|
|
||||||
|
// 2. Iterate through each data object (row)
|
||||||
|
for (final rowData in data) {
|
||||||
|
// 3. Add a fresh instance (this generates the UUID and registers field nodes)
|
||||||
|
final String newUuid = addGroupInstance(
|
||||||
|
groupId,
|
||||||
|
parentUuid: parentUuid,
|
||||||
|
initialData: rowData,
|
||||||
|
);
|
||||||
|
|
||||||
|
// 4. Handle Nested Subgroups (Recursion)
|
||||||
|
final def = _groupDefs[groupId];
|
||||||
|
if (def != null && def.subGroups.isNotEmpty) {
|
||||||
|
for (final subId in def.subGroups) {
|
||||||
|
if (rowData.containsKey(subId) && rowData[subId] is List) {
|
||||||
|
final List<Map<String, dynamic>> subData = List<Map<String, dynamic>>.from(rowData[subId]);
|
||||||
|
|
||||||
|
hydrateGroup(subId, subData, parentUuid: newUuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Retrieves the schema definition for a registered group.
|
/// Retrieves the schema definition for a registered group.
|
||||||
AstromicFormGroupDefinition? getGroupDef(String id) => _groupDefs[id];
|
AstromicFormGroupDefinition? getGroupDef(String id) => _groupDefs[id];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user