Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove more store -> core dependencies #4379

Merged
merged 17 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Action, Store } from '@ngrx/store';
import { combineLatest, Observable, of } from 'rxjs';
import { catchError, first, map, pairwise, share, skipWhile, switchMap, tap } from 'rxjs/operators';

import { LoggerService } from '../../../core/src/core/logger.service';
import { AppState } from '../../../store/src/app-state';
import { entityCatalog } from '../../../store/src/entity-catalog/entity-catalog';
import {
Expand Down Expand Up @@ -50,7 +49,6 @@ const createEndpointArray = (store: Store<AppState>, endpoints: string[] | Entit
export const cfUserRolesFetch: EntityUserRolesFetch = (
endpoints: string[] | EntityUserRolesEndpoint[],
store: Store<AppState>,
logService: LoggerService,
httpClient: HttpClient
) => {
return createEndpointArray(store, endpoints).pipe(
Expand All @@ -61,7 +59,7 @@ export const cfUserRolesFetch: EntityUserRolesFetch = (
cfEndpoints.forEach(endpoint => store.dispatch(new GetCfUserRelations(endpoint.guid, GET_CURRENT_CF_USER_RELATIONS_SUCCESS)))
} else {
// If some endpoints are not connected as admin, go out and fetch the current user's specific roles
const flagsAndRoleRequests = dispatchRoleRequests(cfEndpoints, store, logService, httpClient);
const flagsAndRoleRequests = dispatchRoleRequests(cfEndpoints, store, httpClient);
const allRequestsCompleted = handleCfRequests(flagsAndRoleRequests);
return combineLatest(allRequestsCompleted).pipe(
map(succeeds => succeeds.every(succeeded => !!succeeded)),
Expand All @@ -84,7 +82,6 @@ interface IEndpointConnectionInfo {
function dispatchRoleRequests(
endpoints: EntityUserRolesEndpoint[],
store: Store<AppState>,
logService: LoggerService,
httpClient: HttpClient
): CfsRequestState {
const requests: CfsRequestState = {};
Expand Down Expand Up @@ -117,7 +114,7 @@ function dispatchRoleRequests(
);
}),
catchError(err => {
logService.warn('Failed to fetch current user permissions for a cf: ', err);
console.warn('Failed to fetch current user permissions for a cf: ', err);
store.dispatch(new GetCfUserRelations(endpoint.guid, GET_CURRENT_CF_USER_RELATIONS_FAILED));
return of(err);
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Action } from '@ngrx/store';

import { environment } from '../../../core/src/environments/environment';
import { proxyAPIVersion } from '../jetstream';

export const METRIC_API_START = '[Metrics] API Start';
export const METRIC_API_SUCCESS = '[Metrics] API Success';
export const METRIC_API_FAILED = '[Metrics] API Failed';

const { proxyAPIVersion } = environment;

export const MetricAPIQueryTypes = {
TARGETS: 'targets',
Expand Down
4 changes: 1 addition & 3 deletions src/frontend/packages/store/src/actions/metrics.actions.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { metricEntityType } from '../../../core/src/base-entity-schemas';
import { environment } from '../../../core/src/environments/environment';
import { MetricQueryType } from '../../../core/src/shared/services/metrics-range-selector.types';
import { proxyAPIVersion } from '../jetstream';
import { EntityRequestAction } from '../types/request.types';

export const METRICS_START = '[Metrics] Fetch Start';
export const METRICS_START_SUCCESS = '[Metrics] Fetch Succeeded';
export const METRICS_START_FAILED = '[Metrics] Fetch Failed';

const { proxyAPIVersion } = environment;

export interface IMetricQueryConfigParams {
window?: string;
[key: string]: string | number;
Expand Down
4 changes: 1 addition & 3 deletions src/frontend/packages/store/src/effects/auth.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Actions, Effect, ofType } from '@ngrx/effects';
import { Store } from '@ngrx/store';
import { catchError, map, mergeMap, switchMap, tap } from 'rxjs/operators';

import { LoggerService } from '../../../core/src/core/logger.service';
import { BrowserStandardEncoder } from '../../../core/src/helper';
import {
InvalidSession,
Expand Down Expand Up @@ -44,7 +43,6 @@ export class AuthEffect {
private http: HttpClient,
private actions$: Actions,
private store: Store<DispatchOnlyAppState>,
private logger: LoggerService
) { }

@Effect() loginRequest$ = this.actions$.pipe(
Expand Down Expand Up @@ -164,7 +162,7 @@ export class AuthEffect {
const dashboardData = JSON.parse(storage.getItem(sessionId));
store.dispatch(new HydrateDashboardStateAction(dashboardData));
} catch (e) {
this.logger.warn('Failed to parse user settings from session storage, consider clearing them manually', e);
console.warn('Failed to parse user settings from session storage, consider clearing them manually', e);
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/frontend/packages/store/src/effects/permissions.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Action, Store } from '@ngrx/store';
import { combineLatest, EMPTY, of } from 'rxjs';
import { catchError, map, switchMap } from 'rxjs/operators';

import { LoggerService } from '../../../core/src/core/logger.service';
import { CONNECT_ENDPOINTS_SUCCESS, EndpointActionComplete } from '../actions/endpoint.actions';
import {
GET_CURRENT_USER_RELATIONS,
Expand All @@ -27,15 +26,14 @@ export class PermissionsEffects {
private httpClient: HttpClient,
private actions$: Actions,
private store: Store<AppState>,
private logService: LoggerService
) { }

@Effect() getCurrentUsersPermissions$ = this.actions$.pipe(
ofType<GetCurrentUsersRelations>(GET_CURRENT_USER_RELATIONS),
switchMap(action => {
const allRequestsCompleted = entityCatalog.getAllBaseEndpointTypes().reduce((res, endpointType) => {
if (endpointType.definition.userRolesFetch) {
res.push(endpointType.definition.userRolesFetch([], this.store, this.logService, this.httpClient));
res.push(endpointType.definition.userRolesFetch([], this.store, this.httpClient));
}
return res;
}, []);
Expand All @@ -44,7 +42,7 @@ export class PermissionsEffects {
);
}),
catchError(err => {
this.logService.warn('Failed to fetch current user permissions: ', err);
console.warn('Failed to fetch current user permissions: ', err);
return of(failedAction);
})
);
Expand All @@ -61,12 +59,12 @@ export class PermissionsEffects {
guid: action.guid,
user: action.endpoint.user
}
return endpointType.definition.userRolesFetch([endpoint], this.store, this.logService, this.httpClient).pipe(
return endpointType.definition.userRolesFetch([endpoint], this.store, this.httpClient).pipe(
map(succeeded => succeeded ? successAction : failedAction)
);
}),
catchError(err => {
this.logService.warn('Failed to fetch current user permissions after endpoint connected: ', err);
console.warn('Failed to fetch current user permissions after endpoint connected: ', err);
return of(failedAction);
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { Store } from '@ngrx/store';
import { catchError, first, map, mergeMap, switchMap } from 'rxjs/operators';

import { userFavoritesEntitySchema } from '../../../core/src/base-entity-schemas';
import { entityCatalog } from '../entity-catalog/entity-catalog';
import { UserFavoriteManager } from '../../../core/src/core/user-favorite-manager';
import { environment } from '../../../core/src/environments/environment.prod';
import { ClearPaginationOfEntity } from '../actions/pagination.actions';
import {
GetUserFavoritesAction,
Expand All @@ -28,12 +26,13 @@ import {
UpdateUserFavoriteMetadataSuccessAction,
} from '../actions/user-favourites-actions/update-user-favorite-metadata-action';
import { DispatchOnlyAppState } from '../app-state';
import { entityCatalog } from '../entity-catalog/entity-catalog';
import { proxyAPIVersion } from '../jetstream';
import { NormalizedResponse } from '../types/api.types';
import { PaginatedAction } from '../types/pagination.types';
import { WrapperRequestActionSuccess } from '../types/request.types';
import { IFavoriteMetadata, UserFavorite, userFavoritesPaginationKey } from '../types/user-favorites.types';

const { proxyAPIVersion } = environment;
const favoriteUrlPath = `/pp/${proxyAPIVersion}/favorites`;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Store } from '@ngrx/store';
import { catchError, mergeMap, switchMap } from 'rxjs/operators';

import { userProfileEntitySchema } from '../../../core/src/base-entity-schemas';
import { environment } from '../../../core/src/environments/environment';
import {
FetchUserProfileAction,
GET_USERPROFILE,
Expand All @@ -15,6 +14,7 @@ import {
UpdateUserProfileAction,
} from '../actions/user-profile.actions';
import { entityCatalog } from '../entity-catalog/entity-catalog';
import { proxyAPIVersion } from '../jetstream';
import { rootUpdatingKey } from '../reducers/api-request-reducer/types';
import { UserProfileInfo } from '../types/user-profile.types';
import { DispatchOnlyAppState } from './../app-state';
Expand All @@ -26,8 +26,6 @@ import {
} from './../types/request.types';


const { proxyAPIVersion } = environment;

export const userProfilePasswordUpdatingKey = 'password';

@Injectable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { HttpClient, HttpRequest } from '@angular/common/http';
import { Action, Store } from '@ngrx/store';
import { Observable } from 'rxjs';

import { LoggerService } from '../../../core/src/core/logger.service';
import { JetStreamErrorResponse } from '../../../core/src/jetstream.helpers';
import { AppState, GeneralEntityAppState, InternalAppState } from '../app-state';
import {
Expand Down Expand Up @@ -146,7 +145,6 @@ export interface EntityUserRolesEndpoint {
export type EntityUserRolesFetch = (
endpoints: string[] | EntityUserRolesEndpoint[],
store: Store<AppState>,
logService: LoggerService,
httpClient: HttpClient
) => Observable<boolean>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';
import { filter, first, map, mergeMap } from 'rxjs/operators';

import { environment } from '../../../core/src/environments/environment';
import { InternalAppState } from '../app-state';
import { StratosCatalogEndpointEntity } from '../entity-catalog/entity-catalog-entity/entity-catalog-entity';
import { IStratosEndpointDefinition } from '../entity-catalog/entity-catalog.types';
import { cfAPIVersion, proxyAPIVersion } from '../jetstream';
import { connectedEndpointsOfTypesSelector, endpointOfTypeSelector } from '../selectors/endpoint.selectors';

const { proxyAPIVersion, cfAPIVersion } = environment;
richard-cox marked this conversation as resolved.
Show resolved Hide resolved

@Injectable()
export class PipelineHttpClient {

Expand Down
5 changes: 5 additions & 0 deletions src/frontend/packages/store/src/jetstream.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// API Version to use when making back-end API requests to Jetstraam
export const proxyAPIVersion = 'v1';

// CF API Version
export const cfAPIVersion = 'v2';