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

bringing in the metrics display toggle from the release branch #1705

Merged
merged 4 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/projects/upgrade/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const getEnvironmentConfig = (http: HttpClient, env: Environment) => {
env.withinSubjectExperimentSupportToggle =
config.withinSubjectExperimentSupportToggle ?? env.withinSubjectExperimentSupportToggle ?? false;
env.errorLogsToggle = config.errorLogsToggle ?? env.errorLogsToggle ?? false;
env.metricAnalyticsExperimentDisplayToggle =
config.metricAnalyticsExperimentDisplayToggle ?? env.metricAnalyticsExperimentDisplayToggle ?? false;
})
.catch((error) => {
console.log({ error });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
actionUpsertMetrics,
} from './store/analysis.actions';
import { UpsertMetrics } from './store/analysis.models';
import { Environment } from '../../../environments/environment-types';

const mockStateStore$ = new BehaviorSubject({});
(mockStateStore$ as any).dispatch = jest.fn();
Expand All @@ -22,10 +23,12 @@ jest.mock('./store/analysis.selectors', () => ({

describe('AnalysisService', () => {
const mockStore: any = mockStateStore$;
let mockEnvironment: Environment = { metricAnalyticsExperimentDisplayToggle: true } as Environment;
let service: AnalysisService;

beforeEach(() => {
service = new AnalysisService(mockStore);
service = new AnalysisService(mockStore, mockEnvironment);
jest.resetAllMocks();
});

describe('#queryResultById$', () => {
Expand Down Expand Up @@ -78,12 +81,34 @@ describe('AnalysisService', () => {
});

describe('#executeQuery', () => {
it('should dispatch executeQuery with the supplied string input array', () => {
let originalEnvironment;

beforeEach(() => {
// Save the original environment to restore it after tests
originalEnvironment = { ...mockEnvironment };
});

afterEach(() => {
// Restore the original environment after each test
mockEnvironment = { ...originalEnvironment };
});

it('should dispatch executeQuery with the supplied string input array when metricAnalyticsExperimentDisplayToggle is true', () => {
mockEnvironment = { metricAnalyticsExperimentDisplayToggle: true } as Environment;
const mockQueryIds = ['test', 'test2'];

service.executeQuery(mockQueryIds);

expect(mockStore.dispatch).toHaveBeenLastCalledWith(actionExecuteQuery({ queryIds: mockQueryIds }));
expect(mockStore.dispatch).toHaveBeenCalledWith(actionExecuteQuery({ queryIds: mockQueryIds }));
});

it('should not dispatch executeQuery and log a warning when metricAnalyticsExperimentDisplayToggle is false', () => {
mockEnvironment = { metricAnalyticsExperimentDisplayToggle: false } as Environment;
const mockQueryIds = ['test3', 'test4'];

service.executeQuery(mockQueryIds);

expect(mockStore.dispatch).not.toHaveBeenCalledWith(mockQueryIds);
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@angular/core';
import { Inject, Injectable } from '@angular/core';
import { AppState } from '../core.module';
import { Store, select } from '@ngrx/store';
import {
Expand All @@ -11,10 +11,11 @@ import {
import * as AnalysisActions from './store/analysis.actions';
import { UpsertMetrics } from './store/analysis.models';
import { selectExperimentQueries } from '../experiments/store/experiments.selectors';
import { ENV, Environment } from '../../../environments/environment-types';

@Injectable()
export class AnalysisService {
constructor(private store$: Store<AppState>) {}
constructor(private store$: Store<AppState>, @Inject(ENV) private environment: Environment) {}

isMetricsLoading$ = this.store$.pipe(select(selectIsMetricsLoading));
isQueryExecuting$ = this.store$.pipe(select(selectIsQueryExecuting));
Expand All @@ -35,7 +36,14 @@ export class AnalysisService {
}

executeQuery(queryIds: string[]) {
this.store$.dispatch(AnalysisActions.actionExecuteQuery({ queryIds }));
if (this.environment.metricAnalyticsExperimentDisplayToggle) {
this.store$.dispatch(AnalysisActions.actionExecuteQuery({ queryIds }));
} else {
console.warn(
'executeQuery is currently disabled via metricAnalyticsExperimentDisplayToggle:',
this.environment.metricAnalyticsExperimentDisplayToggle
);
}
}

experimentQueryResult$(experimentId: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,18 @@
<ng-container *ngIf="experiment.queries.length">
<div class="box-shadow"></div>
<!-- Experiment queries results -->
<home-experiment-query-result [experiment]="experiment"></home-experiment-query-result>
<ng-container *ngIf="showMetricAnalysisDisplay; else noMetricsAnalysisView">
<home-experiment-query-result [experiment]="experiment"></home-experiment-query-result>
</ng-container>
<ng-template #noMetricsAnalysisView>
<div class="disabled-analysis-view-messsage-container">
<mat-icon class="warning-icon" color="warn">warning</mat-icon>
<p class="message">
{{ 'home.view-experiment.metrics-analysis-unavailable.text' | translate }}
</p>
</div>
<div class="box-shadow"></div>
</ng-template>
</ng-container>
</div>
</mat-tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,17 @@ $font-size-small: 15px;
margin-bottom: 24px;
padding: 10px;
}

.disabled-analysis-view-messsage-container {
padding-top: 50px;
padding-bottom: 20px;
display: flex;
justify-content: center;

.mat-icon {
margin-right: 20px;
}
}
}

::ng-deep .owl-dt-calendar-table .owl-dt-calendar-cell-selected {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, OnDestroy, ViewEncapsulation } from '@angular/core';
import { Component, OnInit, OnDestroy, ViewEncapsulation, Inject } from '@angular/core';
import { ExperimentService } from '../../../../../core/experiments/experiments.service';
import { MatDialog } from '@angular/material/dialog';
import { ExperimentStatusComponent } from '../../components/modal/experiment-status/experiment-status.component';
Expand Down Expand Up @@ -32,6 +32,7 @@ import {
FactorialConditionTableDataFromConditionPayload,
SimpleExperimentPayloadTableRowData,
} from '../../../../../core/experiment-design-stepper/store/experiment-design-stepper.model';
import { ENV, Environment } from '../../../../../../environments/environment-types';
// Used in view-experiment component only
enum DialogType {
CHANGE_STATUS = 'Change status',
Expand Down Expand Up @@ -101,7 +102,8 @@ export class ViewExperimentComponent implements OnInit, OnDestroy {
private dialog: MatDialog,
private authService: AuthService,
private router: Router,
private _Activatedroute: ActivatedRoute
private _Activatedroute: ActivatedRoute,
@Inject(ENV) private environment: Environment
) {}

get DialogType() {
Expand All @@ -124,6 +126,10 @@ export class ViewExperimentComponent implements OnInit, OnDestroy {
return this.experiment.state === EXPERIMENT_STATE.CANCELLED;
}

get showMetricAnalysisDisplay() {
return this.environment.metricAnalyticsExperimentDisplayToggle;
}

ngOnInit() {
this.isLoadingExperimentDetailStats$ = this.experimentService.isLoadingExperimentDetailStats$;
this.isPollingExperimentDetailStats$ = this.experimentService.isPollingExperimentDetailStats$;
Expand Down
1 change: 1 addition & 0 deletions frontend/projects/upgrade/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
"home.view-experiment.experiment-payloads.column-label.target": "TARGET",
"home.view-experiment.experiment-payloads.column-label.condition": "CONDITION",
"home.view-experiment.experiment-payloads.column-label.payload": "PAYLOAD",
"home.view-experiment.metrics-analysis-unavailable.text": "Experiment metrics analysis has been temporarily disabled in this view. This information is still available when exporting the experiment data.",
"home.view-experiment.graph-type.text": "Type",
"home.view-experiment.graph-conditions.text": "Conditions",
"home.view-experiment.graph-decision-point.text": "Sites",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ export interface Environment {
pollingLimit: number;
api: APIEndpoints;
featureFlagNavToggle: boolean;
withinSubjectExperimentSupportToggle: boolean;
errorLogsToggle: boolean;
withinSubjectExperimentSupportToggle: boolean;
metricAnalyticsExperimentDisplayToggle: boolean;
}

export interface RuntimeEnvironmentConfig {
Expand All @@ -71,4 +72,5 @@ export interface RuntimeEnvironmentConfig {
featureFlagNavToggle?: boolean;
withinSubjectExperimentSupportToggle?: boolean;
errorLogsToggle?: boolean;
metricAnalyticsExperimentDisplayToggle?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const environment = {
featureFlagNavToggle: false,
withinSubjectExperimentSupportToggle: false,
errorLogsToggle: false,
metricAnalyticsExperimentDisplayToggle: true,
api: {
getAllExperiments: '/experiments/paginated',
createNewExperiments: '/experiments',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const environment = {
featureFlagNavToggle: false,
withinSubjectExperimentSupportToggle: false,
errorLogsToggle: false,
metricAnalyticsExperimentDisplayToggle: false,
api: {
getAllExperiments: '/experiments/paginated',
createNewExperiments: '/experiments',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const environment = {
featureFlagNavToggle: false,
withinSubjectExperimentSupportToggle: false,
errorLogsToggle: false,
metricAnalyticsExperimentDisplayToggle: false,
api: {
getAllExperiments: '/experiments/paginated',
createNewExperiments: '/experiments',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const environment = {
featureFlagNavToggle: false,
withinSubjectExperimentSupportToggle: false,
errorLogsToggle: false,
metricAnalyticsExperimentDisplayToggle: false,
api: {
getAllExperiments: '/experiments/paginated',
createNewExperiments: '/experiments',
Expand Down
1 change: 1 addition & 0 deletions frontend/projects/upgrade/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const environment = {
featureFlagNavToggle: true,
withinSubjectExperimentSupportToggle: false,
errorLogsToggle: false,
metricAnalyticsExperimentDisplayToggle: false,
api: {
getAllExperiments: '/experiments/paginated',
createNewExperiments: '/experiments',
Expand Down
Loading