From 3eaf3ab3290094f638b177e5680a199b60af5f66 Mon Sep 17 00:00:00 2001 From: Yagnik Date: Fri, 12 Apr 2024 17:33:26 +0530 Subject: [PATCH 1/3] segment context chips in list and view comp feature added --- .../local-storage/local-storage.service.ts | 20 +++++ .../core/segments/segments.service.spec.ts | 4 +- .../src/app/core/segments/segments.service.ts | 48 +++++++++++- .../core/segments/store/segments.actions.ts | 25 ++++++- .../core/segments/store/segments.effects.ts | 35 ++++++++- .../app/core/segments/store/segments.model.ts | 16 ++++ .../core/segments/store/segments.reducer.ts | 13 ++++ .../core/segments/store/segments.selectors.ts | 8 ++ .../experiment-list.component.ts | 5 +- .../view-experiment.component.html | 2 +- .../segments-list.component.html | 12 ++- .../segments-list/segments-list.component.ts | 73 ++++++++++++++++--- .../view-segment/view-segment.component.html | 2 +- .../view-segment/view-segment.component.ts | 16 +++- types/src/Experiment/enums.ts | 18 +++++ 15 files changed, 267 insertions(+), 30 deletions(-) diff --git a/frontend/projects/upgrade/src/app/core/local-storage/local-storage.service.ts b/frontend/projects/upgrade/src/app/core/local-storage/local-storage.service.ts index 402b360ef6..0115dd9bb0 100755 --- a/frontend/projects/upgrade/src/app/core/local-storage/local-storage.service.ts +++ b/frontend/projects/upgrade/src/app/core/local-storage/local-storage.service.ts @@ -6,6 +6,8 @@ import { EXPERIMENT_SORT_AS, EXPERIMENT_SORT_KEY, } from '../experiments/store/experiments.model'; +import { SegmentLocalStorageKeys, SegmentState } from '../segments/store/segments.model'; +import { SEGMENT_SEARCH_KEY, SEGMENT_SORT_AS, SEGMENT_SORT_KEY } from '../../../../../../../types/src/Experiment/enums'; const APP_PREFIX = 'UPGRADE-'; @@ -19,6 +21,11 @@ export class LocalStorageService { const experimentSearchKey = this.getItem(ExperimentLocalStorageKeys.EXPERIMENT_SEARCH_KEY); const experimentSearchString = this.getItem(ExperimentLocalStorageKeys.EXPERIMENT_SEARCH_STRING); + const segmentSortKey = this.getItem(SegmentLocalStorageKeys.SEGMENT_SORT_KEY); + const segmentSortType = this.getItem(SegmentLocalStorageKeys.SEGMENT_SORT_TYPE); + const segmentSearchKey = this.getItem(SegmentLocalStorageKeys.SEGMENT_SEARCH_KEY); + const segmentSearchString = this.getItem(SegmentLocalStorageKeys.SEGMENT_SEARCH_STRING); + // 1. Populate experiment state const experimentState: ExperimentState = { ids: [], @@ -45,8 +52,21 @@ export class LocalStorageService { currentUserSelectedContext: null, }; + const segmentState: SegmentState = { + ids: [], + entities: {}, + isLoadingSegments: false, + allExperimentSegmentsInclusion: null, + allExperimentSegmentsExclusion: null, + searchKey: segmentSearchKey as SEGMENT_SEARCH_KEY, + searchString: segmentSearchString || null, + sortKey: (segmentSortKey as SEGMENT_SORT_KEY) || SEGMENT_SORT_KEY.NAME, + sortAs: (segmentSortType as SEGMENT_SORT_AS) || SEGMENT_SORT_AS.ASCENDING, + }; + const state = { experiments: experimentState, // experiment state, + segments: segmentState, }; return state; } diff --git a/frontend/projects/upgrade/src/app/core/segments/segments.service.spec.ts b/frontend/projects/upgrade/src/app/core/segments/segments.service.spec.ts index 9f86c3d817..b8bca84d40 100644 --- a/frontend/projects/upgrade/src/app/core/segments/segments.service.spec.ts +++ b/frontend/projects/upgrade/src/app/core/segments/segments.service.spec.ts @@ -11,6 +11,7 @@ const MockStateStore$ = new BehaviorSubject({}); describe('SegmentService', () => { let mockStore: any; let segmentsDataService: any; + let localStorageService: any; let service: SegmentsService; const mockSegmentsList: any = [ { id: 'first', createdAt: '04/25/17 04:34:22 +0000' }, @@ -34,7 +35,8 @@ describe('SegmentService', () => { beforeEach(() => { mockStore = MockStateStore$; segmentsDataService = {}; - service = new SegmentsService(mockStore, segmentsDataService); + localStorageService = {}; + service = new SegmentsService(mockStore, segmentsDataService, localStorageService); }); describe('#allSegments$', () => { diff --git a/frontend/projects/upgrade/src/app/core/segments/segments.service.ts b/frontend/projects/upgrade/src/app/core/segments/segments.service.ts index 67db1cc17d..8e78a1b328 100644 --- a/frontend/projects/upgrade/src/app/core/segments/segments.service.ts +++ b/frontend/projects/upgrade/src/app/core/segments/segments.service.ts @@ -9,21 +9,43 @@ import { selectExperimentSegmentsInclusion, selectExperimentSegmentsExclusion, selectSegmentById, + selectSearchString, + selectSearchKey, + selectSortKey, + selectSortAs, } from './store/segments.selectors'; -import { SegmentInput, UpsertSegmentType } from './store/segments.model'; -import { filter, map, tap } from 'rxjs/operators'; +import { SegmentInput, SegmentLocalStorageKeys, UpsertSegmentType } from './store/segments.model'; +import { filter, first, map, tap } from 'rxjs/operators'; import { Observable, combineLatest } from 'rxjs'; import { SegmentsDataService } from './segments.data.service'; +import { SEGMENT_SEARCH_KEY, SEGMENT_SORT_AS, SEGMENT_SORT_KEY } from '../../../../../../../types/src/Experiment/enums'; +import { LocalStorageService } from '../local-storage/local-storage.service'; @Injectable({ providedIn: 'root' }) export class SegmentsService { - constructor(private store$: Store, private segmentsDataService: SegmentsDataService) {} + constructor( + private store$: Store, + private segmentsDataService: SegmentsDataService, + private localStorageService: LocalStorageService + ) {} isLoadingSegments$ = this.store$.pipe(select(selectIsLoadingSegments)); selectedSegment$ = this.store$.pipe(select(selectSelectedSegment)); + selectSearchString$ = this.store$.pipe(select(selectSearchString)); + selectSearchKey$ = this.store$.pipe(select(selectSearchKey)); + selectSegmentSortKey$ = this.store$.pipe(select(selectSortKey)); + selectSegmentSortAs$ = this.store$.pipe(select(selectSortAs)); allExperimentSegmentsInclusion$ = this.store$.pipe(select(selectExperimentSegmentsInclusion)); allExperimentSegmentsExclusion$ = this.store$.pipe(select(selectExperimentSegmentsExclusion)); + selectSearchSegmentParams(): Observable> { + return combineLatest([this.selectSearchKey$, this.selectSearchString$]).pipe( + filter(([searchKey, searchString]) => !!searchKey && !!searchString), + map(([searchKey, searchString]) => ({ searchKey, searchString })), + first() + ); + } + selectSegmentById(segmentId: string) { return this.store$.pipe( select(selectSegmentById, { segmentId }), @@ -68,6 +90,26 @@ export class SegmentsService { ); } + setSearchKey(searchKey: SEGMENT_SEARCH_KEY) { + this.localStorageService.setItem(SegmentLocalStorageKeys.SEGMENT_SEARCH_KEY, searchKey); + this.store$.dispatch(SegmentsActions.actionSetSearchKey({ searchKey })); + } + + setSearchString(searchString: string) { + this.localStorageService.setItem(SegmentLocalStorageKeys.SEGMENT_SEARCH_STRING, searchString); + this.store$.dispatch(SegmentsActions.actionSetSearchString({ searchString })); + } + + setSortKey(sortKey: SEGMENT_SORT_KEY) { + this.localStorageService.setItem(SegmentLocalStorageKeys.SEGMENT_SORT_KEY, sortKey); + this.store$.dispatch(SegmentsActions.actionSetSortKey({ sortKey })); + } + + setSortingType(sortingType: SEGMENT_SORT_AS) { + this.localStorageService.setItem(SegmentLocalStorageKeys.SEGMENT_SORT_TYPE, sortingType); + this.store$.dispatch(SegmentsActions.actionSetSortingType({ sortingType })); + } + deleteSegment(segmentId: string) { this.store$.dispatch(SegmentsActions.actionDeleteSegment({ segmentId })); } diff --git a/frontend/projects/upgrade/src/app/core/segments/store/segments.actions.ts b/frontend/projects/upgrade/src/app/core/segments/store/segments.actions.ts index 8590d77248..1246edd114 100644 --- a/frontend/projects/upgrade/src/app/core/segments/store/segments.actions.ts +++ b/frontend/projects/upgrade/src/app/core/segments/store/segments.actions.ts @@ -1,5 +1,10 @@ import { createAction, props } from '@ngrx/store'; import { Segment, SegmentInput, UpsertSegmentType, experimentSegmentInclusionExclusionData } from './segments.model'; +import { + SEGMENT_SEARCH_KEY, + SEGMENT_SORT_AS, + SEGMENT_SORT_KEY, +} from '../../../../../../../../types/src/Experiment/enums'; export const actionFetchSegments = createAction('[Segments] Segment', props<{ fromStarting?: boolean }>()); @@ -26,14 +31,14 @@ export const actionUpsertSegmentSuccess = createAction( export const actionUpsertSegmentFailure = createAction('[Segments] Upsert Segment Failure'); -export const actionGetSegmentById = createAction('[Experiment] Get Segment By Id', props<{ segmentId: string }>()); +export const actionGetSegmentById = createAction('[Segments] Get Segment By Id', props<{ segmentId: string }>()); export const actionGetSegmentByIdSuccess = createAction( - '[Experiment] Get Segment By Id Success', + '[Segments] Get Segment By Id Success', props<{ segment: Segment }>() ); -export const actionGetSegmentByIdFailure = createAction('[Experiment] Get Segment By Id Failure'); +export const actionGetSegmentByIdFailure = createAction('[Segments] Get Segment By Id Failure'); export const actionDeleteSegment = createAction('[Segments] Delete Segment', props<{ segmentId: string }>()); @@ -54,3 +59,17 @@ export const actionExportSegments = createAction('[Segments] Export Segment', pr export const actionExportSegmentSuccess = createAction('[Segments] Export Segment Success'); export const actionExportSegmentFailure = createAction('[Segments] Export Segment Failure'); + +export const actionSetSearchKey = createAction( + '[Segments] Set Search key value', + props<{ searchKey: SEGMENT_SEARCH_KEY }>() +); + +export const actionSetSearchString = createAction('[Segments] Set Search String', props<{ searchString: string }>()); + +export const actionSetSortKey = createAction('[Segments] Set Sort key value', props<{ sortKey: SEGMENT_SORT_KEY }>()); + +export const actionSetSortingType = createAction( + '[Segments] Set Sorting type', + props<{ sortingType: SEGMENT_SORT_AS }>() +); diff --git a/frontend/projects/upgrade/src/app/core/segments/store/segments.effects.ts b/frontend/projects/upgrade/src/app/core/segments/store/segments.effects.ts index dc5cc85dff..ffb6af9687 100644 --- a/frontend/projects/upgrade/src/app/core/segments/store/segments.effects.ts +++ b/frontend/projects/upgrade/src/app/core/segments/store/segments.effects.ts @@ -2,12 +2,12 @@ import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import { select, Store } from '@ngrx/store'; -import { catchError, filter, map, switchMap, withLatestFrom } from 'rxjs/operators'; +import { catchError, filter, map, switchMap, tap, withLatestFrom } from 'rxjs/operators'; import { AppState, NotificationService } from '../../core.module'; import { SegmentsDataService } from '../segments.data.service'; import * as SegmentsActions from './segments.actions'; -import { Segment, SegmentReturnedObj, UpsertSegmentType } from './segments.model'; -import { selectAllSegments } from './segments.selectors'; +import { Segment, UpsertSegmentType } from './segments.model'; +import { selectAllSegments, selectSearchString } from './segments.selectors'; import JSZip from 'jszip'; @Injectable() @@ -55,6 +55,35 @@ export class SegmentsEffects { ) ); + fetchSegmentOnSearchString$ = createEffect( + () => + this.actions$.pipe( + ofType(SegmentsActions.actionSetSearchString), + map((action) => action.searchString), + tap((searchString) => { + // Allow empty string as we erasing text from search input + if (searchString !== null) { + this.store$.dispatch(SegmentsActions.actionFetchSegments({ fromStarting: true })); + } + }) + ), + { dispatch: false } + ); + + fetchSegmentOnSearchKeyChange$ = createEffect( + () => + this.actions$.pipe( + ofType(SegmentsActions.actionSetSearchKey), + withLatestFrom(this.store$.pipe(select(selectSearchString))), + tap(([_, searchString]) => { + if (searchString) { + this.store$.dispatch(SegmentsActions.actionFetchSegments({ fromStarting: true })); + } + }) + ), + { dispatch: false } + ); + upsertSegment$ = createEffect(() => this.actions$.pipe( ofType(SegmentsActions.actionUpsertSegment), diff --git a/frontend/projects/upgrade/src/app/core/segments/store/segments.model.ts b/frontend/projects/upgrade/src/app/core/segments/store/segments.model.ts index b4eee74d0a..90c39a4002 100644 --- a/frontend/projects/upgrade/src/app/core/segments/store/segments.model.ts +++ b/frontend/projects/upgrade/src/app/core/segments/store/segments.model.ts @@ -1,6 +1,11 @@ import { AppState } from '../../core.state'; import { EntityState } from '@ngrx/entity'; import { SEGMENT_TYPE, SEGMENT_STATUS } from 'upgrade_types'; +import { + SEGMENT_SEARCH_KEY, + SEGMENT_SORT_AS, + SEGMENT_SORT_KEY, +} from '../../../../../../../../types/src/Experiment/enums'; export { SEGMENT_STATUS }; export enum NewSegmentDialogEvents { @@ -9,6 +14,13 @@ export enum NewSegmentDialogEvents { UPDATE_SEGMENT = 'Update segment', } +export enum SegmentLocalStorageKeys { + SEGMENT_SEARCH_STRING = 'SEGMENT_SEARCH_STRING', + SEGMENT_SEARCH_KEY = 'SEGMENT_KEY_STRING', + SEGMENT_SORT_KEY = 'SEGMENT_SORT_KEY', + SEGMENT_SORT_TYPE = 'SEGMENT_SORT_TYPE', +} + export enum NewSegmentPaths { SEGMENT_OVERVIEW = 'Segment Overview', SEGMENT_MEMBERS = 'Segment Members', @@ -96,6 +108,10 @@ export interface SegmentState extends EntityState { // TODO: remove any allExperimentSegmentsInclusion: any; allExperimentSegmentsExclusion: any; + searchKey: SEGMENT_SEARCH_KEY; + searchString: string; + sortKey: SEGMENT_SORT_KEY; + sortAs: SEGMENT_SORT_AS; } export interface State extends AppState { diff --git a/frontend/projects/upgrade/src/app/core/segments/store/segments.reducer.ts b/frontend/projects/upgrade/src/app/core/segments/store/segments.reducer.ts index 0e7449c1d1..95e29bce57 100644 --- a/frontend/projects/upgrade/src/app/core/segments/store/segments.reducer.ts +++ b/frontend/projects/upgrade/src/app/core/segments/store/segments.reducer.ts @@ -2,6 +2,11 @@ import { createReducer, Action, on } from '@ngrx/store'; import { createEntityAdapter, EntityAdapter } from '@ngrx/entity'; import { SegmentState, Segment } from './segments.model'; import * as SegmentsActions from './segments.actions'; +import { + SEGMENT_SEARCH_KEY, + SEGMENT_SORT_AS, + SEGMENT_SORT_KEY, +} from '../../../../../../../../types/src/Experiment/enums'; export const adapter: EntityAdapter = createEntityAdapter(); @@ -11,6 +16,10 @@ export const initialState: SegmentState = adapter.getInitialState({ isLoadingSegments: false, allExperimentSegmentsInclusion: null, allExperimentSegmentsExclusion: null, + searchKey: SEGMENT_SEARCH_KEY.ALL, + searchString: null, + sortKey: SEGMENT_SORT_KEY.NAME, + sortAs: SEGMENT_SORT_AS.ASCENDING, }); const reducer = createReducer( @@ -43,6 +52,10 @@ const reducer = createReducer( on(SegmentsActions.actionGetSegmentByIdSuccess, (state, { segment }) => adapter.upsertOne(segment, { ...state, isLoadingSegments: false }) ), + on(SegmentsActions.actionSetSearchKey, (state, { searchKey }) => ({ ...state, searchKey })), + on(SegmentsActions.actionSetSearchString, (state, { searchString }) => ({ ...state, searchString })), + on(SegmentsActions.actionSetSortKey, (state, { sortKey }) => ({ ...state, sortKey })), + on(SegmentsActions.actionSetSortingType, (state, { sortingType }) => ({ ...state, sortAs: sortingType })), on(SegmentsActions.actionDeleteSegmentSuccess, (state, { segment }) => adapter.removeOne(segment.id, state)), on(SegmentsActions.actionSetIsLoadingSegments, (state, { isLoadingSegments }) => ({ ...state, isLoadingSegments })) ); diff --git a/frontend/projects/upgrade/src/app/core/segments/store/segments.selectors.ts b/frontend/projects/upgrade/src/app/core/segments/store/segments.selectors.ts index b791219aa3..345d694360 100644 --- a/frontend/projects/upgrade/src/app/core/segments/store/segments.selectors.ts +++ b/frontend/projects/upgrade/src/app/core/segments/store/segments.selectors.ts @@ -36,3 +36,11 @@ export const selectSelectedSegment = createSelector( } } ); + +export const selectSearchKey = createSelector(selectSegmentsState, (state) => state.searchKey); + +export const selectSearchString = createSelector(selectSegmentsState, (state) => state.searchString); + +export const selectSortKey = createSelector(selectSegmentsState, (state) => state.sortKey); + +export const selectSortAs = createSelector(selectSegmentsState, (state) => state.sortAs); diff --git a/frontend/projects/upgrade/src/app/features/dashboard/home/components/experiment-list/experiment-list.component.ts b/frontend/projects/upgrade/src/app/features/dashboard/home/components/experiment-list/experiment-list.component.ts index d6733aa5fa..68f57d974c 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/home/components/experiment-list/experiment-list.component.ts +++ b/frontend/projects/upgrade/src/app/features/dashboard/home/components/experiment-list/experiment-list.component.ts @@ -170,6 +170,7 @@ export class ExperimentListComponent implements OnInit, OnDestroy, AfterViewInit } filterExperimentByChips(tagValue: FLAG_SEARCH_SORT_KEY, type: EXPERIMENT_SEARCH_KEY) { + this.searchValue = tagValue; this.selectedExperimentFilterOption = type; this.applyFilter(tagValue); this.setSearchKey(); @@ -197,7 +198,9 @@ export class ExperimentListComponent implements OnInit, OnDestroy, AfterViewInit } setChipsVisible(experimentId: string, type: string) { - const index = this[type].findIndex((data) => data.experimentId === experimentId); + const index = this[type].findIndex((data) => { + data.experimentId === experimentId; + }); if (index !== -1) { this[type][index] = { experimentId, visibility: true }; } else { 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 04dd520a74..6fe182386b 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 @@ -245,7 +245,7 @@ }} - +
{{ filterOption | titlecase }} @@ -66,7 +66,13 @@
- +
@@ -134,7 +140,7 @@ - + {{ segment.context }} diff --git a/frontend/projects/upgrade/src/app/features/dashboard/segments/components/segments-list/segments-list.component.ts b/frontend/projects/upgrade/src/app/features/dashboard/segments/components/segments-list/segments-list.component.ts index be4d2a3c57..fbc145b2ee 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/segments/components/segments-list/segments-list.component.ts +++ b/frontend/projects/upgrade/src/app/features/dashboard/segments/components/segments-list/segments-list.component.ts @@ -8,7 +8,8 @@ import { AfterViewInit, ChangeDetectorRef, } from '@angular/core'; -import { Observable, Subscription } from 'rxjs'; +import { Observable, Subscription, fromEvent } from 'rxjs'; +import { debounceTime } from 'rxjs/operators'; import { UserPermission } from '../../../../../core/auth/store/auth.models'; import { MatDialog } from '@angular/material/dialog'; import { AuthService } from '../../../../../core/auth/auth.service'; @@ -16,12 +17,12 @@ import { SegmentsService } from '../../../../../core/segments/segments.service'; import { Segment } from '../../../../../core/segments/store/segments.model'; import { NewSegmentComponent } from '../modal/new-segment/new-segment.component'; import { ImportSegmentComponent } from '../modal/import-segment/import-segment.component'; -import { EXPERIMENT_SEARCH_KEY } from '../../../../../core/experiments/store/experiments.model'; import { SegmentStatusPipeType } from '../../../../../shared/pipes/segment-status.pipe'; import { SEGMENT_STATUS } from '../../../../../core/segments/store/segments.model'; import { MatTableDataSource } from '@angular/material/table'; import { MatSort } from '@angular/material/sort'; import { ExportSegmentComponent } from '../../components/modal/export-segment/export-segment.component'; +import { SEGMENT_SEARCH_KEY } from '../../../../../../../../../../types/src/Experiment/enums'; @Component({ selector: 'segments-list', @@ -39,15 +40,17 @@ export class SegmentsListComponent implements OnInit, OnDestroy, AfterViewInit { allSegments: MatTableDataSource; allSegmentsSub: Subscription; + segmentSortKey$: Observable; + segmentSortAs$: Observable; isLoadingSegments$ = this.segmentsService.isLoadingSegments$; segmentFilterOptions = [ - EXPERIMENT_SEARCH_KEY.ALL, - EXPERIMENT_SEARCH_KEY.NAME, - EXPERIMENT_SEARCH_KEY.STATUS, - EXPERIMENT_SEARCH_KEY.CONTEXT, + SEGMENT_SEARCH_KEY.ALL, + SEGMENT_SEARCH_KEY.NAME, + SEGMENT_SEARCH_KEY.STATUS, + SEGMENT_SEARCH_KEY.CONTEXT, ]; statusFilterOptions = Object.values(SEGMENT_STATUS); - selectedSegmentFilterOption = EXPERIMENT_SEARCH_KEY.ALL; + selectedSegmentFilterOption = SEGMENT_SEARCH_KEY.ALL; searchValue: string; contextVisibility = []; @@ -85,22 +88,32 @@ export class SegmentsListComponent implements OnInit, OnDestroy, AfterViewInit { this.cdr.detectChanges(); this.applyFilter(this.searchValue); }); + + this.segmentSortKey$ = this.segmentsService.selectSegmentSortKey$; + this.segmentSortAs$ = this.segmentsService.selectSegmentSortAs$; + + this.segmentsService.selectSearchSegmentParams().subscribe((searchParams: any) => { + // Used when user clicks on context from view segment page + this.searchValue = searchParams.searchString; + this.selectedSegmentFilterOption = searchParams.searchKey; + this.applyFilter(searchParams.searchString); + }); } - filterSegmentPredicate(type: EXPERIMENT_SEARCH_KEY) { + filterSegmentPredicate(type: SEGMENT_SEARCH_KEY) { this.allSegments.filterPredicate = (data, filter: string): boolean => { switch (type) { - case EXPERIMENT_SEARCH_KEY.ALL: + case SEGMENT_SEARCH_KEY.ALL: return ( data.name.toLocaleLowerCase().includes(filter) || data.status.toLocaleLowerCase().includes(filter) || data.context.toLocaleLowerCase().includes(filter) ); - case EXPERIMENT_SEARCH_KEY.NAME: + case SEGMENT_SEARCH_KEY.NAME: return data.name.toLocaleLowerCase().includes(filter); - case EXPERIMENT_SEARCH_KEY.STATUS: + case SEGMENT_SEARCH_KEY.STATUS: return data.status.toLocaleLowerCase().includes(filter); - case EXPERIMENT_SEARCH_KEY.CONTEXT: + case SEGMENT_SEARCH_KEY.CONTEXT: return data.context.toLocaleLowerCase().includes(filter); } }; @@ -113,6 +126,32 @@ export class SegmentsListComponent implements OnInit, OnDestroy, AfterViewInit { } } + setSearchKey() { + this.segmentsService.setSearchKey(this.selectedSegmentFilterOption); + } + + setSearchString(searchString: string) { + this.segmentsService.setSearchString(searchString); + } + + changeSorting(event) { + this.segmentsService.setSortingType(event.direction ? event.direction.toUpperCase() : null); + this.segmentsService.setSortKey(event.direction ? event.active : null); + this.segmentsTableContainer.nativeElement.scroll({ + top: 0, + behavior: 'smooth', + }); + this.segmentsService.fetchSegments(true); + } + + filterSegmentsByChips(tagValue: string, type: SEGMENT_SEARCH_KEY) { + this.searchValue = tagValue; + this.selectedSegmentFilterOption = type; + this.applyFilter(tagValue); + this.setSearchKey(); + this.setSearchString(tagValue); + } + openNewSegmentDialog() { this.dialog.open(NewSegmentComponent, { panelClass: 'new-segment-modal', @@ -140,5 +179,15 @@ export class SegmentsListComponent implements OnInit, OnDestroy, AfterViewInit { // subtract other component's height const windowHeight = window.innerHeight; this.segmentsTableContainer.nativeElement.style.maxHeight = windowHeight - 325 + 'px'; + + fromEvent(this.searchInput.nativeElement, 'keyup') + .pipe(debounceTime(500)) + .subscribe((searchInput) => { + this.setSearchString((searchInput as any).target.value); + }); + } + + get SegmentSearchKey() { + return SEGMENT_SEARCH_KEY; } } diff --git a/frontend/projects/upgrade/src/app/features/dashboard/segments/pages/view-segment/view-segment.component.html b/frontend/projects/upgrade/src/app/features/dashboard/segments/pages/view-segment/view-segment.component.html index 4e068d075f..f2ac4b2f1f 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/segments/pages/view-segment/view-segment.component.html +++ b/frontend/projects/upgrade/src/app/features/dashboard/segments/pages/view-segment/view-segment.component.html @@ -91,7 +91,7 @@
{{ 'global.context.text' | translate }} - + {{ segment.context }} diff --git a/frontend/projects/upgrade/src/app/features/dashboard/segments/pages/view-segment/view-segment.component.ts b/frontend/projects/upgrade/src/app/features/dashboard/segments/pages/view-segment/view-segment.component.ts index 0c523b3380..83bc5eac0f 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/segments/pages/view-segment/view-segment.component.ts +++ b/frontend/projects/upgrade/src/app/features/dashboard/segments/pages/view-segment/view-segment.component.ts @@ -15,7 +15,8 @@ import { SegmentExperimentListComponent } from '../../components/modal/segment-e import { SEGMENT_STATUS } from 'upgrade_types'; import { SegmentStatusPipeType } from '../../../../../shared/pipes/segment-status.pipe'; import { ExportSegmentComponent } from '../../components/modal/export-segment/export-segment.component'; -import { ActivatedRoute } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; +import { SEGMENT_SEARCH_KEY } from '../../../../../../../../../../types/src/Experiment/enums'; @Component({ selector: 'view-segment', templateUrl: './view-segment.component.html', @@ -36,7 +37,8 @@ export class ViewSegmentComponent implements OnInit, OnDestroy { private segmentsService: SegmentsService, private dialog: MatDialog, private authService: AuthService, - private _Activatedroute: ActivatedRoute + private _Activatedroute: ActivatedRoute, + private router: Router ) {} get SegmentStatus() { @@ -88,6 +90,12 @@ export class ViewSegmentComponent implements OnInit, OnDestroy { }); } + searchSegment(type: SEGMENT_SEARCH_KEY, value: string) { + this.segmentsService.setSearchKey(type); + this.segmentsService.setSearchString(value); + this.router.navigate(['/segments']); + } + deleteSegment() { const dialogRef = this.dialog.open(DeleteComponent, { panelClass: 'delete-modal', @@ -133,4 +141,8 @@ export class ViewSegmentComponent implements OnInit, OnDestroy { this.permissionsSub.unsubscribe(); this.segmentIdSub.unsubscribe(); } + + get SegmentSearchKey() { + return SEGMENT_SEARCH_KEY; + } } diff --git a/types/src/Experiment/enums.ts b/types/src/Experiment/enums.ts index aac835cac6..3af47d2c56 100644 --- a/types/src/Experiment/enums.ts +++ b/types/src/Experiment/enums.ts @@ -176,6 +176,24 @@ export enum SEGMENT_STATUS { UNLOCKED = 'Unlocked', } +export enum SEGMENT_SEARCH_KEY { + ALL = 'all', + NAME = 'name', + STATUS = 'status', + CONTEXT = 'context', +} + +export enum SEGMENT_SORT_KEY { + NAME = 'name', + STATUS = 'state', + UPDATED_AT = 'updatedAt', +} + +export enum SEGMENT_SORT_AS { + ASCENDING = 'ASC', + DESCENDING = 'DESC', +} + export enum INCLUSION_CRITERIA { INCLUDE_SPECIFIC = 'Include Specific', EXCEPT = 'Include All Except...', From 09ad10d10f6a08059cdf71dd80c478359ef19d55 Mon Sep 17 00:00:00 2001 From: Yagnik Date: Wed, 17 Apr 2024 18:20:19 +0530 Subject: [PATCH 2/3] fixed review cmts --- .../src/app/core/local-storage/local-storage.service.ts | 2 +- .../upgrade/src/app/core/segments/segments.service.ts | 2 +- .../upgrade/src/app/core/segments/store/segments.model.ts | 7 +------ types/src/index.ts | 3 +++ 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/frontend/projects/upgrade/src/app/core/local-storage/local-storage.service.ts b/frontend/projects/upgrade/src/app/core/local-storage/local-storage.service.ts index 0115dd9bb0..ee395b036a 100755 --- a/frontend/projects/upgrade/src/app/core/local-storage/local-storage.service.ts +++ b/frontend/projects/upgrade/src/app/core/local-storage/local-storage.service.ts @@ -7,7 +7,7 @@ import { EXPERIMENT_SORT_KEY, } from '../experiments/store/experiments.model'; import { SegmentLocalStorageKeys, SegmentState } from '../segments/store/segments.model'; -import { SEGMENT_SEARCH_KEY, SEGMENT_SORT_AS, SEGMENT_SORT_KEY } from '../../../../../../../types/src/Experiment/enums'; +import { SEGMENT_SEARCH_KEY, SEGMENT_SORT_AS, SEGMENT_SORT_KEY } from 'upgrade_types'; const APP_PREFIX = 'UPGRADE-'; diff --git a/frontend/projects/upgrade/src/app/core/segments/segments.service.ts b/frontend/projects/upgrade/src/app/core/segments/segments.service.ts index 8e78a1b328..456996f4c1 100644 --- a/frontend/projects/upgrade/src/app/core/segments/segments.service.ts +++ b/frontend/projects/upgrade/src/app/core/segments/segments.service.ts @@ -18,7 +18,7 @@ import { SegmentInput, SegmentLocalStorageKeys, UpsertSegmentType } from './stor import { filter, first, map, tap } from 'rxjs/operators'; import { Observable, combineLatest } from 'rxjs'; import { SegmentsDataService } from './segments.data.service'; -import { SEGMENT_SEARCH_KEY, SEGMENT_SORT_AS, SEGMENT_SORT_KEY } from '../../../../../../../types/src/Experiment/enums'; +import { SEGMENT_SEARCH_KEY, SEGMENT_SORT_AS, SEGMENT_SORT_KEY } from 'upgrade_types'; import { LocalStorageService } from '../local-storage/local-storage.service'; @Injectable({ providedIn: 'root' }) diff --git a/frontend/projects/upgrade/src/app/core/segments/store/segments.model.ts b/frontend/projects/upgrade/src/app/core/segments/store/segments.model.ts index 90c39a4002..a32422fcd9 100644 --- a/frontend/projects/upgrade/src/app/core/segments/store/segments.model.ts +++ b/frontend/projects/upgrade/src/app/core/segments/store/segments.model.ts @@ -1,11 +1,6 @@ import { AppState } from '../../core.state'; import { EntityState } from '@ngrx/entity'; -import { SEGMENT_TYPE, SEGMENT_STATUS } from 'upgrade_types'; -import { - SEGMENT_SEARCH_KEY, - SEGMENT_SORT_AS, - SEGMENT_SORT_KEY, -} from '../../../../../../../../types/src/Experiment/enums'; +import { SEGMENT_TYPE, SEGMENT_STATUS, SEGMENT_SEARCH_KEY, SEGMENT_SORT_AS, SEGMENT_SORT_KEY } from 'upgrade_types'; export { SEGMENT_STATUS }; export enum NewSegmentDialogEvents { diff --git a/types/src/index.ts b/types/src/index.ts index 4c0adcd5c1..4127505b27 100644 --- a/types/src/index.ts +++ b/types/src/index.ts @@ -28,6 +28,9 @@ export { CONDITION_ORDER, CACHE_PREFIX, ASSIGNMENT_ALGORITHM, + SEGMENT_SEARCH_KEY, + SEGMENT_SORT_AS, + SEGMENT_SORT_KEY, } from './Experiment/enums'; export { IEnrollmentCompleteCondition, From b4356f0b51fdde7d3de992e44978be3bada28a33 Mon Sep 17 00:00:00 2001 From: Yagnik Date: Thu, 25 Apr 2024 15:57:04 +0530 Subject: [PATCH 3/3] Resolved all review comments on PR --- .../Upgrade/src/api/DTO/ExperimentDTO.ts | 4 +-- .../ExperimentPaginatedParamsValidator.ts | 8 ++--- .../FeatureFlagsPaginatedParamsValidator.ts | 8 ++--- .../validators/PaginatedParamsValidator.ts | 6 ++-- .../UserPaginatedParamsValidator.ts | 6 ++-- .../Upgrade/src/api/models/Experiment.ts | 4 +-- .../unit/services/FeatureFlagService.test.ts | 12 +++---- .../test/unit/services/UserService.test.ts | 4 +-- .../experiments/experiments.service.spec.ts | 4 +-- .../core/experiments/experiments.service.ts | 7 ++-- .../experiments/store/experiments.actions.ts | 4 +-- .../store/experiments.effects.spec.ts | 10 +++--- .../experiments/store/experiments.model.ts | 6 ++-- .../store/experiments.reducer.spec.ts | 8 ++--- .../experiments/store/experiments.reducer.ts | 4 +-- .../store/experiments.selector.spec.ts | 4 +-- .../local-storage.service.spec.ts | 8 ++--- .../local-storage/local-storage.service.ts | 7 ++-- .../src/app/core/segments/segments.service.ts | 7 ++-- .../core/segments/store/segments.actions.ts | 4 +-- .../core/segments/store/segments.effects.ts | 33 ++----------------- .../app/core/segments/store/segments.model.ts | 4 +-- .../core/segments/store/segments.reducer.ts | 4 +-- .../experiment-list.component.html | 2 +- .../experiment-list.component.ts | 9 ++--- .../segments-list.component.html | 2 +- .../segments-list/segments-list.component.ts | 10 ++---- types/src/Experiment/enums.ts | 7 +--- types/src/Experiment/interfaces.ts | 4 +-- types/src/index.ts | 3 +- 30 files changed, 79 insertions(+), 124 deletions(-) diff --git a/backend/packages/Upgrade/src/api/DTO/ExperimentDTO.ts b/backend/packages/Upgrade/src/api/DTO/ExperimentDTO.ts index 9f3f305d9b..14cccbf72c 100644 --- a/backend/packages/Upgrade/src/api/DTO/ExperimentDTO.ts +++ b/backend/packages/Upgrade/src/api/DTO/ExperimentDTO.ts @@ -23,7 +23,7 @@ import { EXPERIMENT_STATE, EXPERIMENT_SEARCH_KEY, EXPERIMENT_SORT_KEY, - EXPERIMENT_SORT_AS, + SORT_AS_DIRECTION, FILTER_MODE, IEnrollmentCompleteCondition, IExperimentSearchParams, @@ -39,7 +39,7 @@ import { Type } from 'class-transformer'; export { EXPERIMENT_SEARCH_KEY, - EXPERIMENT_SORT_AS, + SORT_AS_DIRECTION, EXPERIMENT_SORT_KEY, IExperimentSearchParams, IExperimentSortParams, diff --git a/backend/packages/Upgrade/src/api/controllers/validators/ExperimentPaginatedParamsValidator.ts b/backend/packages/Upgrade/src/api/controllers/validators/ExperimentPaginatedParamsValidator.ts index aa551bc189..52733ff4ea 100644 --- a/backend/packages/Upgrade/src/api/controllers/validators/ExperimentPaginatedParamsValidator.ts +++ b/backend/packages/Upgrade/src/api/controllers/validators/ExperimentPaginatedParamsValidator.ts @@ -1,5 +1,5 @@ import { IsNotEmpty, IsDefined, IsNumber, IsEnum, IsString, ValidateNested, IsOptional } from 'class-validator'; -import { EXPERIMENT_SEARCH_KEY, EXPERIMENT_SORT_AS, EXPERIMENT_SORT_KEY } from '../../models/Experiment'; +import { EXPERIMENT_SEARCH_KEY, SORT_AS_DIRECTION, EXPERIMENT_SORT_KEY } from '../../models/Experiment'; import { Type } from 'class-transformer'; class ExperimentSearchParam { @@ -10,7 +10,7 @@ class ExperimentSearchParam { @IsNotEmpty() @IsDefined() @IsString() - public string: string + public string: string; } class ExperimentSortParam { @@ -19,8 +19,8 @@ class ExperimentSortParam { public key: EXPERIMENT_SORT_KEY; @IsNotEmpty() - @IsEnum(EXPERIMENT_SORT_AS) - public sortAs: EXPERIMENT_SORT_AS; + @IsEnum(SORT_AS_DIRECTION) + public sortAs: SORT_AS_DIRECTION; } export class ExperimentPaginatedParamsValidator { diff --git a/backend/packages/Upgrade/src/api/controllers/validators/FeatureFlagsPaginatedParamsValidator.ts b/backend/packages/Upgrade/src/api/controllers/validators/FeatureFlagsPaginatedParamsValidator.ts index d1d85fec56..cdbcfaf59d 100644 --- a/backend/packages/Upgrade/src/api/controllers/validators/FeatureFlagsPaginatedParamsValidator.ts +++ b/backend/packages/Upgrade/src/api/controllers/validators/FeatureFlagsPaginatedParamsValidator.ts @@ -1,6 +1,6 @@ import { Type } from 'class-transformer'; import { IsNotEmpty, IsDefined, IsNumber, IsOptional, ValidateNested, IsEnum, IsString } from 'class-validator'; -import { EXPERIMENT_SORT_AS } from 'upgrade_types'; +import { SORT_AS_DIRECTION } from 'upgrade_types'; // TODO: Move to upgrade types export interface IFeatureFlagSearchParams { @@ -9,7 +9,7 @@ export interface IFeatureFlagSearchParams { } export interface IFeatureFlagSortParams { key: FLAG_SEARCH_SORT_KEY; - sortAs: EXPERIMENT_SORT_AS; + sortAs: SORT_AS_DIRECTION; } export enum FLAG_SEARCH_SORT_KEY { @@ -26,8 +26,8 @@ class IFeatureFlagSortParamsValidator { key: FLAG_SEARCH_SORT_KEY; @IsNotEmpty() - @IsEnum(EXPERIMENT_SORT_AS) - sortAs: EXPERIMENT_SORT_AS; + @IsEnum(SORT_AS_DIRECTION) + sortAs: SORT_AS_DIRECTION; } class IFeatureFlagSearchParamsValidator { diff --git a/backend/packages/Upgrade/src/api/controllers/validators/PaginatedParamsValidator.ts b/backend/packages/Upgrade/src/api/controllers/validators/PaginatedParamsValidator.ts index f89d1e283b..58f3f613fc 100644 --- a/backend/packages/Upgrade/src/api/controllers/validators/PaginatedParamsValidator.ts +++ b/backend/packages/Upgrade/src/api/controllers/validators/PaginatedParamsValidator.ts @@ -1,14 +1,14 @@ import { Type } from 'class-transformer'; import { IsNotEmpty, IsDefined, IsNumber, IsString, IsEnum, IsOptional, ValidateNested } from 'class-validator'; -import { EXPERIMENT_SORT_AS } from 'upgrade_types'; +import { SORT_AS_DIRECTION } from 'upgrade_types'; class SortParamsValidator { @IsNotEmpty() @IsString() key: string; @IsNotEmpty() - @IsEnum(EXPERIMENT_SORT_AS) - sortAs: EXPERIMENT_SORT_AS; + @IsEnum(SORT_AS_DIRECTION) + sortAs: SORT_AS_DIRECTION; } class SearchParamsValidator { diff --git a/backend/packages/Upgrade/src/api/controllers/validators/UserPaginatedParamsValidator.ts b/backend/packages/Upgrade/src/api/controllers/validators/UserPaginatedParamsValidator.ts index 29a850efa7..1389ba3769 100644 --- a/backend/packages/Upgrade/src/api/controllers/validators/UserPaginatedParamsValidator.ts +++ b/backend/packages/Upgrade/src/api/controllers/validators/UserPaginatedParamsValidator.ts @@ -1,6 +1,6 @@ import { Type } from 'class-transformer'; import { IsNotEmpty, IsDefined, IsNumber, IsEnum, IsOptional, IsString, ValidateNested } from 'class-validator'; -import { EXPERIMENT_SORT_AS } from 'upgrade_types'; +import { SORT_AS_DIRECTION } from 'upgrade_types'; export enum USER_SEARCH_SORT_KEY { ALL = 'all', @@ -16,8 +16,8 @@ export class UserSortParamsValidator { key: USER_SEARCH_SORT_KEY; @IsNotEmpty() - @IsEnum(EXPERIMENT_SORT_AS) - sortAs: EXPERIMENT_SORT_AS; + @IsEnum(SORT_AS_DIRECTION) + sortAs: SORT_AS_DIRECTION; } export class UserSearchParamsValidator { diff --git a/backend/packages/Upgrade/src/api/models/Experiment.ts b/backend/packages/Upgrade/src/api/models/Experiment.ts index 66d957187e..32ee2d4e5d 100644 --- a/backend/packages/Upgrade/src/api/models/Experiment.ts +++ b/backend/packages/Upgrade/src/api/models/Experiment.ts @@ -10,7 +10,7 @@ import { EXPERIMENT_STATE, EXPERIMENT_SEARCH_KEY, EXPERIMENT_SORT_KEY, - EXPERIMENT_SORT_AS, + SORT_AS_DIRECTION, FILTER_MODE, IEnrollmentCompleteCondition, IExperimentSearchParams, @@ -30,7 +30,7 @@ import { StratificationFactor } from './StratificationFactor'; export { EXPERIMENT_SEARCH_KEY, - EXPERIMENT_SORT_AS, + SORT_AS_DIRECTION, EXPERIMENT_SORT_KEY, IExperimentSearchParams, IExperimentSortParams, diff --git a/backend/packages/Upgrade/test/unit/services/FeatureFlagService.test.ts b/backend/packages/Upgrade/test/unit/services/FeatureFlagService.test.ts index a9861c095d..0b0d7d5744 100644 --- a/backend/packages/Upgrade/test/unit/services/FeatureFlagService.test.ts +++ b/backend/packages/Upgrade/test/unit/services/FeatureFlagService.test.ts @@ -9,7 +9,7 @@ import { FeatureFlagRepository } from '../../../src/api/repositories/FeatureFlag import { FeatureFlag } from '../../../src/api/models/FeatureFlag'; import { FlagVariationRepository } from '../../../src/api/repositories/FlagVariationRepository'; import { FLAG_SEARCH_SORT_KEY } from '../../../src/api/controllers/validators/FeatureFlagsPaginatedParamsValidator'; -import { EXPERIMENT_SORT_AS } from '../../../../../../types/src'; +import { SORT_AS_DIRECTION } from '../../../../../../types/src'; import { FlagVariation } from '../../../src/api/models/FlagVariation'; import { isUUID } from 'class-validator'; import { v4 as uuid } from 'uuid'; @@ -186,7 +186,7 @@ describe.skip('Feature Flag Service Testing', () => { }, { key: FLAG_SEARCH_SORT_KEY.ALL, - sortAs: EXPERIMENT_SORT_AS.ASCENDING, + sortAs: SORT_AS_DIRECTION.ASCENDING, } ); expect(results).toEqual(mockFlagArr); @@ -203,7 +203,7 @@ describe.skip('Feature Flag Service Testing', () => { }, { key: FLAG_SEARCH_SORT_KEY.ALL, - sortAs: EXPERIMENT_SORT_AS.ASCENDING, + sortAs: SORT_AS_DIRECTION.ASCENDING, } ); expect(results).toEqual(mockFlagArr); @@ -220,7 +220,7 @@ describe.skip('Feature Flag Service Testing', () => { }, { key: FLAG_SEARCH_SORT_KEY.ALL, - sortAs: EXPERIMENT_SORT_AS.ASCENDING, + sortAs: SORT_AS_DIRECTION.ASCENDING, } ); expect(results).toEqual(mockFlagArr); @@ -237,7 +237,7 @@ describe.skip('Feature Flag Service Testing', () => { }, { key: FLAG_SEARCH_SORT_KEY.ALL, - sortAs: EXPERIMENT_SORT_AS.ASCENDING, + sortAs: SORT_AS_DIRECTION.ASCENDING, } ); expect(results).toEqual(mockFlagArr); @@ -254,7 +254,7 @@ describe.skip('Feature Flag Service Testing', () => { }, { key: FLAG_SEARCH_SORT_KEY.ALL, - sortAs: EXPERIMENT_SORT_AS.ASCENDING, + sortAs: SORT_AS_DIRECTION.ASCENDING, } ); expect(results).toEqual(mockFlagArr); diff --git a/backend/packages/Upgrade/test/unit/services/UserService.test.ts b/backend/packages/Upgrade/test/unit/services/UserService.test.ts index c0b73acb35..849d087be2 100644 --- a/backend/packages/Upgrade/test/unit/services/UserService.test.ts +++ b/backend/packages/Upgrade/test/unit/services/UserService.test.ts @@ -6,7 +6,7 @@ import { UserRepository } from '../../../src/api/repositories/UserRepository'; import { User } from '../../../src/api/models/User'; import { UpgradeLogger } from '../../../src/lib/logger/UpgradeLogger'; import { USER_SEARCH_SORT_KEY } from '../../../src/api/controllers/validators/UserPaginatedParamsValidator'; -import { EXPERIMENT_SORT_AS, UserRole } from 'upgrade_types'; +import { SORT_AS_DIRECTION, UserRole } from 'upgrade_types'; import { AWSService } from '../../../src/api/services/AWSService'; import { Emails } from '../../../src/templates/email'; import UserServiceMock from '../controllers/mocks/UserServiceMock'; @@ -138,7 +138,7 @@ describe('User Service Testing', () => { }; const sortParams = { key: USER_SEARCH_SORT_KEY.FIRST_NAME, - sortAs: EXPERIMENT_SORT_AS.DESCENDING, + sortAs: SORT_AS_DIRECTION.DESCENDING, }; const users = await service.findPaginated(0, 0, logger, searchParams, sortParams); expect(repo.createQueryBuilder).toBeCalledWith('users'); diff --git a/frontend/projects/upgrade/src/app/core/experiments/experiments.service.spec.ts b/frontend/projects/upgrade/src/app/core/experiments/experiments.service.spec.ts index ebc50959cf..1dbc25af1b 100644 --- a/frontend/projects/upgrade/src/app/core/experiments/experiments.service.spec.ts +++ b/frontend/projects/upgrade/src/app/core/experiments/experiments.service.spec.ts @@ -10,7 +10,7 @@ import { ExperimentLocalStorageKeys, ExperimentVM, EXPERIMENT_SEARCH_KEY, - EXPERIMENT_SORT_AS, + SORT_AS_DIRECTION, EXPERIMENT_SORT_KEY, EXPERIMENT_STATE, POST_EXPERIMENT_RULE, @@ -540,7 +540,7 @@ describe('ExperimentService', () => { describe('#setSortingType', () => { it('should set localStorage item and dispatch actionSetSortingType with the given input', () => { - const sortingType = EXPERIMENT_SORT_AS.ASCENDING; + const sortingType = SORT_AS_DIRECTION.ASCENDING; service.setSortingType(sortingType); diff --git a/frontend/projects/upgrade/src/app/core/experiments/experiments.service.ts b/frontend/projects/upgrade/src/app/core/experiments/experiments.service.ts index 05425e15d3..2cf97e2923 100644 --- a/frontend/projects/upgrade/src/app/core/experiments/experiments.service.ts +++ b/frontend/projects/upgrade/src/app/core/experiments/experiments.service.ts @@ -7,7 +7,7 @@ import { ExperimentStateInfo, EXPERIMENT_SEARCH_KEY, EXPERIMENT_SORT_KEY, - EXPERIMENT_SORT_AS, + SORT_AS_DIRECTION, DATE_RANGE, ExperimentLocalStorageKeys, EXPERIMENT_STATE, @@ -82,8 +82,7 @@ export class ExperimentService { selectSearchExperimentParams(): Observable> { return combineLatest([this.selectSearchKey$, this.selectSearchString$]).pipe( filter(([searchKey, searchString]) => !!searchKey && !!searchString), - map(([searchKey, searchString]) => ({ searchKey, searchString })), - first() + map(([searchKey, searchString]) => ({ searchKey, searchString })) ); } @@ -191,7 +190,7 @@ export class ExperimentService { this.store$.dispatch(experimentAction.actionSetSortKey({ sortKey })); } - setSortingType(sortingType: EXPERIMENT_SORT_AS) { + setSortingType(sortingType: SORT_AS_DIRECTION) { this.localStorageService.setItem(ExperimentLocalStorageKeys.EXPERIMENT_SORT_TYPE, sortingType); this.store$.dispatch(experimentAction.actionSetSortingType({ sortingType })); } diff --git a/frontend/projects/upgrade/src/app/core/experiments/store/experiments.actions.ts b/frontend/projects/upgrade/src/app/core/experiments/store/experiments.actions.ts index d1b84df391..0b2195a3f5 100644 --- a/frontend/projects/upgrade/src/app/core/experiments/store/experiments.actions.ts +++ b/frontend/projects/upgrade/src/app/core/experiments/store/experiments.actions.ts @@ -6,7 +6,7 @@ import { ExperimentNameVM, EXPERIMENT_SEARCH_KEY, EXPERIMENT_SORT_KEY, - EXPERIMENT_SORT_AS, + SORT_AS_DIRECTION, IExperimentEnrollmentDetailStats, DATE_RANGE, IEnrollmentStatByDate, @@ -117,7 +117,7 @@ export const actionSetSortKey = createAction( export const actionSetSortingType = createAction( '[Experiment] Set Sorting type', - props<{ sortingType: EXPERIMENT_SORT_AS }>() + props<{ sortingType: SORT_AS_DIRECTION }>() ); export const actionFetchAllExperimentNames = createAction('[Experiment] Fetch All Experiment Names'); diff --git a/frontend/projects/upgrade/src/app/core/experiments/store/experiments.effects.spec.ts b/frontend/projects/upgrade/src/app/core/experiments/store/experiments.effects.spec.ts index d86e4b0da1..e45b38e52d 100644 --- a/frontend/projects/upgrade/src/app/core/experiments/store/experiments.effects.spec.ts +++ b/frontend/projects/upgrade/src/app/core/experiments/store/experiments.effects.spec.ts @@ -53,7 +53,7 @@ import { ExperimentEffects } from './experiments.effects'; import { DATE_RANGE, EXPERIMENT_SEARCH_KEY, - EXPERIMENT_SORT_AS, + SORT_AS_DIRECTION, EXPERIMENT_SORT_KEY, EXPERIMENT_STATE, UpsertExperimentType, @@ -109,7 +109,7 @@ describe('ExperimentEffects', () => { Selectors.selectTotalExperiment.setResult(1); Selectors.selectSearchKey.setResult(EXPERIMENT_SEARCH_KEY.ALL); Selectors.selectSortKey.setResult(EXPERIMENT_SORT_KEY.CREATED_AT); - Selectors.selectSortAs.setResult(EXPERIMENT_SORT_AS.ASCENDING); + Selectors.selectSortAs.setResult(SORT_AS_DIRECTION.ASCENDING); Selectors.selectSearchString.setResult('test'); service.getPaginatedExperiment$.subscribe((result: any) => { @@ -129,7 +129,7 @@ describe('ExperimentEffects', () => { Selectors.selectTotalExperiment.setResult(null); Selectors.selectSearchKey.setResult(EXPERIMENT_SEARCH_KEY.ALL); Selectors.selectSortKey.setResult(EXPERIMENT_SORT_KEY.CREATED_AT); - Selectors.selectSortAs.setResult(EXPERIMENT_SORT_AS.ASCENDING); + Selectors.selectSortAs.setResult(SORT_AS_DIRECTION.ASCENDING); Selectors.selectSearchString.setResult('test'); service.getPaginatedExperiment$.subscribe((result: any) => { @@ -158,7 +158,7 @@ describe('ExperimentEffects', () => { Selectors.selectTotalExperiment.setResult(1); Selectors.selectSearchKey.setResult(EXPERIMENT_SEARCH_KEY.ALL); Selectors.selectSortKey.setResult(EXPERIMENT_SORT_KEY.CREATED_AT); - Selectors.selectSortAs.setResult(EXPERIMENT_SORT_AS.ASCENDING); + Selectors.selectSortAs.setResult(SORT_AS_DIRECTION.ASCENDING); Selectors.selectSearchString.setResult('test'); service.getPaginatedExperiment$.pipe(take(2), pairwise()).subscribe((result: any) => { @@ -189,7 +189,7 @@ describe('ExperimentEffects', () => { Selectors.selectTotalExperiment.setResult(1); Selectors.selectSearchKey.setResult(EXPERIMENT_SEARCH_KEY.ALL); Selectors.selectSortKey.setResult(EXPERIMENT_SORT_KEY.CREATED_AT); - Selectors.selectSortAs.setResult(EXPERIMENT_SORT_AS.ASCENDING); + Selectors.selectSortAs.setResult(SORT_AS_DIRECTION.ASCENDING); Selectors.selectSearchString.setResult('test'); service.getPaginatedExperiment$ diff --git a/frontend/projects/upgrade/src/app/core/experiments/store/experiments.model.ts b/frontend/projects/upgrade/src/app/core/experiments/store/experiments.model.ts index c5212577e3..33693498f4 100644 --- a/frontend/projects/upgrade/src/app/core/experiments/store/experiments.model.ts +++ b/frontend/projects/upgrade/src/app/core/experiments/store/experiments.model.ts @@ -6,7 +6,7 @@ import { POST_EXPERIMENT_RULE, EXPERIMENT_SEARCH_KEY, EXPERIMENT_SORT_KEY, - EXPERIMENT_SORT_AS, + SORT_AS_DIRECTION, EXPERIMENT_STATE, IExperimentEnrollmentStats, IExperimentSearchParams, @@ -31,7 +31,7 @@ export { IExperimentEnrollmentStats, EXPERIMENT_SEARCH_KEY, EXPERIMENT_SORT_KEY, - EXPERIMENT_SORT_AS, + SORT_AS_DIRECTION, IExperimentSearchParams, IExperimentSortParams, IExperimentEnrollmentDetailStats, @@ -292,7 +292,7 @@ export interface ExperimentState extends EntityState { searchKey: EXPERIMENT_SEARCH_KEY; searchString: string; sortKey: EXPERIMENT_SORT_KEY; - sortAs: EXPERIMENT_SORT_AS; + sortAs: SORT_AS_DIRECTION; stats: Record; graphInfo: IExperimentGraphInfo; graphRange: DATE_RANGE; diff --git a/frontend/projects/upgrade/src/app/core/experiments/store/experiments.reducer.spec.ts b/frontend/projects/upgrade/src/app/core/experiments/store/experiments.reducer.spec.ts index ccb55a8033..6466c9e050 100644 --- a/frontend/projects/upgrade/src/app/core/experiments/store/experiments.reducer.spec.ts +++ b/frontend/projects/upgrade/src/app/core/experiments/store/experiments.reducer.spec.ts @@ -40,7 +40,7 @@ import { ExperimentState, ExperimentVM, EXPERIMENT_SEARCH_KEY, - EXPERIMENT_SORT_AS, + SORT_AS_DIRECTION, EXPERIMENT_SORT_KEY, UpsertExperimentType, } from './experiments.model'; @@ -559,16 +559,16 @@ describe('ExperimentsReducer', () => { it('action "actionSetSortingType" should set sort-as', () => { const previousState = { ...initialState }; - previousState.sortAs = EXPERIMENT_SORT_AS.DESCENDING; + previousState.sortAs = SORT_AS_DIRECTION.DESCENDING; const testAction: Action = actionSetSortingType({ - sortingType: EXPERIMENT_SORT_AS.ASCENDING, + sortingType: SORT_AS_DIRECTION.ASCENDING, }); const newState = experimentsReducer(previousState, testAction); expect(newState).not.toBe(previousState); - expect(newState.sortAs).toEqual(EXPERIMENT_SORT_AS.ASCENDING); + expect(newState.sortAs).toEqual(SORT_AS_DIRECTION.ASCENDING); }); it('action "actionSetSkipExperiment" should set experiment skip value', () => { diff --git a/frontend/projects/upgrade/src/app/core/experiments/store/experiments.reducer.ts b/frontend/projects/upgrade/src/app/core/experiments/store/experiments.reducer.ts index 03c9ce5311..940bb595a5 100644 --- a/frontend/projects/upgrade/src/app/core/experiments/store/experiments.reducer.ts +++ b/frontend/projects/upgrade/src/app/core/experiments/store/experiments.reducer.ts @@ -2,7 +2,7 @@ import { ExperimentState, Experiment, EXPERIMENT_SEARCH_KEY, - EXPERIMENT_SORT_AS, + SORT_AS_DIRECTION, EXPERIMENT_SORT_KEY, } from './experiments.model'; import { createReducer, on, Action } from '@ngrx/store'; @@ -22,7 +22,7 @@ export const initialState: ExperimentState = adapter.getInitialState({ searchKey: EXPERIMENT_SEARCH_KEY.ALL, searchString: null, sortKey: EXPERIMENT_SORT_KEY.NAME, - sortAs: EXPERIMENT_SORT_AS.ASCENDING, + sortAs: SORT_AS_DIRECTION.ASCENDING, stats: {}, graphInfo: null, graphRange: null, diff --git a/frontend/projects/upgrade/src/app/core/experiments/store/experiments.selector.spec.ts b/frontend/projects/upgrade/src/app/core/experiments/store/experiments.selector.spec.ts index 5836704a58..c5f4dd3244 100644 --- a/frontend/projects/upgrade/src/app/core/experiments/store/experiments.selector.spec.ts +++ b/frontend/projects/upgrade/src/app/core/experiments/store/experiments.selector.spec.ts @@ -1,7 +1,7 @@ import { ASSIGNMENT_ALGORITHM, EXPERIMENT_TYPE, FILTER_MODE, SEGMENT_TYPE } from 'upgrade_types'; import { ExperimentState, - EXPERIMENT_SORT_AS, + SORT_AS_DIRECTION, EXPERIMENT_SORT_KEY, DATE_RANGE, EXPERIMENT_STATE, @@ -211,7 +211,7 @@ describe('Experiments Selectors', () => { searchKey: null, searchString: null, sortKey: EXPERIMENT_SORT_KEY.NAME, - sortAs: EXPERIMENT_SORT_AS.ASCENDING, + sortAs: SORT_AS_DIRECTION.ASCENDING, stats: { '1f12cd8f-7ff9-4731-a4eb-7104918ed252': { id: '1f12cd8f-7ff9-4731-a4eb-7104918ed252', diff --git a/frontend/projects/upgrade/src/app/core/local-storage/local-storage.service.spec.ts b/frontend/projects/upgrade/src/app/core/local-storage/local-storage.service.spec.ts index 06f8647cfd..2c905e6e69 100755 --- a/frontend/projects/upgrade/src/app/core/local-storage/local-storage.service.spec.ts +++ b/frontend/projects/upgrade/src/app/core/local-storage/local-storage.service.spec.ts @@ -1,7 +1,7 @@ import { ExperimentState, EXPERIMENT_SEARCH_KEY, - EXPERIMENT_SORT_AS, + SORT_AS_DIRECTION, EXPERIMENT_SORT_KEY, } from '../experiments/store/experiments.model'; import { LocalStorageService } from './local-storage.service'; @@ -31,7 +31,7 @@ describe('LocalStorageService', () => { searchKey: EXPERIMENT_SEARCH_KEY.ALL, searchString: 'test', sortKey: EXPERIMENT_SORT_KEY.STATUS, - sortAs: EXPERIMENT_SORT_AS.ASCENDING, + sortAs: SORT_AS_DIRECTION.ASCENDING, stats: {}, graphInfo: null, graphRange: null, @@ -55,7 +55,7 @@ describe('LocalStorageService', () => { searchKey: null, searchString: null, sortKey: EXPERIMENT_SORT_KEY.NAME, - sortAs: EXPERIMENT_SORT_AS.ASCENDING, + sortAs: SORT_AS_DIRECTION.ASCENDING, stats: {}, graphInfo: null, graphRange: null, @@ -74,7 +74,7 @@ describe('LocalStorageService', () => { whenCondition: 'when data in local storage, THEN experiment should use those values', expectedValue: expectedStateWithFetchedValues, fetchedSortKey: EXPERIMENT_SORT_KEY.STATUS, - fetchedSortAs: EXPERIMENT_SORT_AS.ASCENDING, + fetchedSortAs: SORT_AS_DIRECTION.ASCENDING, fetchedSearchKey: EXPERIMENT_SEARCH_KEY.ALL, fetchedSearchString: 'test', }, diff --git a/frontend/projects/upgrade/src/app/core/local-storage/local-storage.service.ts b/frontend/projects/upgrade/src/app/core/local-storage/local-storage.service.ts index ee395b036a..e5883ea40e 100755 --- a/frontend/projects/upgrade/src/app/core/local-storage/local-storage.service.ts +++ b/frontend/projects/upgrade/src/app/core/local-storage/local-storage.service.ts @@ -3,11 +3,10 @@ import { ExperimentLocalStorageKeys, ExperimentState, EXPERIMENT_SEARCH_KEY, - EXPERIMENT_SORT_AS, EXPERIMENT_SORT_KEY, } from '../experiments/store/experiments.model'; import { SegmentLocalStorageKeys, SegmentState } from '../segments/store/segments.model'; -import { SEGMENT_SEARCH_KEY, SEGMENT_SORT_AS, SEGMENT_SORT_KEY } from 'upgrade_types'; +import { SEGMENT_SEARCH_KEY, SORT_AS_DIRECTION, SEGMENT_SORT_KEY } from 'upgrade_types'; const APP_PREFIX = 'UPGRADE-'; @@ -38,7 +37,7 @@ export class LocalStorageService { searchKey: experimentSearchKey as EXPERIMENT_SEARCH_KEY, searchString: experimentSearchString || null, sortKey: (experimentSortKey as EXPERIMENT_SORT_KEY) || EXPERIMENT_SORT_KEY.NAME, - sortAs: (experimentSortType as EXPERIMENT_SORT_AS) || EXPERIMENT_SORT_AS.ASCENDING, + sortAs: (experimentSortType as SORT_AS_DIRECTION) || SORT_AS_DIRECTION.ASCENDING, stats: {}, graphInfo: null, graphRange: null, @@ -61,7 +60,7 @@ export class LocalStorageService { searchKey: segmentSearchKey as SEGMENT_SEARCH_KEY, searchString: segmentSearchString || null, sortKey: (segmentSortKey as SEGMENT_SORT_KEY) || SEGMENT_SORT_KEY.NAME, - sortAs: (segmentSortType as SEGMENT_SORT_AS) || SEGMENT_SORT_AS.ASCENDING, + sortAs: (segmentSortType as SORT_AS_DIRECTION) || SORT_AS_DIRECTION.ASCENDING, }; const state = { diff --git a/frontend/projects/upgrade/src/app/core/segments/segments.service.ts b/frontend/projects/upgrade/src/app/core/segments/segments.service.ts index 456996f4c1..663304c64b 100644 --- a/frontend/projects/upgrade/src/app/core/segments/segments.service.ts +++ b/frontend/projects/upgrade/src/app/core/segments/segments.service.ts @@ -18,7 +18,7 @@ import { SegmentInput, SegmentLocalStorageKeys, UpsertSegmentType } from './stor import { filter, first, map, tap } from 'rxjs/operators'; import { Observable, combineLatest } from 'rxjs'; import { SegmentsDataService } from './segments.data.service'; -import { SEGMENT_SEARCH_KEY, SEGMENT_SORT_AS, SEGMENT_SORT_KEY } from 'upgrade_types'; +import { SEGMENT_SEARCH_KEY, SORT_AS_DIRECTION, SEGMENT_SORT_KEY } from 'upgrade_types'; import { LocalStorageService } from '../local-storage/local-storage.service'; @Injectable({ providedIn: 'root' }) @@ -41,8 +41,7 @@ export class SegmentsService { selectSearchSegmentParams(): Observable> { return combineLatest([this.selectSearchKey$, this.selectSearchString$]).pipe( filter(([searchKey, searchString]) => !!searchKey && !!searchString), - map(([searchKey, searchString]) => ({ searchKey, searchString })), - first() + map(([searchKey, searchString]) => ({ searchKey, searchString })) ); } @@ -105,7 +104,7 @@ export class SegmentsService { this.store$.dispatch(SegmentsActions.actionSetSortKey({ sortKey })); } - setSortingType(sortingType: SEGMENT_SORT_AS) { + setSortingType(sortingType: SORT_AS_DIRECTION) { this.localStorageService.setItem(SegmentLocalStorageKeys.SEGMENT_SORT_TYPE, sortingType); this.store$.dispatch(SegmentsActions.actionSetSortingType({ sortingType })); } diff --git a/frontend/projects/upgrade/src/app/core/segments/store/segments.actions.ts b/frontend/projects/upgrade/src/app/core/segments/store/segments.actions.ts index 1246edd114..0ccc32f9a6 100644 --- a/frontend/projects/upgrade/src/app/core/segments/store/segments.actions.ts +++ b/frontend/projects/upgrade/src/app/core/segments/store/segments.actions.ts @@ -2,7 +2,7 @@ import { createAction, props } from '@ngrx/store'; import { Segment, SegmentInput, UpsertSegmentType, experimentSegmentInclusionExclusionData } from './segments.model'; import { SEGMENT_SEARCH_KEY, - SEGMENT_SORT_AS, + SORT_AS_DIRECTION, SEGMENT_SORT_KEY, } from '../../../../../../../../types/src/Experiment/enums'; @@ -71,5 +71,5 @@ export const actionSetSortKey = createAction('[Segments] Set Sort key value', pr export const actionSetSortingType = createAction( '[Segments] Set Sorting type', - props<{ sortingType: SEGMENT_SORT_AS }>() + props<{ sortingType: SORT_AS_DIRECTION }>() ); diff --git a/frontend/projects/upgrade/src/app/core/segments/store/segments.effects.ts b/frontend/projects/upgrade/src/app/core/segments/store/segments.effects.ts index ffb6af9687..1cc427214a 100644 --- a/frontend/projects/upgrade/src/app/core/segments/store/segments.effects.ts +++ b/frontend/projects/upgrade/src/app/core/segments/store/segments.effects.ts @@ -2,12 +2,12 @@ import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import { select, Store } from '@ngrx/store'; -import { catchError, filter, map, switchMap, tap, withLatestFrom } from 'rxjs/operators'; +import { catchError, filter, map, switchMap, withLatestFrom } from 'rxjs/operators'; import { AppState, NotificationService } from '../../core.module'; import { SegmentsDataService } from '../segments.data.service'; import * as SegmentsActions from './segments.actions'; import { Segment, UpsertSegmentType } from './segments.model'; -import { selectAllSegments, selectSearchString } from './segments.selectors'; +import { selectAllSegments } from './segments.selectors'; import JSZip from 'jszip'; @Injectable() @@ -55,35 +55,6 @@ export class SegmentsEffects { ) ); - fetchSegmentOnSearchString$ = createEffect( - () => - this.actions$.pipe( - ofType(SegmentsActions.actionSetSearchString), - map((action) => action.searchString), - tap((searchString) => { - // Allow empty string as we erasing text from search input - if (searchString !== null) { - this.store$.dispatch(SegmentsActions.actionFetchSegments({ fromStarting: true })); - } - }) - ), - { dispatch: false } - ); - - fetchSegmentOnSearchKeyChange$ = createEffect( - () => - this.actions$.pipe( - ofType(SegmentsActions.actionSetSearchKey), - withLatestFrom(this.store$.pipe(select(selectSearchString))), - tap(([_, searchString]) => { - if (searchString) { - this.store$.dispatch(SegmentsActions.actionFetchSegments({ fromStarting: true })); - } - }) - ), - { dispatch: false } - ); - upsertSegment$ = createEffect(() => this.actions$.pipe( ofType(SegmentsActions.actionUpsertSegment), diff --git a/frontend/projects/upgrade/src/app/core/segments/store/segments.model.ts b/frontend/projects/upgrade/src/app/core/segments/store/segments.model.ts index a32422fcd9..ddc3fc9a6c 100644 --- a/frontend/projects/upgrade/src/app/core/segments/store/segments.model.ts +++ b/frontend/projects/upgrade/src/app/core/segments/store/segments.model.ts @@ -1,6 +1,6 @@ import { AppState } from '../../core.state'; import { EntityState } from '@ngrx/entity'; -import { SEGMENT_TYPE, SEGMENT_STATUS, SEGMENT_SEARCH_KEY, SEGMENT_SORT_AS, SEGMENT_SORT_KEY } from 'upgrade_types'; +import { SEGMENT_TYPE, SEGMENT_STATUS, SEGMENT_SEARCH_KEY, SORT_AS_DIRECTION, SEGMENT_SORT_KEY } from 'upgrade_types'; export { SEGMENT_STATUS }; export enum NewSegmentDialogEvents { @@ -106,7 +106,7 @@ export interface SegmentState extends EntityState { searchKey: SEGMENT_SEARCH_KEY; searchString: string; sortKey: SEGMENT_SORT_KEY; - sortAs: SEGMENT_SORT_AS; + sortAs: SORT_AS_DIRECTION; } export interface State extends AppState { diff --git a/frontend/projects/upgrade/src/app/core/segments/store/segments.reducer.ts b/frontend/projects/upgrade/src/app/core/segments/store/segments.reducer.ts index 95e29bce57..af29a45243 100644 --- a/frontend/projects/upgrade/src/app/core/segments/store/segments.reducer.ts +++ b/frontend/projects/upgrade/src/app/core/segments/store/segments.reducer.ts @@ -4,7 +4,7 @@ import { SegmentState, Segment } from './segments.model'; import * as SegmentsActions from './segments.actions'; import { SEGMENT_SEARCH_KEY, - SEGMENT_SORT_AS, + SORT_AS_DIRECTION, SEGMENT_SORT_KEY, } from '../../../../../../../../types/src/Experiment/enums'; @@ -19,7 +19,7 @@ export const initialState: SegmentState = adapter.getInitialState({ searchKey: SEGMENT_SEARCH_KEY.ALL, searchString: null, sortKey: SEGMENT_SORT_KEY.NAME, - sortAs: SEGMENT_SORT_AS.ASCENDING, + sortAs: SORT_AS_DIRECTION.ASCENDING, }); const reducer = createReducer( diff --git a/frontend/projects/upgrade/src/app/features/dashboard/home/components/experiment-list/experiment-list.component.html b/frontend/projects/upgrade/src/app/features/dashboard/home/components/experiment-list/experiment-list.component.html index aac2b87abb..ca6b2f155e 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/home/components/experiment-list/experiment-list.component.html +++ b/frontend/projects/upgrade/src/app/features/dashboard/home/components/experiment-list/experiment-list.component.html @@ -8,7 +8,7 @@ {{ filterOption | titlecase }} diff --git a/frontend/projects/upgrade/src/app/features/dashboard/home/components/experiment-list/experiment-list.component.ts b/frontend/projects/upgrade/src/app/features/dashboard/home/components/experiment-list/experiment-list.component.ts index 68f57d974c..7336cfece6 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/home/components/experiment-list/experiment-list.component.ts +++ b/frontend/projects/upgrade/src/app/features/dashboard/home/components/experiment-list/experiment-list.component.ts @@ -151,8 +151,8 @@ export class ExperimentListComponent implements OnInit, OnDestroy, AfterViewInit } } - setSearchKey() { - this.experimentService.setSearchKey(this.selectedExperimentFilterOption); + setSearchKey(searchKey: EXPERIMENT_SEARCH_KEY) { + this.experimentService.setSearchKey(searchKey); } setSearchString(searchString: FLAG_SEARCH_SORT_KEY) { @@ -170,10 +170,7 @@ export class ExperimentListComponent implements OnInit, OnDestroy, AfterViewInit } filterExperimentByChips(tagValue: FLAG_SEARCH_SORT_KEY, type: EXPERIMENT_SEARCH_KEY) { - this.searchValue = tagValue; - this.selectedExperimentFilterOption = type; - this.applyFilter(tagValue); - this.setSearchKey(); + this.setSearchKey(type); this.setSearchString(tagValue); } diff --git a/frontend/projects/upgrade/src/app/features/dashboard/segments/components/segments-list/segments-list.component.html b/frontend/projects/upgrade/src/app/features/dashboard/segments/components/segments-list/segments-list.component.html index 2458f2c0e4..8023d4230a 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/segments/components/segments-list/segments-list.component.html +++ b/frontend/projects/upgrade/src/app/features/dashboard/segments/components/segments-list/segments-list.component.html @@ -8,7 +8,7 @@ {{ filterOption | titlecase }} diff --git a/frontend/projects/upgrade/src/app/features/dashboard/segments/components/segments-list/segments-list.component.ts b/frontend/projects/upgrade/src/app/features/dashboard/segments/components/segments-list/segments-list.component.ts index fbc145b2ee..47331ada4b 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/segments/components/segments-list/segments-list.component.ts +++ b/frontend/projects/upgrade/src/app/features/dashboard/segments/components/segments-list/segments-list.component.ts @@ -126,8 +126,8 @@ export class SegmentsListComponent implements OnInit, OnDestroy, AfterViewInit { } } - setSearchKey() { - this.segmentsService.setSearchKey(this.selectedSegmentFilterOption); + setSearchKey(searchKey: SEGMENT_SEARCH_KEY) { + this.segmentsService.setSearchKey(searchKey); } setSearchString(searchString: string) { @@ -141,14 +141,10 @@ export class SegmentsListComponent implements OnInit, OnDestroy, AfterViewInit { top: 0, behavior: 'smooth', }); - this.segmentsService.fetchSegments(true); } filterSegmentsByChips(tagValue: string, type: SEGMENT_SEARCH_KEY) { - this.searchValue = tagValue; - this.selectedSegmentFilterOption = type; - this.applyFilter(tagValue); - this.setSearchKey(); + this.setSearchKey(type); this.setSearchString(tagValue); } diff --git a/types/src/Experiment/enums.ts b/types/src/Experiment/enums.ts index 2174b9bef9..49156d7eaf 100644 --- a/types/src/Experiment/enums.ts +++ b/types/src/Experiment/enums.ts @@ -119,7 +119,7 @@ export enum EXPERIMENT_SORT_KEY { POST_EXPERIMENT_RULE = 'postExperimentRule', } -export enum EXPERIMENT_SORT_AS { +export enum SORT_AS_DIRECTION { ASCENDING = 'ASC', DESCENDING = 'DESC', } @@ -195,11 +195,6 @@ export enum SEGMENT_SORT_KEY { UPDATED_AT = 'updatedAt', } -export enum SEGMENT_SORT_AS { - ASCENDING = 'ASC', - DESCENDING = 'DESC', -} - export enum INCLUSION_CRITERIA { INCLUDE_SPECIFIC = 'Include Specific', EXCEPT = 'Include All Except...', diff --git a/types/src/Experiment/interfaces.ts b/types/src/Experiment/interfaces.ts index 904859dc7f..2e0bd6b40c 100644 --- a/types/src/Experiment/interfaces.ts +++ b/types/src/Experiment/interfaces.ts @@ -2,7 +2,7 @@ import { EXPERIMENT_STATE, EXPERIMENT_SEARCH_KEY, EXPERIMENT_SORT_KEY, - EXPERIMENT_SORT_AS, + SORT_AS_DIRECTION, IMetricMetaData, PAYLOAD_TYPE, SUPPORTED_CALIPER_EVENTS, @@ -105,7 +105,7 @@ export interface IExperimentSearchParams { export interface IExperimentSortParams { key: EXPERIMENT_SORT_KEY; - sortAs: EXPERIMENT_SORT_AS; + sortAs: SORT_AS_DIRECTION; } export interface IMetricUnit { diff --git a/types/src/index.ts b/types/src/index.ts index a85e35f9f5..1b3875bd28 100644 --- a/types/src/index.ts +++ b/types/src/index.ts @@ -9,7 +9,7 @@ export { EXPERIMENT_LOG_TYPE, EXPERIMENT_SEARCH_KEY, EXPERIMENT_SORT_KEY, - EXPERIMENT_SORT_AS, + SORT_AS_DIRECTION, UserRole, OPERATION_TYPES, IMetricMetaData, @@ -29,7 +29,6 @@ export { CACHE_PREFIX, ASSIGNMENT_ALGORITHM, SEGMENT_SEARCH_KEY, - SEGMENT_SORT_AS, SEGMENT_SORT_KEY, FEATURE_FLAG_STATUS, } from './Experiment/enums';