Skip to main content
NextYou're reading unreleased docs. Features and APIs may change before release.View latestv1.1.x
Back to iOS

FlowVariablesForm

The FlowVariablesForm view lets a delegated admin override the variables a flow declares for their organization unit. It loads the variables the flow shares with the unit, the values the unit has set, and what the unit may change, shows them as a form, and saves the values that differ from their defaults.

For a shared flow, a variable is offered to a unit only when a sharing policy names it. A variable the unit may not set is shown as set by its owner. This form saves the overrides of a unit the flow was shared with, not the owner's defaults. Change the defaults in the flow's VARIABLES node.

FlowVariablesForm requires .thunderIDProvider(config:) in its ancestor view hierarchy. The signed-in user's access token needs the permissions the server requires to read and update the flow's variables.

Usage​

swift
import SwiftUI
import ThunderIDSwiftUI

struct FlowSettings: View {
let flowId: String
let ouId: String

var body: some View {
FlowVariablesForm(flowId: flowId, ouId: ouId, onSaved: { _ in
print("Saved")
})
}
}

To let the admin pick the flow first, pair it with SharedFlowList.

Parameters​

ParameterTypeRequiredDescription
flowIdString✅Identifier of the flow whose variables are configured.
ouIdString✅The organization unit the overrides belong to.
titleString?❌Heading of the form. Defaults to the translated "Flow variables" heading.
descriptionString?❌Text under the heading.
ouNameString?❌The name of the organization unit, used in the notice and the connection hint.
ownerNameString?❌The name of whoever owns the flow, shown on a variable the unit may not set.
showScopeNoticeBool❌Shows a notice that the settings apply to the organization unit only. Defaults to false. Set ouName for it to read well.
readOnlyBool❌Shows the variables without letting them be changed. Defaults to false.
onSaved((FlowVariableValues) -> Void)?❌Called with the saved overrides.
onCancel(() -> Void)?❌Called when the admin taps Cancel. The button appears only when this is set.
onCreateConnection(() -> Void)?❌Called when the admin asks to create a connection from the hint under a connection variable. Without it, the hint does not offer one.
content(FlowVariablesFormState) -> Content❌Renders custom UI in place of the default form. See Custom Rendering.

Only the values that differ from their defaults are saved. A variable left at its default keeps following the default, even when the owner changes it later.

FlowVariableValues is [String: FlowVariableValue], keyed by the variable's identifier. FlowVariableValue is an enum with the cases .string, .number, and .bool. Read its text property for the value as a string.

Custom Rendering​

Pass a content closure to build the form with any UI while keeping the SDK's validation and rules. FlowVariablesForm still loads and saves the data, and passes the current state to the closure as a FlowVariablesFormState.

swift
FlowVariablesForm(flowId: flowId, ouId: ouId) { state in
VStack(alignment: .leading) {
ForEach(state.variables, id: \.identifier) { definition in
let rule = state.rule(for: definition)
HStack {
Text(definition.label ?? definition.identifier)
Spacer()
if rule.editable {
Text(state.values[definition.identifier]?.text ?? "")
} else {
Text("Set by owner")
}
}
}
Button("Save") { state.submit?() }
.disabled(!state.isValid || state.isSubmitting)
}
}

FlowVariablesFormState Properties​

PropertyTypeDescription
variables[FlowVariableDefinition]The variables to render.
valuesFlowVariableValuesThe current value of each variable.
errors[String: String]The translated message to show under each invalid variable, keyed by identifier.
isValidBoolWhether the values can be submitted.
isSubmittingBoolWhether a submission is in progress.
errorString?The form-level error.
submit(() -> Void)?Submits the current values. Does nothing while they are not valid. nil when the form cannot be saved.
resetToDefaults() -> VoidReturns every variable to its default.
onCancel(() -> Void)?The onCancel parameter.
MethodReturnsDescription
rule(for:)ResolvedFlowVariableRuleWhat the unit may do with a variable: whether it can set its own value, and the default it starts from.
options(for:)[FlowVariableOption]The choices of a select variable, narrowed to what the unit may pick.
setValue(_:for:)VoidSets the value of one variable, by identifier.

BaseFlowVariables​

BaseFlowVariables is the presentational form. It holds no data of its own: pass the variables and handle the submission. Use it to preview a flow's variables or to build a form from data you load yourself.

swift
struct Preview: View {
let variables: [FlowVariableDefinition]

var body: some View {
BaseFlowVariables(variables: variables)
}
}

Without overlay, every variable is editable. Without onSubmit, the form has no save button.

BaseFlowVariables Parameters​

ParameterTypeRequiredDescription
variables[FlowVariableDefinition]✅The variables to render, as the flow declares them.
connections[ConnectionInstance]❌The connections a CONNECTION_SELECT variable can take. Defaults to none.
initialValuesFlowVariableValues?❌The values the form starts with, over each variable's default. A variable left out starts at its default.
overlayResolvedOverlay?❌What the unit may do with each variable, as client.flows.overlayRules(id:ouId:fetcher:) returns it.
isSubmittingBool❌Disables the form and shows a loading state on the save button. Defaults to false.
errorString?❌An error message shown above the variables.
titleString?❌Heading of the form.
descriptionString?❌Text under the heading.
ouNameString?❌The name of the organization unit, used in the notice and the connection hint.
ownerNameString?❌The name of whoever owns the flow, shown on a variable the unit may not set.
showScopeNoticeBool❌Shows a notice that the settings apply to the organization unit only. Defaults to false.
readOnlyBool❌Shows the variables without letting them be changed. Defaults to false.
onSubmit((FlowVariableValues, FlowVariableValues) -> Void)?❌Called when the form is submitted and valid. The first argument holds every value. The second holds the values of the variables the unit may set that differ from their default.
onChange((FlowVariableValues) -> Void)?❌Called with every value after one changes.
onCancel(() -> Void)?❌Called when the admin taps Cancel. The button appears only when this is set, next to the save button, so it also needs onSubmit.
onCreateConnection(() -> Void)?❌Called when the admin asks to create a connection from the hint under a connection variable.
content(FlowVariablesFormState) -> Content❌Renders custom UI in place of the default form.

Each variable type renders its own input:

Variable typeInput
TEXT_INPUT, EMAIL_INPUT, PHONE_INPUT, NUMBER_INPUT, DATE_INPUTText field with the keyboard the type calls for
BOOLEAN_INPUTToggle
SELECT, CONNECTION_SELECTMenu. The first entry shows the default, for example "Use the default: Dark", and returns the variable to it.

Load the Data Yourself​

ThunderIDState.flowVariablesModel(flowId:ouId:fetcher:) returns the FlowVariablesModel behind the form, for a screen built entirely by your app. It is an ObservableObject: hold it as a @StateObject and call load() from .task.

swift
struct CustomSettings: View {
@StateObject private var model: FlowVariablesModel

init(state: ThunderIDState, flowId: String, ouId: String) {
_model = StateObject(wrappedValue: state.flowVariablesModel(flowId: flowId, ouId: ouId))
}

var body: some View {
BaseFlowVariables(
variables: model.definitions,
connections: model.connections,
initialValues: model.overrides,
overlay: model.overlay,
isSubmitting: model.isSaving,
onSubmit: { _, overrides in
Task { _ = await model.save(overrides) }
}
)
.task { await model.load() }
}
}
Property or methodDescription
flowThe flow as the organization unit sees it.
definitionsThe variables the flow declares for the unit.
overridesThe values the unit has set. A variable it has not set is absent, and its default applies.
overlayWhat the unit may do with each variable.
connectionsThe connections a CONNECTION_SELECT variable can take. Loaded only when a variable needs them.
isLoaded, errorWhether everything has arrived, and why it could not be loaded.
isSaving, saveErrorWhether a save is in progress, and why the last one failed.
load()Loads the flow, the unit's values, its rules, and the connections.
save(_:)Replaces the unit's values. A variable left out returns to its default. Never throws: read saveError. Returns the saved values, or nil when the save failed.

