@memberjunction/ng-base-forms 6.1.3 → 6.2.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.
- package/dist/lib/base-form-component.d.ts.map +1 -1
- package/dist/lib/base-form-component.js +43 -40
- package/dist/lib/base-form-component.js.map +1 -1
- package/dist/lib/container/record-form-container.component.d.ts +4 -1
- package/dist/lib/container/record-form-container.component.d.ts.map +1 -1
- package/dist/lib/container/record-form-container.component.js +104 -69
- package/dist/lib/container/record-form-container.component.js.map +1 -1
- package/dist/lib/explorer-entity-data-grid.component.d.ts +14 -1
- package/dist/lib/explorer-entity-data-grid.component.d.ts.map +1 -1
- package/dist/lib/explorer-entity-data-grid.component.js +16 -3
- package/dist/lib/explorer-entity-data-grid.component.js.map +1 -1
- package/dist/lib/field/default-fk-lookup-strategy.d.ts +60 -0
- package/dist/lib/field/default-fk-lookup-strategy.d.ts.map +1 -0
- package/dist/lib/field/default-fk-lookup-strategy.js +173 -0
- package/dist/lib/field/default-fk-lookup-strategy.js.map +1 -0
- package/dist/lib/field/fk-lookup-strategy.d.ts +124 -0
- package/dist/lib/field/fk-lookup-strategy.d.ts.map +1 -0
- package/dist/lib/field/fk-lookup-strategy.js +97 -0
- package/dist/lib/field/fk-lookup-strategy.js.map +1 -0
- package/dist/lib/field/fk-search-utils.d.ts +33 -2
- package/dist/lib/field/fk-search-utils.d.ts.map +1 -1
- package/dist/lib/field/fk-search-utils.js +56 -3
- package/dist/lib/field/fk-search-utils.js.map +1 -1
- package/dist/lib/field/form-field.component.d.ts +151 -9
- package/dist/lib/field/form-field.component.d.ts.map +1 -1
- package/dist/lib/field/form-field.component.js +724 -334
- package/dist/lib/field/form-field.component.js.map +1 -1
- package/dist/lib/field/linked-field-options.d.ts +16 -0
- package/dist/lib/field/linked-field-options.d.ts.map +1 -1
- package/dist/lib/field/linked-field-options.js +17 -0
- package/dist/lib/field/linked-field-options.js.map +1 -1
- package/dist/lib/isa-related-panel/isa-related-card.component.d.ts.map +1 -1
- package/dist/lib/isa-related-panel/isa-related-card.component.js +6 -2
- package/dist/lib/isa-related-panel/isa-related-card.component.js.map +1 -1
- package/dist/lib/isa-related-panel/isa-related-panel.component.d.ts.map +1 -1
- package/dist/lib/isa-related-panel/isa-related-panel.component.js +17 -0
- package/dist/lib/isa-related-panel/isa-related-panel.component.js.map +1 -1
- package/dist/lib/panel/collapsible-panel.component.d.ts +65 -2
- package/dist/lib/panel/collapsible-panel.component.d.ts.map +1 -1
- package/dist/lib/panel/collapsible-panel.component.js +166 -24
- package/dist/lib/panel/collapsible-panel.component.js.map +1 -1
- package/dist/lib/section-indicators/form-section-field-host.d.ts +53 -0
- package/dist/lib/section-indicators/form-section-field-host.d.ts.map +1 -0
- package/dist/lib/section-indicators/form-section-field-host.js +23 -0
- package/dist/lib/section-indicators/form-section-field-host.js.map +1 -0
- package/dist/public-api.d.ts +3 -0
- package/dist/public-api.d.ts.map +1 -1
- package/dist/public-api.js +3 -0
- package/dist/public-api.js.map +1 -1
- package/package.json +18 -18
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The extension point for where the rows in a foreign-key dropdown come from.
|
|
3
|
+
*
|
|
4
|
+
* {@link MjFormFieldComponent} owns the dropdown itself — rendering, keyboard handling, the
|
|
5
|
+
* column plan, the pinned current selection, the recent-picks group and the create-new footer.
|
|
6
|
+
* A strategy owns only the rows, so an app can decide *which* records a given foreign key
|
|
7
|
+
* should offer without forking the field.
|
|
8
|
+
*
|
|
9
|
+
* Registration is through `MJGlobal.ClassFactory`, most specific first:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* // every foreign key that points at Organizations
|
|
13
|
+
* @RegisterClass(FKLookupStrategy, 'MJ_BizApps_Common: Organizations')
|
|
14
|
+
* export class PartyLookupStrategy extends FKLookupStrategy { ... }
|
|
15
|
+
*
|
|
16
|
+
* // just this one field on this one entity
|
|
17
|
+
* @RegisterClass(FKLookupStrategy, 'MJ_BizApps_Orders: Orders.BillToOrganizationID')
|
|
18
|
+
* export class BillToLookupStrategy extends PartyLookupStrategy { ... }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* When nothing is registered the field uses `DefaultFKLookupStrategy`, which is MJ's own
|
|
22
|
+
* behaviour and the case for almost every field in the system.
|
|
23
|
+
*/
|
|
24
|
+
import type { BaseEntity, EntityFieldInfo, EntityInfo, IMetadataProvider } from '@memberjunction/core';
|
|
25
|
+
/** A small marker rendered beside a row's name, e.g. "4 orders". */
|
|
26
|
+
export interface FKLookupChip {
|
|
27
|
+
Text: string;
|
|
28
|
+
Tone?: 'default' | 'info' | 'warn';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* One row a strategy offers. `Values` must contain every field named in
|
|
32
|
+
* {@link FKLookupContext.Fields} — the field maps those into the dropdown's columns, so a row
|
|
33
|
+
* missing the primary key or the name field cannot be rendered or selected.
|
|
34
|
+
*/
|
|
35
|
+
export interface FKLookupRow {
|
|
36
|
+
Values: Record<string, unknown>;
|
|
37
|
+
/** Second line under the name, used to tell look-alikes apart, e.g. "Springfield, IL · northwind.example.org". */
|
|
38
|
+
Secondary?: string;
|
|
39
|
+
Chips?: FKLookupChip[];
|
|
40
|
+
}
|
|
41
|
+
/** A titled group of rows. `Label: null` renders the rows with no header. */
|
|
42
|
+
export interface FKLookupGroup {
|
|
43
|
+
Key: string;
|
|
44
|
+
Label: string | null;
|
|
45
|
+
Rows: FKLookupRow[];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Labels for the dropdown's scope toggle. `primary` names the narrow population the strategy
|
|
49
|
+
* offers first ("Customers"); `all` names the wide one ("All organizations").
|
|
50
|
+
*/
|
|
51
|
+
export interface FKLookupScopeLabels {
|
|
52
|
+
primary: string;
|
|
53
|
+
all: string;
|
|
54
|
+
}
|
|
55
|
+
/** Which population the current lookup is over. Strategies decide what `primary` means. */
|
|
56
|
+
export type FKLookupScope = 'primary' | 'all';
|
|
57
|
+
/** Everything a strategy needs to answer one lookup. Rebuilt per keystroke. */
|
|
58
|
+
export interface FKLookupContext {
|
|
59
|
+
/** The record being edited — the host of the foreign key, not the record being looked up. */
|
|
60
|
+
Record: BaseEntity;
|
|
61
|
+
/** The foreign-key field itself, carrying `RelatedEntityFilter` / `RelatedEntityOrderBy`. */
|
|
62
|
+
FieldInfo: EntityFieldInfo;
|
|
63
|
+
RelatedEntity: EntityInfo;
|
|
64
|
+
Provider: IMetadataProvider;
|
|
65
|
+
/** Fields the dropdown will read from each row: primary key, name, extra columns, icon. */
|
|
66
|
+
Fields: string[];
|
|
67
|
+
/** The related entity's primary key field name. */
|
|
68
|
+
PkField: string;
|
|
69
|
+
/** The related entity's name field name. */
|
|
70
|
+
NameField: string;
|
|
71
|
+
/**
|
|
72
|
+
* The field the user is searching — the name field unless they chose another column on the
|
|
73
|
+
* dropdown's scope pill. A typed query is matched against this column.
|
|
74
|
+
*/
|
|
75
|
+
SearchField: string;
|
|
76
|
+
/** What the user has typed. Empty when the dropdown was opened by focus. */
|
|
77
|
+
Query: string;
|
|
78
|
+
Scope: FKLookupScope;
|
|
79
|
+
MaxRows: number;
|
|
80
|
+
/**
|
|
81
|
+
* From the field's `[FKLookupOptions]` input, plus `ExtraFilter` and `OrderBy` contributed by
|
|
82
|
+
* `[FKExtraFilter]` / `[FKOrderBy]`. Opaque to the field; each strategy documents its own keys.
|
|
83
|
+
*/
|
|
84
|
+
Options: Record<string, unknown>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Base class for a foreign-key lookup strategy. Subclass, implement {@link Lookup}, and register
|
|
88
|
+
* it with `@RegisterClass(FKLookupStrategy, '<key>')` — see the module doc for the key forms.
|
|
89
|
+
*
|
|
90
|
+
* Marked `@OptionalKeyedSpecialization` because a keyed lookup landing on the base is the
|
|
91
|
+
* designed outcome for nearly every foreign key in the system, not a failed resolution.
|
|
92
|
+
*/
|
|
93
|
+
export declare abstract class FKLookupStrategy {
|
|
94
|
+
/**
|
|
95
|
+
* Labels for the scope toggle, or null to hide it. Called before every {@link Lookup} so a
|
|
96
|
+
* strategy can decide per field whether a second population is worth offering.
|
|
97
|
+
*/
|
|
98
|
+
ScopeLabels(_context: FKLookupContext): FKLookupScopeLabels | null;
|
|
99
|
+
/**
|
|
100
|
+
* The rows for the current query and scope, in the order they should render. Called for the
|
|
101
|
+
* empty query too — that is the browse list the user sees on focus.
|
|
102
|
+
*/
|
|
103
|
+
abstract Lookup(context: FKLookupContext): Promise<FKLookupGroup[]>;
|
|
104
|
+
/**
|
|
105
|
+
* Runs after the user picks a row and before the value is written. Return false to cancel the
|
|
106
|
+
* pick — used where choosing a record has a side effect the user should confirm first.
|
|
107
|
+
*/
|
|
108
|
+
BeforeSelect(_context: FKLookupContext, _row: FKLookupRow): Promise<boolean>;
|
|
109
|
+
/**
|
|
110
|
+
* WHERE fragment the field applies when it hydrates the user's recent picks, so a record this
|
|
111
|
+
* strategy's population no longer includes stops being offered under "Recent". Empty means no
|
|
112
|
+
* filter beyond the primary-key list.
|
|
113
|
+
*/
|
|
114
|
+
RecentFilter(_context: FKLookupContext): string;
|
|
115
|
+
/** Values to prefill when the user creates a new related record from the dropdown's footer. */
|
|
116
|
+
CreateDefaults(context: FKLookupContext): Record<string, unknown>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Resolve the strategy for one foreign key: a `<HostEntity>.<FieldName>` registration wins over a
|
|
120
|
+
* `<RelatedEntity>` one. Returns null when neither exists, so the caller can fall back to
|
|
121
|
+
* `DefaultFKLookupStrategy` rather than this module depending on it.
|
|
122
|
+
*/
|
|
123
|
+
export declare function ResolveFKLookupStrategy(hostEntityName: string, fieldName: string, relatedEntityName: string): FKLookupStrategy | null;
|
|
124
|
+
//# sourceMappingURL=fk-lookup-strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fk-lookup-strategy.d.ts","sourceRoot":"","sources":["../../../src/lib/field/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KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,aAAa,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;;;;;GAMG;AACH,8BACsB,gBAAgB;IACpC;;;OAGG;IACI,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,mBAAmB,GAAG,IAAI;IAIzE;;;OAGG;aACa,MAAM,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAE1E;;;OAGG;IACU,YAAY,CAAC,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAIzF;;;;OAIG;IACI,YAAY,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM;IAItD,+FAA+F;IACxF,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAIzE;AAOD;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,MAAM,EACtB,SAAS,EAAE,MAAM,EACjB,iBAAiB,EAAE,MAAM,GACxB,gBAAgB,GAAG,IAAI,CAgBzB"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The extension point for where the rows in a foreign-key dropdown come from.
|
|
3
|
+
*
|
|
4
|
+
* {@link MjFormFieldComponent} owns the dropdown itself — rendering, keyboard handling, the
|
|
5
|
+
* column plan, the pinned current selection, the recent-picks group and the create-new footer.
|
|
6
|
+
* A strategy owns only the rows, so an app can decide *which* records a given foreign key
|
|
7
|
+
* should offer without forking the field.
|
|
8
|
+
*
|
|
9
|
+
* Registration is through `MJGlobal.ClassFactory`, most specific first:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* // every foreign key that points at Organizations
|
|
13
|
+
* @RegisterClass(FKLookupStrategy, 'MJ_BizApps_Common: Organizations')
|
|
14
|
+
* export class PartyLookupStrategy extends FKLookupStrategy { ... }
|
|
15
|
+
*
|
|
16
|
+
* // just this one field on this one entity
|
|
17
|
+
* @RegisterClass(FKLookupStrategy, 'MJ_BizApps_Orders: Orders.BillToOrganizationID')
|
|
18
|
+
* export class BillToLookupStrategy extends PartyLookupStrategy { ... }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* When nothing is registered the field uses `DefaultFKLookupStrategy`, which is MJ's own
|
|
22
|
+
* behaviour and the case for almost every field in the system.
|
|
23
|
+
*/
|
|
24
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
25
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
26
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
27
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
28
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
29
|
+
};
|
|
30
|
+
import { MJGlobal, OptionalKeyedSpecialization } from '@memberjunction/global';
|
|
31
|
+
/**
|
|
32
|
+
* Base class for a foreign-key lookup strategy. Subclass, implement {@link Lookup}, and register
|
|
33
|
+
* it with `@RegisterClass(FKLookupStrategy, '<key>')` — see the module doc for the key forms.
|
|
34
|
+
*
|
|
35
|
+
* Marked `@OptionalKeyedSpecialization` because a keyed lookup landing on the base is the
|
|
36
|
+
* designed outcome for nearly every foreign key in the system, not a failed resolution.
|
|
37
|
+
*/
|
|
38
|
+
let FKLookupStrategy = class FKLookupStrategy {
|
|
39
|
+
/**
|
|
40
|
+
* Labels for the scope toggle, or null to hide it. Called before every {@link Lookup} so a
|
|
41
|
+
* strategy can decide per field whether a second population is worth offering.
|
|
42
|
+
*/
|
|
43
|
+
ScopeLabels(_context) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Runs after the user picks a row and before the value is written. Return false to cancel the
|
|
48
|
+
* pick — used where choosing a record has a side effect the user should confirm first.
|
|
49
|
+
*/
|
|
50
|
+
async BeforeSelect(_context, _row) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* WHERE fragment the field applies when it hydrates the user's recent picks, so a record this
|
|
55
|
+
* strategy's population no longer includes stops being offered under "Recent". Empty means no
|
|
56
|
+
* filter beyond the primary-key list.
|
|
57
|
+
*/
|
|
58
|
+
RecentFilter(_context) {
|
|
59
|
+
return '';
|
|
60
|
+
}
|
|
61
|
+
/** Values to prefill when the user creates a new related record from the dropdown's footer. */
|
|
62
|
+
CreateDefaults(context) {
|
|
63
|
+
const typed = context.Query.trim();
|
|
64
|
+
return typed ? { [context.NameField]: typed } : {};
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
FKLookupStrategy = __decorate([
|
|
68
|
+
OptionalKeyedSpecialization()
|
|
69
|
+
], FKLookupStrategy);
|
|
70
|
+
export { FKLookupStrategy };
|
|
71
|
+
/** Trim + lowercase, so a registration can use whatever casing reads naturally. */
|
|
72
|
+
function normalizeKeyPart(value) {
|
|
73
|
+
return (value ?? '').trim().toLowerCase();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Resolve the strategy for one foreign key: a `<HostEntity>.<FieldName>` registration wins over a
|
|
77
|
+
* `<RelatedEntity>` one. Returns null when neither exists, so the caller can fall back to
|
|
78
|
+
* `DefaultFKLookupStrategy` rather than this module depending on it.
|
|
79
|
+
*/
|
|
80
|
+
export function ResolveFKLookupStrategy(hostEntityName, fieldName, relatedEntityName) {
|
|
81
|
+
const factory = MJGlobal.Instance.ClassFactory;
|
|
82
|
+
const keys = [
|
|
83
|
+
`${normalizeKeyPart(hostEntityName)}.${normalizeKeyPart(fieldName)}`,
|
|
84
|
+
normalizeKeyPart(relatedEntityName),
|
|
85
|
+
];
|
|
86
|
+
for (const key of keys) {
|
|
87
|
+
if (!factory.GetRegistration(FKLookupStrategy, key)) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const resolution = factory.TryCreateInstance(FKLookupStrategy, key);
|
|
91
|
+
if (resolution.Resolved && resolution.Instance) {
|
|
92
|
+
return resolution.Instance;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=fk-lookup-strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fk-lookup-strategy.js","sourceRoot":"","sources":["../../../src/lib/field/fk-lookup-strategy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;;;;;AAGH,OAAO,EAAE,QAAQ,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAqE/E;;;;;;GAMG;AAEI,IAAe,gBAAgB,GAA/B,MAAe,gBAAgB;IACpC;;;OAGG;IACI,WAAW,CAAC,QAAyB;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IAQD;;;OAGG;IACI,KAAK,CAAC,YAAY,CAAC,QAAyB,EAAE,IAAiB;QACpE,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACI,YAAY,CAAC,QAAyB;QAC3C,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,+FAA+F;IACxF,cAAc,CAAC,OAAwB;QAC5C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QACnC,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACrD,CAAC;CACF,CAAA;AArCqB,gBAAgB;IADrC,2BAA2B,EAAE;GACR,gBAAgB,CAqCrC;;AAED,mFAAmF;AACnF,SAAS,gBAAgB,CAAC,KAAa;IACrC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAC5C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CACrC,cAAsB,EACtB,SAAiB,EACjB,iBAAyB;IAEzB,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC;IAC/C,MAAM,IAAI,GAAG;QACX,GAAG,gBAAgB,CAAC,cAAc,CAAC,IAAI,gBAAgB,CAAC,SAAS,CAAC,EAAE;QACpE,gBAAgB,CAAC,iBAAiB,CAAC;KACpC,CAAC;IACF,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,gBAAgB,EAAE,GAAG,CAAC,EAAE,CAAC;YACpD,SAAS;QACX,CAAC;QACD,MAAM,UAAU,GAAG,OAAO,CAAC,iBAAiB,CAAmB,gBAAgB,EAAE,GAAG,CAAC,CAAC;QACtF,IAAI,UAAU,CAAC,QAAQ,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;YAC/C,OAAO,UAAU,CAAC,QAAQ,CAAC;QAC7B,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/**\n * The extension point for where the rows in a foreign-key dropdown come from.\n *\n * {@link MjFormFieldComponent} owns the dropdown itself — rendering, keyboard handling, the\n * column plan, the pinned current selection, the recent-picks group and the create-new footer.\n * A strategy owns only the rows, so an app can decide *which* records a given foreign key\n * should offer without forking the field.\n *\n * Registration is through `MJGlobal.ClassFactory`, most specific first:\n *\n * ```ts\n * // every foreign key that points at Organizations\n * @RegisterClass(FKLookupStrategy, 'MJ_BizApps_Common: Organizations')\n * export class PartyLookupStrategy extends FKLookupStrategy { ... }\n *\n * // just this one field on this one entity\n * @RegisterClass(FKLookupStrategy, 'MJ_BizApps_Orders: Orders.BillToOrganizationID')\n * export class BillToLookupStrategy extends PartyLookupStrategy { ... }\n * ```\n *\n * When nothing is registered the field uses `DefaultFKLookupStrategy`, which is MJ's own\n * behaviour and the case for almost every field in the system.\n */\n\nimport type { BaseEntity, EntityFieldInfo, EntityInfo, IMetadataProvider } from '@memberjunction/core';\nimport { MJGlobal, OptionalKeyedSpecialization } from '@memberjunction/global';\n\n/** A small marker rendered beside a row's name, e.g. \"4 orders\". */\nexport interface FKLookupChip {\n Text: string;\n Tone?: 'default' | 'info' | 'warn';\n}\n\n/**\n * One row a strategy offers. `Values` must contain every field named in\n * {@link FKLookupContext.Fields} — the field maps those into the dropdown's columns, so a row\n * missing the primary key or the name field cannot be rendered or selected.\n */\nexport interface FKLookupRow {\n Values: Record<string, unknown>;\n /** Second line under the name, used to tell look-alikes apart, e.g. \"Springfield, IL · northwind.example.org\". */\n Secondary?: string;\n Chips?: FKLookupChip[];\n}\n\n/** A titled group of rows. `Label: null` renders the rows with no header. */\nexport interface FKLookupGroup {\n Key: string;\n Label: string | null;\n Rows: FKLookupRow[];\n}\n\n/**\n * Labels for the dropdown's scope toggle. `primary` names the narrow population the strategy\n * offers first (\"Customers\"); `all` names the wide one (\"All organizations\").\n */\nexport interface FKLookupScopeLabels {\n primary: string;\n all: string;\n}\n\n/** Which population the current lookup is over. Strategies decide what `primary` means. */\nexport type FKLookupScope = 'primary' | 'all';\n\n/** Everything a strategy needs to answer one lookup. Rebuilt per keystroke. */\nexport interface FKLookupContext {\n /** The record being edited — the host of the foreign key, not the record being looked up. */\n Record: BaseEntity;\n /** The foreign-key field itself, carrying `RelatedEntityFilter` / `RelatedEntityOrderBy`. */\n FieldInfo: EntityFieldInfo;\n RelatedEntity: EntityInfo;\n Provider: IMetadataProvider;\n /** Fields the dropdown will read from each row: primary key, name, extra columns, icon. */\n Fields: string[];\n /** The related entity's primary key field name. */\n PkField: string;\n /** The related entity's name field name. */\n NameField: string;\n /**\n * The field the user is searching — the name field unless they chose another column on the\n * dropdown's scope pill. A typed query is matched against this column.\n */\n SearchField: string;\n /** What the user has typed. Empty when the dropdown was opened by focus. */\n Query: string;\n Scope: FKLookupScope;\n MaxRows: number;\n /**\n * From the field's `[FKLookupOptions]` input, plus `ExtraFilter` and `OrderBy` contributed by\n * `[FKExtraFilter]` / `[FKOrderBy]`. Opaque to the field; each strategy documents its own keys.\n */\n Options: Record<string, unknown>;\n}\n\n/**\n * Base class for a foreign-key lookup strategy. Subclass, implement {@link Lookup}, and register\n * it with `@RegisterClass(FKLookupStrategy, '<key>')` — see the module doc for the key forms.\n *\n * Marked `@OptionalKeyedSpecialization` because a keyed lookup landing on the base is the\n * designed outcome for nearly every foreign key in the system, not a failed resolution.\n */\n@OptionalKeyedSpecialization()\nexport abstract class FKLookupStrategy {\n /**\n * Labels for the scope toggle, or null to hide it. Called before every {@link Lookup} so a\n * strategy can decide per field whether a second population is worth offering.\n */\n public ScopeLabels(_context: FKLookupContext): FKLookupScopeLabels | null {\n return null;\n }\n\n /**\n * The rows for the current query and scope, in the order they should render. Called for the\n * empty query too — that is the browse list the user sees on focus.\n */\n public abstract Lookup(context: FKLookupContext): Promise<FKLookupGroup[]>;\n\n /**\n * Runs after the user picks a row and before the value is written. Return false to cancel the\n * pick — used where choosing a record has a side effect the user should confirm first.\n */\n public async BeforeSelect(_context: FKLookupContext, _row: FKLookupRow): Promise<boolean> {\n return true;\n }\n\n /**\n * WHERE fragment the field applies when it hydrates the user's recent picks, so a record this\n * strategy's population no longer includes stops being offered under \"Recent\". Empty means no\n * filter beyond the primary-key list.\n */\n public RecentFilter(_context: FKLookupContext): string {\n return '';\n }\n\n /** Values to prefill when the user creates a new related record from the dropdown's footer. */\n public CreateDefaults(context: FKLookupContext): Record<string, unknown> {\n const typed = context.Query.trim();\n return typed ? { [context.NameField]: typed } : {};\n }\n}\n\n/** Trim + lowercase, so a registration can use whatever casing reads naturally. */\nfunction normalizeKeyPart(value: string): string {\n return (value ?? '').trim().toLowerCase();\n}\n\n/**\n * Resolve the strategy for one foreign key: a `<HostEntity>.<FieldName>` registration wins over a\n * `<RelatedEntity>` one. Returns null when neither exists, so the caller can fall back to\n * `DefaultFKLookupStrategy` rather than this module depending on it.\n */\nexport function ResolveFKLookupStrategy(\n hostEntityName: string,\n fieldName: string,\n relatedEntityName: string,\n): FKLookupStrategy | null {\n const factory = MJGlobal.Instance.ClassFactory;\n const keys = [\n `${normalizeKeyPart(hostEntityName)}.${normalizeKeyPart(fieldName)}`,\n normalizeKeyPart(relatedEntityName),\n ];\n for (const key of keys) {\n if (!factory.GetRegistration(FKLookupStrategy, key)) {\n continue;\n }\n const resolution = factory.TryCreateInstance<FKLookupStrategy>(FKLookupStrategy, key);\n if (resolution.Resolved && resolution.Instance) {\n return resolution.Instance;\n }\n }\n return null;\n}\n"]}
|
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
*/
|
|
9
9
|
/**
|
|
10
10
|
* Format a raw entity cell value for display in the dropdown.
|
|
11
|
-
* - `Date` → locale date string
|
|
11
|
+
* - `Date` → locale date string; a SQL `date` column (pass its `sqlType`) is a calendar day that
|
|
12
|
+
* arrives as UTC midnight and is rendered as its stored day rather than shifted into the
|
|
13
|
+
* reader's zone (MJ#4210); a timestamp names an instant and stays in local time
|
|
12
14
|
* - `null` / `undefined` → empty string
|
|
13
15
|
* - `boolean` → `Yes` / `No`
|
|
14
16
|
* - everything else → `String(value)`
|
|
15
17
|
*/
|
|
16
|
-
export declare function FormatFKCell(val: unknown): string;
|
|
18
|
+
export declare function FormatFKCell(val: unknown, sqlType?: string | null): string;
|
|
17
19
|
/**
|
|
18
20
|
* In-memory filter/sort over cached rows for the FK dropdown.
|
|
19
21
|
*
|
|
@@ -28,4 +30,33 @@ export declare function FormatFKCell(val: unknown): string;
|
|
|
28
30
|
* @returns A NEW array (never mutates the input) suitable for rendering.
|
|
29
31
|
*/
|
|
30
32
|
export declare function FilterCachedFKRows<T>(rows: ReadonlyArray<T>, query: string, limit: number, getName: (row: T) => unknown): T[];
|
|
33
|
+
/**
|
|
34
|
+
* Rank lookup rows so that names *starting with* what the user typed come before names that
|
|
35
|
+
* merely contain it somewhere, alphabetically within each tier.
|
|
36
|
+
*
|
|
37
|
+
* Three typed letters otherwise match any name containing them anywhere, so an organization
|
|
38
|
+
* whose name merely happens to include the sequence outranks the one the user was reaching for.
|
|
39
|
+
* An empty query is a single tier, alphabetical.
|
|
40
|
+
*
|
|
41
|
+
* @returns A NEW array (never mutates the input).
|
|
42
|
+
*/
|
|
43
|
+
export declare function RankByPrefix<T extends {
|
|
44
|
+
Values: Record<string, unknown>;
|
|
45
|
+
}>(rows: ReadonlyArray<T>, query: string, nameField: string): T[];
|
|
46
|
+
/**
|
|
47
|
+
* Escape free text for interpolation into a SQL Server `LIKE` pattern: quotes doubled so the
|
|
48
|
+
* string literal stays closed, and `%`, `_`, `[` bracketed so a user typing "50%" or "a_b" gets
|
|
49
|
+
* literal matches instead of live wildcards.
|
|
50
|
+
*
|
|
51
|
+
* Bracketing rather than an `ESCAPE` clause, so a caller can drop the result into an existing
|
|
52
|
+
* pattern without also having to declare an escape character.
|
|
53
|
+
*/
|
|
54
|
+
export declare function EscapeSqlLikeValue(text: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Build the `'a','b'` body of an `IN (...)` clause from a list of primary-key values. Blanks and
|
|
57
|
+
* case-insensitive duplicates are dropped; quotes inside a value are doubled.
|
|
58
|
+
*
|
|
59
|
+
* Single-column keys only — a composite key's compact segment is not a SQL literal.
|
|
60
|
+
*/
|
|
61
|
+
export declare function QuoteSqlIdList(ids: ReadonlyArray<string>): string;
|
|
31
62
|
//# sourceMappingURL=fk-search-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fk-search-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/field/fk-search-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"fk-search-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/field/fk-search-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAK1E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,EACtB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,GAC3B,CAAC,EAAE,CAQL;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,EACxE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,EACtB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAChB,CAAC,EAAE,CAKL;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOvD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAUjE"}
|
|
@@ -6,18 +6,21 @@
|
|
|
6
6
|
* and the empty-input "focus-show" (first N, sorted by name). Keeping them out of
|
|
7
7
|
* the Angular component means they can be tested without TestBed / DI.
|
|
8
8
|
*/
|
|
9
|
+
import { IsDateOnlySQLType, FormatDateOnly } from '@memberjunction/core';
|
|
9
10
|
/**
|
|
10
11
|
* Format a raw entity cell value for display in the dropdown.
|
|
11
|
-
* - `Date` → locale date string
|
|
12
|
+
* - `Date` → locale date string; a SQL `date` column (pass its `sqlType`) is a calendar day that
|
|
13
|
+
* arrives as UTC midnight and is rendered as its stored day rather than shifted into the
|
|
14
|
+
* reader's zone (MJ#4210); a timestamp names an instant and stays in local time
|
|
12
15
|
* - `null` / `undefined` → empty string
|
|
13
16
|
* - `boolean` → `Yes` / `No`
|
|
14
17
|
* - everything else → `String(value)`
|
|
15
18
|
*/
|
|
16
|
-
export function FormatFKCell(val) {
|
|
19
|
+
export function FormatFKCell(val, sqlType) {
|
|
17
20
|
if (val === null || val === undefined)
|
|
18
21
|
return '';
|
|
19
22
|
if (val instanceof Date)
|
|
20
|
-
return val.toLocaleDateString();
|
|
23
|
+
return IsDateOnlySQLType(sqlType) ? FormatDateOnly(val) : val.toLocaleDateString();
|
|
21
24
|
if (typeof val === 'boolean')
|
|
22
25
|
return val ? 'Yes' : 'No';
|
|
23
26
|
return String(val);
|
|
@@ -44,4 +47,54 @@ export function FilterCachedFKRows(rows, query, limit, getName) {
|
|
|
44
47
|
}
|
|
45
48
|
return rows.filter(r => FormatFKCell(getName(r)).toLowerCase().includes(q));
|
|
46
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Rank lookup rows so that names *starting with* what the user typed come before names that
|
|
52
|
+
* merely contain it somewhere, alphabetically within each tier.
|
|
53
|
+
*
|
|
54
|
+
* Three typed letters otherwise match any name containing them anywhere, so an organization
|
|
55
|
+
* whose name merely happens to include the sequence outranks the one the user was reaching for.
|
|
56
|
+
* An empty query is a single tier, alphabetical.
|
|
57
|
+
*
|
|
58
|
+
* @returns A NEW array (never mutates the input).
|
|
59
|
+
*/
|
|
60
|
+
export function RankByPrefix(rows, query, nameField) {
|
|
61
|
+
const q = query.trim().toLowerCase();
|
|
62
|
+
const nameOf = (row) => FormatFKCell(row.Values[nameField]).toLowerCase();
|
|
63
|
+
const tierOf = (row) => (!q || nameOf(row).startsWith(q) ? 0 : 1);
|
|
64
|
+
return [...rows].sort((a, b) => tierOf(a) - tierOf(b) || nameOf(a).localeCompare(nameOf(b)));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Escape free text for interpolation into a SQL Server `LIKE` pattern: quotes doubled so the
|
|
68
|
+
* string literal stays closed, and `%`, `_`, `[` bracketed so a user typing "50%" or "a_b" gets
|
|
69
|
+
* literal matches instead of live wildcards.
|
|
70
|
+
*
|
|
71
|
+
* Bracketing rather than an `ESCAPE` clause, so a caller can drop the result into an existing
|
|
72
|
+
* pattern without also having to declare an escape character.
|
|
73
|
+
*/
|
|
74
|
+
export function EscapeSqlLikeValue(text) {
|
|
75
|
+
return (text ?? '')
|
|
76
|
+
.replace(/\0/g, '')
|
|
77
|
+
.replace(/'/g, "''")
|
|
78
|
+
.replace(/\[/g, '[[]')
|
|
79
|
+
.replace(/%/g, '[%]')
|
|
80
|
+
.replace(/_/g, '[_]');
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Build the `'a','b'` body of an `IN (...)` clause from a list of primary-key values. Blanks and
|
|
84
|
+
* case-insensitive duplicates are dropped; quotes inside a value are doubled.
|
|
85
|
+
*
|
|
86
|
+
* Single-column keys only — a composite key's compact segment is not a SQL literal.
|
|
87
|
+
*/
|
|
88
|
+
export function QuoteSqlIdList(ids) {
|
|
89
|
+
const seen = new Set();
|
|
90
|
+
const quoted = [];
|
|
91
|
+
for (const id of ids) {
|
|
92
|
+
const value = (id ?? '').trim();
|
|
93
|
+
if (!value || seen.has(value.toLowerCase()))
|
|
94
|
+
continue;
|
|
95
|
+
seen.add(value.toLowerCase());
|
|
96
|
+
quoted.push(`'${value.replace(/'/g, "''")}'`);
|
|
97
|
+
}
|
|
98
|
+
return quoted.join(',');
|
|
99
|
+
}
|
|
47
100
|
//# sourceMappingURL=fk-search-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fk-search-utils.js","sourceRoot":"","sources":["../../../src/lib/field/fk-search-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH
|
|
1
|
+
{"version":3,"file":"fk-search-utils.js","sourceRoot":"","sources":["../../../src/lib/field/fk-search-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEzE;;;;;;;;GA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CAAC,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;YAAE,SAAS;QACtD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["/**\n * Pure, framework-free helpers for the FK autocomplete in {@link MjFormFieldComponent}.\n *\n * These functions hold the parts of the FK search UX that have real logic worth\n * unit-testing in isolation — cell formatting, the in-memory cached-entity filter,\n * and the empty-input \"focus-show\" (first N, sorted by name). Keeping them out of\n * the Angular component means they can be tested without TestBed / DI.\n */\n\nimport { IsDateOnlySQLType, FormatDateOnly } from '@memberjunction/core';\n\n/**\n * Format a raw entity cell value for display in the dropdown.\n * - `Date` → locale date string; a SQL `date` column (pass its `sqlType`) is a calendar day that\n * arrives as UTC midnight and is rendered as its stored day rather than shifted into the\n * reader's zone (MJ#4210); a timestamp names an instant and stays in local time\n * - `null` / `undefined` → empty string\n * - `boolean` → `Yes` / `No`\n * - everything else → `String(value)`\n */\nexport function FormatFKCell(val: unknown, sqlType?: string | null): string {\n if (val === null || val === undefined) return '';\n if (val instanceof Date) return IsDateOnlySQLType(sqlType) ? FormatDateOnly(val) : val.toLocaleDateString();\n if (typeof val === 'boolean') return val ? 'Yes' : 'No';\n return String(val);\n}\n\n/**\n * In-memory filter/sort over cached rows for the FK dropdown.\n *\n * - **Empty query** → returns the first `limit` rows sorted ascending by the\n * formatted name field (the \"focus-show\" behavior).\n * - **Non-empty query** → returns every row whose formatted name field contains\n * the query as a case-insensitive substring (no limit; the full match set).\n *\n * `getName` extracts the raw name-field value for a row; formatting + comparison\n * are handled here so callers don't duplicate the rules.\n *\n * @returns A NEW array (never mutates the input) suitable for rendering.\n */\nexport function FilterCachedFKRows<T>(\n rows: ReadonlyArray<T>,\n query: string,\n limit: number,\n getName: (row: T) => unknown\n): T[] {\n const q = query.trim().toLowerCase();\n if (q.length === 0) {\n return [...rows]\n .sort((a, b) => FormatFKCell(getName(a)).localeCompare(FormatFKCell(getName(b))))\n .slice(0, limit);\n }\n return rows.filter(r => FormatFKCell(getName(r)).toLowerCase().includes(q));\n}\n\n/**\n * Rank lookup rows so that names *starting with* what the user typed come before names that\n * merely contain it somewhere, alphabetically within each tier.\n *\n * Three typed letters otherwise match any name containing them anywhere, so an organization\n * whose name merely happens to include the sequence outranks the one the user was reaching for.\n * An empty query is a single tier, alphabetical.\n *\n * @returns A NEW array (never mutates the input).\n */\nexport function RankByPrefix<T extends { Values: Record<string, unknown> }>(\n rows: ReadonlyArray<T>,\n query: string,\n nameField: string\n): T[] {\n const q = query.trim().toLowerCase();\n const nameOf = (row: T): string => FormatFKCell(row.Values[nameField]).toLowerCase();\n const tierOf = (row: T): number => (!q || nameOf(row).startsWith(q) ? 0 : 1);\n return [...rows].sort((a, b) => tierOf(a) - tierOf(b) || nameOf(a).localeCompare(nameOf(b)));\n}\n\n/**\n * Escape free text for interpolation into a SQL Server `LIKE` pattern: quotes doubled so the\n * string literal stays closed, and `%`, `_`, `[` bracketed so a user typing \"50%\" or \"a_b\" gets\n * literal matches instead of live wildcards.\n *\n * Bracketing rather than an `ESCAPE` clause, so a caller can drop the result into an existing\n * pattern without also having to declare an escape character.\n */\nexport function EscapeSqlLikeValue(text: string): string {\n return (text ?? '')\n .replace(/\\0/g, '')\n .replace(/'/g, \"''\")\n .replace(/\\[/g, '[[]')\n .replace(/%/g, '[%]')\n .replace(/_/g, '[_]');\n}\n\n/**\n * Build the `'a','b'` body of an `IN (...)` clause from a list of primary-key values. Blanks and\n * case-insensitive duplicates are dropped; quotes inside a value are doubled.\n *\n * Single-column keys only — a composite key's compact segment is not a SQL literal.\n */\nexport function QuoteSqlIdList(ids: ReadonlyArray<string>): string {\n const seen = new Set<string>();\n const quoted: string[] = [];\n for (const id of ids) {\n const value = (id ?? '').trim();\n if (!value || seen.has(value.toLowerCase())) continue;\n seen.add(value.toLowerCase());\n quoted.push(`'${value.replace(/'/g, \"''\")}'`);\n }\n return quoted.join(',');\n}\n"]}
|