feat: add new Tab input (#7032)
* Added TabMixin * Added Tab component on inputs * Added Tab component to initializations * Added tests for tab input * Added Tab Component type * Added options and active tab to input field type * Added tab component on frontend * Instantiate tab component * Update package lock * Refactor input classes and imports for consistency - Reordered imports to maintain consistency across files. - Simplified class definitions by removing unnecessary line breaks. - Updated the `__all__` list in `__init__.py` files to include `TableInput` consistently. - Adjusted test cases for cleaner syntax without altering functionality. * Add constants for tab options limits in input mixin - Introduced `MAX_TAB_OPTIONS` and `MAX_TAB_OPTION_LENGTH` constants for better maintainability. - Updated validation logic in `TabMixin` to use these constants for clearer and more flexible error messages. * Refactor tab input validation tests for improved clarity - Replaced individual test cases for invalid tab inputs with a parameterized test function. - Enhanced test coverage by including cases for too many options, exceeding character limits, and non-string values. - Improved documentation within the test function for better understanding of validation scenarios. * Enhance tab input validation tests with parameterization - Refactored `test_tab_input_valid` to use `pytest.mark.parametrize` for improved test coverage and clarity. - Included multiple scenarios for valid tab inputs, such as standard, fewer options, and empty options. - Updated assertions to reflect the expected outcomes based on parameterized inputs. * Enhance TabInput validation to ensure value is a string and one of the specified options - Updated the `validate_value` method to enforce that the input value is a string. - Added a check to validate that the value is among the allowed options, raising a ValueError with a descriptive message if not. - Improved error handling for better user feedback on invalid inputs. * Fix optional chaining in error handling within CodeAreaModal - Updated the error check in the `delayedFunction` to use optional chaining for safer access to the error detail. - This change ensures that the code handles cases where `detail` may be undefined, improving robustness. * Add 'TAB' field type to schema and update direct types list - Included 'TAB' as a valid field type in the schema conversion dictionary. - Updated the DIRECT_TYPES list to include 'tab', ensuring consistency across type definitions. - These changes enhance the flexibility of the input handling for tab components. * Add unit test * Re-added noqa * fix: unit tests * [autofix.ci] apply automated fixes --------- Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> Co-authored-by: italojohnny <italojohnnydosanjos@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
7aca264fec
commit
95ceb52fa3
14 changed files with 408 additions and 7 deletions
|
|
@ -19,6 +19,7 @@ from langflow.inputs.inputs import (
|
|||
SecretStrInput,
|
||||
SliderInput,
|
||||
StrInput,
|
||||
TabInput,
|
||||
TableInput,
|
||||
)
|
||||
from langflow.inputs.utils import instantiate_input
|
||||
|
|
@ -213,6 +214,81 @@ def test_file_input_valid():
|
|||
assert file_input.value == ["/path/to/file"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("test_id", "options", "value", "expected_options", "expected_value"),
|
||||
[
|
||||
(
|
||||
"standard_valid",
|
||||
["Tab1", "Tab2", "Tab3"],
|
||||
"Tab1",
|
||||
["Tab1", "Tab2", "Tab3"],
|
||||
"Tab1",
|
||||
),
|
||||
(
|
||||
"fewer_options",
|
||||
["Tab1", "Tab2"],
|
||||
"Tab2",
|
||||
["Tab1", "Tab2"],
|
||||
"Tab2",
|
||||
),
|
||||
(
|
||||
"empty_options",
|
||||
[],
|
||||
"",
|
||||
[],
|
||||
"",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_tab_input_valid(test_id, options, value, expected_options, expected_value):
|
||||
"""Test TabInput validation with valid inputs."""
|
||||
data = TabInput(
|
||||
name=f"valid_tab_{test_id}",
|
||||
options=options,
|
||||
value=value,
|
||||
)
|
||||
assert data.options == expected_options
|
||||
assert data.value == expected_value
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("test_id", "options", "value", "error_expected"),
|
||||
[
|
||||
(
|
||||
"too_many_options",
|
||||
["Tab1", "Tab2", "Tab3", "Tab4"],
|
||||
"Tab1",
|
||||
ValidationError,
|
||||
),
|
||||
(
|
||||
"option_too_long",
|
||||
[
|
||||
"Tab1",
|
||||
"ThisTabValueIsTooLongAndExceedsTwentyCharacters",
|
||||
"Tab3",
|
||||
],
|
||||
"Tab1",
|
||||
ValidationError,
|
||||
),
|
||||
(
|
||||
"non_string_value",
|
||||
["Tab1", "Tab2", "Tab3"],
|
||||
123,
|
||||
TypeError,
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_tab_input_invalid(test_id, options, value, error_expected):
|
||||
"""Test TabInput validation with invalid inputs."""
|
||||
if error_expected:
|
||||
with pytest.raises(error_expected):
|
||||
TabInput(
|
||||
name=f"invalid_tab_{test_id}",
|
||||
options=options,
|
||||
value=value,
|
||||
)
|
||||
|
||||
|
||||
def test_instantiate_input_comprehensive():
|
||||
valid_data = {
|
||||
"StrInput": {"name": "str_input", "value": "A string"},
|
||||
|
|
@ -224,6 +300,11 @@ def test_instantiate_input_comprehensive():
|
|||
"name": "multiselect_input",
|
||||
"value": ["option1", "option2"],
|
||||
},
|
||||
"TabInput": {
|
||||
"name": "tab_input",
|
||||
"options": ["Tab1", "Tab2", "Tab3"],
|
||||
"value": "Tab1",
|
||||
},
|
||||
}
|
||||
|
||||
for input_type, data in valid_data.items():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue