Skip to content

Commit

Permalink
feat: enhance custom_js plugin with attribute traversal
Browse files Browse the repository at this point in the history
Include DictTraverser to reshape attributes based on payload
Ensure script attributes are a dictionary and reshape them
before adding to the UX response.
  • Loading branch information
atompie committed Sep 12, 2024
1 parent c56d43f commit 0e37b5a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tracardi/process_engine/action/v1/ux/custom_js/plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json

from tracardi.service.notation.dict_traverser import DictTraverser
from .configuration import Config
from tracardi.service.plugin.domain.register import Plugin, Spec, MetaData, Form, FormGroup, \
FormField, FormComponent
Expand All @@ -18,11 +19,21 @@ async def set_up(self, init):
self.config = validate(init)

async def run(self, payload: dict, in_edge=None) -> Result:
attributes = json.loads(self.config.attributes)

if not isinstance(attributes, dict):
raise ValueError(f"Script attributes must be a dictionary, {type(attributes)} given.")

dot = self._get_dot_accessor(payload)
traverser = DictTraverser(dot)
attributes = traverser.reshape(attributes)

self.ux.append({
"tag": "script",
"props": json.loads(self.config.attributes),
"props": attributes,
"content": self.config.content
})

return Result(port="response", value=payload)


Expand Down

0 comments on commit 0e37b5a

Please sign in to comment.