Skip to content

Commit

Permalink
fix the method for tab to pass value to snowplow (#2157)
Browse files Browse the repository at this point in the history
* fix the method for tab to pass value to snowplow

* refactor a bit
  • Loading branch information
yzlucas authored Dec 17, 2024
1 parent 0065a23 commit ee0bbb6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,6 @@ export class IncidentHeaderPanelComponent implements AfterViewInit, OnInit {
}
}

// printPage(){
// this.requestPrint.emit();
// }

public printPage() {
const twoColumnContent = document.getElementsByClassName('two-column-content-cards-container')[0];
twoColumnContent.classList.add('print');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</app-incident-tabs>
</div>
<div *ngIf="hideOnMobileView()">
<mat-tab-group mat-stretch-tabs-mobile [headerPosition]="above">
<mat-tab-group mat-stretch-tabs-mobile [headerPosition]="above" (selectedIndexChange)="onTabChange($event)">
<mat-tab label="Details">
<incident-info-panel-mobile *ngIf="hideOnMobileView()" [incident]="incident" [evacOrders]="evacOrders" [areaRestrictions]="areaRestrictions"></incident-info-panel-mobile>
</mat-tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { findFireCentreByName, hideOnMobileView } from '../../utils';
templateUrl: './public-incident-page.component.html',
styleUrls: ['./public-incident-page.component.scss'],
})

export class PublicIncidentPageComponent implements OnInit {
public isLoading = true;
public loadingFailed = false;
Expand All @@ -35,7 +36,6 @@ export class PublicIncidentPageComponent implements OnInit {

findFireCentreByName = findFireCentreByName;
hideOnMobileView = hideOnMobileView;

constructor(
private router: ActivatedRoute,
protected cdr: ChangeDetectorRef,
Expand Down Expand Up @@ -294,19 +294,31 @@ export class PublicIncidentPageComponent implements OnInit {
window.location.href = mailtoUrl;
}

onTabChange(event: MatTabChangeEvent) {
onTabChange(event: MatTabChangeEvent | number): void {
const TAB_ACTIONS = [
'incident_details_details_click',
'incident_details_response_click',
'incident_details_gallery_click',
'incident_details_maps_click',
];

const tabLabels = ['Details', 'Response', 'Gallery', 'Maps'];
const url = this.appConfigService.getConfig().application.baseUrl.toString() + this.currentRouter.url.slice(1);
let actionName;
if (event?.tab?.textLabel === 'Response') {
actionName = 'incident_details_response_click';
} else if (event?.tab?.textLabel === 'Gallery') {
actionName = 'incident_details_gallery_click';
} else if (event?.tab?.textLabel === 'Maps') {
actionName = 'incident_details_maps_click';

// Determine the index based on the type of event
const index = typeof event === 'number' ? event : event.index;

// Validate the index to avoid accessing undefined values
if (index < 0 || index >= TAB_ACTIONS.length) {
console.warn('Invalid tab index:', index);
return;
}

const actionName = TAB_ACTIONS[index];
this.snowPlowHelper(url, {
action: actionName,
text: event?.tab?.textLabel
text: tabLabels[index],
});
}

}

0 comments on commit ee0bbb6

Please sign in to comment.