Flow Variable Helpers​

The form is built on these functions from the ThunderID module. Use them with any UI.

FunctionDescription
getFlowVariableDefinitions(_:)Reads the variables a flow declares. A flow shared with the unit lists them in variables. A flow the unit owns declares them on its VARIABLES node. Returns an empty array when the flow declares none.
resolveFlowVariableRule(_:overlay:)Works out what the unit may do with a variable. Returns a ResolvedFlowVariableRule with editable, defaultValue, allowedValues, and excludedValues. Without an overlay, every variable is editable.
getFlowVariableOptions(_:connections:restriction:)Lists what a select variable can take. A SELECT takes the values it declares. A CONNECTION_SELECT takes the connections that match its category and connectionTypes. Any other type returns an empty array.
validateFlowVariableValue(_:_:)Checks a value against the variable's type, options, and rules. Returns a FlowVariableValidationError, or nil when the value is valid.
swift
import ThunderID

let flow = try await client.flows.get(id: flowId, ouId: ouId)
let overlay = try await client.flows.overlayRules(id: flowId, ouId: ouId)

for definition in getFlowVariableDefinitions(flow) {
let rule = resolveFlowVariableRule(definition, overlay: overlay)
let problem = validateFlowVariableValue(definition, rule.defaultValue)
}

The owning unit does not use these helpers: the server rejects an override saved for it with HTTP 400, so it changes defaults in the flow's VARIABLES node.

A SELECT value is validated by its text, as the server does, so "true" is valid for an option true.

The FlowVariableValidationError.Code values are:

codeMeaning
.requiredThe value is empty.
.invalidThe value is not valid for the type, such as text that is not an email address or a number that is not numeric.
.minA number is below min.
.maxA number is above max.
.notOptionA SELECT value is not one of its options.
.minLengthText is shorter than a minLength rule allows.
.maxLengthText is longer than a maxLength rule allows.
.patternText does not match a regex rule.

For the three text rules, the error also carries the rule's message when it has one. The text rules are checked for TEXT_INPUT only, so a value can pass here and still be rejected by the server, which validates again on save. A regex rule that cannot be compiled is skipped, and the server judges it.

FlowVariableDefinition​

PropertyTypeDescription
identifierStringName of the variable, which a {{var(name)}} placeholder uses.
typeFlowVariableTypeThe input the variable is edited with: .textInput, .emailInput, .phoneInput, .numberInput, .dateInput, .booleanInput, .select, or .connectionSelect.
labelString?Display name.
descriptionString?Help text.
defaultValueFlowVariableValue?The value the variable has until another is set.
options[FlowVariableValue]?For a SELECT: the values it can take.
categoryString?For a CONNECTION_SELECT: the kind of connection it takes. The server accepts only IDENTITY_PROVIDER.
connectionTypes[String]?For a CONNECTION_SELECT: limits it to these vendors. The server accepts google, github, oidc, and oauth.
min, maxDouble?For a NUMBER_INPUT: the lowest and highest value.
validation[FlowVariableValidationRule]?Rules a text value has to meet.

Cache Keys​

FlowQueryKeys and FlowVariableQueryKeys name flow resources for caching. ThunderIDState uses them to refetch after a save. Reuse them as keys in your own data fetching cache.

ConstantKeys
FlowQueryKeysflows ("flows")
FlowVariableQueryKeysdefinitions ("flow-variable-definitions"), values ("flow-variable-values")

Internationalization​

The labels, errors, and notices come from the admin.flowVariables keys in the SDK's translations, available in all nine locales.

Explore with AI

ThunderID LogoThunderID Logo

Product

DocsAPIsSDKs
© Copyright Linux Foundation Europe.For web site terms of use, trademark policy and other project policies please see https://linuxfoundation.eu/en/policies.