@zeniai/client-epic-state 5.0.83-betaRR2 → 5.0.83-betaRR3

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.
@@ -1,12 +1,23 @@
1
1
  import { deriveAiCardRowsFromTeams } from './deriveAiCardRowsFromTeams';
2
2
  // Single source of truth for "what the next form draft should look like
3
- // after a watchHandler flush". `create` mode + missing context keep the
4
- // payload as-is; `review` mode re-derives step-2 cardRows from the latest
5
- // teamRows, preserving in-place edits via prevCardRows.
6
- export const applyAiCardCreationFormDraftUpdate = ({ next, context, }) => {
3
+ // after a watchHandler flush".
4
+ //
5
+ // `create` mode + missing context: keep the payload as-is.
6
+ //
7
+ // `review` mode: re-derive step-2 `cardRows` from the latest `teamRows`
8
+ // ONLY when the step-1 selection changed (a team was toggled on/off).
9
+ // Step-2-only edits (dropdown swap, owner change, limit edit) must skip
10
+ // the re-derive because `deriveAiCardRowsFromTeams` matches previous rows
11
+ // by `cardRow.id`, which the dropdown swap has just mutated — running it
12
+ // on a step-2-only diff reverts the user's edit back to the source team's
13
+ // original id/label.
14
+ export const applyAiCardCreationFormDraftUpdate = ({ next, prev, context, }) => {
7
15
  if (context == null || context.mode === 'create') {
8
16
  return next;
9
17
  }
18
+ if (!haveCheckedTeamRowsChanged(prev?.teamRows, next.teamRows)) {
19
+ return next;
20
+ }
10
21
  return {
11
22
  teamRows: next.teamRows,
12
23
  cardRows: deriveAiCardRowsFromTeams({
@@ -18,3 +29,15 @@ export const applyAiCardCreationFormDraftUpdate = ({ next, context, }) => {
18
29
  }),
19
30
  };
20
31
  };
32
+ const haveCheckedTeamRowsChanged = (prevTeamRows, nextTeamRows) => {
33
+ const prevCheckedIds = (prevTeamRows ?? [])
34
+ .filter((row) => row.isChecked)
35
+ .map((row) => row.id);
36
+ const nextCheckedIds = nextTeamRows
37
+ .filter((row) => row.isChecked)
38
+ .map((row) => row.id);
39
+ if (prevCheckedIds.length !== nextCheckedIds.length) {
40
+ return true;
41
+ }
42
+ return prevCheckedIds.some((id, idx) => id !== nextCheckedIds[idx]);
43
+ };
@@ -160,6 +160,7 @@ const issueChargeCard = createSlice({
160
160
  */
161
161
  updateAiCardCreationFormDraft(draft, action) {
162
162
  draft.aiCardCreationFormDraft = applyAiCardCreationFormDraftUpdate({
163
+ prev: draft.aiCardCreationFormDraft,
163
164
  next: action.payload,
164
165
  context: draft.aiCardCreationFormDraftContext,
165
166
  });
@@ -2,5 +2,6 @@ import { AiCardCreationFormDraftSeedContext, CardsFormDraft } from './aiCardCrea
2
2
  export interface ApplyAiCardCreationFormDraftUpdateArgs {
3
3
  context: AiCardCreationFormDraftSeedContext | undefined;
4
4
  next: CardsFormDraft;
5
+ prev: CardsFormDraft | undefined;
5
6
  }
6
- export declare const applyAiCardCreationFormDraftUpdate: ({ next, context, }: ApplyAiCardCreationFormDraftUpdateArgs) => CardsFormDraft;
7
+ export declare const applyAiCardCreationFormDraftUpdate: ({ next, prev, context, }: ApplyAiCardCreationFormDraftUpdateArgs) => CardsFormDraft;
@@ -3,13 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applyAiCardCreationFormDraftUpdate = void 0;
4
4
  const deriveAiCardRowsFromTeams_1 = require("./deriveAiCardRowsFromTeams");
5
5
  // Single source of truth for "what the next form draft should look like
6
- // after a watchHandler flush". `create` mode + missing context keep the
7
- // payload as-is; `review` mode re-derives step-2 cardRows from the latest
8
- // teamRows, preserving in-place edits via prevCardRows.
9
- const applyAiCardCreationFormDraftUpdate = ({ next, context, }) => {
6
+ // after a watchHandler flush".
7
+ //
8
+ // `create` mode + missing context: keep the payload as-is.
9
+ //
10
+ // `review` mode: re-derive step-2 `cardRows` from the latest `teamRows`
11
+ // ONLY when the step-1 selection changed (a team was toggled on/off).
12
+ // Step-2-only edits (dropdown swap, owner change, limit edit) must skip
13
+ // the re-derive because `deriveAiCardRowsFromTeams` matches previous rows
14
+ // by `cardRow.id`, which the dropdown swap has just mutated — running it
15
+ // on a step-2-only diff reverts the user's edit back to the source team's
16
+ // original id/label.
17
+ const applyAiCardCreationFormDraftUpdate = ({ next, prev, context, }) => {
10
18
  if (context == null || context.mode === 'create') {
11
19
  return next;
12
20
  }
21
+ if (!haveCheckedTeamRowsChanged(prev?.teamRows, next.teamRows)) {
22
+ return next;
23
+ }
13
24
  return {
14
25
  teamRows: next.teamRows,
15
26
  cardRows: (0, deriveAiCardRowsFromTeams_1.deriveAiCardRowsFromTeams)({
@@ -22,3 +33,15 @@ const applyAiCardCreationFormDraftUpdate = ({ next, context, }) => {
22
33
  };
23
34
  };
24
35
  exports.applyAiCardCreationFormDraftUpdate = applyAiCardCreationFormDraftUpdate;
36
+ const haveCheckedTeamRowsChanged = (prevTeamRows, nextTeamRows) => {
37
+ const prevCheckedIds = (prevTeamRows ?? [])
38
+ .filter((row) => row.isChecked)
39
+ .map((row) => row.id);
40
+ const nextCheckedIds = nextTeamRows
41
+ .filter((row) => row.isChecked)
42
+ .map((row) => row.id);
43
+ if (prevCheckedIds.length !== nextCheckedIds.length) {
44
+ return true;
45
+ }
46
+ return prevCheckedIds.some((id, idx) => id !== nextCheckedIds[idx]);
47
+ };
@@ -164,6 +164,7 @@ const issueChargeCard = (0, toolkit_1.createSlice)({
164
164
  */
165
165
  updateAiCardCreationFormDraft(draft, action) {
166
166
  draft.aiCardCreationFormDraft = (0, applyAiCardCreationFormDraftUpdate_1.applyAiCardCreationFormDraftUpdate)({
167
+ prev: draft.aiCardCreationFormDraft,
167
168
  next: action.payload,
168
169
  context: draft.aiCardCreationFormDraftContext,
169
170
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.0.83-betaRR2",
3
+ "version": "5.0.83-betaRR3",
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",