Skip to content

Commit

Permalink
Fix favourites helper
Browse files Browse the repository at this point in the history
  • Loading branch information
nwmac committed May 7, 2020
1 parent 17780e1 commit cbc20cc
Show file tree
Hide file tree
Showing 40 changed files with 516 additions and 463 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { EffectsModule } from '@ngrx/effects';
import { NgxChartsModule } from '@swimlane/ngx-charts';
import { of } from 'rxjs';

import { CloudFoundryComponentsModule } from '../../cloud-foundry/src/shared/components/components.module';
import { CloudFoundrySharedModule } from '../../cloud-foundry/src/shared/cf-shared.module';
import { CoreModule } from '../../core/src/core/core.module';
import { EntityCatalogModule } from '../../store/src/entity-catalog.module';
import { MDAppModule } from '../../core/src/core/md.module';
import { SharedModule } from '../../core/src/shared/shared.module';
import { EntityCatalogModule } from '../../store/src/entity-catalog.module';
import { AutoscalerModule } from './core/autoscaler.module';
import { AutoscalerTabExtensionComponent } from './features/autoscaler-tab-extension/autoscaler-tab-extension.component';
import { generateASEntities } from './store/autoscaler-entity-generator';
Expand Down Expand Up @@ -38,7 +38,7 @@ const customRoutes: Routes = [
SharedModule,
MDAppModule,
NgxChartsModule,
CloudFoundryComponentsModule,
CloudFoundrySharedModule,
AutoscalerModule,
RouterModule.forRoot(customRoutes),
EntityCatalogModule.forFeature(generateASEntities),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NgModule } from '@angular/core';
import { NgxChartsModule } from '@swimlane/ngx-charts';

