From cd68b95a3e32b8f74aff2efcf367da83a2e42a5f Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Fri, 5 Jul 2019 08:19:05 -0500 Subject: [PATCH] add a mechanism for ignoring InlineUserProperty's force_override property --- .../spark/Orders/OrderPropertiesEditorVM.cs | 15 ++++++++++++--- src/client/spark/core/Utility/ViewModelBase.cs | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/client/spark/Orders/OrderPropertiesEditorVM.cs b/src/client/spark/Orders/OrderPropertiesEditorVM.cs index bcf276bec..122ac1589 100644 --- a/src/client/spark/Orders/OrderPropertiesEditorVM.cs +++ b/src/client/spark/Orders/OrderPropertiesEditorVM.cs @@ -105,7 +105,7 @@ namespace mbts.spark { var inline_account_src = order_properties.AggregateLatest( model.factory.subscribe_accounts(), (last, change, cache) => convert_inline_account(change.New.account, cache), - (last, props, change) => convert_inline_account(props.account, change.New), + (last, props, change) => convert_inline_account(props.account, change.New, false), () => new InlineUserProperty(), new InlineOrderProperties(), DictionaryHelper.empty()); @@ -263,9 +263,18 @@ namespace mbts.spark { break; } } - InlineUserProperty convert_inline_account(InlineUserProperty account_id, IReadOnlyDictionary account_map) => + // + // Regarding the 3rd parameter, force_override_from_inline_property: + // When using an InlineUserProperty, in the context of assigning a default vs selected item, + // there is somewhat of a conflict between the IObserver> and the + // IObserver> OnNext methods. This 3rd paramter provides yet another override + // to say if the force_override should come from the inline property or if the force_override should + // be disbled, by way of the immediate return in ViewModelBase._try_auto_select when force_override + // is false. Our intent is then accomplished because we are no longer attempting to set a default/ + // selected item when the account_tuples potentially changes + InlineUserProperty convert_inline_account(InlineUserProperty account_id, IReadOnlyDictionary account_map, bool force_override_from_inline_property = true) => account_id.has_value && account_map.TryGetValue(account_id.value, out string name) ? - new InlineUserProperty(new AccountTuple(account_id.value, name), account_id.force_override) : + new InlineUserProperty(new AccountTuple(account_id.value, name), force_override_from_inline_property ? account_id.force_override : false) : new InlineUserProperty(); } diff --git a/src/client/spark/core/Utility/ViewModelBase.cs b/src/client/spark/core/Utility/ViewModelBase.cs index 3800e98bf..8fa702aaf 100644 --- a/src/client/spark/core/Utility/ViewModelBase.cs +++ b/src/client/spark/core/Utility/ViewModelBase.cs @@ -820,6 +820,11 @@ namespace mbts.ui.shell { void _try_auto_select() { if (_is_user_selected_item) { + // if we have a user-selected item and the _desired_item for which we might want to set as the selected item + // isn't force_override, then no change + if (!_desired_item.force_override) { + return; + } if (desired_item_valid() && _desired_item.force_override && _try_match_item(_desired_item.value, out TValue match)) { _set_selected_item(match, SelectionReason.SettingsMandatedSelection); return;