Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Code health] Move task sequence calculation / handling into a separate handler #2958

Open
shobhitagarwal1612 opened this issue Dec 30, 2024 · 3 comments · May be fixed by #2986
Open

[Code health] Move task sequence calculation / handling into a separate handler #2958

shobhitagarwal1612 opened this issue Dec 30, 2024 · 3 comments · May be fixed by #2986
Assignees
Labels
type: code health Improvements to readability or robustness of codebase

Comments

@shobhitagarwal1612
Copy link
Member

Currently, DataCollectionViewModel does a lot of things incl. creation of task sequence and performing various operations using the generated task sequence. This bloats up the class and reduces the code readability / maintainability.

This could be handled in a better way by abstracting out all task sequence related methods into a single wrapper class. This would greatly improve the overall structure of the class.

@shobhitagarwal1612 shobhitagarwal1612 added the type: code health Improvements to readability or robustness of codebase label Dec 30, 2024
@shobhitagarwal1612 shobhitagarwal1612 self-assigned this Dec 30, 2024
@shobhitagarwal1612 shobhitagarwal1612 moved this to In Progress in Ground Dec 30, 2024
@shobhitagarwal1612
Copy link
Member Author

Proposed structure for the sequence handler:

interface TaskSequenceHandler {

  /**
   * Retrieves the task sequence based on the provided inputs and conditions.
   *
   * This function determines the order of tasks to be presented, taking into account any overrides
   * specified by [taskValueOverride].
   *
   * @param taskValueOverride An optional pair where the first element is the task ID and the second
   *   element is the [TaskData] to override the default task data. If null, no override is applied.
   * @return A [Sequence] of [Task] objects representing the ordered tasks.
   */
  fun getTaskSequence(taskValueOverride: Pair<String, TaskData?>? = null): Sequence<Task>

  /**
   * Checks if the specified task is the first task in the displayed sequence.
   *
   * @param taskId The ID of the task to check.
   * @return `true` if the task is the first in the sequence, `false` otherwise.
   */
  fun isFirstPosition(taskId: String): Boolean

  /**
   * Checks if the specified task is the last task in the displayed sequence.
   *
   * @param taskId The ID of the task to check.
   * @return `true` if the task is the last in the sequence, `false` otherwise.
   */
  fun isLastPosition(taskId: String): Boolean

  /**
   * Checks if the specified task with the given data is the last task in the sequence.
   *
   * This method allows checking if a specific task with a particular [TaskData] is the last one.
   *
   * @param taskId The ID of the task to check.
   * @param value The [TaskData] associated with the task.
   * @return `true` if the task with the given data is the last in the sequence, `false` otherwise.
   */
  fun isLastPosition(taskId: String, value: TaskData?): Boolean

  /**
   * Retrieves the ID of the task that precedes the specified task in the sequence.
   *
   * @param taskId The ID of the task for which to find the previous task.
   * @return The ID of the previous task in the sequence.
   */
  fun getPreviousTask(taskId: String): String

  /**
   * Retrieves the ID of the task that follows the specified task in the sequence.
   *
   * @param taskId The ID of the task for which to find the next task.
   * @return The ID of the next task in the sequence.
   */
  fun getNextTask(taskId: String): String

  /**
   * Retrieves the absolute index of the specified task in the original, unfiltered task sequence.
   *
   * This index represents the task's position in the full sequence, regardless of any filtering or
   * modifications that may have occurred.
   *
   * @param taskId The ID of the task for which to find the absolute position.
   * @throws error if the task is not found in the original task sequence.
   */
  fun getAbsolutePosition(taskId: String): Int

  /**
   * Retrieves the relative index in the computed task sequence.
   *
   * The relative index represents the task's position within the currently displayed sequence.
   *
   * @param taskId The ID of the task for which to find the relative position.
   * @throws error if the task is not found in the computed task sequence.
   */
  fun getRelativePosition(taskId: String): Int

  /**
   * Retrieves the position information for the specified task.
   *
   * @param taskId THE ID of the task for which to find the position information.
   */
  fun getTaskPosition(taskId: String): TaskPosition
}

@shobhitagarwal1612
Copy link
Member Author

@gino-m @anandwana001 Thoughts?

@anandwana001
Copy link
Collaborator

abstraction looks like a good approach @shobhitagarwal1612

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: code health Improvements to readability or robustness of codebase
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

2 participants