import { ApplicationService } from '../../../cloud-foundry/src/features/applications/application.service';
import { CloudFoundryComponentsModule } from '../../../cloud-foundry/src/shared/components/components.module';
import { CloudFoundrySharedModule } from '../../../cloud-foundry/src/shared/cf-shared.module';
import { CoreModule } from '../../../core/src/core/core.module';
import { SharedModule } from '../../../core/src/shared/shared.module';
import { AutoscalerBaseComponent } from '../features/autoscaler-base.component';
Expand Down Expand Up @@ -54,7 +54,7 @@ import { AutoscalerRoutingModule } from './autoscaler.routing';
SharedModule,
AutoscalerRoutingModule,
NgxChartsModule,
CloudFoundryComponentsModule,
CloudFoundrySharedModule,
],
declarations: [
AutoscalerBaseComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as moment from 'moment';
import { combineLatest, of } from 'rxjs';
import { map } from 'rxjs/operators';

import { EndpointHealthCheck } from '../../core/endpoints-health-checks';
import { urlValidationExpression } from '../../core/src/core/utils.service';
import { BaseEndpointAuth } from '../../core/src/features/endpoints/endpoint-auth';
import { AppState } from '../../store/src/app-state';
Expand All @@ -13,6 +14,7 @@ import {
} from '../../store/src/entity-catalog/entity-catalog-entity';
import { entityCatalog } from '../../store/src/entity-catalog/entity-catalog.service';
import {
IEntityMetadata,
IStratosEntityDefinition,
StratosEndpointExtensionDefinition,
} from '../../store/src/entity-catalog/entity-catalog.types';
Expand Down Expand Up @@ -88,6 +90,7 @@ import {
userProvidedServiceInstanceEntityType,
} from './cf-entity-types';
import { CfErrorResponse, getCfError } from './cf-error-helpers';
import { getFavoriteFromCfEntity } from './cf-favorites-helpers';
import { IAppFavMetadata, IBasicCFMetaData, IOrgFavMetadata, ISpaceFavMetadata } from './cf-metadata-types';
import { CF_ENDPOINT_TYPE } from './cf-types';
import { appEnvVarActionBuilders } from './entity-action-builders/application-env-var.action-builders';
Expand Down Expand Up @@ -160,6 +163,11 @@ export function generateCFEntities(): StratosBaseCatalogEntity[] {
authTypes: [BaseEndpointAuth.UsernamePassword, BaseEndpointAuth.SSO],
listDetailsComponent: CfEndpointDetailsComponent,
renderPriority: 1,
healthCheck: new EndpointHealthCheck(CF_ENDPOINT_TYPE, (endpoint) => {
entityCatalog.getEntity<IEntityMetadata, any, CfInfoDefinitionActionBuilders>(CF_ENDPOINT_TYPE, cfInfoEntityType)
.actionDispatchManager.dispatchGet(endpoint.guid);
}),
favoriteFromEntity: getFavoriteFromCfEntity,
globalPreRequest: (request, action) => {
return addCfRelationParams(request, action);
},
Expand Down
25 changes: 25 additions & 0 deletions src/frontend/packages/cloud-foundry/src/cf-favorites-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { FavoritesConfigMapper } from '../../core/src/shared/components/favorites-meta-card/favorite-config-mapper';
import { IEntityMetadata } from '../../store/src/entity-catalog/entity-catalog.types';
import { UserFavorite } from '../../store/src/types/user-favorites.types';
import { CfAPIResource } from './store/types/cf-api.types';

export function getFavoriteFromCfEntity<T extends IEntityMetadata = IEntityMetadata>(
entity,
entityKey: string,
favoritesConfigMapper: FavoritesConfigMapper
): UserFavorite<T> {
if (isCfEntity(entity as CfAPIResource)) {
return favoritesConfigMapper.getFavoriteFromEntity<T>(
entityKey,
'cf',
entity.entity.cfGuid,
entity
);
}
return null;
}

function isCfEntity(entity: CfAPIResource) {
return entity && entity.entity.cfGuid && entity.metadata && entity.metadata.guid;
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ApplicationsModule } from './features/applications/applications.module'
import { CloudFoundryModule } from './features/cloud-foundry/cloud-foundry.module';
import { ServiceCatalogModule } from './features/service-catalog/service-catalog.module';
import { ServicesModule } from './features/services/services.module';
import { CloudFoundryComponentsModule } from './shared/components/components.module';
import { CloudFoundrySharedModule } from './shared/cf-shared.module';
import { CfUserService } from './shared/data-services/cf-user.service';
import { CloudFoundryService } from './shared/data-services/cloud-foundry.service';
import { LongRunningCfOperationsService } from './shared/data-services/long-running-cf-op.service';
Expand Down Expand Up @@ -71,7 +71,7 @@ function infoValidator(action: ICFAction, dispatcher) {
ServicesModule,
CloudFoundryStoreModule,
// FIXME: Ensure that anything lazy loaded is not included here - #3675
CloudFoundryComponentsModule,
CloudFoundrySharedModule,
// FIXME: Move cf effects into cf module - #3675
// EffectsModule.for Root([
// PermissionsEffects,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
StratosActionType,
StratosTabType,
} from '../../../../../../core/src/core/extension/extension-service';
import { getFavoriteFromCfEntity } from '../../../../../../core/src/core/user-favorite-helpers';
import { getFavoriteFromEntity } from '../../../../../../core/src/core/user-favorite-helpers';
import { safeUnsubscribe } from '../../../../../../core/src/core/utils.service';
import { IPageSideNavTab } from '../../../../../../core/src/features/dashboard/page-side-nav/page-side-nav.component';
import {
Expand Down Expand Up @@ -52,7 +52,7 @@ export class ApplicationTabsBaseComponent implements OnInit, OnDestroy {

public favorite$ = this.applicationService.app$.pipe(
filter(app => !!app),
map(app => getFavoriteFromCfEntity<IAppFavMetadata>(app.entity, applicationEntityType, this.favoritesConfigMapper))
map(app => getFavoriteFromEntity<IAppFavMetadata>(app.entity, applicationEntityType, this.favoritesConfigMapper, CF_ENDPOINT_TYPE))
);

isBusyUpdating$: Observable<{ updating: boolean }>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ApplicationServiceMock } from '../../../../../../../../core/test-framew
import { EntityServiceFactory } from '../../../../../../../../store/src/entity-service-factory.service';
import { AppStoreModule } from '../../../../../../../../store/src/store.module';
import { generateCfStoreModules } from '../../../../../../../test-framework/cloud-foundry-endpoint-service.helper';
import { CloudFoundryComponentsModule } from '../../../../../../shared/components/components.module';
import { CloudFoundrySharedModule } from '../../../../../../shared/cf-shared.module';
import { ApplicationStateService } from '../../../../../../shared/services/application-state.service';
import { ApplicationService } from '../../../../application.service';
import { cfApplicationEntityServiceFactory } from '../../../application-base.component';
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('BuildTabComponent', () => {
NoopAnimationsModule,
HttpClientModule,
HttpClientTestingModule,
CloudFoundryComponentsModule
CloudFoundrySharedModule
],
providers: [
{ provide: ApplicationService, useClass: ApplicationServiceMock },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
generateCfStoreModules,
generateTestCfEndpointServiceProvider,
} from '../../../../../../../test-framework/cloud-foundry-endpoint-service.helper';
import { CloudFoundryComponentsModule } from '../../../../../../shared/components/components.module';
import { CloudFoundrySharedModule } from '../../../../../../shared/cf-shared.module';
import { ApplicationStateService } from '../../../../../../shared/services/application-state.service';
import { ApplicationService } from '../../../../application.service';
import { ApplicationEnvVarsHelper } from '../build-tab/application-env-vars.service';
Expand All @@ -31,7 +31,7 @@ describe('InstancesTabComponent', () => {
SharedModule,
RouterTestingModule,
NoopAnimationsModule,
CloudFoundryComponentsModule
CloudFoundrySharedModule
],
providers: [
generateTestCfEndpointServiceProvider(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NgModule } from '@angular/core';

import { CoreModule } from '../../../../core/src/core/core.module';
import { SharedModule } from '../../../../core/src/shared/shared.module';
import { CloudFoundryComponentsModule } from '../../shared/components/components.module';
import { CloudFoundrySharedModule } from '../../shared/cf-shared.module';
import { ApplicationDeleteComponent } from './application-delete/application-delete.component';
import {
DeleteAppServiceInstancesComponent,
Expand Down Expand Up @@ -43,7 +43,7 @@ import { SshApplicationComponent } from './ssh-application/ssh-application.compo
CoreModule,
SharedModule,
ApplicationsRoutingModule,
CloudFoundryComponentsModule
CloudFoundrySharedModule
],
declarations: [
ApplicationWallComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { generateTestApplicationServiceProvider } from '../../../../../core/test
import { generateTestEntityServiceProvider } from '../../../../../core/test-framework/entity-service.helper';
import { generateCfStoreModules } from '../../../../test-framework/cloud-foundry-endpoint-service.helper';
import { applicationEntityType } from '../../../cf-entity-types';
import { CloudFoundryComponentsModule } from '../../../shared/components/components.module';
import { CloudFoundrySharedModule } from '../../../shared/cf-shared.module';
import { ApplicationStateService } from '../../../shared/services/application-state.service';
import { ApplicationEnvVarsHelper } from '../application/application-tabs-base/tabs/build-tab/application-env-vars.service';
import { CliInfoApplicationComponent } from './cli-info-application.component';
Expand All @@ -32,7 +32,7 @@ describe('CliInfoApplicationComponent', () => {
SharedModule,
MDAppModule,
RouterTestingModule,
CloudFoundryComponentsModule
CloudFoundrySharedModule
],
providers: [
generateTestEntityServiceProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { CoreModule } from '../../../../../../core/src/core/core.module';
import { SharedModule } from '../../../../../../core/src/shared/shared.module';
import { generateCfStoreModules } from '../../../../../test-framework/cloud-foundry-endpoint-service.helper';
import { CloudFoundryComponentsModule } from './../../../../shared/components/components.module';
import { CloudFoundrySharedModule } from '../../../../shared/cf-shared.module';
import { CreateApplicationStep2Component } from './create-application-step2.component';

describe('CreateApplicationStep2Component', () => {
Expand All @@ -24,7 +24,7 @@ describe('CreateApplicationStep2Component', () => {
CommonModule,
CoreModule,
SharedModule,
CloudFoundryComponentsModule,
CloudFoundrySharedModule,
NoopAnimationsModule,
HttpClientModule,
HttpClientTestingModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NgModule } from '@angular/core';

import { CoreModule } from '../../../../../core/src/core/core.module';
import { SharedModule } from '../../../../../core/src/shared/shared.module';
import { CloudFoundryComponentsModule } from '../../../shared/components/components.module';
import { CloudFoundrySharedModule } from '../../../shared/cf-shared.module';
import { CreateApplicationStep2Component } from './create-application-step2/create-application-step2.component';
import { CreateApplicationStep3Component } from './create-application-step3/create-application-step3.component';
import { CreateApplicationComponent } from './create-application.component';
Expand All @@ -13,7 +13,7 @@ import { CreateApplicationComponent } from './create-application.component';
CommonModule,
CoreModule,
SharedModule,
CloudFoundryComponentsModule
CloudFoundrySharedModule
],
declarations: [
CreateApplicationComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getGitHubAPIURL, GITHUB_API_URL } from '../../../../../core/src/core/gi
import { SharedModule } from '../../../../../core/src/shared/shared.module';
import { TabNavService } from '../../../../../core/tab-nav.service';
import { generateCfStoreModules } from '../../../../test-framework/cloud-foundry-endpoint-service.helper';
import { CloudFoundryComponentsModule } from '../../../shared/components/components.module';
import { CloudFoundrySharedModule } from '../../../shared/cf-shared.module';
import { CfOrgSpaceDataService } from '../../../shared/data-services/cf-org-space-service.service';
import { ApplicationEnvVarsHelper } from '../application/application-tabs-base/tabs/build-tab/application-env-vars.service';
import { CreateApplicationModule } from '../create-application/create-application.module';
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('DeployApplicationComponent', () => {
HttpClientModule,
HttpClientTestingModule,
HttpClientModule,
CloudFoundryComponentsModule
CloudFoundrySharedModule
]
})
.compileComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NgModule } from '@angular/core';

import { CoreModule } from '../../../../../core/src/core/core.module';
import { SharedModule } from '../../../../../core/src/shared/shared.module';
import { CloudFoundryComponentsModule } from '../../../shared/components/components.module';
import { CloudFoundrySharedModule } from '../../../shared/cf-shared.module';
import { CreateApplicationModule } from '../create-application/create-application.module';
import {
DeployApplicationOptionsStepComponent,
Expand All @@ -27,7 +27,7 @@ import { GithubProjectExistsDirective } from './github-project-exists.directive'
SharedModule,
CommonModule,
CreateApplicationModule,
CloudFoundryComponentsModule
CloudFoundrySharedModule
],
declarations: [
DeployApplicationComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NgxChartsModule } from '@swimlane/ngx-charts';

import { CoreModule } from '../../../../core/src/core/core.module';
import { SharedModule } from '../../../../core/src/shared/shared.module';
import { CloudFoundryComponentsModule } from '../../shared/components/components.module';
import { CloudFoundrySharedModule } from '../../shared/cf-shared.module';
import {
CFEndpointsListConfigService,
} from '../../shared/components/list/list-types/cf-endpoints/cf-endpoints-list-config.service';
Expand Down Expand Up @@ -140,7 +140,7 @@ import { RemoveUserComponent } from './users/remove-user/remove-user.component';
CloudFoundryRoutingModule,
RouterModule,
NgxChartsModule,
CloudFoundryComponentsModule
CloudFoundrySharedModule
],
declarations: [
CloudFoundryBaseComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
StratosActionType,
StratosTabType,
} from '../../../../../../../core/src/core/extension/extension-service';
import { getFavoriteFromCfEntity } from '../../../../../../../core/src/core/user-favorite-helpers';
import { getFavoriteFromEntity } from '../../../../../../../core/src/core/user-favorite-helpers';
import { environment } from '../../../../../../../core/src/environments/environment.prod';
import { IPageSideNavTab } from '../../../../../../../core/src/features/dashboard/page-side-nav/page-side-nav.component';
import {
Expand All @@ -21,6 +21,7 @@ import { IHeaderBreadcrumb } from '../../../../../../../core/src/shared/componen
import { EntitySchema } from '../../../../../../../store/src/helpers/entity-schema';
import { UserFavorite } from '../../../../../../../store/src/types/user-favorites.types';
import { cfEntityFactory } from '../../../../../cf-entity-factory';
import { CF_ENDPOINT_TYPE } from '../../../../../cf-types';
import { CfUserService } from '../../../../../shared/data-services/cf-user.service';
import { getActiveRouteCfOrgSpaceProvider } from '../../../cf.helpers';
import { CloudFoundryEndpointService } from '../../../services/cloud-foundry-endpoint.service';
Expand Down Expand Up @@ -92,7 +93,7 @@ export class CloudFoundryOrganizationBaseComponent {
this.schema = cfEntityFactory(organizationEntityType);
this.favorite$ = cfOrgService.org$.pipe(
first(),
map(org => getFavoriteFromCfEntity<IOrgFavMetadata>(org.entity, organizationEntityType, favoritesConfigMapper))
map(org => getFavoriteFromEntity<IOrgFavMetadata>(org.entity, organizationEntityType, favoritesConfigMapper, CF_ENDPOINT_TYPE))
);
this.name$ = cfOrgService.org$.pipe(
map(org => org.entity.entity.name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
StratosActionType,
StratosTabType,
} from '../../../../../../../../core/src/core/extension/extension-service';
import { getFavoriteFromCfEntity } from '../../../../../../../../core/src/core/user-favorite-helpers';
import { getFavoriteFromEntity } from '../../../../../../../../core/src/core/user-favorite-helpers';
import { environment } from '../../../../../../../../core/src/environments/environment.prod';
import { IPageSideNavTab } from '../../../../../../../../core/src/features/dashboard/page-side-nav/page-side-nav.component';
import { ConfirmationDialogService } from '../../../../../../../../core/src/shared/components/confirmation-dialog.service';
Expand All @@ -24,6 +24,7 @@ import { IHeaderBreadcrumb } from '../../../../../../../../core/src/shared/compo
import { RouterNav } from '../../../../../../../../store/src/actions/router.actions';
import { UserFavorite } from '../../../../../../../../store/src/types/user-favorites.types';
import { cfEntityFactory } from '../../../../../../cf-entity-factory';
import { CF_ENDPOINT_TYPE } from '../../../../../../cf-types';
import { CfUserService } from '../../../../../../shared/data-services/cf-user.service';
import { getActiveRouteCfOrgSpaceProvider } from '../../../../cf.helpers';
import { CloudFoundryEndpointService } from '../../../../services/cloud-foundry-endpoint.service';
Expand Down Expand Up @@ -111,7 +112,7 @@ export class CloudFoundrySpaceBaseComponent implements OnDestroy {
favoritesConfigMapper: FavoritesConfigMapper
) {
this.favorite$ = cfSpaceService.space$.pipe(
map(space => getFavoriteFromCfEntity<ISpaceFavMetadata>(space.entity, spaceEntityType, favoritesConfigMapper))
map(space => getFavoriteFromEntity<ISpaceFavMetadata>(space.entity, spaceEntityType, favoritesConfigMapper, CF_ENDPOINT_TYPE))
);
this.isFetching$ = cfSpaceService.space$.pipe(
map(space => space.entityRequestInfo.fetching)
Expand Down
Loading

0 comments on commit cbc20cc

Please sign in to comment.