Skip to content

Commit

Permalink
allow the variant submit component to pass in a callback to determine…
Browse files Browse the repository at this point in the history
… if the variant was newly created or not
  • Loading branch information
acoffman committed Nov 29, 2023
1 parent 99194da commit 9431187
Showing 5 changed files with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -15,16 +15,26 @@
<ng-template #variantCreated>
<ng-container *ngIf="newVariant$ | ngrxPush as variant">
<nz-alert
*ngIf="newlyCreated"
nzType="success"
nzShowIcon
[nzMessage]="successMessage"
[nzDescription]="successDescription"></nz-alert>
[nzDescription]="variantLink"></nz-alert>
<ng-template #successMessage>
New Variant {{ variant.name }} added.
</ng-template>
<ng-template #successDescription>
<ng-template #variantLink>
View its
<a [routerLink]="['/variants', variant.id, 'summary']">details here</a>.
</ng-template>
<nz-alert
*ngIf="!newlyCreated"
nzType="info"
nzShowIcon
[nzMessage]="existsMessage"
[nzDescription]="variantLink"></nz-alert>
<ng-template #existsMessage>
Variant {{ variant.name }} already exists.
</ng-template>
</ng-container>
</ng-template>
Original file line number Diff line number Diff line change
@@ -2,21 +2,14 @@ import {
ChangeDetectionStrategy,
Component,
EventEmitter,
OnDestroy,
OnInit,
Output,
} from '@angular/core'
import { UntypedFormGroup } from '@angular/forms'
import { CvcFieldGridWrapperConfig } from '@app/forms/wrappers/field-grid/field-grid.wrapper'
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},
},
},
],
Original file line number Diff line number Diff line change
@@ -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<number>()
@Output() cvcOnCreate = new EventEmitter<VariantIdWithCreationStatus>()

model: Partial<QuickAddVariantMutationVariables>
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)
}
Original file line number Diff line number Diff line change
@@ -115,6 +115,6 @@
[cvcSearchString]="searchStr"
[cvcGeneId]="onGeneId$ | ngrxPush"
[cvcGeneName]="onGeneName$ | ngrxPush"
(cvcOnCreate)="onPopulate$.next($event)">
(cvcOnCreate)="onSelectOrCreate($event)">
</cvc-variant-quick-add-form>
</ng-template>
15 changes: 12 additions & 3 deletions client/src/app/forms/types/variant-select/variant-select.type.ts
Original file line number Diff line number Diff line change
@@ -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<Partial<CvcVariantSelectFieldProps>>
>
@@ -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<number>): void {
this.selectedGeneId = gid
// if field config indicates that a geneId is required, and none is provided,

0 comments on commit 9431187

Please sign in to comment.