Skip to content

Conversation

@SushanthKS06
Copy link

This PR adds an optional editable: bool = True argument to scenario_selector, allowing users
to disable editing of scenario names and tags when needed.

When editable=False:

  • Scenario selection, sorting, and scenario creation remain functional
  • UI edit controls are hidden
  • Tag/name editing is disabled

This keeps default behavior unchanged while giving developers finer control over UI interactions.

Changes included:

  • Internal implementation of editable behavior
  • Updated JSON configuration (viselements.json)
  • Modified GUI rendering to conditionally hide edit controls
  • Unit tests + integration tests for editable=True and editable=False
  • Example usage file demonstrating the new argument
  • Documentation updates to reflect the new parameter

Backwards compatibility is preserved.

Fixes #2562

- Add optional editable property (default: True)
- Hide edit icons when editable=False
- Preserve all other functionality (selection, sorting, adding)
- Add comprehensive tests and documentation
- Maintain backward compatibility
@SushanthKS06 SushanthKS06 marked this pull request as draft December 26, 2025 16:56
@SushanthKS06 SushanthKS06 marked this pull request as ready for review December 26, 2025 17:54
@SushanthKS06
Copy link
Author

Hi @arcanaxion , this is the implementation for #2562.

Let me know if any changes are needed.

Copy link
Member

@FredLL-Avaiga FredLL-Avaiga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done @SushanthKS06
A few changes are needed
And some file organization ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please follow the naming convention used for the other components (ie <Component>.spec.tsx)

updateScVars?: string;
showSearch?: boolean;
creationNotAllowed?: string;
editable?: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if property type is dynamic_boolean, we need 2 properties (defaultEditable & editable)
and read them with useDynamicProperty
check the implementation of the render property of the Alert component

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure where this file should go but I guess not here
@FabienLelaquais ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure where this file should go but I guess not here
@FabienLelaquais ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure where this file should go but I guess not here
@FabienLelaquais ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure where this file should go but I guess not here
@FabienLelaquais ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure where this file should go but I guess not here
@FabienLelaquais ?

@FredLL-Avaiga FredLL-Avaiga added Core Related to Taipy Core 🖰 GUI Related to GUI 🟨 Priority: Medium Not blocking but should be addressed ✨New feature labels Jan 7, 2026
@jrobinAV jrobinAV requested a review from Copilot January 9, 2026 14:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an optional editable boolean parameter to the scenario_selector visual element, allowing developers to control whether users can edit scenario names and tags. When set to False, the edit UI controls are hidden while preserving other functionality like selection, sorting, and scenario creation.

Key changes:

  • Added editable property to backend configuration with default value of True for backward compatibility
  • Modified frontend to conditionally render edit component based on the property value
  • Included comprehensive test coverage for both backend and frontend

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 23 comments.

Show a summary per file
File Description
taipy/gui_core/viselements.json Added editable property definition with type dynamic(bool) and default True
taipy/gui_core/_GuiCoreLib.py Registered editable as PropertyType.dynamic_boolean with default True
frontend/taipy/src/ScenarioSelector.tsx Added editable prop and conditional rendering of edit component
frontend/taipy/src/ScenarioSelector.editable.test.tsx Frontend tests for editable functionality (contains bugs)
tests/gui_core/test_scenario_selector_editable.py Python unit tests for the editable property
tests/gui_core/test_scenario_selector_editable_integration.py Python integration tests
validate_json_only.py Validation script (should be removed from production)
validate_editable_implementation.py Validation script (should be removed from production)
scenario_selector_editable_example.py Usage example (has bugs, should be moved)
scenario_selector_editable_documentation.md Documentation (should be moved to doc/)
IMPLEMENTATION_SUMMARY.md Implementation notes (should be removed from production)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +103
# Scenario Selector - Editable Property

## Overview

The `scenario_selector` visual element now supports an optional `editable` argument that controls whether users can edit scenario names and tags.

## Property

### editable

- **Type**: `bool`
- **Default**: `True`
- **Dynamic**: Yes (can be bound to state variables)

When `editable=False`:
- Users cannot edit scenario names
- Users cannot edit scenario tags
- The edit icon/button is hidden from the UI
- All other functionality remains available (selection, sorting, adding scenarios if `show_add_button=True`)

## Usage Examples

### Basic Usage - Disable Editing

```python
from taipy.gui import Gui, Markdown

# Disable editing for all scenarios
page = Markdown("""
<|scenario_selector|editable=False|>
""")

gui = Gui(page)
gui.run()
```

### Dynamic Control with State Variable

```python
from taipy.gui import Gui, Markdown, State

# Control editing through state variable
allow_editing = True

def toggle_editing(state: State):
state.allow_editing = not state.allow_editing

page = Markdown("""
<|scenario_selector|editable={allow_editing}|>
<|Toggle Editing|button|on_action=toggle_editing|>
""")

gui = Gui(page)
gui.run()
```

