refactor(scripts): scoped parent query + parent picker for multi-parent templates
Two caveats from the script-scope rollout addressed: 1. ITemplateEngineRepository.GetTemplatesComposingAsync — a scoped query that returns only the templates referencing a given template via Compositions, eager-loaded with their Attributes / Scripts / Compositions. Replaces the GetAllTemplatesAsync + filter pattern in TemplateEdit so the Monaco metadata fetch doesn't pull the entire template catalog to find one parent. 2. Multi-parent picker. The previous implementation suppressed Parent assistance entirely when more than one template composes the open one. Now TemplateEdit collects every parent into _editorParents and renders a small `select` above the script editor when there are >1, letting the user choose which parent's metadata drives Parent.Attributes / Parent.CallScript completion + diagnostics. Single-parent templates skip the picker (no UI change). Zero parents (root template) hide the picker and surface no Parent assistance. Browser-verified on the Sensor Module template (composed by both Pump and Variable Speed Motor): picker shows both options, switching updates the editor's parent metadata immediately via the existing GetContext callback. Test counts unchanged (159 / 199); the new repo method is exercised end-to-end by the parent-picker browser path.
This commit is contained in:
@@ -50,6 +50,16 @@ public class TemplateEngineRepository : ITemplateEngineRepository
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<Template>> GetTemplatesComposingAsync(int composedTemplateId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _context.Templates
|
||||
.Where(t => t.Compositions.Any(c => c.ComposedTemplateId == composedTemplateId))
|
||||
.Include(t => t.Attributes)
|
||||
.Include(t => t.Scripts)
|
||||
.Include(t => t.Compositions)
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public async Task AddTemplateAsync(Template template, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await _context.Templates.AddAsync(template, cancellationToken);
|
||||
|
||||
Reference in New Issue
Block a user