All files / app/codeCharta/ui/attributeSideBar/attributeTypeSelector attributeTypeSelector.component.ts

92.85% Statements 13/14
100% Branches 0/0
75% Functions 3/4
92.3% Lines 12/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 415x 5x 5x 5x 5x 5x 5x               5x       32x   32x             1x       1x                  
import { Component, Input } from "@angular/core"
import { Store } from "@ngrx/store"
import { AttributeTypes, AttributeTypeValue, CcState } from "../../../codeCharta.model"
import { updateAttributeType } from "../../../state/store/fileSettings/attributeTypes/attributeTypes.actions"
import { attributeTypesSelector } from "../../../state/store/fileSettings/attributeTypes/attributeTypes.selector"
import { MatButtonToggleGroup, MatButtonToggle } from "@angular/material/button-toggle"
import { AsyncPipe } from "@angular/common"
 
@Component({
    selector: "cc-attribute-type-selector",
    templateUrl: "./attributeTypeSelector.component.html",
    standalone: true,
    imports: [MatButtonToggleGroup, MatButtonToggle, AsyncPipe]
})
export class AttributeTypeSelectorComponent {
    @Input() metricName: string
    @Input() metricType: keyof AttributeTypes
 
    attributeTypes$ = this.store.select(attributeTypesSelector)
 
    constructor(private store: Store<CcState>) {}
 
    setToAbsolute() {
        this.setAttributeType(AttributeTypeValue.absolute)
    }
 
    setToRelative() {
        this.setAttributeType(AttributeTypeValue.relative)
    }
 
    private setAttributeType(attributeTypeValue: AttributeTypeValue) {
        this.store.dispatch(
            updateAttributeType({
                category: this.metricType,
                name: this.metricName,
                attributeType: attributeTypeValue
            })
        )
    }
}