### Combined with Other Properties

```python
from taipy.gui import Gui, Markdown

# Non-editable selector that still allows adding and searching
page = Markdown("""
<|scenario_selector|editable=False|show_add_button=True|show_search=True|>
""")

gui = Gui(page)
gui.run()
```

## Behavior

### When editable=True (default)
- Edit icons appear next to each scenario
- Users can click edit icons to modify scenario names and tags
- Full editing functionality is available
- Maintains backward compatibility with existing code

### When editable=False
- Edit icons are hidden from the UI
- Users cannot access scenario editing dialogs
- Selection, sorting, filtering, and searching still work normally
- Adding new scenarios still works if `show_add_button=True`

## Backward Compatibility

This change is fully backward compatible. Existing `scenario_selector` implementations will continue to work exactly as before, with editing enabled by default.

## Related Properties

The `editable` property works independently of other `scenario_selector` properties:

- `show_add_button`: Controls whether users can add new scenarios (independent of editing)
- `show_search`: Controls search functionality (independent of editing)
- `filter` and `sort`: Control filtering and sorting (independent of editing)
- `multiple`: Controls multi-selection (independent of editing)

## Use Cases

1. **Read-only dashboards**: Display scenarios without allowing modifications
2. **Role-based access**: Disable editing for certain user roles while preserving other functionality
3. **Approval workflows**: Show scenarios in read-only mode during approval processes
4. **Audit views**: Display historical scenarios without edit capabilities No newline at end of file
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation file should be integrated into the official documentation structure (e.g., doc/ directory) instead of being in the root directory. Standalone markdown files in the root can clutter the repository structure.

Copilot uses AI. Check for mistakes.
def on_scenario_change(state: State, var_name: str, value):
"""Handle scenario selection changes."""
state.selected_scenario = value
print(f"Selected scenario: {value.label if value else 'None'}")
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Scenario class does not have a label property. It has a get_label() method instead. This line should use value.get_label() instead of value.label.

Copilot uses AI. Check for mistakes.
## Current Settings
- **Editable**: {is_editable}
- **Selected Scenario**: {selected_scenario.label if selected_scenario else "None"}
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Scenario class does not have a label property. It has a get_label() method instead. This line should use selected_scenario.get_label() instead of selected_scenario.label.

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +86
it("should still render add button when editable is false", () => {
render(<ScenarioSelector {...mockProps} editable={false} showAddButton={true} />);

// The add button should still be present
expect(screen.getByText("Add scenario")).toBeInTheDocument();
});

Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will fail because the mock of CoreSelector doesn't actually render the "Add scenario" button. The button is rendered in the actual ScenarioSelector component (lines 532-546), not in CoreSelector. Since CoreSelector is mocked, the button won't be present in the DOM. This test should either be removed or the component structure should be tested differently.

Suggested change
it("should still render add button when editable is false", () => {
render(<ScenarioSelector {...mockProps} editable={false} showAddButton={true} />);
// The add button should still be present
expect(screen.getByText("Add scenario")).toBeInTheDocument();
});

Copilot uses AI. Check for mistakes.
Comment on lines +61 to +65
return False

if __name__ == "__main__":
success = validate_viselements_json()
sys.exit(0 if success else 1) No newline at end of file
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This validation script should not be included in the production codebase. Validation scripts are typically temporary files used during development and testing. Consider removing this file before merging, or if it's needed for CI/CD, move it to a tools/ or scripts/ directory.

Suggested change
return False
if __name__ == "__main__":
success = validate_viselements_json()
sys.exit(0 if success else 1)
return False

Copilot uses AI. Check for mistakes.
import pytest
from unittest.mock import Mock

from taipy.gui import Gui
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'Gui' is not used.

Suggested change
from taipy.gui import Gui

Copilot uses AI. Check for mistakes.
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

import pytest
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'pytest' is not used.

Suggested change
import pytest

Copilot uses AI. Check for mistakes.
# specific language governing permissions and limitations under the License.

import pytest
from unittest.mock import Mock, patch
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'Mock' is not used.
Import of 'patch' is not used.

Suggested change
from unittest.mock import Mock, patch

Copilot uses AI. Check for mistakes.
import pytest
from unittest.mock import Mock, patch

from taipy.core import Scenario
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'Scenario' is not used.

Suggested change
from taipy.core import Scenario

Copilot uses AI. Check for mistakes.
from unittest.mock import Mock, patch

from taipy.core import Scenario
from taipy.gui import Gui, Markdown
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'Markdown' is not used.

Suggested change
from taipy.gui import Gui, Markdown
from taipy.gui import Gui

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Core Related to Taipy Core 🖰 GUI Related to GUI ✨New feature 🟨 Priority: Medium Not blocking but should be addressed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[✨ FEATURE] add an "editable" argument to scenario_selector

2 participants