From 00355b2e202e54695832e8d3e616350f74ff8684 Mon Sep 17 00:00:00 2001 From: Falcon Date: Wed, 13 Nov 2024 16:17:57 -0800 Subject: [PATCH] feat: implement package deletion button --- examples/gauge/Components/InterfaceSample.tsx | 44 ++++++-------- .../Components/Pages/Dashboard/Dashboard.tsx | 58 +++++++++++++++++-- 2 files changed, 73 insertions(+), 29 deletions(-) diff --git a/examples/gauge/Components/InterfaceSample.tsx b/examples/gauge/Components/InterfaceSample.tsx index 3becd036..ce51ff55 100644 --- a/examples/gauge/Components/InterfaceSample.tsx +++ b/examples/gauge/Components/InterfaceSample.tsx @@ -24,6 +24,7 @@ export class InterfaceSample extends DisplayComponent { private readonly activeDatabase = Subject.create(null) private readonly databases = ArraySubject.create([]) + private readonly resetPackageList = Subject.create(false) private readonly mainPageIndex = Subject.create(0) private readonly selectedDatabaseIndex = Subject.create(0) private readonly selectedDatabase = Subject.create(null) @@ -65,6 +66,7 @@ export class InterfaceSample extends DisplayComponent { this.selectedDatabase.set(database)} @@ -111,30 +113,22 @@ export class InterfaceSample extends DisplayComponent { this.loadingRef.instance.style.display = "none" }) - // this.executeIcaoButtonRef.instance.addEventListener("click", () => { - // console.time("query") - // this.navigationDataInterface - // .get_arrivals_at_airport(this.icaoInputRef.instance.value) - // .then(procedures => { - // console.info(procedures) - // this.outputRef.instance.textContent = JSON.stringify(procedures, null, 2) - // }) - // .catch(e => console.error(e)) - // .finally(() => console.timeEnd("query")) - // }) - - // this.loadDbRef.instance.addEventListener("click", () => this.handleLoadDbClick()) - - // this.executeSqlButtonRef.instance.addEventListener("click", () => { - // console.time("query") - // this.navigationDataInterface - // .execute_sql(this.sqlInputRef.instance.value, []) - // .then(result => { - // console.info(result) - // this.outputRef.instance.textContent = JSON.stringify(result, null, 2) - // }) - // .catch(e => console.error(e)) - // .finally(() => console.timeEnd("query")) - // }) + this.resetPackageList.map(async val => { + if (!val) { + return + } + + const pkgs = await this.navigationDataInterface.list_available_packages(true) + + const activePackage = await this.navigationDataInterface.get_active_package() + + this.activeDatabase.set(activePackage) + this.selectedDatabase.set(activePackage) + this.selectedDatabaseIndex.set(pkgs.findIndex(pkg => pkg.uuid === activePackage?.uuid)) + + this.databases.set(pkgs) + + this.resetPackageList.set(false) + }) } } diff --git a/examples/gauge/Components/Pages/Dashboard/Dashboard.tsx b/examples/gauge/Components/Pages/Dashboard/Dashboard.tsx index 3a9d2aa6..bca93e19 100644 --- a/examples/gauge/Components/Pages/Dashboard/Dashboard.tsx +++ b/examples/gauge/Components/Pages/Dashboard/Dashboard.tsx @@ -4,6 +4,7 @@ import { FSComponent, MappedSubject, MappedSubscribable, + MutableSubscribable, Subscribable, SubscribableArray, VNode, @@ -14,6 +15,7 @@ import { Button, InterfaceNavbarItemV2, InterfaceSwitch } from "../../Utils" interface DashboardProps extends ComponentProps { databases: SubscribableArray + reloadPackageList: MutableSubscribable selectedDatabase: Subscribable selectedDatabaseIndex: Subscribable setSelectedDatabase: (database: PackageInfo) => void @@ -61,6 +63,42 @@ export class Dashboard extends DisplayComponent { .set_active_package(selectedDatabase.uuid) .then(_res => {}) .catch(err => console.error(err)) + + this.props.reloadPackageList.set(true) + } + + private deleteSelected() { + const prevSelectedDatabase = this.props.selectedDatabase.get() + + if (prevSelectedDatabase === null || this.props.databases.length <= 1) { + return + } + + let pkg + + try { + if (this.props.selectedDatabaseIndex.get() === 0) { + pkg = this.props.databases.get(1) + } else { + pkg = this.props.databases.get(0) + } + } catch { + return + } + + if (this.showActiveDatabase.get()) { + this.props.interface + .set_active_package(pkg.uuid) + .then(_res => {}) + .catch(err => console.error(err)) + } + + this.props.interface + .delete_package(prevSelectedDatabase.uuid) + .then(_res => {}) + .catch(err => console.error(err)) + + this.props.reloadPackageList.set(true) } render(): VNode { @@ -78,9 +116,17 @@ export class Dashboard extends DisplayComponent { /> - +
+ + +
@@ -110,8 +156,12 @@ class ActiveDatabase extends DisplayComponent { [1,

Selected Database

], ]} /> -
+
+
+ UUID: + {this.props.selectedDatabase.map(s => s?.uuid)} +

Bundled

{this.props.selectedDatabase.map(s => s?.is_bundled)}