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

Pages Editor: add "Delete Task from Page" functionality #7075

Merged
merged 6 commits into from
Apr 25, 2024

Conversation

shaunanoordin
Copy link
Member

@shaunanoordin shaunanoordin commented Apr 9, 2024

PR Overview

Part of: Pages Editor MVP project and FEM Lab super-project
Follows #7065
Staging branch URL: https://pr-7075.pfe-preview.zooniverse.org/lab/1982/workflows/editor/3711?env=staging

This PR implements the "Delete Task" functionality, which deletes Tasks from an existing Page. Prior to this PR, you only had the "Delete Page/Step" functionality.

New Behaviour:

  • Tasks in the "Edit Page/Step" modal should now have a "Delete Task" button (trashcan icon).
  • Clicking on the button will prompt users to confirm if they want to delete the task.
    • If this is the only task in a page/step, additional information will be given.
  • Confirming the action will result in the Task being deleted.
    • Cancelling will result in no action.
    • If the only task in a page/step is deleted, the page/step will also be deleted. The Edit Page/Step modal will then close.

⚠️ Important Behind-The-Scenes Bit:

  • cleanupTasksAndSteps() now properly removes Steps/Pages that have 0 Tasks, and removes Tasks that aren't associated with any Page/Step.

Testing Steps

  • Go to the testing URL: https://pr-7065.pfe-preview.zooniverse.org/lab/1982/workflows/editor/3711?env=staging
  • Click on "Quick Setup" in the debug panel to quickly setup a pre-fabricated workflow.
  • Click on the "Edit Page/Step" button (pencil icon) to edit any Page/Step
    • Optional: add new Tasks to this Page/Step.
  • In the "Edit Page/Step" modal, click on the "Delete Task" button (trash can icon) to delete any Task.
    • Observe that Task is correctly removed from the Page.
    • If the Task removed is the last one in the Page, the Page should also be deleted and the Edit Page/Step modal should close.
  • Confirm that changes to the Workflow resource is correct (i.e. check what's submitted to the Panoptes API).
    • Be sure that there are no orphaned references.

Status

Ready for review!

@shaunanoordin shaunanoordin requested a review from a team April 9, 2024 17:19
@coveralls
Copy link

coveralls commented Apr 9, 2024

Coverage Status

coverage: 56.977%. remained the same
when pulling 22dcb15 on pages-editor-pt19
into a82d2f1 on master.

Copy link
Contributor

@goplayoutside3 goplayoutside3 left a comment

Choose a reason for hiding this comment

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

Looks great! I'm able to edit a step by adding or removing a task, and if I delete a lone task, its step is also deleted. When I delete a task that's linked to a previous step, that previous step is automatically modified as expected 👍


// Cleanup, then commit.
const cleanedTasksAndSteps = cleanupTasksAndSteps(newTasks, newSteps);
update(cleanedTasksAndSteps);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! I like how the code comments in this function are easy to read through 👍

Comment on lines 11 to +25
export default function cleanupTasksAndSteps(tasks = {}, steps = []) {
const newTasks = structuredClone(tasks); // Copy tasks
let newSteps = steps.slice(); // Copy steps
let newSteps = structuredClone(steps); // Copy steps. This is a deep copy, compared to steps.slice()

// Remove steps without tasks.
newSteps = newSteps.filter(step => step?.[1]?.taskKeys?.length > 0);

// Remove tasks not associated with any step.
Object.keys(newTasks).forEach(taskKey => {
let existsInAnyStep = false;
newSteps.forEach(step => {
existsInAnyStep = existsInAnyStep || !!step?.[1]?.taskKeys?.includes(taskKey);
});
if (!existsInAnyStep) delete newTasks[taskKey];
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Just linking this FEM Issue about orphaned tasks for documentation. Your implementation here means any project using the Pages Editor solves the bug 🎉 Hopefully all FEM projects soon 🤞

@goplayoutside3 goplayoutside3 self-assigned this Apr 22, 2024
@shaunanoordin
Copy link
Member Author

Thanks Delilah! 👍

@shaunanoordin shaunanoordin merged commit 5d5242a into master Apr 25, 2024
5 checks passed
@shaunanoordin shaunanoordin deleted the pages-editor-pt19 branch April 25, 2024 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants