@memberjunction/ng-entity-viewer 6.2.0-edge.5 → 6.2.0-edge.6
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.
- package/README.md +28 -0
- package/dist/lib/aggregate-setup-dialog/aggregate-setup-dialog.component.d.ts +48 -1
- package/dist/lib/aggregate-setup-dialog/aggregate-setup-dialog.component.d.ts.map +1 -1
- package/dist/lib/aggregate-setup-dialog/aggregate-setup-dialog.component.js +631 -279
- package/dist/lib/aggregate-setup-dialog/aggregate-setup-dialog.component.js.map +1 -1
- package/dist/lib/entity-cards/entity-cards.component.d.ts +2 -0
- package/dist/lib/entity-cards/entity-cards.component.d.ts.map +1 -1
- package/dist/lib/entity-cards/entity-cards.component.js +30 -2
- package/dist/lib/entity-cards/entity-cards.component.js.map +1 -1
- package/dist/lib/entity-data-grid/entity-data-grid.component.d.ts +64 -2
- package/dist/lib/entity-data-grid/entity-data-grid.component.d.ts.map +1 -1
- package/dist/lib/entity-data-grid/entity-data-grid.component.js +516 -187
- package/dist/lib/entity-data-grid/entity-data-grid.component.js.map +1 -1
- package/dist/lib/entity-record-detail-panel/entity-record-detail-panel.component.d.ts +2 -0
- package/dist/lib/entity-record-detail-panel/entity-record-detail-panel.component.d.ts.map +1 -1
- package/dist/lib/entity-record-detail-panel/entity-record-detail-panel.component.js +38 -4
- package/dist/lib/entity-record-detail-panel/entity-record-detail-panel.component.js.map +1 -1
- package/dist/lib/entity-viewer/entity-viewer.component.d.ts +39 -3
- package/dist/lib/entity-viewer/entity-viewer.component.d.ts.map +1 -1
- package/dist/lib/entity-viewer/entity-viewer.component.js +188 -49
- package/dist/lib/entity-viewer/entity-viewer.component.js.map +1 -1
- package/dist/lib/entity-viewer/view-property-chips.d.ts +17 -0
- package/dist/lib/entity-viewer/view-property-chips.d.ts.map +1 -0
- package/dist/lib/entity-viewer/view-property-chips.js +42 -0
- package/dist/lib/entity-viewer/view-property-chips.js.map +1 -0
- package/dist/lib/recycle-bin/recycle-bin-chip.component.d.ts.map +1 -1
- package/dist/lib/recycle-bin/recycle-bin-chip.component.js +5 -4
- package/dist/lib/recycle-bin/recycle-bin-chip.component.js.map +1 -1
- package/dist/lib/recycle-bin/recycle-bin.component.js +3 -3
- package/dist/lib/recycle-bin/recycle-bin.component.js.map +1 -1
- package/dist/lib/utils/record.util.d.ts +21 -1
- package/dist/lib/utils/record.util.d.ts.map +1 -1
- package/dist/lib/utils/record.util.js +108 -0
- package/dist/lib/utils/record.util.js.map +1 -1
- package/dist/lib/view-config-panel/view-config-panel.component.d.ts +378 -54
- package/dist/lib/view-config-panel/view-config-panel.component.d.ts.map +1 -1
- package/dist/lib/view-config-panel/view-config-panel.component.js +3837 -1010
- package/dist/lib/view-config-panel/view-config-panel.component.js.map +1 -1
- package/dist/lib/view-properties-editor/view-properties-editor.component.d.ts +52 -0
- package/dist/lib/view-properties-editor/view-properties-editor.component.d.ts.map +1 -0
- package/dist/lib/view-properties-editor/view-properties-editor.component.js +445 -0
- package/dist/lib/view-properties-editor/view-properties-editor.component.js.map +1 -0
- package/dist/lib/view-selector/view-selector.component.d.ts +22 -1
- package/dist/lib/view-selector/view-selector.component.d.ts.map +1 -1
- package/dist/lib/view-selector/view-selector.component.js +288 -149
- package/dist/lib/view-selector/view-selector.component.js.map +1 -1
- package/dist/lib/view-types/descriptors/calendar-view-type.d.ts +22 -0
- package/dist/lib/view-types/descriptors/calendar-view-type.d.ts.map +1 -0
- package/dist/lib/view-types/descriptors/calendar-view-type.js +38 -0
- package/dist/lib/view-types/descriptors/calendar-view-type.js.map +1 -0
- package/dist/lib/view-types/index.d.ts +3 -2
- package/dist/lib/view-types/index.d.ts.map +1 -1
- package/dist/lib/view-types/index.js +5 -2
- package/dist/lib/view-types/index.js.map +1 -1
- package/dist/lib/view-types/renderers/calendar-placement.d.ts +97 -0
- package/dist/lib/view-types/renderers/calendar-placement.d.ts.map +1 -0
- package/dist/lib/view-types/renderers/calendar-placement.js +145 -0
- package/dist/lib/view-types/renderers/calendar-placement.js.map +1 -0
- package/dist/lib/view-types/renderers/calendar-view-prop-sheet.component.d.ts +36 -0
- package/dist/lib/view-types/renderers/calendar-view-prop-sheet.component.d.ts.map +1 -0
- package/dist/lib/view-types/renderers/calendar-view-prop-sheet.component.js +167 -0
- package/dist/lib/view-types/renderers/calendar-view-prop-sheet.component.js.map +1 -0
- package/dist/lib/view-types/renderers/calendar-view-renderer.component.d.ts +107 -0
- package/dist/lib/view-types/renderers/calendar-view-renderer.component.d.ts.map +1 -0
- package/dist/lib/view-types/renderers/calendar-view-renderer.component.js +501 -0
- package/dist/lib/view-types/renderers/calendar-view-renderer.component.js.map +1 -0
- package/dist/lib/view-types/renderers/grid-view-renderer.component.d.ts +3 -1
- package/dist/lib/view-types/renderers/grid-view-renderer.component.d.ts.map +1 -1
- package/dist/lib/view-types/renderers/grid-view-renderer.component.js +12 -3
- package/dist/lib/view-types/renderers/grid-view-renderer.component.js.map +1 -1
- package/dist/lib/view-types/renderers/map-view-renderer.component.d.ts.map +1 -1
- package/dist/lib/view-types/renderers/map-view-renderer.component.js +3 -3
- package/dist/lib/view-types/renderers/map-view-renderer.component.js.map +1 -1
- package/dist/lib/view-workspace/view-workspace.component.d.ts +34 -1
- package/dist/lib/view-workspace/view-workspace.component.d.ts.map +1 -1
- package/dist/lib/view-workspace/view-workspace.component.js +177 -15
- package/dist/lib/view-workspace/view-workspace.component.js.map +1 -1
- package/dist/module.d.ts +35 -31
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js +21 -3
- package/dist/module.js.map +1 -1
- package/dist/public-api.d.ts +5 -0
- package/dist/public-api.d.ts.map +1 -1
- package/dist/public-api.js +5 -0
- package/dist/public-api.js.map +1 -1
- package/package.json +22 -21
|
@@ -135,10 +135,118 @@ export function ComputeFieldsList(entityInfo, gridState, hostColumnFields) {
|
|
|
135
135
|
if (entityInfo.SupportsGeoCoding && entityInfo.Fields.some(f => f.Name === 'BoundaryGeoJSON')) {
|
|
136
136
|
fields.add('BoundaryGeoJSON');
|
|
137
137
|
}
|
|
138
|
+
// For any polymorphic FK field (where EntityField.EntityIDFieldName is populated) included in
|
|
139
|
+
// the projection, always include its companion EntityIDFieldName column (and any mapped virtual
|
|
140
|
+
// name column) so the grid/cards/detail panel can resolve the target entity and record name
|
|
141
|
+
// even if the user hid the EntityID column in their view settings.
|
|
142
|
+
for (const f of entityInfo.Fields) {
|
|
143
|
+
if (!fields.has(f.Name))
|
|
144
|
+
continue;
|
|
145
|
+
const companionName = f.EntityIDFieldName?.trim();
|
|
146
|
+
if (companionName) {
|
|
147
|
+
const companionField = entityInfo.Fields.find(cf => cf.Name.toLowerCase() === companionName.toLowerCase());
|
|
148
|
+
if (companionField) {
|
|
149
|
+
fields.add(companionField.Name);
|
|
150
|
+
if (companionField.RelatedEntityNameFieldMap) {
|
|
151
|
+
fields.add(companionField.RelatedEntityNameFieldMap);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (f.RelatedEntityNameFieldMap) {
|
|
156
|
+
fields.add(f.RelatedEntityNameFieldMap);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
138
159
|
return Array.from(fields);
|
|
139
160
|
}
|
|
140
161
|
/** @deprecated Use {@link ComputeFieldsList}. */
|
|
141
162
|
export function computeFieldsList(entityInfo, gridState, hostColumnFields) {
|
|
142
163
|
return ComputeFieldsList(entityInfo, gridState, hostColumnFields);
|
|
143
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Resolves the target `EntityInfo` for a polymorphic FK field (`field.EntityIDFieldName`)
|
|
167
|
+
* on a plain record or `BaseEntity`-like map. Strictly relies on the hard metadata link
|
|
168
|
+
* `field.EntityIDFieldName` — never falls back to field-name heuristics.
|
|
169
|
+
*/
|
|
170
|
+
export function ResolvePolymorphicTargetEntity(record, field, provider) {
|
|
171
|
+
const companionName = field.EntityIDFieldName?.trim();
|
|
172
|
+
if (!companionName || !provider || !record)
|
|
173
|
+
return undefined;
|
|
174
|
+
const rawRef = record[companionName];
|
|
175
|
+
if (rawRef == null)
|
|
176
|
+
return undefined;
|
|
177
|
+
const refStr = String(rawRef).trim();
|
|
178
|
+
if (!refStr)
|
|
179
|
+
return undefined;
|
|
180
|
+
return provider.EntityByID(refStr) ?? provider.EntityByName(refStr);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Builds a `CompositeKey` for a polymorphic `RecordID` value against `targetEntity`,
|
|
184
|
+
* supporting both single-column bare values and `Field1|Val1||Field2|Val2` segments.
|
|
185
|
+
*/
|
|
186
|
+
export function BuildPolymorphicCompositeKey(rawRecordId, targetEntity) {
|
|
187
|
+
if (rawRecordId == null)
|
|
188
|
+
return null;
|
|
189
|
+
const str = String(rawRecordId).trim();
|
|
190
|
+
if (!str)
|
|
191
|
+
return null;
|
|
192
|
+
return CompositeKey.FromURLSegment(targetEntity, str);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Stable lookup key for a resolved polymorphic record name in a view's cache map.
|
|
196
|
+
*/
|
|
197
|
+
export function PolymorphicCacheKey(entityName, key) {
|
|
198
|
+
return `${entityName}::${key.ToConcatenatedString()}`;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Batch-resolves human-readable record names for all polymorphic FK fields (`EntityIDFieldName`)
|
|
202
|
+
* across a page of records using a single `provider.GetEntityRecordNames(...)` call.
|
|
203
|
+
*/
|
|
204
|
+
export async function BatchResolvePolymorphicRecordNames(records, entityInfo, provider, existingCache) {
|
|
205
|
+
const cache = existingCache ?? new Map();
|
|
206
|
+
if (!entityInfo?.Fields || !provider || !records || records.length === 0) {
|
|
207
|
+
return cache;
|
|
208
|
+
}
|
|
209
|
+
const polyFields = entityInfo.Fields.filter(f => typeof f.EntityIDFieldName === 'string' && f.EntityIDFieldName.trim().length > 0);
|
|
210
|
+
if (polyFields.length === 0) {
|
|
211
|
+
return cache;
|
|
212
|
+
}
|
|
213
|
+
const pendingByKey = new Map();
|
|
214
|
+
for (const row of records) {
|
|
215
|
+
for (const pf of polyFields) {
|
|
216
|
+
const rawId = row[pf.Name];
|
|
217
|
+
if (rawId == null || rawId === '')
|
|
218
|
+
continue;
|
|
219
|
+
const targetEntity = ResolvePolymorphicTargetEntity(row, pf, provider);
|
|
220
|
+
if (!targetEntity)
|
|
221
|
+
continue;
|
|
222
|
+
const compositeKey = BuildPolymorphicCompositeKey(rawId, targetEntity);
|
|
223
|
+
if (!compositeKey || !compositeKey.HasValue)
|
|
224
|
+
continue;
|
|
225
|
+
const cacheKey = PolymorphicCacheKey(targetEntity.Name, compositeKey);
|
|
226
|
+
if (!cache.has(cacheKey) && !pendingByKey.has(cacheKey)) {
|
|
227
|
+
pendingByKey.set(cacheKey, {
|
|
228
|
+
EntityName: targetEntity.Name,
|
|
229
|
+
CompositeKey: compositeKey,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (pendingByKey.size === 0) {
|
|
235
|
+
return cache;
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
const inputs = Array.from(pendingByKey.values());
|
|
239
|
+
const results = await provider.GetEntityRecordNames(inputs);
|
|
240
|
+
for (const res of results) {
|
|
241
|
+
if (res.Success && res.RecordName) {
|
|
242
|
+
const key = PolymorphicCacheKey(res.EntityName, res.CompositeKey);
|
|
243
|
+
cache.set(key, res.RecordName);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
// Non-fatal: unresolved cells fall back to showing the raw RecordID
|
|
249
|
+
}
|
|
250
|
+
return cache;
|
|
251
|
+
}
|
|
144
252
|
//# sourceMappingURL=record.util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.util.js","sourceRoot":"","sources":["../../../src/lib/utils/record.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGhE;;;GAGG;AACH,MAAM,UAAU,i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KAAK,aAAa,IAAI,CAAC,CAAC,YAAY,KAAK,cAAc,EAAE,CAAC;YACxE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;IACL,CAAC;IACD,0EAA0E;IAC1E,kDAAkD;IAClD,IAAI,UAAU,CAAC,iBAAiB,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,iBAAiB,CAAC,EAAE,CAAC;QAC5F,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC;AAED,iDAAiD;AACjD,MAAM,UAAU,iBAAiB,CAC7B,UAAsB,EACtB,SAAgC,EAChC,gBAA2C;IAE3C,OAAO,iBAAiB,CAAC,UAAU,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC;AACtE,CAAC","sourcesContent":["import { EntityInfo, CompositeKey } from '@memberjunction/core';\nimport { ViewGridState } from '../types';\n\n/**\n * Build a CompositeKey from a plain record using EntityInfo PK fields.\n * Works with both plain objects (from ResultType: 'simple') and BaseEntity instances.\n */\nexport function BuildCompositeKey(record: Record<string, unknown>, entityInfo: EntityInfo): CompositeKey {\n return CompositeKey.FromEntityRecord(entityInfo, record);\n}\n\n/** @deprecated Use {@link BuildCompositeKey}. */\nexport function buildCompositeKey(record: Record<string, unknown>, entityInfo: EntityInfo): CompositeKey {\n return BuildCompositeKey(record, entityInfo);\n}\n\n/**\n * Build a PK concatenated string matching CompositeKey.ToConcatenatedString() format.\n * Used as a stable row identifier for selection, tracking, and map keys.\n */\nexport function BuildPkString(record: Record<string, unknown>, entityInfo: EntityInfo): string {\n return BuildCompositeKey(record, entityInfo).ToConcatenatedString();\n}\n\n/** @deprecated Use {@link BuildPkString}. */\nexport function buildPkString(record: Record<string, unknown>, entityInfo: EntityInfo): string {\n return BuildPkString(record, entityInfo);\n}\n\n/**\n * Rewrite host-supplied column field names to the entity's OWN spelling.\n *\n * A page may reasonably write `field: 'name'` where the entity says `Name`, and the grid resolves\n * host names case-insensitively when it looks up metadata — so such a column *renders*. But the\n * spelling does not stay cosmetic: it becomes the AG Grid colDef's `field`, and therefore its\n * `colId`, and therefore the key in captured grid state and sort settings. Meanwhile the row objects\n * the grid builds are keyed by the ENTITY's spelling. Anything that addresses data or matches state\n * by that name then misses: cells resolve to undefined, the captured state drops the column, a saved\n * sort is discarded.\n *\n * Normalising once, here, is what keeps those two vocabularies from diverging — the alternative is a\n * case-insensitive comparison at every one of those sites, which is the state that produced the bug.\n *\n * Unchanged columns are returned by REFERENCE (so callers can detect a no-op cheaply), and changed\n * ones as copies — the host's own array and objects are never mutated. A name matching no field is\n * left alone for the existing validation to reject.\n */\nexport function CanonicalizeColumnFields<T extends { field: string }>(\n entityInfo: EntityInfo,\n columns: readonly T[],\n): T[] {\n return columns.map(col => {\n const field = entityInfo.Fields.find(f => f.Name.toLowerCase() === col.field.toLowerCase());\n return field && field.Name !== col.field ? { ...col, field: field.Name } : col;\n });\n}\n\n/** @deprecated Use {@link CanonicalizeColumnFields}. */\nexport function canonicalizeColumnFields<T extends { field: string }>(\n entityInfo: EntityInfo,\n columns: readonly T[],\n): T[] {\n return CanonicalizeColumnFields(entityInfo, columns);\n}\n\n/**\n * Compute the Fields array to request from RunView based on EntityInfo and optional grid state.\n * Includes: PK fields, NameField, visible display fields, and timestamp fields.\n */\nexport function ComputeFieldsList(\n entityInfo: EntityInfo,\n gridState?: ViewGridState | null,\n hostColumnFields?: readonly string[] | null,\n): string[] {\n const fields = new Set<string>();\n\n // Fields the HOST explicitly asked to display. Without these, a page that supplies `[Columns]`\n // renders columns whose data was never fetched — every cell shows as empty, which reads as a\n // data bug rather than a missing SELECT. They are added unconditionally (not as an alternative\n // to the branches below) because a host column list says what to SHOW, while DefaultInView and\n // the grid state say what to fetch by default; the host's columns must be a superset, not a\n // replacement. Names are validated against the entity so a stale column can't break the query.\n if (hostColumnFields?.length) {\n for (const name of hostColumnFields) {\n const field = entityInfo.Fields.find(f => f.Name.toLowerCase() === name.toLowerCase());\n // Add the ENTITY's spelling, not the host's. A page may reasonably write `field: 'name'`\n // where the entity says `Name`, and metadata lookups here are case-insensitive so the\n // column is accepted — but this list goes on the wire. On the GraphQL transport it is\n // interpolated straight into the selection set, and GraphQL field names are case\n // SENSITIVE, so the host's spelling produces `Cannot query field \"name\"` and the whole\n // view fails: an error and zero rows, not one odd column. (This Set is case-sensitive\n // too, so the two spellings would not even collapse into one entry.)\n //\n // Callers that hand this function raw host names should also run them through\n // `canonicalizeColumnFields` for the column definitions, or the rendered column will\n // address a key the fetched rows do not have.\n if (field) {\n fields.add(field.Name);\n }\n }\n }\n\n // Always include PK fields\n for (const pk of entityInfo.PrimaryKeys) {\n fields.add(pk.Name);\n }\n\n // Include NameField for display name resolution\n if (entityInfo.NameField) {\n fields.add(entityInfo.NameField.Name);\n }\n\n // Include visible fields from gridState or DefaultInView\n if (gridState?.columnSettings?.length) {\n for (const col of gridState.columnSettings) {\n if (!col.hidden) {\n fields.add(col.Name);\n }\n }\n } else {\n // First try to use DefaultInView fields\n const defaultInViewFields = entityInfo.Fields.filter(f => f.DefaultInView);\n\n if (defaultInViewFields.length > 0) {\n for (const f of defaultInViewFields) {\n fields.add(f.Name);\n }\n } else {\n // Fallback: when no DefaultInView fields are defined, include the first 10\n // non-system fields. This matches the fallback in generateAgColumnDefs()\n // which uses getDefaultFieldsFallback() to show columns even when\n // DefaultInView isn't configured.\n const fallbackFields = entityInfo.Fields\n .filter(f =>\n !f.Name.startsWith('__mj_') &&\n !(f.IsPrimaryKey && f.SQLFullType?.toLowerCase() === 'uniqueidentifier') &&\n (f.Length <= 500 || f.Length < 0) // Exclude very long text unless nvarchar(max)\n )\n .slice(0, 10);\n\n for (const f of fallbackFields) {\n fields.add(f.Name);\n }\n }\n }\n\n // Include __mj timestamp fields (commonly used for sort and display)\n fields.add('__mj_CreatedAt');\n fields.add('__mj_UpdatedAt');\n\n // Lat/lng only — never address-tagged fields. The map uses pre-geocoded\n // coords, never text-based location guessing.\n for (const f of entityInfo.Fields) {\n if (f.ExtendedType === 'GeoLatitude' || f.ExtendedType === 'GeoLongitude') {\n fields.add(f.Name);\n }\n }\n // Gated on SupportsGeoCoding — BoundaryGeoJSON is nvarchar(max), wasteful\n // to pull for grid views that won't render a map.\n if (entityInfo.SupportsGeoCoding && entityInfo.Fields.some(f => f.Name === 'BoundaryGeoJSON')) {\n fields.add('BoundaryGeoJSON');\n }\n\n return Array.from(fields);\n}\n\n/** @deprecated Use {@link ComputeFieldsList}. */\nexport function computeFieldsList(\n entityInfo: EntityInfo,\n gridState?: ViewGridState | null,\n hostColumnFields?: readonly string[] | null,\n): string[] {\n return ComputeFieldsList(entityInfo, gridState, hostColumnFields);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"record.util.js","sourceRoot":"","sources":["../../../src/lib/utils/record.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,YAAY,EAA4C,MAAM,sBAAsB,CAAC;AAG3H;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAA+B,EAAE,UAAsB;IACrF,OAAO,YAAY,CAAC,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AAC7D,CAAC;AAED,iDAAiD;AACjD,MAAM,UAAU,iBAAiB,CAAC,MAA+B,EAAE,UAAsB;IACrF,OAAO,iBAAiB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,MAA+B,EAAE,UAAsB;IACjF,OAAO,iBAAiB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,oBAAoB,EAAE,CAAC;AACxE,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,aAAa,CAAC,MAA+B,EAAE,UAAsB;IACjF,OAAO,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CA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,GAAG,MAAM,QAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;QAC5D,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;YACxB,IAAI,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC;gBAChC,MAAM,GAAG,GAAG,mBAAmB,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC;gBAClE,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;YACnC,CAAC;QACL,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACL,oEAAoE;IACxE,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { EntityInfo, EntityFieldInfo, CompositeKey, EntityRecordNameInput, IMetadataProvider } from '@memberjunction/core';\nimport { ViewGridState } from '../types';\n\n/**\n * Build a CompositeKey from a plain record using EntityInfo PK fields.\n * Works with both plain objects (from ResultType: 'simple') and BaseEntity instances.\n */\nexport function BuildCompositeKey(record: Record<string, unknown>, entityInfo: EntityInfo): CompositeKey {\n return CompositeKey.FromEntityRecord(entityInfo, record);\n}\n\n/** @deprecated Use {@link BuildCompositeKey}. */\nexport function buildCompositeKey(record: Record<string, unknown>, entityInfo: EntityInfo): CompositeKey {\n return BuildCompositeKey(record, entityInfo);\n}\n\n/**\n * Build a PK concatenated string matching CompositeKey.ToConcatenatedString() format.\n * Used as a stable row identifier for selection, tracking, and map keys.\n */\nexport function BuildPkString(record: Record<string, unknown>, entityInfo: EntityInfo): string {\n return BuildCompositeKey(record, entityInfo).ToConcatenatedString();\n}\n\n/** @deprecated Use {@link BuildPkString}. */\nexport function buildPkString(record: Record<string, unknown>, entityInfo: EntityInfo): string {\n return BuildPkString(record, entityInfo);\n}\n\n/**\n * Rewrite host-supplied column field names to the entity's OWN spelling.\n *\n * A page may reasonably write `field: 'name'` where the entity says `Name`, and the grid resolves\n * host names case-insensitively when it looks up metadata — so such a column *renders*. But the\n * spelling does not stay cosmetic: it becomes the AG Grid colDef's `field`, and therefore its\n * `colId`, and therefore the key in captured grid state and sort settings. Meanwhile the row objects\n * the grid builds are keyed by the ENTITY's spelling. Anything that addresses data or matches state\n * by that name then misses: cells resolve to undefined, the captured state drops the column, a saved\n * sort is discarded.\n *\n * Normalising once, here, is what keeps those two vocabularies from diverging — the alternative is a\n * case-insensitive comparison at every one of those sites, which is the state that produced the bug.\n *\n * Unchanged columns are returned by REFERENCE (so callers can detect a no-op cheaply), and changed\n * ones as copies — the host's own array and objects are never mutated. A name matching no field is\n * left alone for the existing validation to reject.\n */\nexport function CanonicalizeColumnFields<T extends { field: string }>(\n entityInfo: EntityInfo,\n columns: readonly T[],\n): T[] {\n return columns.map(col => {\n const field = entityInfo.Fields.find(f => f.Name.toLowerCase() === col.field.toLowerCase());\n return field && field.Name !== col.field ? { ...col, field: field.Name } : col;\n });\n}\n\n/** @deprecated Use {@link CanonicalizeColumnFields}. */\nexport function canonicalizeColumnFields<T extends { field: string }>(\n entityInfo: EntityInfo,\n columns: readonly T[],\n): T[] {\n return CanonicalizeColumnFields(entityInfo, columns);\n}\n\n/**\n * Compute the Fields array to request from RunView based on EntityInfo and optional grid state.\n * Includes: PK fields, NameField, visible display fields, and timestamp fields.\n */\nexport function ComputeFieldsList(\n entityInfo: EntityInfo,\n gridState?: ViewGridState | null,\n hostColumnFields?: readonly string[] | null,\n): string[] {\n const fields = new Set<string>();\n\n // Fields the HOST explicitly asked to display. Without these, a page that supplies `[Columns]`\n // renders columns whose data was never fetched — every cell shows as empty, which reads as a\n // data bug rather than a missing SELECT. They are added unconditionally (not as an alternative\n // to the branches below) because a host column list says what to SHOW, while DefaultInView and\n // the grid state say what to fetch by default; the host's columns must be a superset, not a\n // replacement. Names are validated against the entity so a stale column can't break the query.\n if (hostColumnFields?.length) {\n for (const name of hostColumnFields) {\n const field = entityInfo.Fields.find(f => f.Name.toLowerCase() === name.toLowerCase());\n // Add the ENTITY's spelling, not the host's. A page may reasonably write `field: 'name'`\n // where the entity says `Name`, and metadata lookups here are case-insensitive so the\n // column is accepted — but this list goes on the wire. On the GraphQL transport it is\n // interpolated straight into the selection set, and GraphQL field names are case\n // SENSITIVE, so the host's spelling produces `Cannot query field \"name\"` and the whole\n // view fails: an error and zero rows, not one odd column. (This Set is case-sensitive\n // too, so the two spellings would not even collapse into one entry.)\n //\n // Callers that hand this function raw host names should also run them through\n // `canonicalizeColumnFields` for the column definitions, or the rendered column will\n // address a key the fetched rows do not have.\n if (field) {\n fields.add(field.Name);\n }\n }\n }\n\n // Always include PK fields\n for (const pk of entityInfo.PrimaryKeys) {\n fields.add(pk.Name);\n }\n\n // Include NameField for display name resolution\n if (entityInfo.NameField) {\n fields.add(entityInfo.NameField.Name);\n }\n\n // Include visible fields from gridState or DefaultInView\n if (gridState?.columnSettings?.length) {\n for (const col of gridState.columnSettings) {\n if (!col.hidden) {\n fields.add(col.Name);\n }\n }\n } else {\n // First try to use DefaultInView fields\n const defaultInViewFields = entityInfo.Fields.filter(f => f.DefaultInView);\n\n if (defaultInViewFields.length > 0) {\n for (const f of defaultInViewFields) {\n fields.add(f.Name);\n }\n } else {\n // Fallback: when no DefaultInView fields are defined, include the first 10\n // non-system fields. This matches the fallback in generateAgColumnDefs()\n // which uses getDefaultFieldsFallback() to show columns even when\n // DefaultInView isn't configured.\n const fallbackFields = entityInfo.Fields\n .filter(f =>\n !f.Name.startsWith('__mj_') &&\n !(f.IsPrimaryKey && f.SQLFullType?.toLowerCase() === 'uniqueidentifier') &&\n (f.Length <= 500 || f.Length < 0) // Exclude very long text unless nvarchar(max)\n )\n .slice(0, 10);\n\n for (const f of fallbackFields) {\n fields.add(f.Name);\n }\n }\n }\n\n // Include __mj timestamp fields (commonly used for sort and display)\n fields.add('__mj_CreatedAt');\n fields.add('__mj_UpdatedAt');\n\n // Lat/lng only — never address-tagged fields. The map uses pre-geocoded\n // coords, never text-based location guessing.\n for (const f of entityInfo.Fields) {\n if (f.ExtendedType === 'GeoLatitude' || f.ExtendedType === 'GeoLongitude') {\n fields.add(f.Name);\n }\n }\n // Gated on SupportsGeoCoding — BoundaryGeoJSON is nvarchar(max), wasteful\n // to pull for grid views that won't render a map.\n if (entityInfo.SupportsGeoCoding && entityInfo.Fields.some(f => f.Name === 'BoundaryGeoJSON')) {\n fields.add('BoundaryGeoJSON');\n }\n\n // For any polymorphic FK field (where EntityField.EntityIDFieldName is populated) included in\n // the projection, always include its companion EntityIDFieldName column (and any mapped virtual\n // name column) so the grid/cards/detail panel can resolve the target entity and record name\n // even if the user hid the EntityID column in their view settings.\n for (const f of entityInfo.Fields) {\n if (!fields.has(f.Name)) continue;\n const companionName = f.EntityIDFieldName?.trim();\n if (companionName) {\n const companionField = entityInfo.Fields.find(\n cf => cf.Name.toLowerCase() === companionName.toLowerCase()\n );\n if (companionField) {\n fields.add(companionField.Name);\n if (companionField.RelatedEntityNameFieldMap) {\n fields.add(companionField.RelatedEntityNameFieldMap);\n }\n }\n }\n if (f.RelatedEntityNameFieldMap) {\n fields.add(f.RelatedEntityNameFieldMap);\n }\n }\n\n return Array.from(fields);\n}\n\n/** @deprecated Use {@link ComputeFieldsList}. */\nexport function computeFieldsList(\n entityInfo: EntityInfo,\n gridState?: ViewGridState | null,\n hostColumnFields?: readonly string[] | null,\n): string[] {\n return ComputeFieldsList(entityInfo, gridState, hostColumnFields);\n}\n\n/**\n * Resolves the target `EntityInfo` for a polymorphic FK field (`field.EntityIDFieldName`)\n * on a plain record or `BaseEntity`-like map. Strictly relies on the hard metadata link\n * `field.EntityIDFieldName` — never falls back to field-name heuristics.\n */\nexport function ResolvePolymorphicTargetEntity(\n record: Record<string, unknown>,\n field: EntityFieldInfo,\n provider: IMetadataProvider | null | undefined,\n): EntityInfo | undefined {\n const companionName = field.EntityIDFieldName?.trim();\n if (!companionName || !provider || !record) return undefined;\n const rawRef = record[companionName];\n if (rawRef == null) return undefined;\n const refStr = String(rawRef).trim();\n if (!refStr) return undefined;\n return provider.EntityByID(refStr) ?? provider.EntityByName(refStr);\n}\n\n/**\n * Builds a `CompositeKey` for a polymorphic `RecordID` value against `targetEntity`,\n * supporting both single-column bare values and `Field1|Val1||Field2|Val2` segments.\n */\nexport function BuildPolymorphicCompositeKey(\n rawRecordId: unknown,\n targetEntity: EntityInfo,\n): CompositeKey | null {\n if (rawRecordId == null) return null;\n const str = String(rawRecordId).trim();\n if (!str) return null;\n return CompositeKey.FromURLSegment(targetEntity, str);\n}\n\n/**\n * Stable lookup key for a resolved polymorphic record name in a view's cache map.\n */\nexport function PolymorphicCacheKey(entityName: string, key: CompositeKey): string {\n return `${entityName}::${key.ToConcatenatedString()}`;\n}\n\n/**\n * Batch-resolves human-readable record names for all polymorphic FK fields (`EntityIDFieldName`)\n * across a page of records using a single `provider.GetEntityRecordNames(...)` call.\n */\nexport async function BatchResolvePolymorphicRecordNames(\n records: readonly Record<string, unknown>[],\n entityInfo: EntityInfo | null | undefined,\n provider: IMetadataProvider | null | undefined,\n existingCache?: Map<string, string>,\n): Promise<Map<string, string>> {\n const cache = existingCache ?? new Map<string, string>();\n if (!entityInfo?.Fields || !provider || !records || records.length === 0) {\n return cache;\n }\n\n const polyFields = entityInfo.Fields.filter(\n f => typeof f.EntityIDFieldName === 'string' && f.EntityIDFieldName.trim().length > 0\n );\n if (polyFields.length === 0) {\n return cache;\n }\n\n const pendingByKey = new Map<string, EntityRecordNameInput>();\n for (const row of records) {\n for (const pf of polyFields) {\n const rawId = row[pf.Name];\n if (rawId == null || rawId === '') continue;\n const targetEntity = ResolvePolymorphicTargetEntity(row, pf, provider);\n if (!targetEntity) continue;\n const compositeKey = BuildPolymorphicCompositeKey(rawId, targetEntity);\n if (!compositeKey || !compositeKey.HasValue) continue;\n const cacheKey = PolymorphicCacheKey(targetEntity.Name, compositeKey);\n if (!cache.has(cacheKey) && !pendingByKey.has(cacheKey)) {\n pendingByKey.set(cacheKey, {\n EntityName: targetEntity.Name,\n CompositeKey: compositeKey,\n });\n }\n }\n }\n\n if (pendingByKey.size === 0) {\n return cache;\n }\n\n try {\n const inputs = Array.from(pendingByKey.values());\n const results = await provider.GetEntityRecordNames(inputs);\n for (const res of results) {\n if (res.Success && res.RecordName) {\n const key = PolymorphicCacheKey(res.EntityName, res.CompositeKey);\n cache.set(key, res.RecordName);\n }\n }\n } catch {\n // Non-fatal: unresolved cells fall back to showing the raw RecordID\n }\n\n return cache;\n}\n"]}
|