From 71cd1337e116b7d0d527b3f664d1a2a69ef901b0 Mon Sep 17 00:00:00 2001 From: danoswaltCL Date: Thu, 27 Jun 2024 14:42:46 -0400 Subject: [PATCH] bringing in the metrics display toggle from the release branch --- .../projects/upgrade/src/app/app.module.ts | 2 ++ .../core/analysis/analysis.service.spec.ts | 31 +++++++++++++++++-- .../src/app/core/analysis/analysis.service.ts | 14 +++++++-- .../view-experiment.component.html | 13 +++++++- .../view-experiment.component.scss | 11 +++++++ .../view-experiment.component.ts | 10 ++++-- .../projects/upgrade/src/assets/i18n/en.json | 1 + .../src/environments/environment-types.ts | 4 ++- .../src/environments/environment.bsnl.ts | 1 + .../src/environments/environment.demo.prod.ts | 1 + .../src/environments/environment.prod.ts | 1 + .../src/environments/environment.staging.ts | 1 + .../upgrade/src/environments/environment.ts | 1 + 13 files changed, 81 insertions(+), 10 deletions(-) diff --git a/frontend/projects/upgrade/src/app/app.module.ts b/frontend/projects/upgrade/src/app/app.module.ts index dcd48f9052..8290384486 100755 --- a/frontend/projects/upgrade/src/app/app.module.ts +++ b/frontend/projects/upgrade/src/app/app.module.ts @@ -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 }); diff --git a/frontend/projects/upgrade/src/app/core/analysis/analysis.service.spec.ts b/frontend/projects/upgrade/src/app/core/analysis/analysis.service.spec.ts index 3d6b0e85e3..69d5740828 100644 --- a/frontend/projects/upgrade/src/app/core/analysis/analysis.service.spec.ts +++ b/frontend/projects/upgrade/src/app/core/analysis/analysis.service.spec.ts @@ -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(); @@ -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$', () => { @@ -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); }); }); diff --git a/frontend/projects/upgrade/src/app/core/analysis/analysis.service.ts b/frontend/projects/upgrade/src/app/core/analysis/analysis.service.ts index b527b4d521..4522bc1aca 100644 --- a/frontend/projects/upgrade/src/app/core/analysis/analysis.service.ts +++ b/frontend/projects/upgrade/src/app/core/analysis/analysis.service.ts @@ -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 { @@ -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) {} + constructor(private store$: Store, @Inject(ENV) private environment: Environment) {} isMetricsLoading$ = this.store$.pipe(select(selectIsMetricsLoading)); isQueryExecuting$ = this.store$.pipe(select(selectIsQueryExecuting)); @@ -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) { diff --git a/frontend/projects/upgrade/src/app/features/dashboard/home/pages/view-experiment/view-experiment.component.html b/frontend/projects/upgrade/src/app/features/dashboard/home/pages/view-experiment/view-experiment.component.html index 3900306e47..de8864bb3d 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/home/pages/view-experiment/view-experiment.component.html +++ b/frontend/projects/upgrade/src/app/features/dashboard/home/pages/view-experiment/view-experiment.component.html @@ -952,7 +952,18 @@
- + + + + +
+ warning +

+ {{ 'home.view-experiment.metrics-analysis-unavailable.text' | translate }} +

