Skip to content

Commit

Permalink
Merged in feature/SHIBUI-285 (pull request #33)
Browse files Browse the repository at this point in the history
Updated new filter container to use filter-form component
  • Loading branch information
rmathis committed Mar 29, 2018
1 parent 264637f commit 205287b
Show file tree
Hide file tree
Showing 37 changed files with 954 additions and 497 deletions.
2 changes: 1 addition & 1 deletion ui/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
</ul>
<p>
<ng-container *ngIf="version$ | async">
{{ version }}
{{ formatted$ | async }}
&nbsp;|&nbsp;
</ng-container>
<ng-container i18n="@@label--copyright">Copyright</ng-container> &copy; {{ today | date:'yyyy' }} Internet2
Expand Down
10 changes: 6 additions & 4 deletions ui/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@ import { StoreModule, Store, combineReducers } from '@ngrx/store';
import { AppComponent } from './app.component';

import { User } from './core/model/user';
import * as fromUser from './core/reducer/user.reducer';
import * as fromRoot from './core/reducer';
import { NotificationModule } from './notification/notification.module';
import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap';

describe('AppComponent', () => {
let store: Store<fromRoot.State>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
NgbDropdownModule.forRoot(),
RouterTestingModule,
StoreModule.forRoot({
user: combineReducers(fromUser.reducer),
}),
StoreModule.forRoot({}),
NotificationModule
],
declarations: [
AppComponent
],
}).compileComponents();

store = TestBed.get(Store);
spyOn(store, 'dispatch');
}));

