From 1380f673fd034d0516fb4dfa0d8a187ab3549970 Mon Sep 17 00:00:00 2001 From: Andreas Ernst Date: Fri, 1 Nov 2024 16:18:15 +0100 Subject: [PATCH] some fixes --- .../application-tree.component.ts | 45 ++++++++++++++----- .../applications/application.feature.ts | 44 ++++++++++-------- .../portal-administration-service.service.ts | 16 ++++++- .../portal/PortalAdministrationService.kt | 15 +++++-- .../impl/PortalAdministrationServiceImpl.kt | 23 ++++++++++ 5 files changed, 108 insertions(+), 35 deletions(-) diff --git a/modulefederation/apps/web/src/app/portal/applications/application-tree/application-tree.component.ts b/modulefederation/apps/web/src/app/portal/applications/application-tree/application-tree.component.ts index 93c36ab1..54f6b571 100644 --- a/modulefederation/apps/web/src/app/portal/applications/application-tree/application-tree.component.ts +++ b/modulefederation/apps/web/src/app/portal/applications/application-tree/application-tree.component.ts @@ -68,9 +68,10 @@ export class ApplicationTreeComponent implements OnInit, OnChanges { const version = treeConfig.instance!.version let node : Node - if ( treeConfig.microfrontend) { - // add microfrontend + // new microfrontend? + + if ( treeConfig.microfrontend) { node = { type: "microfrontend", data: treeConfig.microfrontend, @@ -81,22 +82,24 @@ export class ApplicationTreeComponent implements OnInit, OnChanges { } else node = this.dataSource.data.find(node => node.data.name == mfe)! - if (treeConfig.version) { - // add version + // new version? + if (treeConfig.version) { node!.children?.push(node = { type: "microfrontend-version", data: treeConfig.version, + parent: node, children: [] }) } else node = node.children!.find(node => node.data.version == version)! - if (treeConfig.instance) { - // add instance + // instance? + if (treeConfig.instance) { node!.children?.push(node = { type: "microfrontend-instance", + parent: node, data: treeConfig.instance }) } @@ -122,14 +125,34 @@ export class ApplicationTreeComponent implements OnInit, OnChanges { return node } - deletedApplication(node: Node) { - this.dataSource.data.splice(this.dataSource.data.indexOf(node), 1) - this.refreshData() + indexOf(node: Node) { + if ( node.parent) + return node.parent!.children!.indexOf(node) + else + return this.dataSource.data.indexOf(node) } - deletedApplicationVersion(node: Node) { - node.parent?.children?.splice(node.parent?.children.indexOf(node), 1) + // return the node which should be selected + + deletedNode(node: Node) : Node | undefined { + let nextNode : Node | undefined = undefined + const index = this.indexOf(node) + + if ( node.parent) { + const children = node.parent!.children! + + children.splice(index, 1) + nextNode = children.length > 0 ? children[Math.max(children.length - 1, index)] : node.parent + } + else { + const children = this.dataSource.data + children.splice(index, 1) + nextNode = children.length > 0 ? children[Math.max(children.length - 1, index)] : undefined + } + this.refreshData() + + return nextNode } addApplication(application: Application) : Node{ diff --git a/modulefederation/apps/web/src/app/portal/applications/application.feature.ts b/modulefederation/apps/web/src/app/portal/applications/application.feature.ts index bc150846..7534c3c3 100644 --- a/modulefederation/apps/web/src/app/portal/applications/application.feature.ts +++ b/modulefederation/apps/web/src/app/portal/applications/application.feature.ts @@ -168,7 +168,7 @@ export class ApplicationFeatureComponent extends WithCommandToolbar(WithCommands } } - selectNode(node: Node) { + selectNode(node: Node | undefined) { if ( this.dirty) { this.confirmationDialog() .title("Dirty") @@ -195,23 +195,25 @@ export class ApplicationFeatureComponent extends WithCommandToolbar(WithCommands this.selectedMicrofrontendVersion = undefined this.selectedMicrofrontendInstance = undefined - if ( node.type == "microfrontend") - this.selectedMicrofrontend = node.data + if ( node ) { + if ( node.type == "microfrontend") + this.selectedMicrofrontend = node.data - else if ( node.type == "microfrontend-version") { - this.microfrontend = node.parent?.data - this.selectedMicrofrontendVersion = node.data - } + else if ( node.type == "microfrontend-version") { + this.microfrontend = node.parent?.data + this.selectedMicrofrontendVersion = node.data + } - else if ( node.type == "application") - this.selectedApplication = node.data + else if ( node.type == "application") + this.selectedApplication = node.data - else if ( node.type == "application-version") { - this.application = node.parent?.data - this.selectedVersion = node.data + else if ( node.type == "application-version") { + this.application = node.parent?.data + this.selectedVersion = node.data + } } - this.updateCommandState() + this.updateCommandState() } // private @@ -256,24 +258,28 @@ export class ApplicationFeatureComponent extends WithCommandToolbar(WithCommands } deleteApplication(node: Node) { - this.portalAdministrationService.deleteApplication(node.data.name).subscribe() + this.portalAdministrationService.deleteApplication(node.data.name).subscribe(_ => { + this.selectNode( this.tree.deletedNode(node)!) + }) } deleteMicrofrontend(node: Node) { - // TODO + this.portalAdministrationService.deleteMicrofrontend(node.data.name).subscribe(_ => { + this.selectNode( this.tree.deletedNode(node)!) + }) } deleteMicrofrontendVersion(node: Node) { - // TODO + this.portalAdministrationService.deleteMicrofrontendVersion(node.parent!.data.name, node.data.version).subscribe(_ => { + this.selectNode(this.tree.deletedNode(node)!) + }) } deleteApplicationVersion(node: Node) { const application : Application = node.parent?.data this.portalAdministrationService.deleteApplicationVersion(application.name, node.data.version).subscribe(_ => { - this.tree.deletedApplicationVersion(node) - - this.selectNode(node.parent!) + this.selectNode(this.tree.deletedNode(node)!) }) } diff --git a/modulefederation/apps/web/src/app/portal/service/portal-administration-service.service.ts b/modulefederation/apps/web/src/app/portal/service/portal-administration-service.service.ts index 224f738f..c8efc556 100644 --- a/modulefederation/apps/web/src/app/portal/service/portal-administration-service.service.ts +++ b/modulefederation/apps/web/src/app/portal/service/portal-administration-service.service.ts @@ -92,7 +92,7 @@ export class PortalAdministrationService extends AbstractHTTPService { } deleteApplication(application: String) :Observable { - return this.delete(`delete-application/${application}`) + return this.get(`delete-application/${application}`) } readApplications() : Observable{ @@ -110,7 +110,7 @@ export class PortalAdministrationService extends AbstractHTTPService { } deleteApplicationVersion( application: String, version: string) : Observable { - return this.delete(`delete-application-version/${application}/${version}`) + return this.get(`delete-application-version/${application}/${version}`) } // microfrontend @@ -123,6 +123,10 @@ export class PortalAdministrationService extends AbstractHTTPService { return this.post(`update-microfrontend`, microfrontend) } + deleteMicrofrontend( microfrontend: String) : Observable { + return this.get(`delete-microfrontend/${microfrontend}`) + } + // microfrontend versions readMicrofrontendVersions() : Observable { @@ -133,6 +137,10 @@ export class PortalAdministrationService extends AbstractHTTPService { return this.post(`update-microfrontend-version`, version) } + deleteMicrofrontendVersion( microfrontend: String, version : String) : Observable { + return this.get(`delete-microfrontend-version/${microfrontend}/${version}`) + } + // microfrontend instances updateMicrofrontendInstance(instance: MicrofrontendInstance) : Observable { @@ -143,6 +151,10 @@ export class PortalAdministrationService extends AbstractHTTPService { return this.post(`register-microfrontend-instance`, manifest) } + deleteMicrofrontendInstance( microfrontend: String, version : String, instance : String) : Observable { + return this.get(`delete-microfrontend-instance/${microfrontend}/${version}/${instance}`) + } + // TEST computeApplicationVersionConfiguration(application: number) : Observable { diff --git a/portal/core/src/main/java/com/serious/portal/PortalAdministrationService.kt b/portal/core/src/main/java/com/serious/portal/PortalAdministrationService.kt index f99050a0..ebb08a3e 100644 --- a/portal/core/src/main/java/com/serious/portal/PortalAdministrationService.kt +++ b/portal/core/src/main/java/com/serious/portal/PortalAdministrationService.kt @@ -55,7 +55,7 @@ interface PortalAdministrationService : Service { @PostMapping("create-stage") fun createStage(@RequestBody stage: String) - @DeleteMapping("delete-stage/{stage}") + @GetMapping("delete-stage/{stage}") fun deleteStage(@PathVariable stage: String) @GetMapping("read-stages") @@ -75,7 +75,7 @@ interface PortalAdministrationService : Service { @PostMapping("update-application") fun updateApplication(@RequestBody application: Application) : Application - @DeleteMapping("delete-application/{application}") + @GetMapping("delete-application/{application}") fun deleteApplication(@PathVariable application: String) @GetMapping("read-applications") @@ -91,7 +91,7 @@ interface PortalAdministrationService : Service { @PostMapping("update-application-version") fun updateApplicationVersion(@RequestBody application: ApplicationVersion) : ApplicationVersion - @DeleteMapping("delete-application-version/{application}/{version}") + @GetMapping("delete-application-version/{application}/{version}") fun deleteApplicationVersion(@PathVariable application: String, @PathVariable version: String) // microfrontend @@ -104,6 +104,9 @@ interface PortalAdministrationService : Service { @ResponseBody fun updateMicrofrontend(@RequestBody version: Microfrontend) : Microfrontend + @GetMapping("delete-microfrontend/{microfrontend}") + fun deleteMicrofrontend(@PathVariable microfrontend: String) + // microfrontend version @GetMapping("read-microfrontend-versions") @@ -114,6 +117,9 @@ interface PortalAdministrationService : Service { @ResponseBody fun updateMicrofrontendVersion(@RequestBody version: MicrofrontendVersion) : MicrofrontendVersion + @GetMapping("delete-microfrontend-version/{microfrontend}/{version}") + fun deleteMicrofrontendVersion(@PathVariable microfrontend: String, @PathVariable version: String) + // microfrontend instance @PostMapping("update-microfrontend-instance") @@ -123,4 +129,7 @@ interface PortalAdministrationService : Service { @PostMapping("register-microfrontend-instance") @ResponseBody fun registerMicrofrontendInstance(@RequestBody manifest: Manifest) : MicrofrontendRegistryResult + + @GetMapping("delete-microfrontend-instance/{microfrontend}/{version}/{instance}") + fun deleteMicrofrontendInstance(@PathVariable microfrontend: String, @PathVariable version: String, @PathVariable instance: String) } diff --git a/portal/core/src/main/java/com/serious/portal/impl/PortalAdministrationServiceImpl.kt b/portal/core/src/main/java/com/serious/portal/impl/PortalAdministrationServiceImpl.kt index 963ab45f..db98d89e 100644 --- a/portal/core/src/main/java/com/serious/portal/impl/PortalAdministrationServiceImpl.kt +++ b/portal/core/src/main/java/com/serious/portal/impl/PortalAdministrationServiceImpl.kt @@ -389,6 +389,11 @@ class PortalAdministrationServiceImpl : PortalAdministrationService { return microfrontend } + @Transactional + override fun deleteMicrofrontend(@PathVariable microfrontend: String) { + this.microfrontendRepository.deleteById(microfrontend) + } + // microfrontend versions @Transactional @@ -412,8 +417,26 @@ class PortalAdministrationServiceImpl : PortalAdministrationService { return version } + @Transactional + override fun deleteMicrofrontendVersion(microfrontend: String, version: String) { + val microfrontend = this.microfrontendRepository.findById(microfrontend).get() + val version = microfrontend.versions.find { mfev -> mfev.version == version }!! + + microfrontendVersionRepository.delete(version) + } + // microfrontend instance + @Transactional + override fun deleteMicrofrontendInstance(microfrontend: String, version: String, instance: String) { + val microfrontend = this.microfrontendRepository.findById(microfrontend).get() + val version = microfrontend.versions.find { mfev -> mfev.version == version }!! + val instance = version.instances.find { i -> i.uri == instance } + + microfrontendInstanceRepository.delete(instance!!) + } + + @Transactional override fun updateMicrofrontendInstance(instance: MicrofrontendInstance) : MicrofrontendInstance { val entity = this.microfrontendInstanceRepository.findById(instance.uri).get()