Open sfmskywalker opened 3 weeks ago
To implement a new Map
activity in Elsa Workflows that allows users to apply a transformation to each item in a collection, you would need to follow these steps:
Define the Map Activity Class:
Create a new class for the Map
activity that inherits from a suitable base class, such as Activity
or another more specific base if applicable in Elsa.
Specify Inputs and Outputs:
Use the [ActivityInput]
attribute to define the input collection and the [ActivityOutput]
attribute to define the output list that will hold the transformed items.
Implement the Body Property:
The Body
property should be of type IActivity
and will contain the transformation logic. This property can be implemented using the ActivityBuilder
class or similar, which allows for the inclusion of other activities like Sequence
or Flowchart
.
Implement the Iteration Mechanism:
In the OnExecute
or ExecuteAsync
method of the Map
activity, implement the logic to iterate over the input collection. For each item, execute the Body
activity and collect the result.
Collect the Transformed Items:
As the Body
activity executes for each item, collect the outputs into a new list. This list will be the final output of the Map
activity.
Handle Different Collection Types:
Ensure that the Map
activity can handle different types of collections by either using interfaces like IEnumerable
or by providing overloads or generic versions of the activity.
Optimize for Large Collections: Consider performance implications for large collections. You may need to implement asynchronous execution or batching to ensure efficient processing.
Testing:
Write unit tests to verify that the Map
activity behaves as expected, including its ability to handle various collection types and sizes.
Documentation:
Document the new Map
activity, explaining how to use it, the expected inputs and outputs, and providing examples of common use cases.
Integration with Elsa Designer:
If you want the Map
activity to be available in the Elsa Designer, you will need to create a corresponding front-end component that allows users to configure the Map
activity's properties, including the Body
transformation logic.
This new Map
activity would be similar to the ForEach
activity already present in Elsa but with the added capability of transforming each item and collecting the results. It would be a valuable addition for users who need to perform complex transformations on collections without writing custom looping logic.
This comment was generated by Glime.
Summary: Introduce a new
Map
activity that allows users to apply a transformation to each item in a collection. The transformation logic should be defined within aBody
property, which can host any activity likeSequence
orFlowchart
.Details:
IActivity
. This property represents the transformation logic to be applied to each item in the input collection.Map
activity needs to iterate over the input collection, executing theBody
activity for each item.Body
activity produces an output which should be collected into a new list.Map
activity outputs the new list, which consists of the transformed items.Expected Behavior:
Map
activity should be versatile, capable of handling different types of collections (e.g., lists, arrays).Use Case: This feature would be beneficial for scenarios where a set of items needs to be individually processed and transformed, potentially using complex logic encapsulated within other activities like
Sequence
orFlowchart
.Think of it like the
Select
for LINQ andArray.map
in JavaScript.