Skip to content

Commit

Permalink
Merge pull request #3226 from mashehu/add-toggle-all-shortcut
Browse files Browse the repository at this point in the history
create: add shortcut to toggle all switches
  • Loading branch information
mashehu authored Oct 15, 2024
2 parents b834c0f + 8379afd commit 7a2edd3
Show file tree
Hide file tree
Showing 18 changed files with 1,542 additions and 1,517 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update-textual-snapshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Run pytest to update snapshots
id: pytest
run: |
python3 -m pytest tests/test_create_app.py --snapshot-update --color=yes --durations=0
python3 -m pytest tests/pipelines/test_create_app.py --snapshot-update --color=yes --durations=0
continue-on-error: true

# indication that the run has finished
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
### General

- Include .nf-core.yml in `nf-core pipelines bump-version` ([#3220](https://github.com/nf-core/tools/pull/3220))
- create: add shortcut to toggle all switches ([#3226](https://github.com/nf-core/tools/pull/3226))

## [v3.0.2 - Titanium Tapir Patch](https://github.com/nf-core/tools/releases/tag/3.0.2) - [2024-10-11]

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Optionally followed by the description that you want to add to the changelog.

- Update Textual snapshots:

If the Textual snapshots (run by `tests/test_crate_app.py`) fail, an HTML report is generated and uploaded as an artifact.
If the Textual snapshots (run by `tests/pipelines/test_crate_app.py`) fail, an HTML report is generated and uploaded as an artifact.
If you are sure that these changes are correct, you can automatically update the snapshots form the PR by posting a comment with the magic words:

```
Expand Down
17 changes: 13 additions & 4 deletions nf_core/pipelines/create/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
"""A Textual app to create a pipeline."""

import logging
from pathlib import Path

import click
import yaml
from textual.app import App
from textual.widgets import Button
from textual.widgets import Button, Switch

import nf_core
from nf_core.pipelines.create import utils
from nf_core.pipelines.create.basicdetails import BasicDetails
from nf_core.pipelines.create.custompipeline import CustomPipeline
Expand Down Expand Up @@ -46,6 +43,7 @@ class PipelineCreateApp(App[utils.CreateConfig]):
BINDINGS = [
("d", "toggle_dark", "Toggle dark mode"),
("q", "quit", "Quit"),
("a", "toggle_all", "Toggle all"),
]
SCREENS = {
"welcome": WelcomeScreen(),
Expand Down Expand Up @@ -105,3 +103,14 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
def action_toggle_dark(self) -> None:
"""An action to toggle dark mode."""
self.dark: bool = not self.dark

def action_toggle_all(self) -> None:
"""An action to toggle all Switches."""
switches = self.query(Switch)
if not switches:
return # No Switches widgets found
# Determine the new state based on the first switch
new_state = not switches.first().value if switches.first() else True
for switch in switches:
switch.value = new_state
self.refresh()
18 changes: 16 additions & 2 deletions nf_core/pipelines/create/custompipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from textual import on
from textual.app import ComposeResult
from textual.containers import Center, ScrollableContainer
from textual.containers import Center, Horizontal, ScrollableContainer
from textual.screen import Screen
from textual.widgets import Button, Footer, Header, Markdown, Switch
from textual.widgets import Button, Footer, Header, Markdown, Static, Switch

from nf_core.pipelines.create.utils import PipelineFeature

Expand All @@ -22,7 +22,13 @@ def compose(self) -> ComposeResult:
"""
)
)
yield Horizontal(
Switch(id="toggle_all", value=True),
Static("Toggle all features", classes="feature_title"),
classes="custom_grid",
)
yield ScrollableContainer(id="features")

yield Center(
Button("Back", id="back", variant="default"),
Button("Continue", id="continue", variant="success"),
Expand All @@ -35,6 +41,7 @@ def on_mount(self) -> None:
self.query_one("#features").mount(
PipelineFeature(feature["help_text"], feature["short_description"], feature["description"], name)
)
self.query_one("#toggle_all", Switch).value = True

@on(Button.Pressed, "#continue")
def on_button_pressed(self, event: Button.Pressed) -> None:
Expand All @@ -45,3 +52,10 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
if not this_switch.value:
skip.append(this_switch.id)
self.parent.TEMPLATE_CONFIG.__dict__.update({"skip_features": skip, "is_nfcore": False})

@on(Switch.Changed, "#toggle_all")
def on_toggle_all(self, event: Switch.Changed) -> None:
"""Handle toggling all switches."""
new_state = event.value
for feature in self.query("PipelineFeature"):
feature.query_one(Switch).value = new_state
2 changes: 1 addition & 1 deletion nf_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def fetch_wf_config(wf_path: Path, cache_config: bool = True) -> dict:

# If we can, save a cached copy
# HINT: during testing phase (in test_download, for example) we don't want
# to save configuration copy in $HOME, otherwise the tests/test_download.py::DownloadTest::test_wf_use_local_configs
# to save configuration copy in $HOME, otherwise the tests/pipelines/test_download.py::DownloadTest::test_wf_use_local_configs
# will fail after the first attempt. It's better to not save temporary data
# in others folders than tmp when doing tests in general
if cache_path and cache_config:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
246 changes: 123 additions & 123 deletions tests/pipelines/__snapshots__/test_create_app/test_choose_type.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
258 changes: 129 additions & 129 deletions tests/pipelines/__snapshots__/test_create_app/test_customisation_help.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
246 changes: 123 additions & 123 deletions tests/pipelines/__snapshots__/test_create_app/test_final_details.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
260 changes: 130 additions & 130 deletions tests/pipelines/__snapshots__/test_create_app/test_github_details.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
238 changes: 119 additions & 119 deletions tests/pipelines/__snapshots__/test_create_app/test_github_question.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
255 changes: 128 additions & 127 deletions tests/pipelines/__snapshots__/test_create_app/test_type_custom.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
252 changes: 126 additions & 126 deletions tests/pipelines/__snapshots__/test_create_app/test_type_nfcore.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
250 changes: 125 additions & 125 deletions tests/pipelines/__snapshots__/test_create_app/test_welcome.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7a2edd3

Please sign in to comment.