Skip to content

Commit

Permalink
Merged in feature/SHIBUI-729 (pull request #171)
Browse files Browse the repository at this point in the history
SHIBUI-729 Implemented filter re-ordering

Approved-by: Shibui Jenkins <shibui.jenkins@gmail.com>
Approved-by: Ryan Mathis <rmathis@unicon.net>
  • Loading branch information
rmathis committed Aug 22, 2018
1 parent 98aa4ba commit bf5288e
Show file tree
Hide file tree
Showing 24 changed files with 613 additions and 142 deletions.
59 changes: 59 additions & 0 deletions ui/src/app/contention/reducer/contention.reducer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { reducer, initialState as snapshot, getContention } from './contention.reducer';
import { ContentionActionTypes, ShowContentionAction, ResolveContentionAction, CancelContentionAction } from '../action/contention.action';

describe('Contention Reducer', () => {

const contention = {
base: {},
ours: {},
theirs: {},

rejectionObject: {},
resolutionObject: {},

ourChanges: {},
theirChanges: {},

handlers: {
resolve: (value: {}) => ({}),
reject: (value: {}) => ({})
}
};

const populated = { ...snapshot, contention: { ...contention } };

const resolution = { value: contention.ours, handlers: contention.handlers };

describe('undefined action', () => {
it('should return the default state', () => {
const result = reducer(snapshot, {} as any);

expect(result).toEqual(snapshot);
});
});

describe(`${ContentionActionTypes.SHOW_CONTENTION}`, () => {
it('should reset to initial state', () => {
expect(reducer(snapshot, new ShowContentionAction(contention))).toEqual(populated);
});
});

describe(`${ContentionActionTypes.RESOLVE_CONTENTION}`, () => {
it('should reset to initial state', () => {
expect(reducer(snapshot, new ResolveContentionAction(resolution))).toEqual(snapshot);
});
});

describe(`${ContentionActionTypes.CANCEL_CONTENTION}`, () => {
it('should reset to initial state', () => {
expect(reducer(snapshot, new CancelContentionAction(resolution))).toEqual(snapshot);
});
});

describe(`getContention method`, () => {
it('should return the contention object from the state', () => {
expect(getContention(snapshot)).toBe(snapshot.contention);
expect(getContention(populated)).toEqual(contention);
});
});
});
20 changes: 20 additions & 0 deletions ui/src/app/metadata/domain/domain.util.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as util from './domain.util';
import { MetadataProvider } from './model';

describe('Domain Utility methods', () => {

Expand Down Expand Up @@ -33,4 +34,23 @@ describe('Domain Utility methods', () => {
expect(util.getEntityIdsFn(entities)).toEqual(['foo', 'bar']);
});
});

describe('mergeProviderOrderFn', () => {
const providers = <MetadataProvider[]>[
{ resourceId: 'foo', name: 'foo', '@type': 'foo', enabled: true, xmlId: 'id', sortKey: 1, metadataFilters: [] },
{ resourceId: 'bar', name: 'bar', '@type': 'bar', enabled: false, xmlId: 'id2', sortKey: 2, metadataFilters: [] },
{ resourceId: 'baz', name: 'baz', '@type': 'baz', enabled: false, xmlId: 'id3', sortKey: 3, metadataFilters: [] }
];
it('1 should sort the list accordingly', () => {
let order = ['bar', 'foo', 'baz'],
ordered = util.mergeOrderFn([...providers], order);
expect(ordered.indexOf(providers[0])).toBe(1);
});

it('2 should sort the list accordingly', () => {
let order = ['foo', 'bar', 'baz'],
ordered = util.mergeOrderFn(providers, order);
expect(ordered.indexOf(providers[0])).toBe(0);
});
});
});
12 changes: 12 additions & 0 deletions ui/src/app/metadata/domain/domain.util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Metadata } from './domain.type';

/*
* Utility functions
*/
Expand All @@ -8,3 +10,13 @@ export const getInCollectionFn = (entities, selectedId) => {
return selectedId && entities[selectedId];
};
export const getEntityIdsFn = list => list.map(entity => entity.entityId);

