Skip to content

Commit

Permalink
feat: implementing some of the undo/redo for wizard steps
Browse files Browse the repository at this point in the history
  • Loading branch information
joanise committed Sep 23, 2024
1 parent a7356bb commit 9e81dc8
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions everyvoice/wizard/dataset.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import glob
import os
import random
Expand Down Expand Up @@ -55,6 +56,9 @@ def effect(self):
f"Great! The Configuration Wizard 🧙 finished the configuration for your dataset named '{self.response}'"
)

def is_reversible(self):
return True


class DatasetPermissionStep(Step):
DEFAULT_NAME = StepNames.dataset_permission_step
Expand Down Expand Up @@ -106,6 +110,9 @@ def validate(self, response) -> bool:
)
return valid_path and contains_wavs

def is_reversible(self):
return True


class SampleRateConfigStep(Step):
DEFAULT_NAME = StepNames.sample_rate_config_step
Expand All @@ -131,6 +138,9 @@ def validate(self, response):
)
return False

def is_reversible(self):
return True


class FilelistStep(Step):
DEFAULT_NAME = StepNames.filelist_step
Expand All @@ -146,6 +156,9 @@ def sanitize_input(self, response):
def validate(self, response) -> bool:
return validate_path(response, is_file=True, exists=True)

def is_reversible(self):
return True


class FilelistFormatStep(Step):
DEFAULT_NAME = StepNames.filelist_format_step
Expand Down Expand Up @@ -410,9 +423,19 @@ def effect(self):
# Rename the filelist header with the standard header name
if "selected_headers" not in self.state:
self.state["selected_headers"] = []
self.saved_state = {
"selected_headers": copy.copy(self.state["selected_headers"]),
"filelist_headers": copy.copy(self.state["filelist_headers"]),
}
self.state["selected_headers"].append(self.response)
self.state["filelist_headers"][self.response] = self.header_name

def is_reversible(self):
return True

def undo(self):
self.state.update(self.saved_state)


class LanguageHeaderStep(HeaderStep):
def effect(self):
Expand All @@ -438,6 +461,9 @@ def effect(self):
)
)

def is_reversible(self):
return False


class HasHeaderLineStep(Step):
"""Check if the data set has a header line, and insert one if not.
Expand Down Expand Up @@ -557,6 +583,9 @@ def effect(self):
f"Great! '{self.response}' will be used as the speaker ID for this dataset."
)

def is_reversible(self):
return True


class HasLanguageStep(Step):
DEFAULT_NAME = StepNames.data_has_language_value_step
Expand Down

0 comments on commit 9e81dc8

Please sign in to comment.