Skip to content

Commit

Permalink
Remove Select from AQL builder in Criteria mode
Browse files Browse the repository at this point in the history
  • Loading branch information
askask committed Aug 20, 2024
1 parent 8b4a9e1 commit 331d9ee
Show file tree
Hide file tree
Showing 19 changed files with 217 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
<h2 class="mat-headline-3">From</h2>
<h2 *ngIf="dialogMode !== AqlBuilderDialogMode.Criteria" class="mat-headline-3">From</h2>

<div class="num-select-box contains" fxLayout="column" fxLayoutGap="20px">
<div *ngIf="dialogMode === AqlBuilderDialogMode.Criteria">
<h2 class="mat-headline-3 pointer" (click)="setDestination()">From</h2>
<div
class="num-select-flag pointer"
[ngClass]="{
'num-select-flag--active': aqbModel.selectDestination === AqbSelectDestination.From
}"
role="button"
tabindex="0"
aria-labelledby="section-heading"
(keydown.enter)="setDestination()"
(keydown.space)="setDestination()"
(click)="setDestination()"
data-test="aqb__select__set-destination-button"
>
<fa-icon icon="check"></fa-icon>
</div>
</div>

<div
class="num-select-box"
fxLayout="column"
fxLayoutGap="20px"
[ngClass]="{
'num-select-box--active': aqbModel.selectDestination === AqbSelectDestination.From,
contains: dialogMode !== AqlBuilderDialogMode.Criteria
}"
>
<num-aql-builder-contains-group
*ngFor="let composition of compositions; let i = index"
role="list"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AqbContainsCompositionUiModel } from '../../../../shared/models/aqb/aqb
import { AqbUiModel } from '../../../../shared/models/aqb/aqb-ui.model'

import { AqlBuilderContainsComponent } from './aql-builder-contains.component'
import { FontAwesomeTestingModule } from '@fortawesome/angular-fontawesome/testing'

describe('AqlBuilderContainsComponent', () => {
let component: AqlBuilderContainsComponent
Expand Down Expand Up @@ -35,6 +36,7 @@ describe('AqlBuilderContainsComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [AqlBuilderContainsComponent, ContainsGroupStubComponent],
imports: [FontAwesomeTestingModule],
}).compileComponents()
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component, Input } from '@angular/core'
import { AqbContainsCompositionUiModel } from '../../../../shared/models/aqb/aqb-contains-composition-ui.model'
import { AqbUiModel } from '../../../../shared/models/aqb/aqb-ui.model'
import { AqbSelectDestination } from '../../../../shared/models/aqb/aqb-select-destination.enum'
import { AqlBuilderDialogMode } from '../../../../shared/models/archetype-query-builder/aql-builder-dialog-mode.enum'

