mohitbagra / vsts-extensions

Repo holding all my VSTS extensions
MIT License
46 stars 30 forks source link

Improve Workflow of AddNewRelationAction by defining the reverse relation on the new item instead #94

Open jongleur1983 opened 2 years ago

jongleur1983 commented 2 years ago

We use the extension for some use cases and I like it. A small issue often people in our team struggle with is the workflow on an AddNewRelationAction.

As an example we have configured an "Add Review Task" action that adds a new work item of type task with a certain template to an existing Product Backlog Item as a one click action.

It should make it easy to create such a task. Unfortunately the required workflow is as follows:

  1. From the PBI click the OneClickAction button "Create Review Task".
  2. Fill in possible required content (often even the template is sufficient as is
  3. Save the Review Task (with it's content, not saving the relation as it's not yet attached to the Review Task, but to the PRBI)
  4. Save the PBI the review Task is added to (to apply the relation as well).

Often Step4 is forgotten, and I think there's a relatively easy way to fix that in the extension logic.

How the extension works, yet The current logic from https://github.com/mohitbagra/vsts-extensions/blob/master/src/Apps/OneClick/scripts/RuleActions/AddNewRelationAction.tsx as far as I understand it adds the Relation to the PBI and therefore requires saving that.

How it could be improved Instead, the Reverse of that relation could be added to the new, unsaved item.

Required code changes (as pseudo code as I don't know yet how to implement and especially test changes)

Affected parts of the code should be these: https://github.com/mohitbagra/vsts-extensions/blob/master/src/Apps/OneClick/scripts/RuleActions/AddNewRelationAction.tsx#L64-L79

Here, the savedWorkItem (which is the newly created one) is addad as a relation to the existing Item. Rephrasing that part by some kind of pseudo code:

const selectedRelationType = RelationTypeAsConfiguredForAction(); // in my example "child-of"
const relation = new Relation(to: newItem, type: selectedRelationType)M
workItemFormService.addWorkItemRelations([relation]);

I propose to instead do the following before saving the work item at all:

const selectedRelationType = InverseRelationTypeAsConfiguredForAction(); // in my example "parent-of"
const relation = new Relation(url: originalPbi, rel: selectedRealtionType.referenceName);
AddRelationToNewItem(relation)