export const mergeOrderFn = (entities: Metadata[], order: string[]): Metadata[] => {
return [...entities.sort(
(a: Metadata, b: Metadata) => {
const aIndex = order.indexOf(a.resourceId);
const bIndex = order.indexOf(b.resourceId);
return aIndex > bIndex ? 1 : bIndex > aIndex ? -1 : 0;
}
)];
};
3 changes: 0 additions & 3 deletions ui/src/app/metadata/domain/model/metadata-order.ts

This file was deleted.

1 change: 1 addition & 0 deletions ui/src/app/metadata/domain/model/metadata-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '../model';

export interface MetadataResolver extends MetadataBase {
resourceId?: string;
entityId: string;
serviceProviderName: string;
organization?: Organization;
Expand Down
20 changes: 15 additions & 5 deletions ui/src/app/metadata/domain/service/filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,38 @@ import { MetadataFilter } from '../../domain/model';
export class MetadataFilterService {

readonly endpoint = '/MetadataResolvers';
readonly order = 'FiltersPositionOrder';
readonly base = '/api';
readonly path = 'Filters';

constructor(
private http: HttpClient
) { }
query(providerId: string): Observable<MetadataFilter[]> {
return this.http.get<MetadataFilter[]>(`${this.base}${this.endpoint}/${providerId}/Filters`);
return this.http.get<MetadataFilter[]>(`${this.base}${this.endpoint}/${providerId}/${this.path}`);
}

find(providerId: string, filterId: string): Observable<MetadataFilter> {
return this.http.get<MetadataFilter>(`${this.base}${this.endpoint}/${providerId}/Filters/${ filterId }`);
return this.http.get<MetadataFilter>(`${this.base}${this.endpoint}/${providerId}/${this.path}/${filterId}`);
}

update(providerId: string, filter: MetadataFilter): Observable<MetadataFilter> {
return this.http.put<MetadataFilter>(`${this.base}${this.endpoint}/${providerId}/Filters/${ filter.resourceId }`, filter);
return this.http.put<MetadataFilter>(`${this.base}${this.endpoint}/${providerId}/${this.path}/${ filter.resourceId }`, filter);
}

save(providerId: string, filter: MetadataFilter): Observable<MetadataFilter> {
return this.http.post<MetadataFilter>(`${this.base}${this.endpoint}/${providerId}/Filters`, filter);
return this.http.post<MetadataFilter>(`${this.base}${this.endpoint}/${providerId}/${this.path}`, filter);
}

getOrder(providerId: string): Observable<string[]> {
return this.http.get<string[]>(`${this.base}${this.endpoint}/${providerId}/${this.order}`);
}

setOrder(providerId: string, order: string[]): Observable<string[]> {
return this.http.post<string[]>(`${this.base}${this.endpoint}/${providerId}/${this.order}`, order);
}

remove(providerId: string, filterId: string): Observable<string> {
return this.http.delete<string>(`${this.base}${this.endpoint}/${providerId}/Filters/${ filterId }`);
return this.http.delete<string>(`${this.base}${this.endpoint}/${providerId}/${this.path}/${filterId}`);
}
}
14 changes: 8 additions & 6 deletions ui/src/app/metadata/domain/service/provider.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

import { MetadataProvider } from '../../domain/model';
import { FileBackedHttpMetadataProvider } from '../model/providers';
import { ProviderOrder } from '../model/metadata-order';


@Injectable()
Expand Down Expand Up @@ -36,11 +34,15 @@ export class MetadataProviderService {
return this.http.post<MetadataProvider>(`${this.base}${this.endpoint}`, provider);
}

getOrder(): Observable<ProviderOrder> {
return this.http.get<ProviderOrder>(`${this.base}${this.order}`);
getOrder(): Observable<string[]> {
return this.http.get<{ [resourceIds: string]: string[] }>(`${this.base}${this.order}`).pipe(
map(
(order: {[resourceIds: string]: string[]}) => order.resourceIds
)
);
}

setOrder(order: ProviderOrder): Observable<ProviderOrder> {
return this.http.post<ProviderOrder>(`${this.base}${this.order}`, order);
setOrder(order: string[]): Observable<string[]> {
return this.http.post<string[]>(`${this.base}${this.order}`, { resourceIds: order });
}
}
74 changes: 71 additions & 3 deletions ui/src/app/metadata/filter/action/collection.action.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Action } from '@ngrx/store';
import { MetadataFilter } from '../../domain/model/metadata-filter';
import { Update } from '@ngrx/entity';

import { MetadataFilter } from '../../domain/model/metadata-filter';

export enum FilterCollectionActionTypes {
SELECT_FILTER_REQUEST = '[Metadata Filter Collection] Select Filter Request',
SELECT_FILTER_SUCCESS = '[Metadata Filter Collection] Select Filter Success',
Expand All @@ -21,7 +22,18 @@ export enum FilterCollectionActionTypes {

REMOVE_FILTER_REQUEST = '[Metadata Filter Collection] Remove Filter Request',
REMOVE_FILTER_SUCCESS = '[Metadata Filter Collection] Remove Filter Success',
REMOVE_FILTER_FAIL = '[Metadata Filter Collection] Remove Filter Fail'
REMOVE_FILTER_FAIL = '[Metadata Filter Collection] Remove Filter Fail',

SET_ORDER_FILTER_REQUEST = '[Metadata Filter Collection] Set Order Filter Request',
SET_ORDER_FILTER_SUCCESS = '[Metadata Filter Collection] Set Order Filter Success',
SET_ORDER_FILTER_FAIL = '[Metadata Filter Collection] Set Order Filter Fail',

GET_ORDER_FILTER_REQUEST = '[Metadata Filter Collection] Get Order Filter Request',
GET_ORDER_FILTER_SUCCESS = '[Metadata Filter Collection] Get Order Filter Success',
GET_ORDER_FILTER_FAIL = '[Metadata Filter Collection] Get Order Filter Fail',

CHANGE_FILTER_ORDER_UP = '[Metadata Filter Collection] Change Order Up',
CHANGE_FILTER_ORDER_DOWN = '[Metadata Filter Collection] Change Order Down',
}

export class SelectFilter implements Action {
Expand Down Expand Up @@ -114,6 +126,54 @@ export class RemoveFilterFail implements Action {
constructor(public error: Error) { }
}

export class SetOrderFilterRequest implements Action {
readonly type = FilterCollectionActionTypes.SET_ORDER_FILTER_REQUEST;

constructor(public payload: string[]) { }
}

export class SetOrderFilterSuccess implements Action {
readonly type = FilterCollectionActionTypes.SET_ORDER_FILTER_SUCCESS;

constructor() { }
}

export class SetOrderFilterFail implements Action {
readonly type = FilterCollectionActionTypes.SET_ORDER_FILTER_FAIL;

constructor(public payload: Error) { }
}

export class GetOrderFilterRequest implements Action {
readonly type = FilterCollectionActionTypes.GET_ORDER_FILTER_REQUEST;

constructor() { }
}

export class GetOrderFilterSuccess implements Action {
readonly type = FilterCollectionActionTypes.GET_ORDER_FILTER_SUCCESS;

constructor(public payload: string[]) { }
}

export class GetOrderFilterFail implements Action {
readonly type = FilterCollectionActionTypes.GET_ORDER_FILTER_FAIL;

constructor(public payload: Error) { }
}

export class ChangeFilterOrderUp implements Action {
readonly type = FilterCollectionActionTypes.CHANGE_FILTER_ORDER_UP;

constructor(public payload: string) { }
}

export class ChangeFilterOrderDown implements Action {
readonly type = FilterCollectionActionTypes.CHANGE_FILTER_ORDER_DOWN;

constructor(public payload: string) { }
}

export type FilterCollectionActionsUnion =
| LoadFilterRequest
| LoadFilterSuccess
Expand All @@ -129,4 +189,12 @@ export type FilterCollectionActionsUnion =
| SelectFilterFail
| UpdateFilterRequest
| UpdateFilterSuccess
| UpdateFilterFail;
| UpdateFilterFail
| ChangeFilterOrderDown
| ChangeFilterOrderUp
| GetOrderFilterRequest
| GetOrderFilterSuccess
| GetOrderFilterFail
| SetOrderFilterRequest
| SetOrderFilterSuccess
| SetOrderFilterFail;
Loading

0 comments on commit bf5288e

Please sign in to comment.