Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datapoints-graph): [MTM-59265] Context should now be automatically transformed for dp2 widget #36

Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import { DatapointSelectorModule } from '@c8y/ngx-components/datapoint-selector'
import { aggregationType } from '@c8y/client';
import { AnimationBuilder } from '@angular/animations';
import { take } from 'rxjs/operators';
import { ActivatedRoute } from '@angular/router';
import { AlarmEventSelectionListComponent } from '../alarm-event-selector/alarm-event-selection-list/alarm-event-selection-list.component';
import { DragDropModule } from '@angular/cdk/drag-drop';
import { AlarmDetails, EventDetails } from '../alarm-event-selector';
import { ContextDashboardComponent } from '@c8y/ngx-components/context-dashboard';

describe('DatapointsGraphWidgetConfigComponent', () => {
let component: DatapointsGraphWidgetConfigComponent;
Expand Down Expand Up @@ -85,14 +85,8 @@ describe('DatapointsGraphWidgetConfigComponent', () => {
NgForm,
{ provide: AnimationBuilder, useValue: { build: () => null } },
{
provide: ActivatedRoute,
useValue: {
root: {
firstChild: {
snapshot: { data: { contextData: mockContextData } },
},
},
},
provide: ContextDashboardComponent,
useValue: { context: mockContextData },
},
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Input,
OnDestroy,
OnInit,
Optional,
ViewEncapsulation,
} from '@angular/core';
import {
Expand Down Expand Up @@ -31,10 +32,10 @@ import {
DatapointAttributesFormConfig,
DatapointSelectorModalOptions,
} from '@c8y/ngx-components/datapoint-selector';
import { ActivatedRoute } from '@angular/router';
import { omit } from 'lodash-es';
import { aggregationType } from '@c8y/client';
import { AlarmDetails, EventDetails } from '../alarm-event-selector';
import { ContextDashboardComponent } from '@c8y/ngx-components/context-dashboard';

@Component({
selector: 'c8y-datapoints-graph-widget-config',
Expand Down Expand Up @@ -81,15 +82,16 @@ export class DatapointsGraphWidgetConfigComponent
private formBuilder: FormBuilder,
private form: NgForm,
private translate: TranslateService,
private route: ActivatedRoute
@Optional() private dashboardContextComponent: ContextDashboardComponent
) {
this.formGroup = this.initForm();
}

ngOnInit() {
const context = this.route.root.firstChild?.snapshot.data?.['contextData'];
const context = this.dashboardContextComponent?.context;
eniosultan marked this conversation as resolved.
Show resolved Hide resolved
if (context?.id) {
eniosultan marked this conversation as resolved.
Show resolved Hide resolved
this.datapointSelectionConfig.contextAsset = context;
const { id } = context;
eniosultan marked this conversation as resolved.
Show resolved Hide resolved
this.datapointSelectionConfig.contextAsset = { id };
}
this.form.form.addControl('config', this.formGroup);
this.formGroup.patchValue(this.config || {});
Expand Down
Loading