Skip to content

Commit

Permalink
Merge pull request #1445 from CarnegieLearningWeb/enhancement/make-se…
Browse files Browse the repository at this point in the history
…gment-context-chips-for-search-functional

Segment context chips in list and view comp feature added
  • Loading branch information
Yagnik56 authored Apr 29, 2024
2 parents fd58641 + a6f4cd7 commit f398e84
Show file tree
Hide file tree
Showing 35 changed files with 285 additions and 95 deletions.
4 changes: 2 additions & 2 deletions backend/packages/Upgrade/src/api/DTO/ExperimentDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
EXPERIMENT_STATE,
EXPERIMENT_SEARCH_KEY,
EXPERIMENT_SORT_KEY,
EXPERIMENT_SORT_AS,
SORT_AS_DIRECTION,
FILTER_MODE,
IEnrollmentCompleteCondition,
IExperimentSearchParams,
Expand All @@ -39,7 +39,7 @@ import { Type } from 'class-transformer';

export {
EXPERIMENT_SEARCH_KEY,
EXPERIMENT_SORT_AS,
SORT_AS_DIRECTION,
EXPERIMENT_SORT_KEY,
IExperimentSearchParams,
IExperimentSortParams,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -10,7 +10,7 @@ class ExperimentSearchParam {
@IsNotEmpty()
@IsDefined()
@IsString()
public string: string
public string: string;
}

class ExperimentSortParam {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
Expand 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 {
Expand Down
4 changes: 2 additions & 2 deletions backend/packages/Upgrade/src/api/models/Experiment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
EXPERIMENT_STATE,
EXPERIMENT_SEARCH_KEY,
EXPERIMENT_SORT_KEY,
EXPERIMENT_SORT_AS,
SORT_AS_DIRECTION,
FILTER_MODE,
IEnrollmentCompleteCondition,
IExperimentSearchParams,
Expand All @@ -30,7 +30,7 @@ import { StratificationFactor } from './StratificationFactor';

export {
EXPERIMENT_SEARCH_KEY,
EXPERIMENT_SORT_AS,
SORT_AS_DIRECTION,
EXPERIMENT_SORT_KEY,
IExperimentSearchParams,
IExperimentSortParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ExperimentLocalStorageKeys,
ExperimentVM,
EXPERIMENT_SEARCH_KEY,
EXPERIMENT_SORT_AS,
SORT_AS_DIRECTION,
EXPERIMENT_SORT_KEY,
EXPERIMENT_STATE,
POST_EXPERIMENT_RULE,
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ExperimentStateInfo,
EXPERIMENT_SEARCH_KEY,
EXPERIMENT_SORT_KEY,
EXPERIMENT_SORT_AS,
SORT_AS_DIRECTION,
DATE_RANGE,
ExperimentLocalStorageKeys,
EXPERIMENT_STATE,
Expand Down Expand Up @@ -82,8 +82,7 @@ export class ExperimentService {
selectSearchExperimentParams(): Observable<Record<string, unknown>> {
return combineLatest([this.selectSearchKey$, this.selectSearchString$]).pipe(
filter(([searchKey, searchString]) => !!searchKey && !!searchString),
map(([searchKey, searchString]) => ({ searchKey, searchString })),
first()
map(([searchKey, searchString]) => ({ searchKey, searchString }))
);
}

Expand Down Expand Up @@ -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 }));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ExperimentNameVM,
EXPERIMENT_SEARCH_KEY,
EXPERIMENT_SORT_KEY,
EXPERIMENT_SORT_AS,
SORT_AS_DIRECTION,
IExperimentEnrollmentDetailStats,
DATE_RANGE,
IEnrollmentStatByDate,
Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
POST_EXPERIMENT_RULE,
EXPERIMENT_SEARCH_KEY,
EXPERIMENT_SORT_KEY,
EXPERIMENT_SORT_AS,
SORT_AS_DIRECTION,
EXPERIMENT_STATE,
IExperimentEnrollmentStats,
IExperimentSearchParams,
Expand All @@ -31,7 +31,7 @@ export {
IExperimentEnrollmentStats,
EXPERIMENT_SEARCH_KEY,
EXPERIMENT_SORT_KEY,
EXPERIMENT_SORT_AS,
SORT_AS_DIRECTION,
IExperimentSearchParams,
IExperimentSortParams,
IExperimentEnrollmentDetailStats,
Expand Down Expand Up @@ -292,7 +292,7 @@ export interface ExperimentState extends EntityState<Experiment> {
searchKey: EXPERIMENT_SEARCH_KEY;
searchString: string;
sortKey: EXPERIMENT_SORT_KEY;
sortAs: EXPERIMENT_SORT_AS;
sortAs: SORT_AS_DIRECTION;
stats: Record<string, IExperimentEnrollmentDetailStats>;
graphInfo: IExperimentGraphInfo;
graphRange: DATE_RANGE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
ExperimentState,
ExperimentVM,
EXPERIMENT_SEARCH_KEY,
EXPERIMENT_SORT_AS,
SORT_AS_DIRECTION,
EXPERIMENT_SORT_KEY,
UpsertExperimentType,
} from './experiments.model';
Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down
Loading

0 comments on commit f398e84

Please sign in to comment.