Skip to content

Commit fe4e5e8

Browse files
ptoneScion Agent (template-import-selector-lead)
andauthored
Fix import progress streaming and pass names on single-template import (#443)
Per-project import handlers now support NDJSON streaming when the client sends Accept: application/x-ndjson, matching the unified endpoint. This fixes the progress display (per-resource events) and the post-import summary (the NDJSON done event uses the correct "imported" field name). Also passes discovered names to executeImport even for the count===1 case, ensuring the import is scoped to the exact resource that was discovered. Co-authored-by: Scion Agent (template-import-selector-lead) <agent@scion.dev>
1 parent 95fc666 commit fe4e5e8

2 files changed

Lines changed: 25 additions & 11 deletions

File tree

pkg/hub/handlers.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10204,13 +10204,20 @@ func (s *Server) handleProjectImportTemplates(w http.ResponseWriter, r *http.Req
1020410204
return
1020510205
}
1020610206

10207-
var imported []string
10208-
if req.WorkspacePath != "" {
10209-
imported, err = s.importFromWorkspace(ctx, project, req.WorkspacePath, store.TemplateScopeProject, s.templateImportKind(), nil, req.Names)
10210-
} else {
10207+
run := func(progress importProgressFunc) ([]string, error) {
10208+
if req.WorkspacePath != "" {
10209+
return s.importFromWorkspace(ctx, project, req.WorkspacePath, store.TemplateScopeProject, s.templateImportKind(), progress, req.Names)
10210+
}
1021110211
req.SourceURL = config.NormalizeTemplateSourceURL(req.SourceURL)
10212-
imported, err = s.importFromRemote(ctx, projectID, req.SourceURL, store.TemplateScopeProject, s.templateImportKind(), nil, req.Names)
10212+
return s.importFromRemote(ctx, projectID, req.SourceURL, store.TemplateScopeProject, s.templateImportKind(), progress, req.Names)
1021310213
}
10214+
10215+
if importAcceptsNDJSON(r) {
10216+
s.streamImport(w, run)
10217+
return
10218+
}
10219+
10220+
imported, err := run(nil)
1021410221
if err != nil {
1021510222
writeError(w, http.StatusBadRequest, "import_failed", err.Error(), nil)
1021610223
return
@@ -10296,13 +10303,20 @@ func (s *Server) handleProjectImportHarnessConfigs(w http.ResponseWriter, r *htt
1029610303
return
1029710304
}
1029810305

10299-
var imported []string
10300-
if req.WorkspacePath != "" {
10301-
imported, err = s.importFromWorkspace(ctx, project, req.WorkspacePath, store.HarnessConfigScopeProject, s.harnessConfigImportKind(), nil, req.Names)
10302-
} else {
10306+
run := func(progress importProgressFunc) ([]string, error) {
10307+
if req.WorkspacePath != "" {
10308+
return s.importFromWorkspace(ctx, project, req.WorkspacePath, store.HarnessConfigScopeProject, s.harnessConfigImportKind(), progress, req.Names)
10309+
}
1030310310
req.SourceURL = config.NormalizeTemplateSourceURL(req.SourceURL)
10304-
imported, err = s.importFromRemote(ctx, projectID, req.SourceURL, store.HarnessConfigScopeProject, s.harnessConfigImportKind(), nil, req.Names)
10311+
return s.importFromRemote(ctx, projectID, req.SourceURL, store.HarnessConfigScopeProject, s.harnessConfigImportKind(), progress, req.Names)
1030510312
}
10313+
10314+
if importAcceptsNDJSON(r) {
10315+
s.streamImport(w, run)
10316+
return
10317+
}
10318+
10319+
imported, err := run(nil)
1030610320
if err != nil {
1030710321
writeError(w, http.StatusBadRequest, "import_failed", err.Error(), nil)
1030810322
return

web/src/components/shared/resource-import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export class ScionResourceImport extends LitElement {
277277
}
278278

279279
if (discovered.count === 1) {
280-
await this.executeImport();
280+
await this.executeImport(discovered.resources);
281281
return;
282282
}
283283

0 commit comments

Comments
 (0)