Skip to content

EditDialog.GetNewValue is getting too big #275

@tznind

Description

@tznind

We have logic that answers the following question:

  • Given a property of arbitrary Type with current value oldValue
  • What UI should I show to illicit a new value from the user
  • Run that UI
  • Did the UI cancel or complete?
  • If complete return true and out the new value

This is that method:

internal static bool GetNewValue(Design design, Property property, object? oldValue, out object? newValue)

There are really 2 possibilities that this method decides:

  • Show a modal (e.g. enter a string)
  • Show an 'editor' (e.g. PosEditor)

This is hard to test and getting too big.

Possible Solutions

Add a shared interface for all editors INewValueGetter (PosEditor, SizeEditor etc)

Create a new class PropertyValueFactory with function Create that takes a Design, Property and oldValue then returns an INewValueGetter.

This will allow for unit testing that the correct decisions about what editor should be shown to be written and move the logic of this tree into its own class.

Advantages

In #271 I have started down the route of a more complex ArrayEditor. Having this logic in its own class would make it possible to centralize 'new value' logic.

Testability

Automation style of tests e.g. mocking INewValueGetter with test implementations that simulate the user driving editor to create a given value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions