Update input types and record template in TextComponent and its subclasses

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-03-30 18:46:36 -03:00
commit 3f70560caf
3 changed files with 31 additions and 8 deletions

View file

@ -12,16 +12,29 @@ class TextComponent(CustomComponent):
def build_config(self):
return {
"input_value": {"display_name": "Value", "input_types": ["Record"], "info": "Text or Record to be passed."},
"record_template": {"display_name": "Record Template", "multiline": True},
"input_value": {
"display_name": "Value",
"input_types": ["Text", "Record"],
"info": "Text or Record to be passed.",
},
"record_template": {
"display_name": "Record Template",
"multiline": True,
"info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.",
"advanced": True,
},
}
def build(
self,
input_value: Optional[Union[Text, Record]] = "",
record_template: Optional[str] = "Text: {text}\nData: {data}",
record_template: Optional[str] = "{text}",
) -> Text:
if isinstance(input_value, Record):
if record_template == "":
# it should be dynamically set to the Record's .text_key value
# meaning, if text_key = "bacon", then record_template = "{bacon}"
record_template = "{" + input_value.text_key + "}"
input_value = records_to_text(template=record_template, records=input_value)
self.status = input_value
if not input_value:

View file

@ -13,15 +13,20 @@ class TextInput(TextComponent):
return {
"input_value": {
"display_name": "Value",
"input_types": ["Record"],
"input_types": ["Text", "Record"],
"info": "Text or Record to be passed as input.",
},
"record_template": {"display_name": "Record Template", "multiline": True},
"record_template": {
"display_name": "Record Template",
"multiline": True,
"info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.",
"advanced": True,
},
}
def build(
self,
input_value: Optional[str] = "",
record_template: Optional[str] = "{text}",
record_template: Optional[str] = "",
) -> Text:
return super().build(input_value=input_value, record_template=record_template)

View file

@ -16,8 +16,13 @@ class TextOutput(TextComponent):
"input_types": ["Record"],
"info": "Text or Record to be passed as output.",
},
"record_template": {"display_name": "Record Template", "multiline": True},
"record_template": {
"display_name": "Record Template",
"multiline": True,
"info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.",
"advanced": True,
},
}
def build(self, input_value: Optional[Text] = "", record_template: str = "{text}") -> Text:
def build(self, input_value: Optional[Text] = "", record_template: str = "") -> Text:
return super().build(input_value=input_value, record_template=record_template)