-
Notifications
You must be signed in to change notification settings - Fork 2
[Environments] Adding configuration flow #3492
Conversation
4e9c162
to
f100da9
Compare
tools/Environments/DevHome.Environments/Strings/en-us/Resources.resw
Outdated
Show resolved
Hide resolved
tools/SetupFlow/DevHome.SetupFlow/ViewModels/SetupFlowViewModel.cs
Outdated
Show resolved
Hide resolved
@@ -73,6 +75,7 @@ public partial class ComputeSystemViewModel : ComputeSystemCardBase, IRecipient< | |||
IComputeSystem system, | |||
ComputeSystemProvider provider, | |||
Func<ComputeSystemCardBase, bool> removalAction, | |||
Action<ComputeSystemReviewItem>? configurationAction, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this constructor is getting pretty big, we should combine some of these parameters into objects. E.g we can have an object to contain the actions like:
// In a new class called DevHomeUIActions
public Func<ComputeSystemCardBase, bool> RemoveComputeSystem;
public Action<ComputeSystemReviewItem>? StartComputeSystemSetup;
public DevHomeUIActions(
Func<ComputeSystemCardBase, bool> removalAction,
Action<ComputeSystemReviewItem>? startConfigurationFlowAction)
{
// add to public properties....
RemoveComputeSystem = removalAction;
StartComputeSystemSetup = startConfigurationFlowAction
}
///// DevHomeUIActions end
// Then use it as a parameter for the `ComputeSystemViewModel`'s constructor
private readonly ComputeSystemReviewItem _reviewItem;
private readonly DevHomeUIActions _uiActions;
public ComputeSystemViewModel(
IComputeSystemManager manager,
IComputeSystem system,
ComputeSystemProvider provider,
DevHomeUIActions uiActions,
string packageFullName,
Window window)
{
...
ComputeSystem = new(system);
_uiActions = uiActions;
_reviewItem = new (ComputeSystem , provider);
...
}
If we do it this way, we don't need to add the new field above (_configurationAction
) on line 61 in this PR. As it'll be in the UIActions property. Your codeflow will remain the same, this just helps keep the constructor more manageable. In the future we can reduce the number of parameters further by doing more consolidation, but I think for what we're doing in this PR, this should suffice.
Since we know the provider and the ComputeSystemCache are available in the constructor, we can also create the ComputeSystemReviewItem directly in the constructor. See comment below on how we can use it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gonna skip this for a later PR that might add more; quite a few examples with 7 or more parameters in the constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding my 2-cents. A ctor with many parameters tells me that this class is trying to do too many things. I wonder if this class can be split? No need to respond to this comment.
@@ -151,6 +152,12 @@ public static List<OperationsViewModel> FillLaunchButtonOperations(ComputeSystem | |||
_stringResource.GetLocalized("Operations_Terminate"), "\uEE95", computeSystem.TerminateAsync, ComputeSystemOperations.Terminate)); | |||
} | |||
|
|||
if (supportedOperations.HasFlag(ComputeSystemOperations.ApplyConfiguration) && configurationCallback is not null) | |||
{ | |||
operations.Add(new OperationsViewModel( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments in ComputeSystemViewModel.cs
, I don't think we'll need to update the DataExtractor code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
@@ -5,6 +5,7 @@ | |||
using System.Threading.Tasks; | |||
using CommunityToolkit.Mvvm.Input; | |||
using CommunityToolkit.Mvvm.Messaging; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments in ComputeSystemViewModel.cs
file as I believe with those changes we won't need to make any changes to this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
tools/SetupFlow/DevHome.SetupFlow/ViewModels/MainPageViewModel.cs
Outdated
Show resolved
Hide resolved
tools/SetupFlow/DevHome.SetupFlow/ViewModels/SetupFlowViewModel.cs
Outdated
Show resolved
Hide resolved
tools/Environments/DevHome.Environments/Strings/en-us/Resources.resw
Outdated
Show resolved
Hide resolved
@@ -133,7 +137,7 @@ private async Task InitializeOperationDataAsync() | |||
ShouldShowDotOperations = false; | |||
ShouldShowSplitButton = false; | |||
|
|||
RegisterForAllOperationMessages(DataExtractor.FillDotButtonOperations(ComputeSystem, _mainWindow), DataExtractor.FillLaunchButtonOperations(ComputeSystem)); | |||
RegisterForAllOperationMessages(DataExtractor.FillDotButtonOperations(ComputeSystem, _mainWindow), DataExtractor.FillLaunchButtonOperations(_provider, ComputeSystem, _configurationAction)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the above changes we can then simplify what you did in the DataExtractor. We can have a method in this ComputeSystemViewModel
class like:
private void AddStartSetupFlowOperation()
{
var operations = ComputeSystem.SupportedOperations.Value;
if (!operations .HasFlag(ComputeSystemOperations.ApplyConfiguration) ||
_uiActions.StartComputeSystemSetup == null))
{
return;
}
// Use lambda to create Action that does not take a parameter
var configurationAction = () =>
{
_uiActions.StartComputeSystemSetup(_reviewItem)
};
LaunchOperations.Add(new OperationsViewModel(
_stringResource.GetLocalized("Operations_ApplyConfiguration"), "\uE835", configurationAction));
}
This can be called right after this FillLaunchButtonOperations
call without the need to pass the provider or the action to the DataExtractor
. This way you don't need to update code in the DataExtractor or OperationsViewModel. We'd just be using the constructor for OperationsViewModel
that already exists which takes in an Action
.
We'll end up with something like:
RegisterForAllOperationMessages(DataExtractor.FillDotButtonOperations(ComputeSystem, _mainWindow), DataExtractor.FillLaunchButtonOperations(ComputeSystem));
AddStartSetupFlowOperation();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
Summary of the pull request
This PR adds the feature to start the configuration flow from the Environments page.
Adds a new button, Setup, which directly takes the UI to the setup flow page.
Adding.config.flow.mp4
PR checklist