@zeniai/client-epic-state 5.1.42-betaDI4 → 5.1.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  2. package/lib/entity/snackbar/snackbarTypes.js +1 -1
  3. package/lib/entity/task/taskPayload.d.ts +1 -2
  4. package/lib/entity/task/taskPayload.js +1 -8
  5. package/lib/entity/task/taskReducer.d.ts +1 -8
  6. package/lib/entity/task/taskReducer.js +4 -29
  7. package/lib/entity/task/taskState.d.ts +0 -1
  8. package/lib/entity/tenant/epic/saveExternalConnectionEpic.js +15 -11
  9. package/lib/epic.d.ts +3 -5
  10. package/lib/epic.js +3 -5
  11. package/lib/esm/entity/snackbar/snackbarTypes.js +1 -1
  12. package/lib/esm/entity/task/taskPayload.js +1 -8
  13. package/lib/esm/entity/task/taskReducer.js +3 -28
  14. package/lib/esm/entity/tenant/epic/saveExternalConnectionEpic.js +15 -11
  15. package/lib/esm/epic.js +3 -5
  16. package/lib/esm/index.js +7 -7
  17. package/lib/esm/view/companyTaskManagerView/epics/fetchCompanyTaskManagerViewEpic.js +0 -3
  18. package/lib/esm/view/companyTaskManagerView/epics/fetchTaskManagerMetricsEpic.js +1 -7
  19. package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +7 -0
  20. package/lib/esm/view/taskManager/taskDetailView/epics/initializeTaskToLocalStoreEpic.js +0 -1
  21. package/lib/esm/view/taskManager/taskDetailView/epics/saveTaskDetailEpic.js +9 -70
  22. package/lib/esm/view/taskManager/taskDetailView/taskDetailReducer.js +2 -56
  23. package/lib/esm/view/taskManager/taskDetailView/taskDetailSelector.js +9 -32
  24. package/lib/esm/view/taskManager/taskListView/epics/fetchTaskListEpic.js +1 -3
  25. package/lib/esm/view/taskManager/taskListView/taskList.js +0 -1
  26. package/lib/esm/view/taskManager/taskListView/taskListReducer.js +12 -240
  27. package/lib/esm/view/taskManager/taskListView/taskListSelector.js +0 -1
  28. package/lib/esm/view/taskManager/taskListView/taskListViewHelpers.js +0 -58
  29. package/lib/esm/view/transactionDetail/epics/saveTransactionHelper.js +22 -0
  30. package/lib/esm/view/transactionDetail/epics/updateTransactionDetailEpic.js +75 -3
  31. package/lib/esm/view/transactionDetail/journalEntryLinesViewModel.js +58 -0
  32. package/lib/esm/view/transactionDetail/transactionDetailLocalDataHelper.js +10 -8
  33. package/lib/esm/view/transactionDetail/transactionDetailReducer.js +66 -1
  34. package/lib/index.d.ts +10 -10
  35. package/lib/index.js +25 -25
  36. package/lib/view/companyTaskManagerView/epics/fetchCompanyTaskManagerViewEpic.js +0 -3
  37. package/lib/view/companyTaskManagerView/epics/fetchTaskManagerMetricsEpic.js +1 -7
  38. package/lib/view/companyView/types/cockpitTypes.d.ts +0 -3
  39. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  40. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +7 -0
  41. package/lib/view/taskManager/taskDetailView/epics/initializeTaskToLocalStoreEpic.js +0 -1
  42. package/lib/view/taskManager/taskDetailView/epics/saveTaskDetailEpic.d.ts +2 -2
  43. package/lib/view/taskManager/taskDetailView/epics/saveTaskDetailEpic.js +8 -69
  44. package/lib/view/taskManager/taskDetailView/taskDetail.d.ts +0 -15
  45. package/lib/view/taskManager/taskDetailView/taskDetailReducer.d.ts +2 -14
  46. package/lib/view/taskManager/taskDetailView/taskDetailReducer.js +3 -57
  47. package/lib/view/taskManager/taskDetailView/taskDetailSelector.d.ts +1 -2
  48. package/lib/view/taskManager/taskDetailView/taskDetailSelector.js +7 -30
  49. package/lib/view/taskManager/taskListView/epics/fetchTaskListEpic.js +1 -3
  50. package/lib/view/taskManager/taskListView/taskList.d.ts +1 -1
  51. package/lib/view/taskManager/taskListView/taskList.js +0 -1
  52. package/lib/view/taskManager/taskListView/taskListPayload.d.ts +0 -4
  53. package/lib/view/taskManager/taskListView/taskListReducer.d.ts +2 -6
  54. package/lib/view/taskManager/taskListView/taskListReducer.js +13 -241
  55. package/lib/view/taskManager/taskListView/taskListSelector.js +0 -1
  56. package/lib/view/taskManager/taskListView/taskListViewHelpers.d.ts +0 -11
  57. package/lib/view/taskManager/taskListView/taskListViewHelpers.js +1 -60
  58. package/lib/view/transactionDetail/epics/saveTransactionHelper.js +22 -0
  59. package/lib/view/transactionDetail/epics/updateTransactionDetailEpic.d.ts +5 -1
  60. package/lib/view/transactionDetail/epics/updateTransactionDetailEpic.js +77 -4
  61. package/lib/view/transactionDetail/journalEntryLinesViewModel.d.ts +27 -0
  62. package/lib/view/transactionDetail/journalEntryLinesViewModel.js +61 -1
  63. package/lib/view/transactionDetail/transactionDetailLocalDataHelper.js +10 -8
  64. package/lib/view/transactionDetail/transactionDetailReducer.d.ts +11 -2
  65. package/lib/view/transactionDetail/transactionDetailReducer.js +67 -2
  66. package/lib/view/transactionDetail/transactionDetailState.d.ts +8 -1
  67. package/lib/view/transactionDetail/transactionDetailTypes.d.ts +2 -0
  68. package/package.json +1 -1
  69. package/lib/esm/view/taskManager/taskDetailView/epics/createSubTaskEpic.js +0 -96
  70. package/lib/esm/view/taskManager/taskDetailView/epics/fetchSubTasksEpic.js +0 -53
  71. package/lib/view/taskManager/taskDetailView/epics/createSubTaskEpic.d.ts +0 -9
  72. package/lib/view/taskManager/taskDetailView/epics/createSubTaskEpic.js +0 -100
  73. package/lib/view/taskManager/taskDetailView/epics/fetchSubTasksEpic.d.ts +0 -8
  74. package/lib/view/taskManager/taskDetailView/epics/fetchSubTasksEpic.js +0 -57
