@zeniai/client-epic-state 5.0.84-betaJK7 → 5.0.84-betaVR1

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 (33) hide show
  1. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  2. package/lib/entity/snackbar/snackbarTypes.js +0 -1
  3. package/lib/entity/task/taskPayload.d.ts +0 -1
  4. package/lib/entity/task/taskPayload.js +0 -13
  5. package/lib/entity/task/taskReducer.d.ts +1 -5
  6. package/lib/entity/task/taskReducer.js +2 -8
  7. package/lib/entity/task/taskState.d.ts +0 -1
  8. package/lib/epic.d.ts +1 -2
  9. package/lib/epic.js +1 -2
  10. package/lib/esm/entity/snackbar/snackbarTypes.js +0 -1
  11. package/lib/esm/entity/task/taskPayload.js +0 -13
  12. package/lib/esm/entity/task/taskReducer.js +1 -7
  13. package/lib/esm/epic.js +1 -2
  14. package/lib/esm/index.js +4 -2
  15. package/lib/esm/view/taskManager/taskDetailView/epics/fetchTaskDetailEpic.js +0 -13
  16. package/lib/esm/view/taskManager/taskDetailView/taskDetailReducer.js +1 -23
  17. package/lib/esm/view/taskManager/taskDetailView/taskDetailSelector.js +3 -6
  18. package/lib/esm/view/transactionDetail/journalEntryLinesViewModel.js +113 -0
  19. package/lib/index.d.ts +6 -3
  20. package/lib/index.js +22 -15
  21. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  22. package/lib/view/taskManager/taskDetailView/epics/fetchTaskDetailEpic.d.ts +1 -2
  23. package/lib/view/taskManager/taskDetailView/epics/fetchTaskDetailEpic.js +0 -13
  24. package/lib/view/taskManager/taskDetailView/taskDetail.d.ts +0 -12
  25. package/lib/view/taskManager/taskDetailView/taskDetailReducer.d.ts +2 -6
  26. package/lib/view/taskManager/taskDetailView/taskDetailReducer.js +2 -24
  27. package/lib/view/taskManager/taskDetailView/taskDetailSelector.js +3 -6
  28. package/lib/view/transactionDetail/journalEntryLinesViewModel.d.ts +73 -0
  29. package/lib/view/transactionDetail/journalEntryLinesViewModel.js +124 -0
  30. package/package.json +1 -1
  31. package/lib/esm/view/taskManager/taskDetailView/epics/createSubTaskEpic.js +0 -80
  32. package/lib/view/taskManager/taskDetailView/epics/createSubTaskEpic.d.ts +0 -9
  33. package/lib/view/taskManager/taskDetailView/epics/createSubTaskEpic.js +0 -84
@@ -1,7 +1,7 @@
1
1
  import { FetchState, ID } from '../../../commonStateTypes/common';
2
2
  import { ZeniAPIStatus } from '../../../responsePayload';
3
3
  import { HistoricEventPayload } from '../../spendManagement/commonHistoryView/commonHistoryPayload';
4
- import { CreateSubTaskPayload, EditTaskLocalData, TaskDetailViewState } from './taskDetail';
4
+ import { EditTaskLocalData, TaskDetailViewState } from './taskDetail';
5
5
  export declare const initialState: TaskDetailViewState;
6
6
  export declare const fetchTaskDetailPage: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[cacheOverride: boolean, taskId?: string | undefined], {
7
7
  cacheOverride: boolean;
@@ -34,11 +34,7 @@ export declare const fetchTaskDetailPage: import("@reduxjs/toolkit").ActionCreat
34
34
  error?: ZeniAPIStatus;
35
35
  newTaskId?: ID;
36
36
  taskId?: ID;
37
- }, "taskDetailView/saveTaskSuccessOrFailure">, createSubTask: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[payload: CreateSubTaskPayload], CreateSubTaskPayload, "taskDetailView/createSubTask", never, never>, createSubTaskSuccessOrFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
38
- fetchState: FetchState;
39
- error?: ZeniAPIStatus;
40
- newTaskId?: ID;
41
- }, "taskDetailView/createSubTaskSuccessOrFailure">, deleteTask: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[taskId?: string | undefined], {
37
+ }, "taskDetailView/saveTaskSuccessOrFailure">, deleteTask: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[taskId?: string | undefined], {
42
38
  taskId: string | undefined;
43
39
  }, "taskDetailView/deleteTask", never, never>, removeTaskDetail: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, "taskDetailView/removeTaskDetail">, deleteTaskSuccessOrFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
44
40
  fetchState: FetchState;
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  var _a;
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.updateDeletedTagToLocalStore = exports.updateCreatedTagToLocalStore = exports.clearTaskDetail = exports.updateTaskHistoryFetchStatus = exports.updateTaskHistory = exports.fetchTaskHistory = exports.unsnoozeTask = exports.snoozeTaskSuccessOrFailure = exports.snoozeTask = exports.deleteTaskSuccessOrFailure = exports.removeTaskDetail = exports.deleteTask = exports.createSubTaskSuccessOrFailure = exports.createSubTask = exports.saveTaskSuccessOrFailure = exports.archiveTaskSuccessOrFailure = exports.archiveTask = exports.saveTaskDetail = exports.discardTaskUpdatesInLocalStore = exports.saveTaskUpdatesToLocalStore = exports.updateEditTaskFetchStatus = exports.initializeTaskToLocalStore = exports.fetchTaskDetail = exports.fetchTaskDetailPage = exports.initialState = void 0;
7
+ exports.updateDeletedTagToLocalStore = exports.updateCreatedTagToLocalStore = exports.clearTaskDetail = exports.updateTaskHistoryFetchStatus = exports.updateTaskHistory = exports.fetchTaskHistory = exports.unsnoozeTask = exports.snoozeTaskSuccessOrFailure = exports.snoozeTask = exports.deleteTaskSuccessOrFailure = exports.removeTaskDetail = exports.deleteTask = exports.saveTaskSuccessOrFailure = exports.archiveTaskSuccessOrFailure = exports.archiveTask = exports.saveTaskDetail = exports.discardTaskUpdatesInLocalStore = exports.saveTaskUpdatesToLocalStore = exports.updateEditTaskFetchStatus = exports.initializeTaskToLocalStore = exports.fetchTaskDetail = exports.fetchTaskDetailPage = exports.initialState = void 0;
8
8
  const toolkit_1 = require("@reduxjs/toolkit");
9
9
  const get_1 = __importDefault(require("lodash/get"));
10
10
  const commonHistory_1 = require("../../spendManagement/commonHistoryView/commonHistory");
@@ -13,10 +13,6 @@ const taskDetail_1 = require("./taskDetail");
13
13
  exports.initialState = {
14
14
  newTaskState: taskDetail_1.initialTaskDetail,
15
15
  editTaskStateById: {},
16
- subTaskCreateStatus: {
17
- fetchState: 'Not-Started',
18
- error: undefined,
19
- },
20
16
  taskHistoryById: {},
21
17
  };
22
18
  const taskDetailView = (0, toolkit_1.createSlice)({
@@ -329,28 +325,10 @@ const taskDetailView = (0, toolkit_1.createSlice)({
329
325
  error,
330
326
  };
331
327
  },
332
- createSubTask: {
333
- reducer(draft) {
334
- draft.subTaskCreateStatus = {
335
- fetchState: 'In-Progress',
336
- error: undefined,
337
- };
338
- },
339
- prepare(payload) {
340
- return { payload };
341
- },
342
- },
343
- createSubTaskSuccessOrFailure(draft, action) {
344
- const { fetchState, error } = action.payload;
345
- draft.subTaskCreateStatus = {
346
- fetchState,
347
- error,
348
- };
349
- },
350
328
  clearTaskDetail(draft) {
351
329
  Object.assign(draft, exports.initialState);
352
330
  },
353
331
  },
354
332
  });
355
- _a = taskDetailView.actions, exports.fetchTaskDetailPage = _a.fetchTaskDetailPage, exports.fetchTaskDetail = _a.fetchTaskDetail, exports.initializeTaskToLocalStore = _a.initializeTaskToLocalStore, exports.updateEditTaskFetchStatus = _a.updateEditTaskFetchStatus, exports.saveTaskUpdatesToLocalStore = _a.saveTaskUpdatesToLocalStore, exports.discardTaskUpdatesInLocalStore = _a.discardTaskUpdatesInLocalStore, exports.saveTaskDetail = _a.saveTaskDetail, exports.archiveTask = _a.archiveTask, exports.archiveTaskSuccessOrFailure = _a.archiveTaskSuccessOrFailure, exports.saveTaskSuccessOrFailure = _a.saveTaskSuccessOrFailure, exports.createSubTask = _a.createSubTask, exports.createSubTaskSuccessOrFailure = _a.createSubTaskSuccessOrFailure, exports.deleteTask = _a.deleteTask, exports.removeTaskDetail = _a.removeTaskDetail, exports.deleteTaskSuccessOrFailure = _a.deleteTaskSuccessOrFailure, exports.snoozeTask = _a.snoozeTask, exports.snoozeTaskSuccessOrFailure = _a.snoozeTaskSuccessOrFailure, exports.unsnoozeTask = _a.unsnoozeTask, exports.fetchTaskHistory = _a.fetchTaskHistory, exports.updateTaskHistory = _a.updateTaskHistory, exports.updateTaskHistoryFetchStatus = _a.updateTaskHistoryFetchStatus, exports.clearTaskDetail = _a.clearTaskDetail, exports.updateCreatedTagToLocalStore = _a.updateCreatedTagToLocalStore, exports.updateDeletedTagToLocalStore = _a.updateDeletedTagToLocalStore;
333
+ _a = taskDetailView.actions, exports.fetchTaskDetailPage = _a.fetchTaskDetailPage, exports.fetchTaskDetail = _a.fetchTaskDetail, exports.initializeTaskToLocalStore = _a.initializeTaskToLocalStore, exports.updateEditTaskFetchStatus = _a.updateEditTaskFetchStatus, exports.saveTaskUpdatesToLocalStore = _a.saveTaskUpdatesToLocalStore, exports.discardTaskUpdatesInLocalStore = _a.discardTaskUpdatesInLocalStore, exports.saveTaskDetail = _a.saveTaskDetail, exports.archiveTask = _a.archiveTask, exports.archiveTaskSuccessOrFailure = _a.archiveTaskSuccessOrFailure, exports.saveTaskSuccessOrFailure = _a.saveTaskSuccessOrFailure, exports.deleteTask = _a.deleteTask, exports.removeTaskDetail = _a.removeTaskDetail, exports.deleteTaskSuccessOrFailure = _a.deleteTaskSuccessOrFailure, exports.snoozeTask = _a.snoozeTask, exports.snoozeTaskSuccessOrFailure = _a.snoozeTaskSuccessOrFailure, exports.unsnoozeTask = _a.unsnoozeTask, exports.fetchTaskHistory = _a.fetchTaskHistory, exports.updateTaskHistory = _a.updateTaskHistory, exports.updateTaskHistoryFetchStatus = _a.updateTaskHistoryFetchStatus, exports.clearTaskDetail = _a.clearTaskDetail, exports.updateCreatedTagToLocalStore = _a.updateCreatedTagToLocalStore, exports.updateDeletedTagToLocalStore = _a.updateDeletedTagToLocalStore;
356
334
  exports.default = taskDetailView.reducer;
@@ -144,16 +144,13 @@ exports.allTaskPriority = [
144
144
  },
145
145
  ];
146
146
  const showFormFooter = (taskDetailLocalData, taskDetailInStore) => {
147
- if (taskDetailInStore == null) {
148
- return false;
149
- }
150
- if (taskDetailLocalData.name !== taskDetailInStore.name ||
147
+ if (taskDetailLocalData.name !== taskDetailInStore?.name ||
151
148
  taskDetailLocalData.description !== taskDetailInStore.description ||
152
149
  taskDetailLocalData.priority !== taskDetailInStore.priority.code ||
153
150
  taskDetailLocalData.status !== taskDetailInStore.status.code ||
154
151
  !(0, isEqual_1.default)(taskDetailInStore.tagIds, taskDetailLocalData.tagIds) ||
155
- !(0, isEqual_1.default)(taskDetailLocalData.assignee, taskDetailInStore.assignees ?? []) ||
156
- !(0, isEqual_1.default)(taskDetailLocalData.groupAssignees, taskDetailInStore.groupAssignees ?? []) ||
152
+ !(0, isEqual_1.default)(taskDetailLocalData.assignee, taskDetailInStore?.assignees ?? []) ||
153
+ !(0, isEqual_1.default)(taskDetailLocalData.groupAssignees, taskDetailInStore?.groupAssignees ?? []) ||
157
154
  !(0, isEqual_1.default)(taskDetailLocalData.fileIds, taskDetailInStore.fileIds ?? []) ||
158
155
  !(0, isEqual_1.default)(taskDetailLocalData.dueDate, taskDetailInStore.dueDate) ||
159
156
  !(0, isEqual_1.default)(taskDetailLocalData.type, taskDetailInStore.type) ||
@@ -0,0 +1,73 @@
1
+ import { Amount } from '../../commonStateTypes/amount';
2
+ import { SortOrder } from '../../commonStateTypes/selectorTypes/sortOrderTypes';
3
+ import { JournalEntryTransactionLine, Line, TransactionLineBase } from '../../entity/transaction/stateTypes/transactionLine';
4
+ /**
5
+ * View-model helpers for the new Journal Entry table view (see
6
+ * web-components `journalEntryTable`). Keeps presentation-agnostic
7
+ * logic — totals, sort, line-filter — colocated in epic-state so it
8
+ * is testable and reusable.
9
+ */
10
+ export declare const JOURNAL_ENTRY_SORT_KEYS: readonly ["description", "name", "category", "class", "debit", "credit"];
11
+ export declare const toJournalEntrySortKey: (v: string) => "name" | "description" | "category" | "class" | "credit" | "debit";
12
+ export type JournalEntrySortKey = ReturnType<typeof toJournalEntrySortKey>;
13
+ export interface JournalEntryRowSortConfig {
14
+ sortKey: JournalEntrySortKey;
15
+ sortOrder: SortOrder;
16
+ }
17
+ export declare const journalEntryDefaultSortConfig: JournalEntryRowSortConfig;
18
+ type AmountBearer = Pick<TransactionLineBase, 'amount'>;
19
+ /**
20
+ * Sums the `amount.amount` field of every line and returns an `Amount`
21
+ * whose currencyCode/currencySymbol are taken from the first line.
22
+ * Returns `undefined` for an empty list.
23
+ *
24
+ * Mirrors legacy `calculateTotal` in
25
+ * `web-components/src/components/transactionDetail/items/TransactionLinesJournalEntry.tsx`
26
+ * but without the `Object.assign` ceremony and with stable currency carry-over.
27
+ */
28
+ export declare const sumJournalEntryAmounts: (lines: ReadonlyArray<AmountBearer>) => Amount | undefined;
29
+ /**
30
+ * Splits `lines` by `postingType` into debit/credit totals.
31
+ *
32
+ * Fixes the operator-precedence bug from legacy
33
+ * `calculateCombinedTotalAmount` where
34
+ * `totalAmount?.amount ?? 0 + (...) + (...)` parses as
35
+ * `totalAmount?.amount ?? (0 + ... + ...)` so the `(...)`'s only get
36
+ * added when `totalAmount` is nullish. The new implementation just sums
37
+ * every debit (or credit) line including the un/miscategorized ones in
38
+ * one pass, so the result is always the true sum.
39
+ */
40
+ export declare const journalEntryTotalsByPostingSide: (lines: ReadonlyArray<Pick<JournalEntryTransactionLine, "amount" | "postingType">>) => {
41
+ creditTotal?: Amount;
42
+ debitTotal?: Amount;
43
+ };
44
+ /**
45
+ * Drops `linked_transaction_line` entries — equivalent to legacy
46
+ * `filterOutLinkedTransactionLine` in `transactionDetail.helpers.ts`.
47
+ */
48
+ export declare const filterJournalEntryLinesExcludingLinked: <T extends Pick<Line, "type">>(lines?: ReadonlyArray<T>) => T[];
49
+ /**
50
+ * Accessor functions resolve the sort value for each column from a
51
+ * line. The new table reads display-formatted values from the form
52
+ * (selected option label, entity name, etc.), so callers pass in
53
+ * accessors that match their `LineInfo` shape rather than baking the
54
+ * column-to-form-field mapping into epic-state.
55
+ */
56
+ export interface JournalEntrySortAccessors<T> {
57
+ category: (line: T) => string;
58
+ class: (line: T) => string;
59
+ credit: (line: T) => number;
60
+ debit: (line: T) => number;
61
+ description: (line: T) => string;
62
+ name: (line: T) => string;
63
+ }
64
+ /**
65
+ * Stable, accessor-driven sort over arbitrary line shapes. Lines that
66
+ * resolve to the same key value preserve their original relative order
67
+ * thanks to lodash's stable `orderBy`.
68
+ *
69
+ * Strings are lower-cased before comparison so the order is predictable
70
+ * across mixed-case data. Numbers (debit/credit) compare directly.
71
+ */
72
+ export declare const sortJournalEntryLines: <T>(lines: ReadonlyArray<T>, config: JournalEntryRowSortConfig, accessors: JournalEntrySortAccessors<T>) => T[];
73
+ export {};
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.sortJournalEntryLines = exports.filterJournalEntryLinesExcludingLinked = exports.journalEntryTotalsByPostingSide = exports.sumJournalEntryAmounts = exports.journalEntryDefaultSortConfig = exports.toJournalEntrySortKey = exports.JOURNAL_ENTRY_SORT_KEYS = void 0;
7
+ const orderBy_1 = __importDefault(require("lodash/orderBy"));
8
+ const stringToUnion_1 = require("../../commonStateTypes/stringToUnion");
9
+ /**
10
+ * View-model helpers for the new Journal Entry table view (see
11
+ * web-components `journalEntryTable`). Keeps presentation-agnostic
12
+ * logic — totals, sort, line-filter — colocated in epic-state so it
13
+ * is testable and reusable.
14
+ */
15
+ // ---------------------------------------------------------------------------
16
+ // Sort keys
17
+ // ---------------------------------------------------------------------------
18
+ exports.JOURNAL_ENTRY_SORT_KEYS = [
19
+ 'description',
20
+ 'name',
21
+ 'category',
22
+ 'class',
23
+ 'debit',
24
+ 'credit',
25
+ ];
26
+ const toJournalEntrySortKey = (v) => (0, stringToUnion_1.stringToUnion)(v, exports.JOURNAL_ENTRY_SORT_KEYS);
27
+ exports.toJournalEntrySortKey = toJournalEntrySortKey;
28
+ exports.journalEntryDefaultSortConfig = {
29
+ sortKey: 'description',
30
+ sortOrder: 'ascending',
31
+ };
32
+ /**
33
+ * Sums the `amount.amount` field of every line and returns an `Amount`
34
+ * whose currencyCode/currencySymbol are taken from the first line.
35
+ * Returns `undefined` for an empty list.
36
+ *
37
+ * Mirrors legacy `calculateTotal` in
38
+ * `web-components/src/components/transactionDetail/items/TransactionLinesJournalEntry.tsx`
39
+ * but without the `Object.assign` ceremony and with stable currency carry-over.
40
+ */
41
+ const sumJournalEntryAmounts = (lines) => {
42
+ if (lines.length === 0) {
43
+ return undefined;
44
+ }
45
+ const first = lines[0].amount;
46
+ let total = 0;
47
+ for (const line of lines) {
48
+ total += line.amount?.amount ?? 0;
49
+ }
50
+ return {
51
+ amount: total,
52
+ currencyCode: first?.currencyCode ?? '',
53
+ currencySymbol: first?.currencySymbol ?? '',
54
+ };
55
+ };
56
+ exports.sumJournalEntryAmounts = sumJournalEntryAmounts;
57
+ /**
58
+ * Splits `lines` by `postingType` into debit/credit totals.
59
+ *
60
+ * Fixes the operator-precedence bug from legacy
61
+ * `calculateCombinedTotalAmount` where
62
+ * `totalAmount?.amount ?? 0 + (...) + (...)` parses as
63
+ * `totalAmount?.amount ?? (0 + ... + ...)` so the `(...)`'s only get
64
+ * added when `totalAmount` is nullish. The new implementation just sums
65
+ * every debit (or credit) line including the un/miscategorized ones in
66
+ * one pass, so the result is always the true sum.
67
+ */
68
+ const journalEntryTotalsByPostingSide = (lines) => {
69
+ const debitLines = [];
70
+ const creditLines = [];
71
+ for (const line of lines) {
72
+ if (line.postingType === 'debit') {
73
+ debitLines.push(line);
74
+ }
75
+ else if (line.postingType === 'credit') {
76
+ creditLines.push(line);
77
+ }
78
+ }
79
+ return {
80
+ debitTotal: (0, exports.sumJournalEntryAmounts)(debitLines),
81
+ creditTotal: (0, exports.sumJournalEntryAmounts)(creditLines),
82
+ };
83
+ };
84
+ exports.journalEntryTotalsByPostingSide = journalEntryTotalsByPostingSide;
85
+ // ---------------------------------------------------------------------------
86
+ // Filter
87
+ // ---------------------------------------------------------------------------
88
+ /**
89
+ * Drops `linked_transaction_line` entries — equivalent to legacy
90
+ * `filterOutLinkedTransactionLine` in `transactionDetail.helpers.ts`.
91
+ */
92
+ const filterJournalEntryLinesExcludingLinked = (lines) => lines?.filter((line) => line.type !== 'linked_transaction_line') ?? [];
93
+ exports.filterJournalEntryLinesExcludingLinked = filterJournalEntryLinesExcludingLinked;
94
+ const sortOrderToLodash = (sortOrder) => sortOrder === 'descending' ? 'desc' : 'asc';
95
+ /**
96
+ * Stable, accessor-driven sort over arbitrary line shapes. Lines that
97
+ * resolve to the same key value preserve their original relative order
98
+ * thanks to lodash's stable `orderBy`.
99
+ *
100
+ * Strings are lower-cased before comparison so the order is predictable
101
+ * across mixed-case data. Numbers (debit/credit) compare directly.
102
+ */
103
+ const sortJournalEntryLines = (lines, config, accessors) => {
104
+ const accessor = (line) => {
105
+ switch (config.sortKey) {
106
+ case 'description':
107
+ return accessors.description(line).toLowerCase();
108
+ case 'name':
109
+ return accessors.name(line).toLowerCase();
110
+ case 'category':
111
+ return accessors.category(line).toLowerCase();
112
+ case 'class':
113
+ return accessors.class(line).toLowerCase();
114
+ case 'debit':
115
+ return accessors.debit(line);
116
+ case 'credit':
117
+ return accessors.credit(line);
118
+ default:
119
+ return accessors.description(line).toLowerCase();
120
+ }
121
+ };
122
+ return (0, orderBy_1.default)([...lines], [accessor], [sortOrderToLodash(config.sortOrder)]);
123
+ };
124
+ exports.sortJournalEntryLines = sortJournalEntryLines;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.0.84-betaJK7",
3
+ "version": "5.0.84-betaVR1",
4
4
  "description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/esm/index.js",
@@ -1,80 +0,0 @@
1
- import { from, of } from 'rxjs';
2
- import { catchError, filter, mergeMap } from 'rxjs/operators';
3
- import { convertHHMMStrToMinutes } from '../../../../commonStateTypes/fiscalYearHelpers/formatMinutesToFromHHMM';
4
- import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
5
- import { appendSubTaskId, updateTasks, } from '../../../../entity/task/taskReducer';
6
- import { getTaskById } from '../../../../entity/task/taskSelector';
7
- import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
8
- import { updateTaskListOnNewTaskCreationSuccess } from '../../taskListView/taskListReducer';
9
- import { createSubTask, createSubTaskSuccessOrFailure, } from '../taskDetailReducer';
10
- export const createSubTaskEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(createSubTask.match), mergeMap((action) => {
11
- const state = state$.value;
12
- const parentTask = getTaskById(state.taskState, action.payload.parentTaskId);
13
- const parentTaskGroupId = parentTask?.taskGroupIds[0];
14
- const isTaskListFetched = state.taskListState.fetchState === 'Completed';
15
- const payload = prepareSubTaskPayload(action.payload, parentTaskGroupId);
16
- return zeniAPI
17
- .postAndGetJSON(`${zeniAPI.apiEndPoints.taskMicroServiceBaseUrl}/1.0/task-manager/tasks`, payload)
18
- .pipe(mergeMap((response) => {
19
- if (isSuccessResponse(response) &&
20
- response.data != null &&
21
- response.data.tasks.length > 0) {
22
- const newTaskId = response.data.tasks[0].task_id;
23
- const actions = [
24
- updateTasks(response.data.tasks),
25
- appendSubTaskId({
26
- parentTaskId: action.payload.parentTaskId,
27
- subTaskId: newTaskId,
28
- }),
29
- createSubTaskSuccessOrFailure({
30
- fetchState: 'Completed',
31
- newTaskId,
32
- }),
33
- openSnackbar({
34
- messageSection: 'create_sub_task',
35
- messageText: 'success',
36
- type: 'success',
37
- }),
38
- ];
39
- if (isTaskListFetched === true && parentTaskGroupId != null) {
40
- actions.push(updateTaskListOnNewTaskCreationSuccess({
41
- taskGroupId: parentTaskGroupId,
42
- task: response.data.tasks[0],
43
- }));
44
- }
45
- return from(actions);
46
- }
47
- else {
48
- return of(createSubTaskSuccessOrFailure({
49
- fetchState: 'Error',
50
- error: response.status,
51
- }), openSnackbar({
52
- messageSection: 'create_sub_task',
53
- messageText: 'failed',
54
- type: 'error',
55
- variables: [
56
- {
57
- variableName: '_api-error_',
58
- variableValue: response.status.message,
59
- },
60
- ],
61
- }));
62
- }
63
- }), catchError((error) => of(createSubTaskSuccessOrFailure({
64
- fetchState: 'Error',
65
- error: createZeniAPIStatus('Unexpected Error', 'Create Sub Task REST API call errored out' +
66
- JSON.stringify(error)),
67
- }))));
68
- }));
69
- const prepareSubTaskPayload = (subTask, parentTaskGroupId) => ({
70
- name: subTask.name,
71
- assignees: subTask.assignee,
72
- description: subTask.description,
73
- priority: subTask.priority,
74
- status: subTask.status,
75
- tags: subTask.tagIds,
76
- time_spent: convertHHMMStrToMinutes(subTask.timeSpent),
77
- group_assignees: subTask.groupAssignees,
78
- parent_task_id: subTask.parentTaskId,
79
- task_group_ids: parentTaskGroupId == null ? [] : [parentTaskGroupId],
80
- });
@@ -1,9 +0,0 @@
1
- import { ActionsObservable, StateObservable } from 'redux-observable';
2
- import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
3
- import { appendSubTaskId, updateTasks } from '../../../../entity/task/taskReducer';
4
- import { RootState } from '../../../../reducer';
5
- import { ZeniAPI } from '../../../../zeniAPI';
6
- import { updateTaskListOnNewTaskCreationSuccess } from '../../taskListView/taskListReducer';
7
- import { createSubTask, createSubTaskSuccessOrFailure } from '../taskDetailReducer';
8
- export type ActionType = ReturnType<typeof createSubTask> | ReturnType<typeof updateTasks> | ReturnType<typeof appendSubTaskId> | ReturnType<typeof openSnackbar> | ReturnType<typeof updateTaskListOnNewTaskCreationSuccess> | ReturnType<typeof createSubTaskSuccessOrFailure>;
9
- export declare const createSubTaskEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => import("rxjs").Observable<ActionType>;
@@ -1,84 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSubTaskEpic = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const operators_1 = require("rxjs/operators");
6
- const formatMinutesToFromHHMM_1 = require("../../../../commonStateTypes/fiscalYearHelpers/formatMinutesToFromHHMM");
7
- const snackbarReducer_1 = require("../../../../entity/snackbar/snackbarReducer");
8
- const taskReducer_1 = require("../../../../entity/task/taskReducer");
9
- const taskSelector_1 = require("../../../../entity/task/taskSelector");
10
- const responsePayload_1 = require("../../../../responsePayload");
11
- const taskListReducer_1 = require("../../taskListView/taskListReducer");
12
- const taskDetailReducer_1 = require("../taskDetailReducer");
13
- const createSubTaskEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(taskDetailReducer_1.createSubTask.match), (0, operators_1.mergeMap)((action) => {
14
- const state = state$.value;
15
- const parentTask = (0, taskSelector_1.getTaskById)(state.taskState, action.payload.parentTaskId);
16
- const parentTaskGroupId = parentTask?.taskGroupIds[0];
17
- const isTaskListFetched = state.taskListState.fetchState === 'Completed';
18
- const payload = prepareSubTaskPayload(action.payload, parentTaskGroupId);
19
- return zeniAPI
20
- .postAndGetJSON(`${zeniAPI.apiEndPoints.taskMicroServiceBaseUrl}/1.0/task-manager/tasks`, payload)
21
- .pipe((0, operators_1.mergeMap)((response) => {
22
- if ((0, responsePayload_1.isSuccessResponse)(response) &&
23
- response.data != null &&
24
- response.data.tasks.length > 0) {
25
- const newTaskId = response.data.tasks[0].task_id;
26
- const actions = [
27
- (0, taskReducer_1.updateTasks)(response.data.tasks),
28
- (0, taskReducer_1.appendSubTaskId)({
29
- parentTaskId: action.payload.parentTaskId,
30
- subTaskId: newTaskId,
31
- }),
32
- (0, taskDetailReducer_1.createSubTaskSuccessOrFailure)({
33
- fetchState: 'Completed',
34
- newTaskId,
35
- }),
36
- (0, snackbarReducer_1.openSnackbar)({
37
- messageSection: 'create_sub_task',
38
- messageText: 'success',
39
- type: 'success',
40
- }),
41
- ];
42
- if (isTaskListFetched === true && parentTaskGroupId != null) {
43
- actions.push((0, taskListReducer_1.updateTaskListOnNewTaskCreationSuccess)({
44
- taskGroupId: parentTaskGroupId,
45
- task: response.data.tasks[0],
46
- }));
47
- }
48
- return (0, rxjs_1.from)(actions);
49
- }
50
- else {
51
- return (0, rxjs_1.of)((0, taskDetailReducer_1.createSubTaskSuccessOrFailure)({
52
- fetchState: 'Error',
53
- error: response.status,
54
- }), (0, snackbarReducer_1.openSnackbar)({
55
- messageSection: 'create_sub_task',
56
- messageText: 'failed',
57
- type: 'error',
58
- variables: [
59
- {
60
- variableName: '_api-error_',
61
- variableValue: response.status.message,
62
- },
63
- ],
64
- }));
65
- }
66
- }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, taskDetailReducer_1.createSubTaskSuccessOrFailure)({
67
- fetchState: 'Error',
68
- error: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Create Sub Task REST API call errored out' +
69
- JSON.stringify(error)),
70
- }))));
71
- }));
72
- exports.createSubTaskEpic = createSubTaskEpic;
73
- const prepareSubTaskPayload = (subTask, parentTaskGroupId) => ({
74
- name: subTask.name,
75
- assignees: subTask.assignee,
76
- description: subTask.description,
77
- priority: subTask.priority,
78
- status: subTask.status,
79
- tags: subTask.tagIds,
80
- time_spent: (0, formatMinutesToFromHHMM_1.convertHHMMStrToMinutes)(subTask.timeSpent),
81
- group_assignees: subTask.groupAssignees,
82
- parent_task_id: subTask.parentTaskId,
83
- task_group_ids: parentTaskGroupId == null ? [] : [parentTaskGroupId],
84
- });