Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import ArcGIS
import Observation

private import os

@MainActor @Observable
class EmbeddedFeatureFormViewModel {
/// The current focused element, if one exists.
Expand Down Expand Up @@ -88,7 +90,13 @@ class EmbeddedFeatureFormViewModel {
func evaluateExpressions() {
evaluateTask?.cancel()
evaluateTask = Task {
_ = try? await featureForm.evaluateExpressions()
if let errors = try? await featureForm.evaluateExpressions(), !errors.isEmpty {
for evaluationError in errors {
Logger.featureFormView.error(
"Error evaluating expression: \(evaluationError.error.localizedDescription)"
)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ extension FeatureFormView {
embeddedFeatureFormViewModel, element, filter, source, assetType
)
)
.accessibilityIdentifier("Asset Type \(assetType.name) \(assetType.code)")
}
} header: {
HStack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import ArcGIS
import SwiftUI

private import os

extension FeatureFormView {
/// A view to configure and add a utility network association.
struct UtilityAssociationCreationView: View {
Expand All @@ -30,7 +32,7 @@ extension FeatureFormView {
/// See also: `includeContentVisibility`.
@State private var contentIsVisible: Bool = false
/// How far along an edge the association is located.
@State private var fractionAlongEdge: Double = 0.5
@State private var fractionAlongEdge: Double = 0
/// The options for a utility network feature when creating an association.
@State private var options: UtilityAssociationFeatureOptions? = nil
/// A Boolean value which indicates when the configured association is being added.
Expand Down Expand Up @@ -82,17 +84,18 @@ extension FeatureFormView {
func addAssociation() async {
guard let options else { return }
do {
let result: UtilityAssociationResult
if includeContentVisibility {
try await element.addAssociation(feature: candidate.feature, filter: filter, isContainmentVisible: contentIsVisible)
result = try await element.addAssociation(feature: candidate.feature, filter: filter, isContainmentVisible: contentIsVisible)
} else {
switch (options.isFractionAlongEdgeValid, terminalForFromSide, terminalForToSide) {
result = switch (options.isFractionAlongEdgeValid, terminalForFromSide, terminalForToSide) {
case let (true, .some(terminal), .none):
try await element.addAssociation(feature: candidate.feature, filter: filter, fractionAlongEdge: fractionAlongEdge, terminal: terminal)
case let (true, .none, .some(terminal)):
try await element.addAssociation(feature: candidate.feature, filter: filter, fractionAlongEdge: fractionAlongEdge, terminal: terminal)
case (true, .none, .none):
try await element.addAssociation(feature: candidate.feature, filter: filter, fractionAlongEdge: fractionAlongEdge)
case (false, .some, .some):
case (false, _, _):
Comment on lines -95 to +98
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix for Apollo 1461.

try await element.addAssociation(
feature: candidate.feature,
featureTerminal: candidateIsToElement
Expand All @@ -107,6 +110,7 @@ extension FeatureFormView {
try await element.addAssociation(feature: candidate.feature, filter: filter)
}
}
Logger.featureFormView.info("Association added to \(result.title)")
// After the association is created, remove the creation
// workflow views from the navigation path. This includes:
// 1. UtilityAssociationCreationView
Expand All @@ -120,6 +124,9 @@ extension FeatureFormView {
// views to avoid errors here. (FB20395585)
// https://developer.apple.com/forums/thread/802221#802221021
navigationPath?.wrappedValue.removeLast(4)
} catch let error as ArcGIS.InvalidArgumentError {
addAssociationError = .other(error.details)
alertIsPresented = true
} catch {
addAssociationError = .anyError(error)
alertIsPresented = true
Expand Down Expand Up @@ -243,8 +250,8 @@ extension FeatureFormView {
} label: {
Text(LocalizedStringResource.fractionAlongEdge)
}
Slider(value: $fractionAlongEdge, in: 0...1) { _ in
LocalizedStringResource.fractionAlongEdge
Slider(value: $fractionAlongEdge, in: 0...1) {
Text(LocalizedStringResource.fractionAlongEdge)
Comment on lines +253 to +254
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolves warning Expression of type 'LocalizedStringResource' is unused - wrong symbol was being used.

}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Test Runner/Test Runner/TestViews/FeatureFormTestView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ private extension FeatureFormTestView {
.init("testCase_12_4", objectID: 2584, layerName: "Electric Distribution Device", portalID: .napervilleElectricUtilityNetwork, credentialInfo: .sampleServer7Viewer01),
.init("testCase_12_5", objectID: 3321, layerName: "Electric Distribution Device", portalID: .napervilleElectricUtilityNetwork, credentialInfo: .sampleServer7Viewer01),
.init("testCase_12_6", objectID: 3321, layerName: "Electric Distribution Device", portalID: .napervilleElectricUtilityNetwork, credentialInfo: .sampleServer7Viewer01),
.init("testCase_13_1", objectID: 3321, layerName: "Electric Distribution Device", portalID: .napervilleElectricUtilityNetwork, credentialInfo: .sampleServer7Viewer01),
.init("testCase_13_2", objectID: 5050, layerName: "Electric Distribution Device", portalID: .napervilleElectricUtilityNetwork, credentialInfo: .sampleServer7Viewer01),
.init("testCase_13_3", objectID: 311, layerName: "Electric Distribution Junction", portalID: .napervilleElectricUtilityNetwork, credentialInfo: .sampleServer7Viewer01),
]}
}

Expand Down
Loading