BaseDetailComponent

BaseDetailComponent

A base class for entity detail views. It should be used in conjunction with the BaseEntityResolver.

Example

@Component({
  selector: 'app-my-entity',
  templateUrl: './my-entity.component.html',
  styleUrls: ['./my-entity.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class GlobalSettingsComponent extends BaseDetailComponent<MyEntity.Fragment> implements OnInit {
  detailForm: FormGroup;

  constructor(
    router: Router,
    route: ActivatedRoute,
    serverConfigService: ServerConfigService,
    protected dataService: DataService,
    private formBuilder: FormBuilder,
  ) {
    super(route, router, serverConfigService, dataService);
    this.detailForm = this.formBuilder.group({
      name: [''],
    });
  }

  protected setFormValues(entity: MyEntity.Fragment, languageCode: LanguageCode): void {
    this.detailForm.patchValue({
      name: entity.name,
    });
  }
}

Signature

class BaseDetailComponent<Entity extends { id: string; updatedAt?: string }> implements DeactivateAware {
  entity$: Observable<Entity>;
  availableLanguages$: Observable<LanguageCode[]>;
  languageCode$: Observable<LanguageCode>;
  isNew$: Observable<boolean>;
  id: string;
  abstract abstract detailForm: FormGroup;
  protected protected destroy$ = new Subject<void>();
  constructor(route: ActivatedRoute, router: Router, serverConfigService: ServerConfigService, dataService: DataService)
  init() => ;
  destroy() => ;
  setLanguage(code: LanguageCode) => ;
  canDeactivate() => boolean;
  protected abstract setFormValues(entity: Entity, languageCode: LanguageCode) => void;
  protected setCustomFieldFormValues(customFields: CustomFieldConfig[], formGroup: AbstractControl | null, entity: T, currentTranslation?: TranslationOf<T>) => ;
  protected getCustomFieldConfig(key: Exclude<keyof CustomFields, '__typename'>) => CustomFieldConfig[];
  protected setQueryParam(key: string, value: any) => ;
}

Implements

  • DeactivateAware

Members

entity$

property
type:
Observable<Entity>

availableLanguages$

property
type:
Observable<LanguageCode[]>

languageCode$

property
type:
Observable<LanguageCode>

isNew$

property
type:
Observable<boolean>

id

property
type:
string

detailForm

abstract property
type:
FormGroup

destroy$

protected property
type:

constructor

protected method
type:
(route: ActivatedRoute, router: Router, serverConfigService: ServerConfigService, dataService: DataService) => BaseDetailComponent

init

method
type:
() =>

destroy

method
type:
() =>

setLanguage

method
type:
(code: LanguageCode) =>

canDeactivate

method
type:
() => boolean

setFormValues

protected abstract method
type:
(entity: Entity, languageCode: LanguageCode) => void

setCustomFieldFormValues

protected method
type:
(customFields: CustomFieldConfig[], formGroup: AbstractControl | null, entity: T, currentTranslation?: TranslationOf<T>) =>

getCustomFieldConfig

protected method
type:
(key: Exclude<keyof CustomFields, '__typename'>) => CustomFieldConfig[]

setQueryParam

protected method
type:
(key: string, value: any) =>