Skip to content

Commit bd58fc4

Browse files
authored
feat: migrate get instance context (#85)
1 parent 2006f15 commit bd58fc4

File tree

25 files changed

+556
-34
lines changed

25 files changed

+556
-34
lines changed

ScriptBeeClient/src/app/pages/projects/project-details/model/currently-loaded-models/currently-loaded-models.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<div class="currently-loaded-models-content">
44
<span>Used Linkers: </span>
5-
<!-- TODO FIXIT(#70): populate from api-->
5+
<!-- TODO FIXIT(#61): populate from api-->
66
@for (linker of []; track linker) {
77
{{ linker }}
88
}

ScriptBeeClient/src/app/pages/projects/project-details/model/currently-loaded-models/currently-loaded-models.component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Component, computed, input } from '@angular/core';
22
import { TreeNode } from '../../../../../types/tree-node';
33
import { SelectableTreeComponent } from '../../../../../components/selectable-tree/selectable-tree.component';
4-
import { InstanceInfo } from '../../../../../types/instance';
54

65
@Component({
76
selector: 'app-currently-loaded-models',
@@ -10,10 +9,10 @@ import { InstanceInfo } from '../../../../../types/instance';
109
imports: [SelectableTreeComponent],
1110
})
1211
export class CurrentlyLoadedModelsComponent {
13-
instanceInfo = input.required<InstanceInfo>();
12+
instanceId = input.required<string>();
1413

1514
loadedFiles = computed<TreeNode[]>(() => {
16-
// TODO FIXIT(#70): populate from api
15+
// TODO FIXIT(#61): populate from api
1716
return convertToTreeNodes({});
1817
});
1918
}

ScriptBeeClient/src/app/pages/projects/project-details/model/project-context/project-context.component.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Component, computed, input } from '@angular/core';
2-
import { InstanceInfo } from '../../../../../types/instance';
32
import { createRxResourceHandler } from '../../../../../utils/resource';
43
import { ProjectContextService } from '../../../../../services/projects/project-context.service';
54
import { CenteredSpinnerComponent } from '../../../../../components/centered-spinner/centered-spinner.component';
@@ -18,39 +17,35 @@ import { ProjectContext } from '../../../../../types/returned-context-slice';
1817
})
1918
export class ProjectContextComponent {
2019
projectId = input.required<string>();
21-
instanceInfo = input.required<InstanceInfo>();
20+
instanceId = input.required<string>();
2221

2322
context = computed<TreeNode[]>(() => {
2423
return convertToTreeNodes(this.projectContextResource.value() ?? []);
2524
});
2625

2726
projectContextResource = createRxResourceHandler({
28-
request: () => ({ projectId: this.projectId(), instanceInfo: this.instanceInfo() }),
29-
loader: (params) => this.projectContextService.getProjectContext(params.request.projectId, params.request.instanceInfo.id),
27+
request: () => ({ projectId: this.projectId(), instanceId: this.instanceId() }),
28+
loader: (params) => this.projectContextService.getProjectContext(params.request.projectId, params.request.instanceId),
3029
});
3130

3231
clearContextHandler = apiHandler(
3332
(params: { projectId: string; instanceId: string }) => this.projectContextService.clearContext(params.projectId, params.instanceId),
34-
(data) => {
35-
console.log(data);
36-
}
33+
() => this.projectContextResource.reload()
3734
);
3835

3936
reloadContextHandler = apiHandler(
4037
(params: { projectId: string; instanceId: string }) => this.projectContextService.reloadContext(params.projectId, params.instanceId),
41-
(data) => {
42-
console.log(data);
43-
}
38+
() => this.projectContextResource.reload()
4439
);
4540

4641
constructor(private projectContextService: ProjectContextService) {}
4742

4843
onReloadModelsClick() {
49-
this.reloadContextHandler.execute({ projectId: this.projectId(), instanceId: this.instanceInfo().id });
44+
this.reloadContextHandler.execute({ projectId: this.projectId(), instanceId: this.instanceId() });
5045
}
5146

5247
onClearContextButtonClick() {
53-
this.clearContextHandler.execute({ projectId: this.projectId(), instanceId: this.instanceInfo().id });
48+
this.clearContextHandler.execute({ projectId: this.projectId(), instanceId: this.instanceId() });
5449
}
5550
}
5651

