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

modified task status flow #583

Merged
merged 10 commits into from Mar 22, 2024
94 changes: 82 additions & 12 deletions app/controllers/tasks.js
Expand Up @@ -42,7 +42,7 @@ export default class TasksController extends Controller {
@tracked showTasks = false;
@tracked showFetchButton = this.isShowFetchButton() && !this.alreadyFetched;
alreadyFetched = localStorage.getItem('already-fetched');

resetCurrentTask = null;
get isDevMode() {
return this.featureFlag.isDevMode;
}
Expand Down Expand Up @@ -97,16 +97,23 @@ export default class TasksController extends Controller {
const requestBody = { ...object };
const taskCompletionPercentage = object.percentCompleted;
if (taskCompletionPercentage) {
if (taskCompletionPercentage === TASK_PERCENTAGE.completedPercentage) {
this.isDevMode === true
? (requestBody.status = 'DONE')
: (requestBody.status = 'COMPLETED');
if (
taskCompletionPercentage === TASK_PERCENTAGE.completedPercentage &&
!this.dev
) {
requestBody.status = 'COMPLETED';
}
requestBody.percentCompleted = parseInt(taskCompletionPercentage);
}
return requestBody;
}

getTaskById(taskId) {
const indexOfSelectedTask = this.allTasks.findIndex(
Atifsid marked this conversation as resolved.
Show resolved Hide resolved
(task) => task.id === taskId
);
const selectedTask = this.allTasks[indexOfSelectedTask];
return selectedTask;
}
@action goBack() {
this.showModal = false;
this.onTaskChange('percentCompleted', '75');
Expand Down Expand Up @@ -143,9 +150,12 @@ export default class TasksController extends Controller {
delete this.taskFields[prop];
}
this.taskFields[key] = value;
if (this.resetCurrentTask) {
this.resetCurrentTask();
}
}

@action async updateTask(taskId, error) {
@action async updateTask(taskId) {
this.disabled = true;
this.buttonRequired = false;
const taskData = this.taskFields;
Expand Down Expand Up @@ -195,7 +205,9 @@ export default class TasksController extends Controller {
toastNotificationTimeoutOptions
);
this.disabled = false;
error();
if (this.resetCurrentTask) {
this.resetCurrentTask();
}
}
} catch (err) {
this.toast.error(
Expand All @@ -204,7 +216,9 @@ export default class TasksController extends Controller {
toastNotificationTimeoutOptions
);
console.error('Error : ', err);
error();
if (this.resetCurrentTask) {
this.resetCurrentTask();
}
} finally {
this.disabled = false;
}
Expand Down Expand Up @@ -263,15 +277,71 @@ export default class TasksController extends Controller {
}
}

@action async handleUpdateTask(taskId, error) {
@action async handleUpdateTask(taskId, resetCurrentTask) {
this.resetCurrentTask = resetCurrentTask;
const taskData = this.taskFields;
if (taskData.percentCompleted === TASK_PERCENTAGE.completedPercentage) {
const currentTask = this.getTaskById(taskId);
const isCurrentTaskStatusInProgress =
currentTask.status === this.TASK_KEYS.IN_PROGRESS;
const isCurrentTaskStatusBlock =
currentTask.status === this.TASK_KEYS.BLOCKED;
const isNewTaskStatusInProgress =
taskData.status === this.TASK_KEYS.IN_PROGRESS;
const isNewTaskStatusBlock = taskData.status === this.TASK_KEYS.BLOCKED;
const isCurrProgress100 =
parseInt(currentTask.percentCompleted || 0) === 100;
const isCurrProgress0 = parseInt(currentTask.percentCompleted || 0) === 0;

if (this.dev && taskData.status) {
if (
skv93-coder marked this conversation as resolved.
Show resolved Hide resolved
isNewTaskStatusInProgress &&
!isCurrentTaskStatusBlock &&
!isCurrProgress0
) {
this.message = 'Proceeding further will make task progress 0%.';
this.showModal = true;
this.buttonRequired = true;
this.tempTaskId = taskId;
this.taskFields.percentCompleted = 0;

return;
}
if (
isCurrentTaskStatusInProgress &&
!isNewTaskStatusBlock &&
!isCurrProgress100
) {
this.message = 'Proceeding further will make task progress 100%.';
this.showModal = true;
this.buttonRequired = true;
this.tempTaskId = taskId;
this.taskFields.percentCompleted = 100;
return;
}
if (
isCurrentTaskStatusBlock &&
!isNewTaskStatusInProgress &&
!isCurrProgress100
skv93-coder marked this conversation as resolved.
Show resolved Hide resolved
) {
this.message = `The progress of current task is ${currentTask.percentCompleted}%. Proceeding further will make task progress 100%.`;
this.showModal = true;
this.buttonRequired = true;
this.tempTaskId = taskId;
this.taskFields.percentCompleted = 100;
skv93-coder marked this conversation as resolved.
Show resolved Hide resolved
return;
}
}

if (
taskData.percentCompleted === TASK_PERCENTAGE.completedPercentage &&
!this.dev
) {
this.message = TASK_MESSAGES.MARK_DONE;
this.showModal = true;
this.buttonRequired = true;
this.tempTaskId = taskId;
} else {
return this.updateTask(taskId, error);
return this.updateTask(taskId);
}
}
}
75 changes: 75 additions & 0 deletions tests/integration/components/tasks-test.js
skv93-coder marked this conversation as resolved.
Show resolved Hide resolved
Expand Up @@ -80,4 +80,79 @@ module('Integration | Component | tasks', function (hooks) {
);
assert.dom('[data-test-task-spinner]').doesNotExist();
});
test('changing the task status from any status other than BLOCKED to IN_PROGRESS inform proceeding further will make progress 0', async function (assert) {
tasks[0].status = 'SMOKE_TESTING';
this.set('dev', true);
const ctrl = this.owner.lookup('controller:tasks');

// before action
assert.equal(ctrl.showModal, false);
assert.equal(ctrl.message, '');

ctrl.allTasks = tasks;
ctrl.dev = true;
ctrl.taskFields = {
status: 'IN_PROGRESS',
};

//action
ctrl.send('handleUpdateTask', tasks[0].id, () => {});

//after action
assert.equal(ctrl.showModal, true);
assert.equal(
ctrl.message,
'Proceeding further will make task progress 0%.'
);
});
test('changing the task status from IN_PROGRESS to any status other than BLOCKED inform proceeding further will make progress 100', async function (assert) {
tasks[0].status = 'IN_PROGRESS';
this.set('dev', true);
const ctrl = this.owner.lookup('controller:tasks');

// before action
assert.equal(ctrl.showModal, false);
assert.equal(ctrl.message, '');

ctrl.allTasks = tasks;
ctrl.dev = true;
ctrl.taskFields = {
status: 'SMOKE_TESTING',
};

// action
ctrl.send('handleUpdateTask', tasks[0].id, () => {});

// after action
assert.equal(ctrl.showModal, true);
assert.equal(
ctrl.message,
'Proceeding further will make task progress 100%.'
);
});
test('changing the task status from BLOCKED to any status other than IN_PROGRESS when percentCompleted is less than 100, inform the user proceeding further will make progress 100', async function (assert) {
tasks[0].status = 'BLOCKED';
this.set('dev', true);
const ctrl = this.owner.lookup('controller:tasks');

// before action
assert.equal(ctrl.showModal, false);
assert.equal(ctrl.message, '');

ctrl.allTasks = tasks;
ctrl.dev = true;
ctrl.taskFields = {
status: 'SMOKE_TESTING',
};

// action
skv93-coder marked this conversation as resolved.
Show resolved Hide resolved
ctrl.send('handleUpdateTask', tasks[0].id, () => {});

// after action
assert.equal(ctrl.showModal, true);
assert.equal(
ctrl.message,
`The progress of current task is ${tasks[0].percentCompleted}%. Proceeding further will make task progress 100%.`
);
});
});