@memberjunction/ng-record-merge 6.2.0 → 6.3.0-edge.0

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 (2) hide show
  1. package/README.md +196 -0
  2. package/package.json +7 -7
package/README.md ADDED
@@ -0,0 +1,196 @@
1
+ # @memberjunction/ng-record-merge
2
+
3
+ A reusable Angular widget for **comparing two records side by side and choosing, field by field,
4
+ which values survive a merge** — plus a thin service that fetches the field comparison from the
5
+ server.
6
+
7
+ It is the merge UI used by the entity grid's **Merge** button in `@memberjunction/ng-entity-viewer`.
8
+ How merging works end to end — `Metadata.MergeRecords`, dependency re-pointing, logging, auto-merge
9
+ and duplicate detection — is covered in the
10
+ [Duplicate Management Guide](../../../../guides/DUPLICATE_MANAGEMENT_GUIDE.md).
11
+
12
+ > **The panel does not merge anything.** It collects the user's choices and emits them. The host
13
+ > builds the `RecordMergeRequest` and calls `MergeRecords` on its provider.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @memberjunction/ng-record-merge
19
+ ```
20
+
21
+ ```typescript
22
+ import { RecordMergeModule } from '@memberjunction/ng-record-merge';
23
+
24
+ @NgModule({
25
+ imports: [RecordMergeModule],
26
+ })
27
+ export class MyFeatureModule {}
28
+ ```
29
+
30
+ `RecordMergePanelComponent` is NgModule-declared (`standalone: false`); import `RecordMergeModule`.
31
+ `RecordComparisonService` is `providedIn: 'root'`.
32
+
33
+ ## What's in the package
34
+
35
+ | Export | Kind | Purpose |
36
+ |---|---|---|
37
+ | `RecordMergeModule` | NgModule | Declares and exports the panel |
38
+ | `RecordMergePanelComponent` (`mj-record-merge-panel`) | Component | Two-column comparison with per-field selection and a confirm step |
39
+ | `RecordComparisonService` | Service | Calls the `RecordComparison.Compare` Remote Operation for the field-level comparison |
40
+ | `FieldComparison`, `MergeConfig`, `MergeComparisonResult`, `MergeConfirmedEvent`, `FieldSelectionEvent`, `MergeActionResult` | Types | The panel's data contracts |
41
+
42
+ ## `mj-record-merge-panel`
43
+
44
+ ### Inputs
45
+
46
+ | Input | Type | Default | Description |
47
+ |---|---|---|---|
48
+ | `Fields` | `FieldComparison[]` | `[]` | One row per field: left and right values, whether they conflict, which side is selected, read-only flag, data type |
49
+ | `Config` | `MergeConfig \| null` | `null` | Entity name, the two record IDs, the column labels, and which side survives. The panel renders an empty state until this is set. |
50
+ | `ShowConflictsOnly` | `boolean` | `false` | Start with only the conflicting fields visible (the user can toggle) |
51
+ | `MergeEnabled` | `boolean` | `true` | Show the **Merge Records** / **Cancel** footer. Set it to `false` for a comparison-only view. |
52
+ | `IsMerging` | `boolean` | `false` | Shows *Merging…* and disables the footer buttons while the host's merge call is running |
53
+
54
+ `Fields` and `Config` are read when the panel initializes (the conflict counts are computed in
55
+ `ngOnInit`). To show a different pair, re-create the panel — for example inside an `@if` keyed on the
56
+ pair — rather than mutating the inputs in place.
57
+
58
+ ### Outputs
59
+
60
+ | Output | Payload | When |
61
+ |---|---|---|
62
+ | `MergeConfirmed` | `MergeConfirmedEvent` (`Config`, `ResolvedFields`) | The user confirmed the merge in the panel's confirmation dialog |
63
+ | `MergeCancelled` | `void` | The user clicked **Cancel** |
64
+ | `FieldSelected` | `FieldSelectionEvent` (`FieldName`, `SelectedSide`, `Value`) | The user picked a side for one field |
65
+
66
+ ### Behaviour
67
+
68
+ - Header: *Record Comparison*, the entity name, and *N conflicts / M fields*; a toggle between
69
+ **Show Conflicts Only** and **Show All Fields**.
70
+ - Click a value to keep it; the column headers have *select all from this side* buttons. Read-only
71
+ fields (`IsReadOnly`) show a lock and cannot be changed.
72
+ - Values render as text; `null`/`undefined` show as *(empty)*, booleans as *Yes*/*No*, dates in the
73
+ user's locale.
74
+ - **Merge Records** opens a confirmation (*"This will merge the selected field values and create a
75
+ merge log. This action cannot be undone."*) with **Confirm Merge** and **Cancel**. Only confirming
76
+ emits `MergeConfirmed`.
77
+ - The panel compares **two** records. For three or more, use the Duplicates dashboard or call
78
+ `MergeRecords` directly.
79
+
80
+ ## Wiring it up
81
+
82
+ ```typescript
83
+ import { CompositeKey, RecordMergeRequest } from '@memberjunction/core';
84
+ import { FieldComparison, MergeConfig, MergeConfirmedEvent, RecordComparisonService } from '@memberjunction/ng-record-merge';
85
+
86
+ export class MyMergeHost extends BaseAngularComponent {
87
+ private comparison = inject(RecordComparisonService);
88
+ public Fields: FieldComparison[] = [];
89
+ public Config: MergeConfig | null = null;
90
+ public IsMerging = false;
91
+
92
+ public async Load(entityName: string, left: CompositeKey, right: CompositeKey): Promise<void> {
93
+ // Key values travel as strings.
94
+ const toKey = (k: CompositeKey) => ({
95
+ KeyValuePairs: k.KeyValuePairs.map(kv => ({ FieldName: kv.FieldName, Value: String(kv.Value) })),
96
+ });
97
+ const result = await this.comparison.GetRecordComparison(
98
+ { EntityName: entityName, Keys: [toKey(left), toKey(right)] },
99
+ this.ProviderToUse
100
+ );
101
+ if (!result.Success || !result.Output) {
102
+ // show result.ErrorMessage
103
+ return;
104
+ }
105
+ this.Fields = result.Output.Fields.map(f => ({
106
+ FieldName: f.FieldName,
107
+ DisplayLabel: f.DisplayName,
108
+ LeftValue: f.Cells[0]?.Value ?? null,
109
+ RightValue: f.Cells[1]?.Value ?? null,
110
+ HasConflict: f.Differs,
111
+ SelectedSide: 'left',
112
+ IsReadOnly: false, // look the field up on the EntityInfo and use its ReadOnly flag
113
+ DataType: '',
114
+ }));
115
+ this.Config = {
116
+ EntityName: entityName,
117
+ LeftRecordID: left.ToURLSegment(),
118
+ RightRecordID: right.ToURLSegment(),
119
+ SurvivorSide: 'left',
120
+ LeftLabel: result.Output.Records[0]?.Label ?? 'Left',
121
+ RightLabel: result.Output.Records[1]?.Label ?? 'Right',
122
+ };
123
+ }
124
+
125
+ public async OnMergeConfirmed(e: MergeConfirmedEvent, survivor: CompositeKey, loser: CompositeKey): Promise<void> {
126
+ const takeFrom: 'left' | 'right' = e.Config.SurvivorSide === 'left' ? 'right' : 'left';
127
+ const request: RecordMergeRequest = {
128
+ EntityName: e.Config.EntityName,
129
+ SurvivingRecordCompositeKey: survivor,
130
+ RecordsToMerge: [loser],
131
+ // Only the fields where the user kept the OTHER record's value need to be sent.
132
+ FieldMap: e.ResolvedFields
133
+ .filter(f => f.HasConflict && !f.IsReadOnly && f.SelectedSide === takeFrom)
134
+ .map(f => ({ FieldName: f.FieldName, Value: takeFrom === 'left' ? f.LeftValue : f.RightValue })),
135
+ };
136
+ this.IsMerging = true;
137
+ try {
138
+ const result = await this.ProviderToUse.MergeRecords(request);
139
+ // check result.Success / result.OverallStatus and notify the user
140
+ } finally {
141
+ this.IsMerging = false;
142
+ }
143
+ }
144
+ }
145
+ ```
146
+
147
+ ```html
148
+ @if (Config) {
149
+ <mj-record-merge-panel
150
+ [Fields]="Fields"
151
+ [Config]="Config"
152
+ [ShowConflictsOnly]="true"
153
+ [IsMerging]="IsMerging"
154
+ (MergeConfirmed)="OnMergeConfirmed($event, survivorKey, loserKey)"
155
+ (MergeCancelled)="Config = null">
156
+ </mj-record-merge-panel>
157
+ }
158
+ ```
159
+
160
+ The working reference is `GridViewRendererComponent` in `@memberjunction/ng-entity-viewer`
161
+ (`src/lib/view-types/renderers/grid-view-renderer.component.ts`): it gates the Merge button on
162
+ `AllowRecordMerge` and the user's update and delete permissions, refuses IS-A subtype records, shows
163
+ each side's dependent-record count, lets the user pick which record to keep, and sends a `FieldMap`
164
+ of the conflicting writable fields taken from the record being merged away.
165
+
166
+ ## `RecordComparisonService`
167
+
168
+ ```typescript
169
+ GetRecordComparison(
170
+ input: RecordComparisonCompareInput, // EntityName, Keys (column 0 = reference), optional IncludeFields
171
+ provider?: IMetadataProvider | null // pass the component's ProviderToUse
172
+ ): Promise<RemoteOpResult<RecordComparisonCompareOutput>>
173
+ ```
174
+
175
+ A thin wrapper over the `RecordComparison.Compare` Remote Operation, implemented on the server by
176
+ [`@memberjunction/record-comparison`](../../../RecordComparison/README.md). It never throws for
177
+ logical failures: check `Success` and read `Output` (`Records`, `Fields`). The comparison runs as the
178
+ calling user, skips primary keys and `__mj_*` columns, and drops fields that are empty in every
179
+ record.
180
+
181
+ ## Dependencies
182
+
183
+ - `@memberjunction/core`, `@memberjunction/core-entities`, `@memberjunction/global`
184
+ - `@memberjunction/ng-ui-components` (empty state), `@memberjunction/ng-shared-generic`
185
+ - `@angular/core`, `@angular/common` (peers)
186
+
187
+ ## Development
188
+
189
+ ```bash
190
+ pnpm run build
191
+ pnpm run test
192
+ ```
193
+
194
+ ## License
195
+
196
+ Business Source License 1.1 — see [LICENSE](../../../../LICENSE) for details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/ng-record-merge",
3
- "version": "6.2.0",
3
+ "version": "6.3.0-edge.0",
4
4
  "description": "MemberJunction: Reusable record merge/comparison panel for side-by-side entity record comparison and field-by-field merge selection",
5
5
  "main": "./dist/public-api.js",
6
6
  "typings": "./dist/public-api.d.ts",
@@ -13,7 +13,7 @@
13
13
  "devDependencies": {
14
14
  "@angular/compiler": "21.2.22",
15
15
  "@angular/compiler-cli": "21.2.22",
16
- "@memberjunction/ng-test-utils": "6.2.0",
16
+ "@memberjunction/ng-test-utils": "6.3.0-edge.0",
17
17
  "vitest": "^4.0.18"
18
18
  },
19
19
  "peerDependencies": {
@@ -21,11 +21,11 @@
21
21
  "@angular/core": "^21.2.22"
22
22
  },
23
23
  "dependencies": {
24
- "@memberjunction/ng-ui-components": "6.2.0",
25
- "@memberjunction/core": "6.2.0",
26
- "@memberjunction/core-entities": "6.2.0",
27
- "@memberjunction/global": "6.2.0",
28
- "@memberjunction/ng-shared-generic": "6.2.0",
24
+ "@memberjunction/ng-ui-components": "6.3.0-edge.0",
25
+ "@memberjunction/core": "6.3.0-edge.0",
26
+ "@memberjunction/core-entities": "6.3.0-edge.0",
27
+ "@memberjunction/global": "6.3.0-edge.0",
28
+ "@memberjunction/ng-shared-generic": "6.3.0-edge.0",
29
29
  "rxjs": "^7.8.2",
30
30
  "tslib": "^2.8.1"
31
31
  },