it('should create the app', async(() => {
Expand Down
10 changes: 3 additions & 7 deletions ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Store } from '@ngrx/store';
import 'rxjs/add/operator/takeWhile';
import 'rxjs/add/operator/map';

import * as fromRoot from './core/reducer';
import { VersionInfo } from './core/model/version';
Expand All @@ -17,21 +17,17 @@ export class AppComponent implements OnInit {
title = 'Shib UI';
version$: Observable<VersionInfo>;
version: string;
formatted$: Observable<string>;
today = new Date();

constructor(private store: Store<fromRoot.State>) {
this.version$ = this.store.select(fromRoot.getVersionInfo);
this.formatted$ = this.version$.map(v => v && v.build ? `${v.build.version}-${v.git.commit.id}` : '');
}

ngOnInit(): void {
this.store.dispatch(new LoadProviderRequest());
this.store.dispatch(new LoadDraftRequest());
this.store.dispatch(new VersionInfoLoadRequestAction());

this.version$.subscribe(v => {
if (v && v.build) {
this.version = `${v.build.version}-${v.git.commit.id}`;
}
});
}
}
22 changes: 22 additions & 0 deletions ui/src/app/core/reducer/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as fromIndex from './index';
import * as fromUser from './user.reducer';
import * as fromVersion from './version.reducer';
import { VersionInfo } from '../model/version';

describe('Core index reducers', () => {
const state: fromIndex.CoreState = {
user: fromUser.initialState as fromUser.UserState,
version: fromVersion.initialState as fromVersion.VersionState
};

describe('getUserStateFn function', () => {
it('should return the user state', () => {
expect(fromIndex.getUserStateFn(state)).toEqual(state.user);
});
});
describe('getVersionStateFn function', () => {
it('should return the version state', () => {
expect(fromIndex.getVersionStateFn(state)).toEqual(state.version);
});
});
});
4 changes: 3 additions & 1 deletion ui/src/app/core/reducer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ export const reducers = {
};

export const getCoreFeature = createFeatureSelector<CoreState>('core');
export const getUserStateFn = (state: CoreState) => state.user;
export const getVersionStateFn = (state: CoreState) => state.version;

export const getUserState = createSelector(getCoreFeature, (state: CoreState) => state.user);
export const getUserState = createSelector(getCoreFeature, getUserStateFn);
export const getUser = createSelector(getUserState, fromUser.getUser);
export const isFetching = createSelector(getUserState, fromUser.isFetching);
export const getUserError = createSelector(getUserState, fromUser.getError);
Expand Down
98 changes: 98 additions & 0 deletions ui/src/app/core/reducer/version.reducer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { reducer } from './version.reducer';
import * as fromVersion from './version.reducer';
import * as actions from '../action/version.action';
import { VersionInfo } from '../model/version';

describe('Version Reducer', () => {
const initialState: fromVersion.VersionState = {
info: {},
loading: false,
error: null
};

const version: VersionInfo = {
git: {
commit: {
time: '2018-03-28T20:14:36Z',
id: '40aff48'
},
branch: 'feature/SHIBUI-285'
},
build: {
version: '1.0.0',
artifact: 'shibui',
name: 'master',
group: 'foo',
time: '2018-03-29T14:51:38.975Z'
}
};

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

describe('Version Load Request', () => {
it('should set loading to true', () => {
const action = new actions.VersionInfoLoadRequestAction();
const result = reducer(initialState, action);
expect(result.loading).toBe(true);
});
});

describe('Version Load Success', () => {
it('should set loading to false', () => {
const action = new actions.VersionInfoLoadSuccessAction(version);
const result = reducer(initialState, action);
expect(result.loading).toBe(false);
});

it('should set the version data to the payload', () => {
const action = new actions.VersionInfoLoadSuccessAction(version);
const result = reducer(initialState, action);
expect(result.info).toEqual(version);
});
});

describe('Version Load Success', () => {
it('should set loading to false', () => {
const action = new actions.VersionInfoLoadErrorAction(new Error());
const result = reducer(initialState, action);
expect(result.loading).toBe(false);
});

it('should add an error to state', () => {
const err = new Error('fail!');
const action = new actions.VersionInfoLoadErrorAction(err);
const result = reducer(initialState, action);
expect(result.error).toEqual(err);
});
});

describe('getVersionInfo selector', () => {
it('should return the version info from state', () => {
const action = new actions.VersionInfoLoadSuccessAction(version);
const result = reducer(initialState, action);
expect(fromVersion.getVersionInfo(result)).toEqual(version);
});
});

describe('getError selector', () => {
it('should return the version error from state', () => {
const err = new Error('fail');
const action = new actions.VersionInfoLoadErrorAction(err);
const result = reducer(initialState, action);
expect(fromVersion.getVersionError(result)).toEqual(err);
});
});

describe('getLoading selector', () => {
it('should return the version loading status from state', () => {
const action = new actions.VersionInfoLoadRequestAction();
const result = reducer(initialState, action);
expect(fromVersion.getVersionIsLoading(result)).toBe(true);
});
});
});
8 changes: 6 additions & 2 deletions ui/src/app/edit-provider/container/editor.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@
<logout-form *ngSwitchCase="5" [provider]="latest$ | async"></logout-form>
<key-info-form *ngSwitchCase="6" [provider]="latest$ | async"></key-info-form>
<assertion-form *ngSwitchCase="7" [provider]="latest$ | async"></assertion-form>
<relying-party-form *ngSwitchCase="8" [provider]="latest$ | async"></relying-party-form>
<attribute-release-form *ngSwitchCase="9" [provider]="latest$ | async"></attribute-release-form>
<div class="row" *ngSwitchCase="8">
<relying-party-form [provider]="latest$ | async" class="form-section col-xl-6"></relying-party-form>
</div>
<div class="row" *ngSwitchCase="9">
<attribute-release-form [provider]="latest$ | async" class="form-section col-xl-6"></attribute-release-form>
</div>
</div>
</div>
</div>
Expand Down
8 changes: 6 additions & 2 deletions ui/src/app/edit-provider/container/wizard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@
<logout-form *ngSwitchCase="5" [provider]="provider$ | async"></logout-form>
<key-info-form *ngSwitchCase="6" [provider]="provider$ | async"></key-info-form>
<assertion-form *ngSwitchCase="7" [provider]="provider$ | async"></assertion-form>
<relying-party-form *ngSwitchCase="8" [provider]="provider$ | async"></relying-party-form>
<attribute-release-form *ngSwitchCase="9" [provider]="provider$ | async"></attribute-release-form>
<div class="row" *ngSwitchCase="8">
<relying-party-form [provider]="provider$ | async" class="col-xl-6"></relying-party-form>
</div>
<div class="row" *ngSwitchCase="9">
<attribute-release-form [provider]="provider$ | async" class="col-xl-6"></attribute-release-form>
</div>
<finish-form *ngSwitchCase="10" [provider]="provider$ | async"></finish-form>
</div>
</div>
Expand Down
56 changes: 49 additions & 7 deletions ui/src/app/metadata-filter/action/filter.action.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import { Action } from '@ngrx/store';

import { QueryParams } from '../../core/model/query';
import { MetadataProvider } from '../../metadata-provider/model/metadata-provider';

export const QUERY_ENTITY_IDS = '[Filter] Query Entity Ids';
export const VIEW_MORE_IDS = '[Filter] View More Ids Modal';
export const CANCEL_VIEW_MORE = '[Filter] Cancel View More';
export const SELECT_ID = '[Filter] Select Entity ID';
export const CANCEL_CREATE_FILTER = '[Filter] Cancel Create Filter';
export const LOAD_ENTITY_IDS_SUCCESS = '[Entity ID Collection] Load Entity Ids Success';
export const LOAD_ENTITY_IDS_ERROR = '[Entity ID Collection] Load Entity Ids Error';

export const CREATE_FILTER = '[Filter] Create Filter';
export const UPDATE_FILTER = '[Filter] Update Filter';
export const SAVE_FILTER = '[Filter] Save Filter';
export const SAVE_FILTER_SUCCESS = '[Filter] Save Filter Success';
export const SAVE_FILTER_ERROR = '[Filter] Save Filter Error';
export const CANCEL_CREATE_FILTER = '[Filter] Cancel Create Filter';

export class QueryEntityIds implements Action {
readonly type = QUERY_ENTITY_IDS;

constructor(public payload: QueryParams) { }
}

export class CancelCreateFilter implements Action {
readonly type = CANCEL_CREATE_FILTER;
}

export class ViewMoreIds implements Action {
readonly type = VIEW_MORE_IDS;

Expand Down Expand Up @@ -48,11 +51,50 @@ export class LoadEntityIdsError implements Action {
constructor(public payload: Error) { }
}

export class CreateFilter implements Action {
readonly type = CREATE_FILTER;

constructor(public payload: MetadataProvider) { }
}

export class UpdateFilter implements Action {
readonly type = UPDATE_FILTER;

constructor(public payload: Partial<MetadataProvider>) { }
}

export class SaveFilter implements Action {
readonly type = SAVE_FILTER;

constructor(public payload: Partial<MetadataProvider>) { }
}

export class SaveFilterSuccess implements Action {
readonly type = SAVE_FILTER_SUCCESS;

constructor(public payload: MetadataProvider) { }
}

export class SaveFilterError implements Action {
readonly type = SAVE_FILTER_ERROR;

constructor(public payload: Error) { }
}

export class CancelCreateFilter implements Action {
readonly type = CANCEL_CREATE_FILTER;
}

export type Actions =
| ViewMoreIds
| CancelViewMore
| CancelCreateFilter
| SelectId
| LoadEntityIdsSuccess
| LoadEntityIdsError
| QueryEntityIds;
| QueryEntityIds
| CreateFilter
| UpdateFilter
| SaveFilter
| SaveFilterSuccess
| SaveFilterError
| CancelCreateFilter;
Loading

0 comments on commit 205287b

Please sign in to comment.