100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
UI updates: Gateway dashboard fix incorrect URL when navigating to an already active tunnel (#1551)
Martin Peeterse2d268f0b523
diff --git a/ui/component/or-dashboard-builder/src/widgets/gateway-widget.ts b/ui/component/or-dashboard-builder/src/widgets/gateway-widget.tsindex b788c9bef..e54d0fad4 100644--- a/ui/component/or-dashboard-builder/src/widgets/gateway-widget.ts+++ b/ui/component/or-dashboard-builder/src/widgets/gateway-widget.ts@@ -30,7 +30,7 @@ const styling = css`flex-wrap: wrap;position: relative;}-`+`;export interface GatewayWidgetConfig extends WidgetConfig {gatewayId?: string;@@ -55,6 +55,10 @@ export class GatewayWidget extends OrWidget {@state()protected _loading = true;+ /**+ * Cache of the active {@link GatwayTunnelInfo} we receive from the HTTP API.+ * It contains all necessary information, such as ID, assigned port, target information, and autoCloseTime.+ */@state()protected _activeTunnel?: GatewayTunnelInfo;@@ -77,7 +81,7 @@ export class GatewayWidget extends OrWidget {getDefaultConfig(): GatewayWidgetConfig {return getDefaultWidgetConfig();}- }+ };}refreshContent(force: boolean): void {@@ -92,10 +96,10 @@ export class GatewayWidget extends OrWidget {if(this._activeTunnel) {if(this._startedByUser) {this._stopTunnel(this._activeTunnel).then(() => {- console.warn("Stopped the active tunnel, as it was created through the widget.")+ console.warn("Stopped the active tunnel, as it was created through the widget.");});} else {- console.warn("Keeping the active tunnel open, as it is not started through the widget.")+ console.warn("Keeping the active tunnel open, as it is not started through the widget.");}}@@ -151,7 +155,7 @@ export class GatewayWidget extends OrWidget {></or-mwc-input>`, () => html`<or-mwc-input .type="${InputType.BUTTON}" icon="open-in-new" label="${i18next.t('gatewayTunnels.open')}" outlined .disabled="${disabled}"- @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this._onTunnelNavigateClick(ev)}"+ @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this._onTunnelNavigateClick(ev, this._activeTunnel)}"></or-mwc-input>`)}</div>@@ -210,9 +214,9 @@ export class GatewayWidget extends OrWidget {/*** HTML callback function when 'open' button is pressed, meant to start using the tunnel.*/- protected _onTunnelNavigateClick(ev: OrInputChangedEvent) {- if (this._isConfigComplete(this.widgetConfig)) {- this._navigateToTunnel(this._getTunnelInfoByConfig(this.widgetConfig));+ protected _onTunnelNavigateClick(ev: OrInputChangedEvent, activeTunnel?: GatewayTunnelInfo) {+ if(activeTunnel) {+ this._navigateToTunnel(activeTunnel);} else {console.warn("Could not navigate to tunnel as configuration is not complete.")}@@ -350,7 +354,7 @@ export class GatewayWidget extends OrWidget {* It will open in a new browser tab automatically.*/protected _navigateToTunnel(info: GatewayTunnelInfo): void {- if (!info.realm || !info.gatewayId || !info.target || !info.targetPort) {+ if (!info.id || !info.realm || !info.gatewayId || !info.target || !info.targetPort) {console.warn("Could not navigate to tunnel, as some provided information was not set.");}const address = this._getTunnelAddress(info);@@ -367,6 +371,7 @@ export class GatewayWidget extends OrWidget {/*** Internal function to get the tunnel address based on {@link GatewayTunnelInfo}+ * WARNING: Could return incorrect address if not all fields are set.*/protected _getTunnelAddress(info: GatewayTunnelInfo): string | undefined {switch (info.type) {@@ -404,6 +409,7 @@ export class GatewayWidget extends OrWidget {/*** Internal function that parses a {@link GatewayWidgetConfig} into a new {@link GatewayTunnelInfo}.+ * Be aware: this does not information received from the HTTP API such as ID, assigned port, etc. Please use {@link _activeTunnel} for this.*/protected _getTunnelInfoByConfig(config: GatewayWidgetConfig): GatewayTunnelInfo {return {