+
+
+
diff --git a/frontend/projects/upgrade/src/app/features/dashboard/home/pages/view-experiment/view-experiment.component.scss b/frontend/projects/upgrade/src/app/features/dashboard/home/pages/view-experiment/view-experiment.component.scss index 47113edc80..0c08e02c00 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/home/pages/view-experiment/view-experiment.component.scss +++ b/frontend/projects/upgrade/src/app/features/dashboard/home/pages/view-experiment/view-experiment.component.scss @@ -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 { diff --git a/frontend/projects/upgrade/src/app/features/dashboard/home/pages/view-experiment/view-experiment.component.ts b/frontend/projects/upgrade/src/app/features/dashboard/home/pages/view-experiment/view-experiment.component.ts index 0ca78e4a2c..e39c389ebe 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/home/pages/view-experiment/view-experiment.component.ts +++ b/frontend/projects/upgrade/src/app/features/dashboard/home/pages/view-experiment/view-experiment.component.ts @@ -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'; @@ -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', @@ -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() { @@ -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$; diff --git a/frontend/projects/upgrade/src/assets/i18n/en.json b/frontend/projects/upgrade/src/assets/i18n/en.json index 5e57f98da1..f4daad2bb1 100644 --- a/frontend/projects/upgrade/src/assets/i18n/en.json +++ b/frontend/projects/upgrade/src/assets/i18n/en.json @@ -246,6 +246,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", diff --git a/frontend/projects/upgrade/src/environments/environment-types.ts b/frontend/projects/upgrade/src/environments/environment-types.ts index aa189af8bf..3580d10186 100644 --- a/frontend/projects/upgrade/src/environments/environment-types.ts +++ b/frontend/projects/upgrade/src/environments/environment-types.ts @@ -59,8 +59,9 @@ export interface Environment { pollingLimit: number; api: APIEndpoints; featureFlagNavToggle: boolean; - withinSubjectExperimentSupportToggle: boolean; errorLogsToggle: boolean; + withinSubjectExperimentSupportToggle: boolean; + metricAnalyticsExperimentDisplayToggle: boolean; } export interface RuntimeEnvironmentConfig { @@ -71,4 +72,5 @@ export interface RuntimeEnvironmentConfig { featureFlagNavToggle?: boolean; withinSubjectExperimentSupportToggle?: boolean; errorLogsToggle?: boolean; + metricAnalyticsExperimentDisplayToggle?: boolean; } diff --git a/frontend/projects/upgrade/src/environments/environment.bsnl.ts b/frontend/projects/upgrade/src/environments/environment.bsnl.ts index 2efeddb526..78d11f14ff 100644 --- a/frontend/projects/upgrade/src/environments/environment.bsnl.ts +++ b/frontend/projects/upgrade/src/environments/environment.bsnl.ts @@ -13,6 +13,7 @@ export const environment = { featureFlagNavToggle: false, withinSubjectExperimentSupportToggle: false, errorLogsToggle: false, + metricAnalyticsExperimentDisplayToggle: true, api: { getAllExperiments: '/experiments/paginated', createNewExperiments: '/experiments', diff --git a/frontend/projects/upgrade/src/environments/environment.demo.prod.ts b/frontend/projects/upgrade/src/environments/environment.demo.prod.ts index b41b0bb018..075a02037f 100755 --- a/frontend/projects/upgrade/src/environments/environment.demo.prod.ts +++ b/frontend/projects/upgrade/src/environments/environment.demo.prod.ts @@ -13,6 +13,7 @@ export const environment = { featureFlagNavToggle: false, withinSubjectExperimentSupportToggle: false, errorLogsToggle: false, + metricAnalyticsExperimentDisplayToggle: false, api: { getAllExperiments: '/experiments/paginated', createNewExperiments: '/experiments', diff --git a/frontend/projects/upgrade/src/environments/environment.prod.ts b/frontend/projects/upgrade/src/environments/environment.prod.ts index 962b584476..fb7aad0702 100755 --- a/frontend/projects/upgrade/src/environments/environment.prod.ts +++ b/frontend/projects/upgrade/src/environments/environment.prod.ts @@ -13,6 +13,7 @@ export const environment = { featureFlagNavToggle: false, withinSubjectExperimentSupportToggle: false, errorLogsToggle: false, + metricAnalyticsExperimentDisplayToggle: false, api: { getAllExperiments: '/experiments/paginated', createNewExperiments: '/experiments', diff --git a/frontend/projects/upgrade/src/environments/environment.staging.ts b/frontend/projects/upgrade/src/environments/environment.staging.ts index 51c001752b..144bb38cdf 100644 --- a/frontend/projects/upgrade/src/environments/environment.staging.ts +++ b/frontend/projects/upgrade/src/environments/environment.staging.ts @@ -13,6 +13,7 @@ export const environment = { featureFlagNavToggle: false, withinSubjectExperimentSupportToggle: false, errorLogsToggle: false, + metricAnalyticsExperimentDisplayToggle: false, api: { getAllExperiments: '/experiments/paginated', createNewExperiments: '/experiments', diff --git a/frontend/projects/upgrade/src/environments/environment.ts b/frontend/projects/upgrade/src/environments/environment.ts index 336a8e1cc0..774d1998ab 100755 --- a/frontend/projects/upgrade/src/environments/environment.ts +++ b/frontend/projects/upgrade/src/environments/environment.ts @@ -18,6 +18,7 @@ export const environment = { featureFlagNavToggle: true, withinSubjectExperimentSupportToggle: false, errorLogsToggle: false, + metricAnalyticsExperimentDisplayToggle: false, api: { getAllExperiments: '/experiments/paginated', createNewExperiments: '/experiments',