Skip to content

Commit

Permalink
Merge pull request #959 from griffithlab/fix-variant-creation-message
Browse files Browse the repository at this point in the history
Fix variant creation success message.
  • Loading branch information
susannasiebert authored Dec 1, 2023
2 parents 18c653b + a6a02e1 commit 6a76ffc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
19 changes: 2 additions & 17 deletions client/src/app/forms/config/variant-submit/variant-submit.form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import { CvcVariantSelectFieldOption } from '@app/forms/types/variant-select/var
import { Maybe, Variant } from '@app/generated/civic.apollo'
import { FormlyFieldConfig, FormlyFormOptions } from '@ngx-formly/core'
import { BehaviorSubject } from 'rxjs'
import {
FormGene,
FormMolecularProfile,
FormVariant,
} from '@app/forms/forms.interfaces'
import { NzFormLayoutType } from 'ng-zorro-antd/form'
import { EntityFieldSubjectMap } from '@app/forms/states/base.state'
import { Apollo, gql } from 'apollo-angular'
Expand All @@ -29,18 +24,6 @@ type VariantSubmitState = {
fields: EntityFieldSubjectMap
}

// interface FormModel {
// fields: {
// gene: FormGene[]
// variant: FormVariant[]
// }
// }

// export interface SelectedVariant {
// variantId: number
// molecularProfile: FormMolecularProfile
// }

@Component({
selector: 'cvc-variant-submit-form',
templateUrl: './variant-submit.form.html',
Expand All @@ -56,6 +39,7 @@ export class VariantSubmitForm {
form: UntypedFormGroup
config: FormlyFieldConfig[]
layout: NzFormLayoutType = 'horizontal'
newlyCreated?: boolean

finderState: VariantSubmitState = {
formLayout: this.layout,
Expand Down Expand Up @@ -101,6 +85,7 @@ export class VariantSubmitForm {
showExtra: false,
},
hideLabel: true,
isNewlyCreatedCallback: (isNew: boolean): void => {this.newlyCreated = isNew},
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -196,9 +194,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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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,
Expand All @@ -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>>
>
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6a76ffc

Please sign in to comment.