ScriptBeeClient/src/app/pages/projects/project-details/model/project-model-page.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
} @else if (currentInstanceInfoResource.error()) {
3232
<app-error-state [error]="currentInstanceInfoResource.error()!" />
3333
} @else {
34-
<app-currently-loaded-models [instanceInfo]="currentInstanceInfoResource.value()!" />
34+
<app-currently-loaded-models [instanceId]="currentInstanceInfoResource.value()!.id" />
3535
}
3636

3737
<mat-divider />
@@ -41,7 +41,7 @@
4141
} @else if (currentInstanceInfoResource.error()) {
4242
<app-error-state [error]="currentInstanceInfoResource.error()!" />
4343
} @else {
44-
<app-project-context [projectId]="projectId()!" [instanceInfo]="currentInstanceInfoResource.value()!" />
44+
<app-project-context [projectId]="projectId()!" [instanceId]="currentInstanceInfoResource.value()!.id" />
4545
}
4646
</mat-card>
4747
}

src/Adapters/Driven/Rest/Api/IContextApi.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ namespace ScriptBee.Rest.Api;
55

66
public interface IContextApi
77
{
8+
[Get("/api/context")]
9+
Task<IEnumerable<RestContextSlice>> Get(CancellationToken cancellationToken);
10+
811
[Post("/api/context/clear")]
912
Task Clear(CancellationToken cancellationToken);
1013

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using ScriptBee.Domain.Model.Context;
2+
3+
namespace ScriptBee.Rest.Contracts;
4+
5+
public class RestContextSlice
6+
{
7+
public required string Model { get; set; }
8+
9+
public required IEnumerable<string> PluginIds { get; set; }
10+
11+
public ContextSlice Map()
12+
{
13+
return new ContextSlice(Model, PluginIds);
14+
}
15+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Refit;
2+
using ScriptBee.Domain.Model.Context;
3+
using ScriptBee.Domain.Model.Instance;
4+
using ScriptBee.Ports.Instance;
5+
using ScriptBee.Rest.Api;
6+
7+
namespace ScriptBee.Rest;
8+
9+
public class GetInstanceContextAdapter(IHttpClientFactory httpClientFactory) : IGetInstanceContext
10+
{
11+
public async Task<IEnumerable<ContextSlice>> Get(
12+
InstanceInfo instanceInfo,
13+
CancellationToken cancellationToken = default
14+
)
15+
{
16+
var client = httpClientFactory.CreateClient();
17+
client.BaseAddress = new Uri(instanceInfo.Url);
18+
19+
var contextApi = RestService.For<IContextApi>(client);
20+
21+
var restContextSlices = await contextApi.Get(cancellationToken);
22+
return restContextSlices.Select(s => s.Map());
23+
}
24+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using ScriptBee.Domain.Model.Context;
2+
3+
namespace ScriptBee.Analysis.Web.EndpointDefinitions.Context.Contracts;
4+
5+
public record WebContextSlice(string Model, IEnumerable<string> PluginIds)
6+
{
7+
public static WebContextSlice Map(ContextSlice contextSlice)
8+
{
9+
return new WebContextSlice(contextSlice.Model, contextSlice.PluginIds);
10+
}
11+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.AspNetCore.Http.HttpResults;
2+
using ScriptBee.Analysis.Web.EndpointDefinitions.Context.Contracts;
3+
using ScriptBee.Common.Web;
4+
using ScriptBee.Service.Analysis;
5+
using ScriptBee.UseCases.Analysis;
6+
7+
namespace ScriptBee.Analysis.Web.EndpointDefinitions.Context;
8+
9+
public class GetContextEndpoint : IEndpointDefinition
10+
{
11+
public void DefineServices(IServiceCollection services)
12+
{
13+
services.AddSingleton<IGetContextUseCase, GetContextService>();
14+
}
15+
16+
public void DefineEndpoints(IEndpointRouteBuilder app)
17+
{
18+
app.MapGet("/api/context", GetContext);
19+
}
20+
21+
private static Ok<IEnumerable<WebContextSlice>> GetContext(IGetContextUseCase useCase)
22+
{
23+
var contextSlices = useCase.Get();
24+
25+
return TypedResults.Ok(contextSlices.Select(WebContextSlice.Map));
26+
}
27+
}

src/Adapters/Driving/Web/EndpointDefinitions/Context/Contracts/WebGetProjectContextResponse.cs

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)