From 94311870f6d02adc06aaf11585fddf64c9311164 Mon Sep 17 00:00:00 2001 From: Adam Coffman Date: Wed, 29 Nov 2023 15:06:35 -0600 Subject: [PATCH] allow the variant submit component to pass in a callback to determine if the variant was newly created or not --- .../variant-submit/variant-submit.form.html | 14 ++++++++++++-- .../config/variant-submit/variant-submit.form.ts | 11 +++-------- .../variant-quick-add/variant-quick-add.form.ts | 14 +++++--------- .../types/variant-select/variant-select.type.html | 2 +- .../types/variant-select/variant-select.type.ts | 15 ++++++++++++--- 5 files changed, 33 insertions(+), 23 deletions(-) diff --git a/client/src/app/forms/config/variant-submit/variant-submit.form.html b/client/src/app/forms/config/variant-submit/variant-submit.form.html index 554bee066..25336f5ec 100644 --- a/client/src/app/forms/config/variant-submit/variant-submit.form.html +++ b/client/src/app/forms/config/variant-submit/variant-submit.form.html @@ -15,16 +15,26 @@ + [nzDescription]="variantLink"> New Variant {{ variant.name }} added. - + View its details here. + + + Variant {{ variant.name }} already exists. + diff --git a/client/src/app/forms/config/variant-submit/variant-submit.form.ts b/client/src/app/forms/config/variant-submit/variant-submit.form.ts index 0d79b2ed0..808703f8f 100644 --- a/client/src/app/forms/config/variant-submit/variant-submit.form.ts +++ b/client/src/app/forms/config/variant-submit/variant-submit.form.ts @@ -2,8 +2,6 @@ import { ChangeDetectionStrategy, Component, EventEmitter, - OnDestroy, - OnInit, Output, } from '@angular/core' import { UntypedFormGroup } from '@angular/forms' @@ -11,12 +9,7 @@ import { CvcFieldGridWrapperConfig } from '@app/forms/wrappers/field-grid/field- import { CvcVariantSelectFieldOption } from '@app/forms/types/variant-select/variant-select.type' import { Maybe, Variant } from '@app/generated/civic.apollo' import { FormlyFieldConfig, FormlyFormOptions } from '@ngx-formly/core' -import { BehaviorSubject, Subject } from 'rxjs' -import { - FormGene, - FormMolecularProfile, - FormVariant, -} from '@app/forms/forms.interfaces' +import { BehaviorSubject } from 'rxjs' import { NzFormLayoutType } from 'ng-zorro-antd/form' import { EntityFieldSubjectMap } from '@app/forms/states/base.state' import { Apollo, gql } from 'apollo-angular' @@ -58,6 +51,7 @@ export class VariantSubmitForm { form: UntypedFormGroup config: FormlyFieldConfig[] layout: NzFormLayoutType = 'horizontal' + newlyCreated?: boolean finderState: VariantSubmitState = { formLayout: this.layout, @@ -103,6 +97,7 @@ export class VariantSubmitForm { showExtra: false, }, hideLabel: true, + isNewlyCreatedCallback: (isNew: boolean): void => {this.newlyCreated = isNew}, }, }, ], diff --git a/client/src/app/forms/types/variant-select/variant-quick-add/variant-quick-add.form.ts b/client/src/app/forms/types/variant-select/variant-quick-add/variant-quick-add.form.ts index 039b51e70..ae4abe2be 100644 --- a/client/src/app/forms/types/variant-select/variant-quick-add/variant-quick-add.form.ts +++ b/client/src/app/forms/types/variant-select/variant-quick-add/variant-quick-add.form.ts @@ -19,14 +19,12 @@ import { QuickAddVariantGQL, QuickAddVariantMutation, QuickAddVariantMutationVariables, - Variant, - VariantSelectTypeaheadFieldsFragment, } from '@app/generated/civic.apollo' import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy' -import { FormlyFieldConfig, FormlyFormOptions } from '@ngx-formly/core' +import { FormlyFieldConfig } from '@ngx-formly/core' import { NzFormLayoutType } from 'ng-zorro-antd/form' -import { BehaviorSubject, Observable, Subject } from 'rxjs' -import { CvcOrgSubmitButtonFieldConfig } from '../../org-submit-button/org-submit-button.type' +import { BehaviorSubject, Subject } from 'rxjs' +import { VariantIdWithCreationStatus } from '../variant-select.type' type VariantQuickAddModel = { name?: string @@ -62,7 +60,7 @@ export class CvcVariantQuickAddForm implements OnChanges { this.searchString$.next(str) } - @Output() cvcOnCreate = new EventEmitter() + @Output() cvcOnCreate = new EventEmitter() model: Partial form: UntypedFormGroup @@ -193,9 +191,7 @@ export class CvcVariantQuickAddForm implements OnChanges { this.formMessageDisplay$.next({ message: undefined }) setTimeout(() => { if (data && data.createVariant) { - const variant = data.createVariant - .variant as VariantSelectTypeaheadFieldsFragment - this.cvcOnCreate.next(variant.id) + this.cvcOnCreate.next({id: data.createVariant.variant.id, new: data.createVariant.new}) } }, 1000) } diff --git a/client/src/app/forms/types/variant-select/variant-select.type.html b/client/src/app/forms/types/variant-select/variant-select.type.html index 729f4603a..1d255236e 100644 --- a/client/src/app/forms/types/variant-select/variant-select.type.html +++ b/client/src/app/forms/types/variant-select/variant-select.type.html @@ -115,6 +115,6 @@ [cvcSearchString]="searchStr" [cvcGeneId]="onGeneId$ | ngrxPush" [cvcGeneName]="onGeneName$ | ngrxPush" - (cvcOnCreate)="onPopulate$.next($event)"> + (cvcOnCreate)="onSelectOrCreate($event)"> diff --git a/client/src/app/forms/types/variant-select/variant-select.type.ts b/client/src/app/forms/types/variant-select/variant-select.type.ts index 9fb12158f..93c4c4c4b 100644 --- a/client/src/app/forms/types/variant-select/variant-select.type.ts +++ b/client/src/app/forms/types/variant-select/variant-select.type.ts @@ -30,7 +30,6 @@ import { FormlyFieldConfig, FormlyFieldProps, } from '@ngx-formly/core' -import { Apollo } from 'apollo-angular' import { NzSelectOptionInterface } from 'ng-zorro-antd/select' import { BehaviorSubject, @@ -39,16 +38,19 @@ import { map, Observable, ReplaySubject, - startWith, Subject, scan, withLatestFrom, filter, take, } from 'rxjs' -import { tag } from 'rxjs-spy/operators' import mixin from 'ts-mixin-extended' +export interface VariantIdWithCreationStatus { + new: boolean + id: number +} + export type CvcVariantSelectFieldOption = Partial< FieldTypeConfig> > @@ -265,6 +267,13 @@ export class CvcVariantSelectField ) } + onSelectOrCreate(variant: VariantIdWithCreationStatus) { + this.onPopulate$.next(variant.id) + if(this.props.isNewlyCreatedCallback) { + this.props.isNewlyCreatedCallback(variant.new) + } + } + private onGeneId(gid: Maybe): void { this.selectedGeneId = gid // if field config indicates that a geneId is required, and none is provided,