@@ -1,8 +1,8 @@
1
1
  import isEqual from 'lodash/isEqual';
2
- import { reduceAnyFetchState } from '../../../commonStateTypes/reduceFetchState';
2
+ import { reduceFetchState } from '../../../commonStateTypes/reduceFetchState';
3
3
  import { getClassesByIds } from '../../../entity/class/classSelector';
4
4
  import { getFilesByFileIds } from '../../../entity/file/fileSelector';
5
- import { getTaskById, getTasksByIds } from '../../../entity/task/taskSelector';
5
+ import { getTaskById } from '../../../entity/task/taskSelector';
6
6
  import { getUserAndUserRole, } from '../../companyView/types/userAndRole';
7
7
  import { getFileDeleteStatusById, getFileUpdateNameStatusById, } from '../../fileView/fileViewSelector';
8
8
  import { getUserList, } from '../../userListView/userListViewSelector';
@@ -27,13 +27,8 @@ export const getTaskDetail = (state, taskId) => {
27
27
  let recurringSourceTaskId = undefined;
28
28
  let snoozedUntil = undefined;
29
29
  let taskGroupId = undefined;
30
- let subtasks = [];
31
30
  if (taskId != null && sourceTaskDetail != null) {
32
31
  const taskEntity = getTaskById(taskState, taskId);
33
- subtasks =
34
- taskEntity != null
35
- ? getTasksByIds(taskState, taskEntity.subTasksIds)
36
- : [];
37
32
  const fileIdsInEntity = taskEntity?.fileIds ?? [];
38
33
  if (taskEntity != null) {
39
34
  createdByUser = getUserAndUserRole(userState, userRoleState, addressState, taskEntity.createdBy);
@@ -43,37 +38,26 @@ export const getTaskDetail = (state, taskId) => {
43
38
  snoozedUntil = taskEntity.snoozedUntil;
44
39
  taskGroupId = taskEntity.taskGroupIds[0];
45
40
  }
46
- // Treat "no entry" as Completed so it doesn't block the combined
47
- // fetch state. The Not-Started default would pin the detail page
48
- // below Completed forever before the first fetchSubTasks dispatches.
49
- const completedSubTaskStatus = {
50
- fetchState: 'Completed',
51
- error: undefined,
52
- };
53
- const subTaskStatus = taskDetailState.subTaskListFetchStatusByParentId[taskId] ??
54
- completedSubTaskStatus;
55
41
  if (fileIdsInEntity.length > 0) {
56
- fetchStatus = reduceAnyFetchState([
42
+ fetchStatus = reduceFetchState([
57
43
  fileViewState.fetchFilesStatus,
58
44
  sourceTaskDetail.fetchTaskStatus,
59
45
  userList,
60
46
  classListState,
61
- subTaskStatus,
62
47
  ]);
63
48
  }
64
49
  else {
65
- fetchStatus = reduceAnyFetchState([
50
+ fetchStatus = reduceFetchState([
66
51
  sourceTaskDetail.fetchTaskStatus,
67
52
  userList,
68
53
  classListState,
69
- subTaskStatus,
70
54
  ]);
71
55
  }
72
56
  showTaskDetailFormFooter = showFormFooter(sourceTaskDetail.taskDetailLocalData, taskEntity);
73
57
  taskHistory = taskDetailState.taskHistoryById[taskId]?.historicEvents ?? [];
74
58
  }
75
59
  else if (taskId == null) {
76
- fetchStatus = reduceAnyFetchState([userList, classListState]);
60
+ fetchStatus = reduceFetchState([userList, classListState]);
77
61
  }
78
62
  const { classIds } = classListState;
79
63
  const allAccountingClasses = getClassesByIds(classState, {
@@ -106,7 +90,6 @@ export const getTaskDetail = (state, taskId) => {
106
90
  showTaskDetailFormFooter,
107
91
  snoozedUntil,
108
92
  taskGroupId,
109
- subtasks,
110
93
  };
111
94
  };
112
95
  export const allTaskStatus = [
@@ -154,16 +137,13 @@ export const allTaskPriority = [
154
137
  },
155
138
  ];
156
139
  const showFormFooter = (taskDetailLocalData, taskDetailInStore) => {
157
- if (taskDetailInStore == null) {
158
- return false;
159
- }
160
- if (taskDetailLocalData.name !== taskDetailInStore.name ||
140
+ if (taskDetailLocalData.name !== taskDetailInStore?.name ||
161
141
  taskDetailLocalData.description !== taskDetailInStore.description ||
162
142
  taskDetailLocalData.priority !== taskDetailInStore.priority.code ||
163
143
  taskDetailLocalData.status !== taskDetailInStore.status.code ||
164
144
  !isEqual(taskDetailInStore.tagIds, taskDetailLocalData.tagIds) ||
165
- !isEqual(taskDetailLocalData.assignee, taskDetailInStore.assignees ?? []) ||
166
- !isEqual(taskDetailLocalData.groupAssignees, taskDetailInStore.groupAssignees ?? []) ||
145
+ !isEqual(taskDetailLocalData.assignee, taskDetailInStore?.assignees ?? []) ||
146
+ !isEqual(taskDetailLocalData.groupAssignees, taskDetailInStore?.groupAssignees ?? []) ||
167
147
  !isEqual(taskDetailLocalData.fileIds, taskDetailInStore.fileIds ?? []) ||
168
148
  !isEqual(taskDetailLocalData.dueDate, taskDetailInStore.dueDate) ||
169
149
  !isEqual(taskDetailLocalData.type, taskDetailInStore.type) ||
@@ -171,10 +151,7 @@ const showFormFooter = (taskDetailLocalData, taskDetailInStore) => {
171
151
  !isEqual(taskDetailLocalData.recurringFrequency, taskDetailInStore.recurringFrequency) ||
172
152
  !isEqual(taskDetailLocalData.recurringDaysOfWeek, taskDetailInStore.recurringDaysOfWeek) ||
173
153
  !isEqual(taskDetailLocalData.recurringStartDate, taskDetailInStore.recurringStartDate) ||
174
- !isEqual(taskDetailLocalData.timeSpent, taskDetailInStore.timeSpent) ||
175
- !isEqual(taskDetailLocalData.taskGroupId, taskDetailInStore.taskGroupIds.length > 0
176
- ? taskDetailInStore.taskGroupIds[0]
177
- : undefined)) {
154
+ !isEqual(taskDetailLocalData.timeSpent, taskDetailInStore.timeSpent)) {
178
155
  return true;
179
156
  }
180
157
  return false;
@@ -9,17 +9,15 @@ export const fetchTaskListEpic = (actions$, _state$, zeniAPI) => actions$.pipe(f
9
9
  .getJSON(`${zeniAPI.apiEndPoints.taskMicroServiceBaseUrl}/1.0/task-manager/tasks?query=${encodeURIComponent(`{"task_type": "all"}`)}`)
10
10
  .pipe(mergeMap((response) => {
11
11
  if (isSuccessResponse(response) && response.data != null) {
12
- const { tasks, deleted, archived, snoozed, completed } = response.data;
12
+ const { tasks, deleted, archived, snoozed } = response.data;
13
13
  const allTasks = [
14
14
  ...tasks,
15
- ...(completed ?? []),
16
15
  ...(deleted ?? []),
17
16
  ...(archived ?? []),
18
17
  ...(snoozed ?? []),
19
18
  ];
20
19
  return of(updateTasks(allTasks), updateTaskList({
21
20
  data: tasks,
22
- completed: completed ?? [],
23
21
  deleted: deleted ?? [],
24
22
  archived: archived ?? [],
25
23
  snoozed: snoozed ?? [],
@@ -1,7 +1,6 @@
1
1
  import { stringToUnion, stringToUnionStrict, } from '../../../commonStateTypes/stringToUnion';
2
2
  export const ALL_TASK_LIST_TABS = [
3
3
  'live',
4
- 'completed',
5
4
  'archived',
6
5
  'deleted',
7
6
  'snoozed',
@@ -1,5 +1,4 @@
1
1
  import { createSlice } from '@reduxjs/toolkit';
2
- import { updateTasks } from '../../../entity/task/taskReducer';
3
2
  import { toPriorityCodeType, toTaskStatusCodeType, } from '../../../entity/task/taskState';
4
3
  import { date, dateNow } from '../../../zeniDayJS';
5
4
  import { toDueDateGroupKeyType, } from './taskList';
@@ -43,7 +42,6 @@ export const initialState = {
43
42
  currentTab: 'live',
44
43
  byTab: {
45
44
  live: { ...initialTabData },
46
- completed: { ...initialTabData },
47
45
  archived: { ...initialTabData },
48
46
  deleted: { ...initialTabData },
49
47
  snoozed: { ...initialTabData },
@@ -65,12 +63,14 @@ export const initialState = {
65
63
  },
66
64
  filters: {
67
65
  categoryCombinationOperator: 'AND',
68
- // Default to no filters. The Completed tab now owns the "hide resolved
69
- // tasks from the live list" responsibility via the byTab split in
70
- // updateTaskList / updateTaskFromListView / the updateTasks
71
- // extraReducer. Keeping the historical `status != resolved` filter
72
- // here would empty out the Completed tab.
73
- categories: [],
66
+ categories: [
67
+ {
68
+ field: 'status',
69
+ matchingOperator: 'not_equal',
70
+ values: ['resolved'],
71
+ valuesCombinationOperator: 'ANY',
72
+ },
73
+ ],
74
74
  },
75
75
  hasValidState() {
76
76
  return this.fetchState == 'Completed';
@@ -102,16 +102,13 @@ const taskList = createSlice({
102
102
  draft.error = undefined;
103
103
  },
104
104
  updateTaskList(draft, action) {
105
- const { data, archived, completed, deleted, snoozed } = action.payload;
105
+ const { data, archived, deleted, snoozed } = action.payload;
106
106
  draft.fetchState = 'Completed';
107
107
  draft.error = undefined;
108
108
  // Group live tasks
109
109
  const liveGrouped = getGroupedTaskIds(data);
110
110
  draft.byTab.live = toTabData(liveGrouped);
111
111
  // Group other tabs if provided
112
- if (completed != null) {
113
- draft.byTab.completed = toTabData(getGroupedTaskIds(completed));
114
- }
115
112
  if (archived != null) {
116
113
  draft.byTab.archived = toTabData(getGroupedTaskIds(archived));
117
114
  }
@@ -357,26 +354,9 @@ const taskList = createSlice({
357
354
  draft.taskIdsByAssignees[assigneeKey] = draft.taskIdsByAssignees[assigneeKey].filter((taskId) => taskId !== currentTaskState.id);
358
355
  draft.taskIdsByTags[tagsKey] = draft.taskIdsByTags[tagsKey].filter((taskId) => taskId !== currentTaskState.id);
359
356
  draft.taskIdsByDueDate[dueDateKey] = draft.taskIdsByDueDate[dueDateKey].filter((taskId) => taskId !== currentTaskState.id);
360
- // Remove from EVERY previous group bucket the task lived in, not
361
- // just the destination bucket. Otherwise a detail-page save that
362
- // moves a task from group A to group B leaves the row listed
363
- // under both A and B until refetch.
364
- const previousGroupIds = currentTaskState.taskGroupIds ?? [];
365
- const allGroupIdsToClean = new Set([
366
- ...previousGroupIds,
367
- taskGroupId,
368
- ]);
369
- allGroupIdsToClean.forEach((gid) => {
370
- if (draft.taskIdsByGroupsIds[gid] != null) {
371
- draft.taskIdsByGroupsIds[gid] = draft.taskIdsByGroupsIds[gid].filter((id) => id !== currentTaskState.id);
372
- }
373
- });
357
+ draft.taskIdsByGroupsIds[taskGroupId] = draft.taskIdsByGroupsIds[taskGroupId].filter((taskId) => taskId !== currentTaskState.id);
374
358
  }
375
359
  doUpdateTaskList(draft, task, taskGroupId);
376
- // Mirror top-level grouping into the active tab's byTab snapshot,
377
- // otherwise the next updateTaskListTab call copies stale byTab data
378
- // back over this optimistic update.
379
- syncTopLevelToActiveTab(draft);
380
360
  },
381
361
  updateTaskListOnCreateTaskFromTemplateSuccess(draft, action) {
382
362
  const { tasks } = action.payload;
@@ -400,7 +380,6 @@ const taskList = createSlice({
400
380
  const taskId = task.id;
401
381
  draft.updateTasksFetchState.fetchState = 'In-Progress';
402
382
  draft.updateTasksFetchState.error = undefined;
403
- let didMigrateTab = false;
404
383
  if (updates.priority != null) {
405
384
  const prevPriorityCode = toPriorityCodeType(task.priority.code);
406
385
  draft.taskIdsByPriority[prevPriorityCode] = draft.taskIdsByPriority[prevPriorityCode].filter((id) => id != taskId);
@@ -412,25 +391,6 @@ const taskList = createSlice({
412
391
  draft.taskIdsByStatus[prevStatusCode] = draft.taskIdsByStatus[prevStatusCode].filter((id) => id != taskId);
413
392
  const newStatusCode = toTaskStatusCodeType(updates.status.code);
414
393
  draft.taskIdsByStatus[newStatusCode].push(taskId);
415
- // Optimistically re-bucket between the live and completed tabs
416
- // when status transitions in/out of "resolved", so the task
417
- // moves to the Completed tab without waiting for the next
418
- // fetch. Mirrors backend split in task_handler.py: only
419
- // `resolved` counts as completed; `done` stays Active.
420
- //
421
- // Subtasks travel with their parent — they appear nested under
422
- // the parent row, not as standalone entries in byTab.taskIds.
423
- // So we only rebucket parent tasks (tasks with no parentTaskId).
424
- const isTopLevelTask = task.parentTaskId == null;
425
- const wasCompleted = prevStatusCode === 'resolved';
426
- const isCompleted = newStatusCode === 'resolved';
427
- if (isTopLevelTask && wasCompleted !== isCompleted) {
428
- const from = isCompleted ? 'live' : 'completed';
429
- const to = isCompleted ? 'completed' : 'live';
430
- const updatedTask = { ...task, ...updates };
431
- migrateTaskBetweenTabs(draft, taskId, updatedTask, from, to);
432
- didMigrateTab = true;
433
- }
434
394
  }
435
395
  if (updates.assignees != null) {
436
396
  const prevGroupId = getAssigneesGroupKey(task.assignees);
@@ -470,18 +430,7 @@ const taskList = createSlice({
470
430
  };
471
431
  }
472
432
  }
473
- if (didMigrateTab) {
474
- // The migration moved the task out of the source byTab and into
475
- // the destination byTab. The active tab's grouping arrays are
476
- // now authoritative — mirror them back to the top-level so the
477
- // UI sees the task gone from Live (or freshly arrived in
478
- // Completed). Inverse of syncTopLevelToActiveTab, used only on
479
- // this path.
480
- copyTabDataToTopLevel(draft, draft.byTab[draft.currentTab]);
481
- }
482
- else {
483
- syncTopLevelToActiveTab(draft);
484
- }
433
+ syncTopLevelToActiveTab(draft);
485
434
  },
486
435
  updateTasksListOnUpdateTaskSuccess(draft) {
487
436
  draft.updateTasksFetchState.fetchState = 'Completed';
@@ -494,80 +443,12 @@ const taskList = createSlice({
494
443
  removeTaskFromList(draft, action) {
495
444
  removeTaskIds(draft, [action.payload]);
496
445
  },
497
- /**
498
- * Remove a task id from a single group bucket without touching tab
499
- * membership or other groupings. Used when the user clears a task's
500
- * group on the Detail page so the row stops appearing under the old
501
- * group while saveTaskDetailEpic skips the standard list re-insert.
502
- */
503
- removeTaskFromGroupBucket(draft, action) {
504
- const { taskId, taskGroupId } = action.payload;
505
- if (draft.taskIdsByGroupsIds[taskGroupId] != null) {
506
- draft.taskIdsByGroupsIds[taskGroupId] = draft.taskIdsByGroupsIds[taskGroupId].filter((id) => id !== taskId);
507
- }
508
- // Mirror to the active tab's grouping so the UI re-renders.
509
- const activeTab = draft.byTab[draft.currentTab];
510
- if (activeTab.taskIdsByGroupsIds[taskGroupId] != null) {
511
- activeTab.taskIdsByGroupsIds[taskGroupId] =
512
- activeTab.taskIdsByGroupsIds[taskGroupId].filter((id) => id !== taskId);
513
- }
514
- },
515
446
  clearTaskList(draft) {
516
447
  Object.assign(draft, initialState);
517
448
  },
518
449
  },
519
- extraReducers: (builder) => {
520
- // When the entity store receives updated tasks (e.g. from task detail
521
- // save, snooze/archive/unarchive, etc.), re-bucket parent tasks between
522
- // the live and completed tabs based on the new status. Mirrors the
523
- // backend split in task_handler.py: only `resolved` parents count as
524
- // completed. Subtasks are nested under their parent row, so they
525
- // never move between tabs on their own.
526
- builder.addCase(updateTasks, (draft, action) => {
527
- action.payload.forEach((taskPayload) => {
528
- // Only re-bucket parents; subtasks (parent_task_id is a non-empty
529
- // string) are nested under their parent row and don't move tabs.
530
- if (taskPayload.parent_task_id != null &&
531
- taskPayload.parent_task_id !== '') {
532
- return;
533
- }
534
- const taskId = taskPayload.task_id;
535
- // `TaskPayload.status` is required per the type — every producer
536
- // in this repo sends it, and `mapTaskPayloadToTask` dereferences
537
- // it unguarded. The optional chain + null guard are defensive
538
- // only, in case a downstream consumer (web-app-ui / cockpit-ui)
539
- // ever dispatches `updateTasks` with a partial payload; in that
540
- // case we treat missing status as "no status change" and skip
541
- // re-bucketing so we don't migrate a Completed task back into
542
- // the Live tab.
543
- const statusCode = taskPayload.status?.code;
544
- if (statusCode == null) {
545
- return;
546
- }
547
- const isCompleted = statusCode === 'resolved';
548
- const targetTab = isCompleted ? 'completed' : 'live';
549
- const otherTab = isCompleted ? 'live' : 'completed';
550
- // Skip if the task isn't currently in either of these buckets
551
- // (archived/snoozed/deleted are managed by their own actions).
552
- const inLive = draft.byTab.live.taskIds.includes(taskId);
553
- const inCompleted = draft.byTab.completed.taskIds.includes(taskId);
554
- if (!inLive && !inCompleted) {
555
- return;
556
- }
557
- if (draft.byTab[otherTab].taskIds.includes(taskId)) {
558
- migrateTaskPayloadBetweenTabs(draft, taskId, taskPayload, otherTab, targetTab);
559
- }
560
- else if (!draft.byTab[targetTab].taskIds.includes(taskId)) {
561
- draft.byTab[targetTab].taskIds.push(taskId);
562
- }
563
- });
564
- // Re-sync the top-level taskIds / grouping arrays for whichever
565
- // tab the user is currently looking at.
566
- copyTabDataToTopLevel(draft, draft.byTab[draft.currentTab]);
567
- });
568
- },
569
450
  });
570
- export const { fetchTaskListPage, fetchTaskList, updateTaskList, updateTaskListTab, updateTaskListFetchStatus, updateTaskListSearchText, updateTaskListUIState, updateTaskFilters, updateTaskListOnNewGroupCreationSuccess, bulkUpdateTaskList, updateTasksListOnBulkUpdateTasksSuccess, updateTasksListOnBulkUpdateTasksFailure, initiateTaskListLocalData, updateTaskListLocalData, updateTaskListOnTaskGroupDeletion, dragNDropTasks, updateTaskListOnNewTaskCreationSuccess, updateTaskListOnTaskGroupNameUpdate, updateTaskFromListView, updateTasksListOnUpdateTaskSuccess, updateTasksListOnUpdateTaskFailure, updateTaskListOnCreateTaskFromTemplateSuccess, removeTaskFromList, removeTaskFromGroupBucket, clearTaskList, } = taskList.actions;
451
+ export const { fetchTaskListPage, fetchTaskList, updateTaskList, updateTaskListTab, updateTaskListFetchStatus, updateTaskListSearchText, updateTaskListUIState, updateTaskFilters, updateTaskListOnNewGroupCreationSuccess, bulkUpdateTaskList, updateTasksListOnBulkUpdateTasksSuccess, updateTasksListOnBulkUpdateTasksFailure, initiateTaskListLocalData, updateTaskListLocalData, updateTaskListOnTaskGroupDeletion, dragNDropTasks, updateTaskListOnNewTaskCreationSuccess, updateTaskListOnTaskGroupNameUpdate, updateTaskFromListView, updateTasksListOnUpdateTaskSuccess, updateTasksListOnUpdateTaskFailure, updateTaskListOnCreateTaskFromTemplateSuccess, removeTaskFromList, clearTaskList, } = taskList.actions;
571
452
  export default taskList.reducer;
572
453
  /**
573
454
  * helpers
@@ -674,115 +555,6 @@ const copyTabDataToTopLevel = (draft, tabData) => {
674
555
  draft.taskIdsByDueDate = tabData.taskIdsByDueDate;
675
556
  draft.taskIdsByTags = tabData.taskIdsByTags;
676
557
  };
677
- /**
678
- * Migrate a parent task between two `byTab` buckets (live ↔ completed)
679
- * when its status flips into / out of `resolved`. The destination tab
680
- * picks up the task in EVERY grouping dimension (status, priority,
681
- * group id, assignees, dueDate, tags) using the UPDATED task as the
682
- * source-of-truth for the new bucket keys. Otherwise the Completed tab
683
- * shows the task in the right tab-level list but the grouped views
684
- * (Group by Status, Group by Priority, etc.) miss it until the next
685
- * full fetch.
686
- */
687
- const migrateTaskBetweenTabs = (draft, taskId, updatedTask, from, to) => {
688
- const fromTab = draft.byTab[from];
689
- const toTab = draft.byTab[to];
690
- // Source tab: drop the task from every grouping dimension.
691
- removeIdsFromTabData(fromTab, [taskId]);
692
- // Destination tab: add the task to taskIds (deduped) plus the
693
- // appropriate bucket inside each grouping dimension based on the
694
- // updated task.
695
- if (!toTab.taskIds.includes(taskId)) {
696
- toTab.taskIds.push(taskId);
697
- }
698
- const priorityKey = toPriorityCodeType(updatedTask.priority.code);
699
- if (!toTab.taskIdsByPriority[priorityKey].includes(taskId)) {
700
- toTab.taskIdsByPriority[priorityKey].push(taskId);
701
- }
702
- const statusKey = toTaskStatusCodeType(updatedTask.status.code);
703
- if (!toTab.taskIdsByStatus[statusKey].includes(taskId)) {
704
- toTab.taskIdsByStatus[statusKey].push(taskId);
705
- }
706
- const dueDateKey = updatedTask.dueDate != null
707
- ? getDueDateGroupKey(updatedTask.dueDate.toString())
708
- : 'upcoming';
709
- if (!toTab.taskIdsByDueDate[dueDateKey].includes(taskId)) {
710
- toTab.taskIdsByDueDate[dueDateKey].push(taskId);
711
- }
712
- const assigneeKey = getAssigneesGroupKey(updatedTask.assignees);
713
- if (toTab.taskIdsByAssignees[assigneeKey] == null) {
714
- toTab.taskIdsByAssignees[assigneeKey] = [taskId];
715
- }
716
- else if (!toTab.taskIdsByAssignees[assigneeKey].includes(taskId)) {
717
- toTab.taskIdsByAssignees[assigneeKey].push(taskId);
718
- }
719
- const tagIds = [...updatedTask.tagIds].sort();
720
- const tagsKey = tagIds.join(',');
721
- if (toTab.taskIdsByTags[tagsKey] == null) {
722
- toTab.taskIdsByTags[tagsKey] = [taskId];
723
- }
724
- else if (!toTab.taskIdsByTags[tagsKey].includes(taskId)) {
725
- toTab.taskIdsByTags[tagsKey].push(taskId);
726
- }
727
- (updatedTask.taskGroupIds ?? []).forEach((groupId) => {
728
- if (toTab.taskIdsByGroupsIds[groupId] == null) {
729
- toTab.taskIdsByGroupsIds[groupId] = [taskId];
730
- }
731
- else if (!toTab.taskIdsByGroupsIds[groupId].includes(taskId)) {
732
- toTab.taskIdsByGroupsIds[groupId].push(taskId);
733
- }
734
- });
735
- };
736
- /**
737
- * `updateTasks` extraReducer variant — same migration semantics but
738
- * keyed off the raw `TaskPayload` instead of the rich `Task` entity.
739
- */
740
- const migrateTaskPayloadBetweenTabs = (draft, taskId, payload, from, to) => {
741
- const fromTab = draft.byTab[from];
742
- const toTab = draft.byTab[to];
743
- removeIdsFromTabData(fromTab, [taskId]);
744
- if (!toTab.taskIds.includes(taskId)) {
745
- toTab.taskIds.push(taskId);
746
- }
747
- if (payload.priority?.code != null) {
748
- const priorityKey = toPriorityCodeType(payload.priority.code);
749
- if (!toTab.taskIdsByPriority[priorityKey].includes(taskId)) {
750
- toTab.taskIdsByPriority[priorityKey].push(taskId);
751
- }
752
- }
753
- if (payload.status?.code != null) {
754
- const statusKey = toTaskStatusCodeType(payload.status.code);
755
- if (!toTab.taskIdsByStatus[statusKey].includes(taskId)) {
756
- toTab.taskIdsByStatus[statusKey].push(taskId);
757
- }
758
- }
759
- const dueDateKey = getDueDateGroupKey(payload.due_date);
760
- if (!toTab.taskIdsByDueDate[dueDateKey].includes(taskId)) {
761
- toTab.taskIdsByDueDate[dueDateKey].push(taskId);
762
- }
763
- const assigneeKey = getAssigneesGroupKey(payload.assignees ?? []);
764
- if (toTab.taskIdsByAssignees[assigneeKey] == null) {
765
- toTab.taskIdsByAssignees[assigneeKey] = [taskId];
766
- }
767
- else if (!toTab.taskIdsByAssignees[assigneeKey].includes(taskId)) {
768
- toTab.taskIdsByAssignees[assigneeKey].push(taskId);
769
- }
770
- const tagsKey = getTagsGroupKey(payload.tags ?? []);
771
- if (toTab.taskIdsByTags[tagsKey] == null) {
772
- toTab.taskIdsByTags[tagsKey] = [taskId];
773
- }
774
- else if (!toTab.taskIdsByTags[tagsKey].includes(taskId)) {
775
- toTab.taskIdsByTags[tagsKey].push(taskId);
776
- }
777
- (payload.task_group_ids ?? []).forEach((groupId) => {
778
- if (toTab.taskIdsByGroupsIds[groupId] == null) {
779
- toTab.taskIdsByGroupsIds[groupId] = [taskId];
780
- }
781
- else if (!toTab.taskIdsByGroupsIds[groupId].includes(taskId)) {
782
- toTab.taskIdsByGroupsIds[groupId].push(taskId);
783
- }
784
- });
785
- };
786
558
  const removeIdsFromTabData = (tabData, taskIds) => {
787
559
  const removedSet = new Set(taskIds);
788
560
  const isRemoved = (id) => removedSet.has(id);
@@ -334,7 +334,6 @@ export const getAllTasks = createSelector((state) => state.taskListState, (state
334
334
  const taskGroupTemplates = getTaskGroupTemplateByIds(taskGroupTemplateState, taskGroupTemplateViewState.taskGroupTemplateIds);
335
335
  const tabCounts = {
336
336
  live: taskListState.byTab.live.taskIds.length,
337
- completed: taskListState.byTab.completed.taskIds.length,
338
337
  archived: taskListState.byTab.archived.taskIds.length,
339
338
  deleted: taskListState.byTab.deleted.taskIds.length,
340
339
  snoozed: taskListState.byTab.snoozed.taskIds.length,
@@ -48,61 +48,3 @@ export const getTaskUpdates = (groupByKey, groupId) => {
48
48
  taskGroupIds: [groupId],
49
49
  };
50
50
  };
51
- /**
52
- * Sort a subtask list by one of the sortable columns. Pure — no state
53
- * dependency. `statusOrder` is derived from `allTaskStatus` so any new
54
- * status added upstream slots in by its enum position instead of
55
- * falling into a catch-all bucket.
56
- */
57
- export const sortSubtasks = (subtasks, sortKey, sortOrder, userList, tagList) => {
58
- if (sortKey == null) {
59
- return subtasks;
60
- }
61
- const statusOrder = allTaskStatus.reduce((acc, status, index) => {
62
- acc[status.code] = index;
63
- return acc;
64
- }, {});
65
- const unknownStatusRank = allTaskStatus.length;
66
- const cmpStr = (a, b) => a.localeCompare(b, undefined, { sensitivity: 'base' });
67
- const keyFn = (task) => {
68
- if (sortKey === 'name') {
69
- return task.name ?? '';
70
- }
71
- if (sortKey === 'status') {
72
- return statusOrder[task.status.code] ?? unknownStatusRank;
73
- }
74
- if (sortKey === 'assignee') {
75
- const firstId = task.assignees?.[0];
76
- if (firstId == null) {
77
- return '';
78
- }
79
- const user = userList.find((candidate) => candidate.userId === firstId);
80
- return user
81
- ? `${user.firstName ?? ''} ${user.lastName ?? ''}`.trim()
82
- : '';
83
- }
84
- if (sortKey === 'tag') {
85
- const firstTagId = task.tagIds?.[0];
86
- if (firstTagId == null) {
87
- return '';
88
- }
89
- const tag = tagList.find((candidate) => candidate.tagId === firstTagId);
90
- return tag?.name ?? '';
91
- }
92
- return '';
93
- };
94
- const copy = [...subtasks];
95
- copy.sort((a, b) => {
96
- const av = keyFn(a);
97
- const bv = keyFn(b);
98
- let cmp;
99
- if (typeof av === 'number' && typeof bv === 'number') {
100
- cmp = av - bv;
101
- }
102
- else {
103
- cmp = cmpStr(String(av), String(bv));
104
- }
105
- return sortOrder === 'asc' ? cmp : -cmp;
106
- });
107
- return copy;
108
- };
@@ -45,7 +45,15 @@ export const toTransactionUpdatesFromTransactionDetailLocalData = (transactionDe
45
45
  let lastUpdatedCategory;
46
46
  let lastUpdatedClass;
47
47
  // single recommendation to just pick the last recommendation in the list of lines
48
+ const existingLineIds = new Set(transaction.lines?.map((l) => l.id) ?? []);
49
+ const deletedLineIds = new Set((transactionDetailLocalData.deletedLineIds ?? []).filter((id) => existingLineIds.has(id)));
50
+ // Collect new lines — in lineItemById but not yet in transaction.lines.
51
+ const addedLines = Object.values(transactionDetailLocalData.lineItemById).filter((item) => !existingLineIds.has(item.id));
48
52
  transaction.lines?.forEach((line) => {
53
+ // Skip lines the user deleted in edit mode.
54
+ if (deletedLineIds.has(line.id)) {
55
+ return;
56
+ }
49
57
  const lineItem = transactionDetailLocalData.lineItemById[line.id];
50
58
  if (line.type === 'transaction_with_account_and_class_line' ||
51
59
  line.type === 'transaction_with_product_or_service_line' ||
@@ -56,6 +64,7 @@ export const toTransactionUpdatesFromTransactionDetailLocalData = (transactionDe
56
64
  const entityDetails = getEntityDetails(selectedEntity, lineItem, transactionDetailLocalData.vendorUpdates, transactionDetailLocalData.customerUpdates);
57
65
  updatesByLineId[line.id] = {
58
66
  lineDescription: lineItem.lineDescription,
67
+ amount: lineItem.amount,
59
68
  class: lineItem.class,
60
69
  account: lineItem.account,
61
70
  // Project is at the transaction level for invoice/credit_memo; omit from lines.
@@ -77,6 +86,17 @@ export const toTransactionUpdatesFromTransactionDetailLocalData = (transactionDe
77
86
  currentSelectedEntityLine.type === 'vendor'
78
87
  ? lineItem.vendor
79
88
  : undefined,
89
+ // Carry the JE debit/credit side so a split edit that flips an
90
+ // existing line's posting side persists through the line patch.
91
+ ...(line.type === 'journal_entry_transaction_line'
92
+ ? {
93
+ postingType: lineItem.postingType,
94
+ postingTypeName: lineItem.postingType != null
95
+ ? lineItem.postingType.charAt(0).toUpperCase() +
96
+ lineItem.postingType.slice(1)
97
+ : lineItem.postingTypeName,
98
+ }
99
+ : {}),
80
100
  };
81
101
  }
82
102
  let hasCategoryChanged = false;
@@ -163,6 +183,8 @@ export const toTransactionUpdatesFromTransactionDetailLocalData = (transactionDe
163
183
  and all the line items are NOT uncategorized*/
164
184
  markAsMiscatUpdates: isTransactionMisCategorized,
165
185
  anyBulkUpdates: isBulkUpdate,
186
+ addedLines: addedLines.length > 0 ? addedLines : undefined,
187
+ deletedLineIds: deletedLineIds.size > 0 ? [...deletedLineIds] : undefined,
166
188
  };
167
189
  };
168
190
  const doUpdateEntityUpdates = (entityUpdates, entityId, entityType, recommendation, isBulkUpdate = false, updatedEntityId, entityName) => {