@Component({
selector: 'num-aql-builder-contains',
Expand All @@ -16,6 +18,9 @@ export class AqlBuilderContainsComponent {
@Input()
compositions: AqbContainsCompositionUiModel[] = []

@Input()
dialogMode: AqlBuilderDialogMode = AqlBuilderDialogMode.Criteria

deleteCompositionByReferenceId(compositionReferenceId: number): void {
this.aqbModel.handleDeletionByCompositionReferenceIds([compositionReferenceId])
this.compositions = this.compositions.filter(
Expand All @@ -26,4 +31,11 @@ export class AqlBuilderContainsComponent {
deleteArchetypesByReferenceIds(archetypeReferenceIds: number[]): void {
this.aqbModel.handleDeletionByArchetypeReferenceIds(archetypeReferenceIds)
}

setDestination(): void {
this.aqbModel.selectDestination = AqbSelectDestination.From
}

protected readonly AqbSelectDestination = AqbSelectDestination
protected readonly AqlBuilderDialogMode = AqlBuilderDialogMode
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<section fxLayout="row wrap" fxLayoutGap="15px" fxLayoutAlign="start center">
<div class="name-field mat-body-strong" data-test="aqb__select__item__name">
<span>{{ item.name | archetype: true }}</span>
<span *ngIf="item.isComposition"> ({{ item.templateId }})</span>
<span *ngIf="item.modelType"> ({{ item.templateId }})</span>
</div>
</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('AqlBuilderSelectItemComponent', () => {
containmentTreeNode,
compositionReferenceId,
archetypeReferenceId,
false,
'archetype',
templateId
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
<h2 id="section-heading" class="mat-headline-3 pointer" (click)="setDestination()">Select</h2>
<div
class="num-select-flag pointer"
[ngClass]="{
'num-select-flag--active': aqbModel.selectDestination === AqbSelectDestination.Select
}"
role="button"
tabindex="0"
aria-labelledby="section-heading"
(keydown.enter)="setDestination()"
(keydown.space)="setDestination()"
(click)="setDestination()"
data-test="aqb__select__set-destination-button"
>
<fa-icon icon="check"></fa-icon>
<div *ngIf="dialogMode === AqlBuilderDialogMode.Criteria">
<h2 id="section-heading" class="mat-headline-3">Select</h2>
<p>
{{ 'QUERIES.NO_SELECT' | translate }}
</p>
</div>
<div
class="num-select-box"
fxLayout="column"
[ngClass]="{
'num-select-box--active': aqbModel.selectDestination === AqbSelectDestination.Select
}"
>
<num-aql-builder-select-item
class="aqb-item mat-elevation-z2"

<div *ngIf="dialogMode !== AqlBuilderDialogMode.Criteria">
<h2 id="section-heading" class="mat-headline-3 pointer" (click)="setDestination()">Select</h2>
<div
class="num-select-flag pointer"
[ngClass]="{
'aqb-item--last': i === aqbModel.select.length - 1
'num-select-flag--active': aqbModel.selectDestination === AqbSelectDestination.Select
}"
fxLayout="row"
fxLayoutAlign="space-between start"
*ngFor="let item of aqbModel.select; let i = index"
[item]="item"
(deleteItem)="deleteItem(i)"
data-test="aqb__select__item"
></num-aql-builder-select-item>
role="button"
tabindex="0"
aria-labelledby="section-heading"
(keydown.enter)="setDestination()"
(keydown.space)="setDestination()"
(click)="setDestination()"
data-test="aqb__select__set-destination-button"
>
<fa-icon icon="check"></fa-icon>
</div>
<div
class="num-select-box"
fxLayout="column"
[ngClass]="{
'num-select-box--active': aqbModel.selectDestination === AqbSelectDestination.Select
}"
>
<num-aql-builder-select-item
class="aqb-item mat-elevation-z2"
[ngClass]="{
'aqb-item--last': i === aqbModel.select.length - 1
}"
fxLayout="row"
fxLayoutAlign="space-between start"
*ngFor="let item of aqbModel.select; let i = index"
[item]="item"
(deleteItem)="deleteItem(i)"
data-test="aqb__select__item"
></num-aql-builder-select-item>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, Input } from '@angular/core'

import { AqbSelectDestination } from '../../../../shared/models/aqb/aqb-select-destination.enum'
import { AqbUiModel } from '../../../../shared/models/aqb/aqb-ui.model'
import { AqlBuilderDialogMode } from '../../../../shared/models/archetype-query-builder/aql-builder-dialog-mode.enum'

@Component({
selector: 'num-aql-builder-select',
Expand All @@ -15,11 +16,16 @@ export class AqlBuilderSelectComponent {
@Input()
aqbModel: AqbUiModel

@Input()
dialogMode: AqlBuilderDialogMode = AqlBuilderDialogMode.Criteria

deleteItem(index: number): void {
this.aqbModel.select.splice(index, 1)
}

setDestination(): void {
this.aqbModel.selectDestination = AqbSelectDestination.Select
}

protected readonly AqlBuilderDialogMode = AqlBuilderDialogMode
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
class="mat-tree-node__display-name"
[ngClass]="{
'mat-tree-node__display-name--disabled':
mode === Mode.DataRetrieval && selectDestination === Destination.Select
(mode === Mode.DataRetrieval && selectDestination === Destination.Select) ||
(mode === Mode.Criteria && selectDestination === Destination.From)
}"
>{{ node.displayName }}</span
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('AqlEditorCeatorComponent', () => {

describe('When a query is supposed to be created with the builder', () => {
const dialogContentPayload: IAqlBuilderDialogInput = {
mode: AqlBuilderDialogMode.Criteria,
mode: AqlBuilderDialogMode.Search,
model: new AqbUiModel(),
}
const dialogConfig: DialogConfig = {
Expand All @@ -158,7 +158,7 @@ describe('AqlEditorCeatorComponent', () => {
}

it('should open the dialog with the config including the content payload', () => {
component.openBuilderDialog(AqlBuilderDialogMode.Criteria)
component.openBuilderDialog(AqlBuilderDialogMode.Search)
expect(mockDialogService.openDialog).toHaveBeenCalledTimes(1)
expect(dialogCallParameter.dialogContentComponent).toEqual(
dialogConfig.dialogContentComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import {
VALIDATION_ERROR_CONFIG,
VALIDATION_SUCCESS_CONFIG,
} from './constants'
import { AqbSelectDestination } from '../../../../shared/models/aqb/aqb-select-destination.enum'
import { AqbSelectItemUiModel } from '../../../../shared/models/aqb/aqb-select-item-ui.model'
import { IContainmentTreeNode } from '../../models/containment-tree-node.interface'

@Component({
selector: 'num-aql-editor-creator',
Expand Down Expand Up @@ -115,6 +118,14 @@ export class AqlEditorCeatorComponent {
}

openBuilderDialog(mode: AqlBuilderDialogMode): void {
if (mode === AqlBuilderDialogMode.Criteria) {
const node = new (class implements IContainmentTreeNode {
displayName = 'EHR'
})()
this.aqbModel.selectDestination = AqbSelectDestination.From
this.aqbModel.select = [new AqbSelectItemUiModel(node, 0, 0, 'ehr', '')]
}

const dialogContentPayload: IAqlBuilderDialogInput = {
mode: mode,
model: this.aqbModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
></num-aql-builder-templates>

<section role="region" fxFlex="auto" fxLayout="column" fxLayoutGap="24px">
<num-aql-builder-select [aqbModel]="aqbModel"></num-aql-builder-select>
<num-aql-builder-select
[aqbModel]="aqbModel"
[dialogMode]="dialogInput.mode"
></num-aql-builder-select>
<num-aql-builder-contains
[aqbModel]="aqbModel"
[compositions]="compositions"
[dialogMode]="dialogInput.mode"
></num-aql-builder-contains>
<num-aql-builder-where
[aqbModel]="aqbModel"
Expand All @@ -31,7 +35,11 @@

<num-button
type="primary"
[isDisabled]="!aqbModel.select.length"
[isDisabled]="
dialogInput.mode === AqlBuilderDialogMode.Criteria
? !aqbModel.contains.compositions.size
: !aqbModel.select.length
"
(singleClick)="handleDialogConfirm()"
data-test="aqb__confirm-button"
>{{ 'BUTTON.APPLY_SELECTION' | translate }}</num-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { AqbUiModel } from '../../../../shared/models/aqb/aqb-ui.model'
import { COMPILE_ERROR_CONFIG } from './constants'

import { DialogAqlBuilderComponent } from './dialog-aql-builder.component'
import { selectClickTestCases } from './tests/select-click-testcases'
import { ISelectClickTest, selectClickTestCases } from './tests/select-click-testcases'

describe('DialogAqlBuilderComponent', () => {
let component: DialogAqlBuilderComponent
Expand All @@ -36,11 +36,13 @@ describe('DialogAqlBuilderComponent', () => {
@Component({ selector: 'num-aql-builder-select', template: '' })
class SelectStubComponent {
@Input() aqbModel: any
@Input() dialogMode: any
}
@Component({ selector: 'num-aql-builder-contains', template: '' })
class ContainsStubComponent {
@Input() compositions: any
@Input() aqbModel: any
@Input() dialogMode: any
}
@Component({ selector: 'num-aql-builder-where', template: '' })
class WhereStubComponent {
Expand Down Expand Up @@ -86,10 +88,10 @@ describe('DialogAqlBuilderComponent', () => {
jest.clearAllMocks()
})

describe('When the dialog is in aqlEditor mode', () => {
describe('When the dialog is in Search mode', () => {
beforeEach(() => {
component.dialogInput = {
mode: AqlBuilderDialogMode.Criteria,
mode: AqlBuilderDialogMode.Search,
model: new AqbUiModel(),
}

Expand All @@ -100,9 +102,20 @@ describe('DialogAqlBuilderComponent', () => {
expect(component).toBeTruthy()
expect(aqlEditorService.getTemplates).toHaveBeenCalled()
})
})

describe('When the dialog is', () => {
beforeEach(() => {
component.dialogInput = {
mode: AqlBuilderDialogMode.Search, //overwritten in test
model: new AqbUiModel(),
}

fixture.detectChanges()
})

test.each(selectClickTestCases)(
'should call or not call the aqb Model to handle the clickEvent',
test.each<ISelectClickTest>(selectClickTestCases)(
'in $mode mode should call or not call the aqb Model to handle the clickEvent (%#)',
(testcase) => {
jest.spyOn(component.aqbModel, 'handleElementSelect')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,22 @@ export class DialogAqlBuilderComponent

return false
}
isAllowedSelectionInEditor(clickEvent: IAqbSelectClick): boolean {

isAllowedSelectionInCriteria(clickEvent: IAqbSelectClick): boolean {
if (this.aqbModel.selectDestination === AqbSelectDestination.From) {
if (!clickEvent.item.rmType) {
return true
}
} else {
if (clickEvent.item.rmType) {
return true
}
}

return false
}

isAllowedSelectionInSearch(clickEvent: IAqbSelectClick): boolean {
if (this.aqbModel.selectDestination === AqbSelectDestination.Select) {
return true
} else {
Expand All @@ -96,9 +111,14 @@ export class DialogAqlBuilderComponent
}

isAllowedSelection(clickEvent: IAqbSelectClick): boolean {
return this.dialogInput.mode === AqlBuilderDialogMode.DataRetrieval
? this.isAllowedSelectionInRetrieval(clickEvent)
: this.isAllowedSelectionInEditor(clickEvent)
switch (this.dialogInput.mode) {
case AqlBuilderDialogMode.DataRetrieval:
return this.isAllowedSelectionInRetrieval(clickEvent)
case AqlBuilderDialogMode.Criteria:
return this.isAllowedSelectionInCriteria(clickEvent)
case AqlBuilderDialogMode.Search:
return this.isAllowedSelectionInSearch(clickEvent)
}
}

handleItemSelect(clickEvent: IAqbSelectClick): void {
Expand Down Expand Up @@ -126,4 +146,6 @@ export class DialogAqlBuilderComponent
handleDialogCancel(): void {
this.closeDialog.emit()
}

protected readonly AqlBuilderDialogMode = AqlBuilderDialogMode
}
Loading

0 comments on commit 331d9ee

Please sign in to comment.