feat(central-ui): NodeBrowserDialog emits full node + optional ShowSearch
Fully suppress search UI (box + results panel) when ShowSearch=false, and reset search state on ShowAsync so a reused dialog never shows stale results.
This commit is contained in:
@@ -22,15 +22,18 @@
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<input class="form-control" data-test="node-search-input"
|
||||
@bind="_searchQuery" @bind:event="oninput"
|
||||
@onkeydown="SearchOnEnter"
|
||||
placeholder="Search the address space by name or path…" />
|
||||
<button class="btn btn-outline-primary" data-test="node-search-button" @onclick="SearchAsync">Search</button>
|
||||
</div>
|
||||
@if (ShowSearch)
|
||||
{
|
||||
<div class="input-group mb-3">
|
||||
<input class="form-control" data-test="node-search-input"
|
||||
@bind="_searchQuery" @bind:event="oninput"
|
||||
@onkeydown="SearchOnEnter"
|
||||
placeholder="Search the address space by name or path…" />
|
||||
<button class="btn btn-outline-primary" data-test="node-search-button" @onclick="SearchAsync">Search</button>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (_searchActive)
|
||||
@if (ShowSearch && _searchActive)
|
||||
{
|
||||
<div class="node-browser-search mb-3">
|
||||
@if (_searchResults.Count == 0)
|
||||
@@ -113,8 +116,19 @@
|
||||
[Parameter] public EventCallback<string> OnSelected { get; set; }
|
||||
[Parameter] public EventCallback OnCancelled { get; set; }
|
||||
|
||||
/// <summary>Additive: receives the full selected <see cref="BrowseNode"/> (incl.
|
||||
/// DataType) on confirm, alongside the existing string-id <see cref="OnSelected"/>.
|
||||
/// Optional — existing callers that only wire OnSelected are unaffected.</summary>
|
||||
[Parameter] public EventCallback<BrowseNode> OnNodeSelected { get; set; }
|
||||
|
||||
/// <summary>When false, hides the address-space search box. Set false for protocols
|
||||
/// that don't implement IAddressSpaceSearchable (e.g. MxGateway), where search would
|
||||
/// always fail. Default true preserves OPC UA behaviour.</summary>
|
||||
[Parameter] public bool ShowSearch { get; set; } = true;
|
||||
|
||||
private bool _isVisible;
|
||||
private string? _selectedNodeId;
|
||||
private BrowseNode? _selectedNode;
|
||||
private string _manualNodeId = "";
|
||||
private BrowseFailure? _failure;
|
||||
private string _failureMessage = "";
|
||||
@@ -148,6 +162,10 @@
|
||||
/// </summary>
|
||||
public string? DataType { get; init; }
|
||||
|
||||
/// <summary>The originating BrowseNode, retained so selection can emit the
|
||||
/// full node (incl. DataType) via OnNodeSelected.</summary>
|
||||
public BrowseNode? Source { get; init; }
|
||||
|
||||
public List<TreeNode>? Children { get; set; } // null = not loaded yet
|
||||
public bool Expanded { get; set; }
|
||||
public bool Loading { get; set; }
|
||||
@@ -174,6 +192,14 @@
|
||||
_isVisible = true;
|
||||
_manualNodeId = initialNodeId ?? "";
|
||||
_selectedNodeId = initialNodeId;
|
||||
_selectedNode = null;
|
||||
// Reset any prior search state so a reused dialog instance never renders
|
||||
// stale results on re-open (and the search panel stays fully suppressed
|
||||
// when ShowSearch is false).
|
||||
_searchActive = false;
|
||||
_searchQuery = "";
|
||||
_searchResults = new();
|
||||
_searchCapReached = false;
|
||||
await LoadRootAsync();
|
||||
}
|
||||
|
||||
@@ -195,7 +221,7 @@
|
||||
}
|
||||
|
||||
private static TreeNode ToTreeNode(BrowseNode c) =>
|
||||
new(c.NodeId, c.DisplayName, c.NodeClass, c.HasChildren) { DataType = c.DataType };
|
||||
new(c.NodeId, c.DisplayName, c.NodeClass, c.HasChildren) { DataType = c.DataType, Source = c };
|
||||
|
||||
private async Task ToggleAsync(TreeNode node)
|
||||
{
|
||||
@@ -311,6 +337,7 @@
|
||||
if (node.NodeClass != BrowseNodeClass.Variable) return;
|
||||
_selectedNodeId = node.NodeId;
|
||||
_manualNodeId = node.NodeId;
|
||||
_selectedNode = node;
|
||||
}
|
||||
|
||||
private void Select(TreeNode node)
|
||||
@@ -318,6 +345,7 @@
|
||||
if (node.NodeClass != BrowseNodeClass.Variable) return;
|
||||
_selectedNodeId = node.NodeId;
|
||||
_manualNodeId = node.NodeId;
|
||||
_selectedNode = node.Source;
|
||||
}
|
||||
|
||||
// Task 17: map each BrowseFailureKind to a friendly UI message. Messages are
|
||||
@@ -349,13 +377,19 @@
|
||||
private void UseManual()
|
||||
{
|
||||
_selectedNodeId = _manualNodeId.Trim();
|
||||
_selectedNode = null;
|
||||
}
|
||||
|
||||
private async Task Confirm()
|
||||
{
|
||||
_isVisible = false;
|
||||
if (!string.IsNullOrWhiteSpace(_selectedNodeId))
|
||||
{
|
||||
await OnSelected.InvokeAsync(_selectedNodeId!);
|
||||
if (OnNodeSelected.HasDelegate)
|
||||
await OnNodeSelected.InvokeAsync(
|
||||
_selectedNode ?? new BrowseNode(_selectedNodeId!, _selectedNodeId!, BrowseNodeClass.Variable, HasChildren: false));
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Cancel()
|
||||
|
||||
Reference in New Issue
Block a user