Update input types and record template in TextComponent and its subclasses
This commit is contained in:
parent
87710df466
commit
3f70560caf
3 changed files with 31 additions and 8 deletions
|
|
@ -12,16 +12,29 @@ class TextComponent(CustomComponent):
|
||||||
|
|
||||||
def build_config(self):
|
def build_config(self):
|
||||||
return {
|
return {
|
||||||
"input_value": {"display_name": "Value", "input_types": ["Record"], "info": "Text or Record to be passed."},
|
"input_value": {
|
||||||
"record_template": {"display_name": "Record Template", "multiline": True},
|
"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(
|
def build(
|
||||||
self,
|
self,
|
||||||
input_value: Optional[Union[Text, Record]] = "",
|
input_value: Optional[Union[Text, Record]] = "",
|
||||||
record_template: Optional[str] = "Text: {text}\nData: {data}",
|
record_template: Optional[str] = "{text}",
|
||||||
) -> Text:
|
) -> Text:
|
||||||
if isinstance(input_value, Record):
|
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)
|
input_value = records_to_text(template=record_template, records=input_value)
|
||||||
self.status = input_value
|
self.status = input_value
|
||||||
if not input_value:
|
if not input_value:
|
||||||
|
|
|
||||||
|
|
@ -13,15 +13,20 @@ class TextInput(TextComponent):
|
||||||
return {
|
return {
|
||||||
"input_value": {
|
"input_value": {
|
||||||
"display_name": "Value",
|
"display_name": "Value",
|
||||||
"input_types": ["Record"],
|
"input_types": ["Text", "Record"],
|
||||||
"info": "Text or Record to be passed as input.",
|
"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(
|
def build(
|
||||||
self,
|
self,
|
||||||
input_value: Optional[str] = "",
|
input_value: Optional[str] = "",
|
||||||
record_template: Optional[str] = "{text}",
|
record_template: Optional[str] = "",
|
||||||
) -> Text:
|
) -> Text:
|
||||||
return super().build(input_value=input_value, record_template=record_template)
|
return super().build(input_value=input_value, record_template=record_template)
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,13 @@ class TextOutput(TextComponent):
|
||||||
"input_types": ["Record"],
|
"input_types": ["Record"],
|
||||||
"info": "Text or Record to be passed as output.",
|
"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)
|
return super().build(input_value=input_value, record_template=record_template)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue