Foundational types and base classes for Angular components in the MemberJunction ecosystem, providing common functionality and type definitions.
This package provides essential building blocks for Angular applications using MemberJunction:
npm install @memberjunction/ng-base-types
Abstract base class that all MemberJunction Angular components should extend:
import { BaseAngularComponent } from '@memberjunction/ng-base-types';
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'my-component',
templateUrl: './my-component.html'
})
export class MyComponent extends BaseAngularComponent implements OnInit {
ngOnInit() {
// Access the metadata provider
const metadata = this.ProviderToUse;
// Use RunView functionality
const viewProvider = this.RunViewToUse;
// Execute queries
const queryProvider = this.RunQueryToUse;
// Run reports
const reportProvider = this.RunReportToUse;
}
}
| Property | Type | Description |
|---|---|---|
Provider |
IMetadataProvider | null |
Optional custom provider instance. If not specified, uses the default global provider. |
| Method | Return Type | Description |
|---|---|---|
ProviderToUse |
IMetadataProvider |
Returns the Provider if specified, otherwise returns the default Metadata.Provider |
RunViewToUse |
IRunViewProvider |
Returns the provider cast as IRunViewProvider for running views |
RunQueryToUse |
IRunQueryProvider |
Returns the provider cast as IRunQueryProvider for executing queries |
RunReportToUse |
IRunReportProvider |
Returns the provider cast as IRunReportProvider for running reports |
Constants for event type identification:
const BaseFormComponentEventCodes = {
BASE_CODE: 'BaseFormComponent_Event',
EDITING_COMPLETE: 'EDITING_COMPLETE',
REVERT_PENDING_CHANGES: 'REVERT_PENDING_CHANGES',
POPULATE_PENDING_RECORDS: 'POPULATE_PENDING_RECORDS'
}
Base class for all form component events:
class BaseFormComponentEvent {
subEventCode: string; // Event type identifier
elementRef: any; // Reference to the emitting element
returnValue: any; // Optional return value
}
Specialized event emitted when form editing is complete:
class FormEditingCompleteEvent extends BaseFormComponentEvent {
subEventCode: string = BaseFormComponentEventCodes.EDITING_COMPLETE;
pendingChanges: PendingRecordItem[] = [];
}
Represents a record pending save or delete:
class PendingRecordItem {
entityObject: BaseEntity; // The entity to be processed
action: 'save' | 'delete' = 'save'; // Action to perform
}
import { Component, OnInit } from '@angular/core';
import { BaseAngularComponent } from '@memberjunction/ng-base-types';
import { GraphQLDataProvider } from '@memberjunction/graphql-dataprovider';
@Component({
selector: 'app-custom-provider',
template: `
<div>
<child-component [Provider]="customProvider"></child-component>
</div>
`
})
export class CustomProviderComponent extends BaseAngularComponent implements OnInit {
customProvider: GraphQLDataProvider;
ngOnInit() {
// Create a custom provider for a different API endpoint
this.customProvider = new GraphQLDataProvider({
endpoint: 'https://api.example.com/graphql',
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
}
});
}
}
import { Component, EventEmitter, Output } from '@angular/core';
import {
BaseAngularComponent,
BaseFormComponentEvent,
BaseFormComponentEventCodes,
FormEditingCompleteEvent,
PendingRecordItem
} from '@memberjunction/ng-base-types';
@Component({
selector: 'app-form-handler',
template: `...`
})
export class FormHandlerComponent extends BaseAngularComponent {
@Output() formEvent = new EventEmitter<BaseFormComponentEvent>();
async handleFormSubmit(entities: BaseEntity[]) {
// Create the event
const event = new FormEditingCompleteEvent();
// Add pending changes
event.pendingChanges = entities.map(entity => ({
entityObject: entity,
action: 'save' as const
}));
// Emit the event
this.formEvent.emit(event);
}
onFormEvent(event: BaseFormComponentEvent) {
switch (event.subEventCode) {
case BaseFormComponentEventCodes.EDITING_COMPLETE:
const editEvent = event as FormEditingCompleteEvent;
this.processPendingChanges(editEvent.pendingChanges);
break;
case BaseFormComponentEventCodes.REVERT_PENDING_CHANGES:
this.revertChanges();
break;
case BaseFormComponentEventCodes.POPULATE_PENDING_RECORDS:
this.populateRecords();
break;
}
}
private async processPendingChanges(changes: PendingRecordItem[]) {
for (const item of changes) {
try {
if (item.action === 'save') {
await item.entityObject.Save();
} else if (item.action === 'delete') {
await item.entityObject.Delete();
}
} catch (error) {
console.error(`Failed to ${item.action} entity:`, error);
}
}
}
}
import { Component } from '@angular/core';
import { BaseAngularComponent } from '@memberjunction/ng-base-types';
import { GraphQLDataProvider } from '@memberjunction/graphql-dataprovider';
@Component({
selector: 'app-multi-tenant',
template: `
<div class="tenant-a">
<user-list [Provider]="tenantAProvider"></user-list>
</div>
<div class="tenant-b">
<user-list [Provider]="tenantBProvider"></user-list>
</div>
`
})
export class MultiTenantComponent extends BaseAngularComponent {
tenantAProvider = new GraphQLDataProvider({
endpoint: 'https://tenant-a.example.com/graphql'
});
tenantBProvider = new GraphQLDataProvider({
endpoint: 'https://tenant-b.example.com/graphql'
});
}
@memberjunction/core: Core MemberJunction functionality@memberjunction/core-entities: Entity definitions@memberjunction/global: Global utilitiestslib: TypeScript runtime helpers@angular/common: ^18.0.2@angular/core: ^18.0.2This package uses Angular's ngc compiler for building:
npm run build
The package is configured with:
This package is designed to work seamlessly with other MemberJunction packages:
If upgrading from a previous version:
BaseAngularComponentMetadata usage with this.ProviderToUseRunQueryToUse and RunReportToUse getters in the current implementation have incomplete type casting. Ensure your provider implements all required interfaces.When contributing to this package:
ISC