diff --git a/src/frontend/packages/cf-autoscaler/src/shared/list-types/app-autoscaler-event/cf-app-autoscaler-events-config.service.spec.ts b/src/frontend/packages/cf-autoscaler/src/shared/list-types/app-autoscaler-event/cf-app-autoscaler-events-config.service.spec.ts index 56fe3b5865..fcfbc0bf81 100644 --- a/src/frontend/packages/cf-autoscaler/src/shared/list-types/app-autoscaler-event/cf-app-autoscaler-events-config.service.spec.ts +++ b/src/frontend/packages/cf-autoscaler/src/shared/list-types/app-autoscaler-event/cf-app-autoscaler-events-config.service.spec.ts @@ -5,9 +5,6 @@ import { inject, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { createEmptyStoreModule } from '@stratosui/store/testing'; -import { GetApplication } from '../../../../../cloud-foundry/src/actions/application.actions'; -import { cfEntityFactory } from '../../../../../cloud-foundry/src/cf-entity-factory'; -import { applicationEntityType } from '../../../../../cloud-foundry/src/cf-entity-types'; import { ApplicationsModule } from '../../../../../cloud-foundry/src/features/applications/applications.module'; import { generateTestApplicationServiceProvider, @@ -15,7 +12,6 @@ import { import { CoreModule } from '../../../../../core/src/core/core.module'; import { SharedModule } from '../../../../../core/src/shared/shared.module'; import { AppTestModule } from '../../../../../core/test-framework/core-test.helper'; -import { generateTestEntityServiceProvider } from '../../../../../core/test-framework/entity-service.helper'; import { EntityCatalogHelper } from '../../../../../store/src/entity-catalog/entity-catalog-entity/entity-catalog.service'; import { EntityServiceFactory } from '../../../../../store/src/entity-service-factory.service'; import { EntityMonitorFactory } from '../../../../../store/src/monitors/entity-monitor.factory.service'; @@ -35,11 +31,6 @@ describe('CfAppAutoscalerEventsConfigService', () => { EntityServiceFactory, EntityMonitorFactory, EntityCatalogHelper, - generateTestEntityServiceProvider( - appGuid, - cfEntityFactory(applicationEntityType), - new GetApplication(appGuid, cfGuid) - ), generateTestApplicationServiceProvider(appGuid, cfGuid), HttpClient, ], diff --git a/src/frontend/packages/cf-autoscaler/src/store/autoscaler-entity-factory.ts b/src/frontend/packages/cf-autoscaler/src/store/autoscaler-entity-factory.ts index 21df01c5dd..13c1ff8089 100644 --- a/src/frontend/packages/cf-autoscaler/src/store/autoscaler-entity-factory.ts +++ b/src/frontend/packages/cf-autoscaler/src/store/autoscaler-entity-factory.ts @@ -1,8 +1,8 @@ import { Schema, schema } from 'normalizr'; import { getAPIResourceGuid } from '../../../cloud-foundry/src/store/selectors/api.selectors'; -import { metricEntityType } from '../../../store/src/base-entity-schemas'; import { EntitySchema } from '../../../store/src/helpers/entity-schema'; +import { metricEntityType } from '../../../store/src/helpers/stratos-entity-factory'; export const appAutoscalerInfoEntityType = 'autoscalerInfo'; export const appAutoscalerHealthEntityType = 'autoscalerHealth'; diff --git a/src/frontend/packages/cf-autoscaler/src/store/autoscaler-entity-generator.ts b/src/frontend/packages/cf-autoscaler/src/store/autoscaler-entity-generator.ts index ec1414cb64..4e71099074 100644 --- a/src/frontend/packages/cf-autoscaler/src/store/autoscaler-entity-generator.ts +++ b/src/frontend/packages/cf-autoscaler/src/store/autoscaler-entity-generator.ts @@ -1,10 +1,10 @@ import { IOrgFavMetadata } from '../../../cloud-foundry/src/cf-metadata-types'; -import { metricEntityType } from '../../../store/src/base-entity-schemas'; import { StratosBaseCatalogEntity, StratosCatalogEntity, } from '../../../store/src/entity-catalog/entity-catalog-entity/entity-catalog-entity'; import { IStratosEndpointDefinition } from '../../../store/src/entity-catalog/entity-catalog.types'; +import { metricEntityType } from '../../../store/src/helpers/stratos-entity-factory'; import { APIResource } from '../../../store/src/types/api.types'; import { IFavoriteMetadata } from '../../../store/src/types/user-favorites.types'; import { AppAutoscalerEvent, AppAutoscalerHealth, AppAutoscalerPolicy, AppScalingTrigger } from './app-autoscaler.types'; diff --git a/src/frontend/packages/cloud-foundry/src/actions/cf-event.actions.ts b/src/frontend/packages/cloud-foundry/src/actions/cf-event.actions.ts index ad2daf059f..c6bb0e3aff 100644 --- a/src/frontend/packages/cloud-foundry/src/actions/cf-event.actions.ts +++ b/src/frontend/packages/cloud-foundry/src/actions/cf-event.actions.ts @@ -1,6 +1,6 @@ import { HttpParams, HttpRequest } from '@angular/common/http'; -import { endpointSchemaKey } from '../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../store/src/helpers/stratos-entity-factory'; import { PaginatedAction } from '../../../store/src/types/pagination.types'; import { cfEntityFactory } from '../cf-entity-factory'; import { cfEventEntityType } from '../cf-entity-types'; @@ -18,7 +18,7 @@ export class GetAllCfEvents extends CFStartAction implements PaginatedAction { constructor(public paginationKey: string, public endpointGuid) { super(); - this.paginationKey = this.paginationKey || createEntityRelationPaginationKey(endpointSchemaKey, endpointGuid); + this.paginationKey = this.paginationKey || createEntityRelationPaginationKey(endpointEntityType, endpointGuid); this.options = new HttpRequest( 'GET', 'events', diff --git a/src/frontend/packages/cloud-foundry/src/actions/domains.actions.ts b/src/frontend/packages/cloud-foundry/src/actions/domains.actions.ts index 13d4f6d59b..d593428b5f 100644 --- a/src/frontend/packages/cloud-foundry/src/actions/domains.actions.ts +++ b/src/frontend/packages/cloud-foundry/src/actions/domains.actions.ts @@ -1,6 +1,6 @@ import { HttpRequest } from '@angular/common/http'; -import { endpointSchemaKey } from '../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../store/src/helpers/stratos-entity-factory'; import { PaginatedAction } from '../../../store/src/types/pagination.types'; import { ICFAction } from '../../../store/src/types/request.types'; import { cfEntityFactory } from '../cf-entity-factory'; @@ -36,7 +36,7 @@ export class FetchAllDomains extends CFStartAction implements PaginatedAction { 'GET', 'domains', ); - this.paginationKey = this.paginationKey || createEntityRelationPaginationKey(endpointSchemaKey, endpointGuid); + this.paginationKey = this.paginationKey || createEntityRelationPaginationKey(endpointEntityType, endpointGuid); } actions = [GET_ALL_DOMAIN, GET_ALL_DOMAIN_SUCCESS, GET_ALL_DOMAIN_FAILED]; entity = [cfEntityFactory(domainEntityType)]; diff --git a/src/frontend/packages/cloud-foundry/src/actions/feature-flags.actions.ts b/src/frontend/packages/cloud-foundry/src/actions/feature-flags.actions.ts index 6ec461e70b..5c1967a0c1 100644 --- a/src/frontend/packages/cloud-foundry/src/actions/feature-flags.actions.ts +++ b/src/frontend/packages/cloud-foundry/src/actions/feature-flags.actions.ts @@ -1,7 +1,7 @@ import { HttpRequest } from '@angular/common/http'; import { getActions } from '../../../store/src/actions/action.helper'; -import { endpointSchemaKey } from '../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../store/src/helpers/stratos-entity-factory'; import { PaginatedAction } from '../../../store/src/types/pagination.types'; import { RequestEntityLocation } from '../../../store/src/types/request.types'; import { cfEntityFactory } from '../cf-entity-factory'; @@ -12,7 +12,7 @@ import { CFStartAction } from './cf-action.types'; export class GetAllFeatureFlags extends CFStartAction implements PaginatedAction { constructor(public endpointGuid: string, public paginationKey: string = null) { super(); - this.paginationKey = this.paginationKey || createEntityRelationPaginationKey(endpointSchemaKey, this.endpointGuid); + this.paginationKey = this.paginationKey || createEntityRelationPaginationKey(endpointEntityType, this.endpointGuid); this.options = new HttpRequest( 'GET', `config/feature_flags` diff --git a/src/frontend/packages/cloud-foundry/src/actions/stack.action.ts b/src/frontend/packages/cloud-foundry/src/actions/stack.action.ts index b4a274ee38..ac77391430 100644 --- a/src/frontend/packages/cloud-foundry/src/actions/stack.action.ts +++ b/src/frontend/packages/cloud-foundry/src/actions/stack.action.ts @@ -2,7 +2,7 @@ import { HttpRequest } from '@angular/common/http'; import { getActions } from '../../../store/src/actions/action.helper'; import { entityCatalog } from '../../../store/src/entity-catalog/entity-catalog'; -import { endpointSchemaKey } from '../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../store/src/helpers/stratos-entity-factory'; import { PaginatedAction } from '../../../store/src/types/pagination.types'; import { ICFAction } from '../../../store/src/types/request.types'; import { stackEntityType } from '../cf-entity-types'; @@ -38,7 +38,7 @@ export class GetAllStacks extends CFStartAction implements PaginatedAction { 'GET', 'stacks' ); - this.paginationKey = createEntityRelationKey(endpointSchemaKey, endpointGuid); + this.paginationKey = createEntityRelationKey(endpointEntityType, endpointGuid); } paginationKey: string; actions = getActions('Stack', 'Fetch all'); diff --git a/src/frontend/packages/cloud-foundry/src/actions/user-provided-service.actions.ts b/src/frontend/packages/cloud-foundry/src/actions/user-provided-service.actions.ts index 0080cf6962..6ef888f96d 100644 --- a/src/frontend/packages/cloud-foundry/src/actions/user-provided-service.actions.ts +++ b/src/frontend/packages/cloud-foundry/src/actions/user-provided-service.actions.ts @@ -2,7 +2,7 @@ import { HttpRequest } from '@angular/common/http'; import { getActions } from '../../../store/src/actions/action.helper'; import { EntityCatalogEntityConfig } from '../../../store/src/entity-catalog/entity-catalog.types'; -import { endpointSchemaKey } from '../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../store/src/helpers/stratos-entity-factory'; import { PaginatedAction } from '../../../store/src/types/pagination.types'; import { ICFAction } from '../../../store/src/types/request.types'; import { cfEntityFactory } from '../cf-entity-factory'; @@ -39,7 +39,7 @@ export class GetAllUserProvidedServices extends CFStartAction implements Paginat ) { super(); this.paginationKey = paginationKey || (spaceGuid ? createEntityRelationPaginationKey(spaceEntityType, spaceGuid) : - createEntityRelationPaginationKey(endpointSchemaKey, endpointGuid)); + createEntityRelationPaginationKey(endpointEntityType, endpointGuid)); this.options = new HttpRequest( 'GET', `user_provided_service_instances`, diff --git a/src/frontend/packages/cloud-foundry/src/actions/users.actions.ts b/src/frontend/packages/cloud-foundry/src/actions/users.actions.ts index 40f7d57afc..73d008753b 100644 --- a/src/frontend/packages/cloud-foundry/src/actions/users.actions.ts +++ b/src/frontend/packages/cloud-foundry/src/actions/users.actions.ts @@ -1,8 +1,8 @@ import { HttpRequest } from '@angular/common/http'; import { getActions } from '../../../store/src/actions/action.helper'; -import { endpointSchemaKey } from '../../../store/src/helpers/entity-factory'; import { EntitySchema } from '../../../store/src/helpers/entity-schema'; +import { endpointEntityType } from '../../../store/src/helpers/stratos-entity-factory'; import { PaginatedAction } from '../../../store/src/types/pagination.types'; import { EntityRequestAction } from '../../../store/src/types/request.types'; import { cfEntityFactory } from '../cf-entity-factory'; @@ -51,7 +51,7 @@ export class GetAllCfUsersAsAdmin extends CFStartAction implements PaginatedActi paginationKey?: string ) { super(); - this.paginationKey = paginationKey || createEntityRelationPaginationKey(endpointSchemaKey, endpointGuid); + this.paginationKey = paginationKey || createEntityRelationPaginationKey(endpointEntityType, endpointGuid); this.options = new HttpRequest( 'GET', 'users' diff --git a/src/frontend/packages/cloud-foundry/src/cf-entity-factory.ts b/src/frontend/packages/cloud-foundry/src/cf-entity-factory.ts index 40a49404ee..33bbedf4f7 100644 --- a/src/frontend/packages/cloud-foundry/src/cf-entity-factory.ts +++ b/src/frontend/packages/cloud-foundry/src/cf-entity-factory.ts @@ -1,5 +1,5 @@ -import { metricEntityType } from '../../store/src/base-entity-schemas'; import { EntitySchema } from '../../store/src/helpers/entity-schema'; +import { metricEntityType } from '../../store/src/helpers/stratos-entity-factory'; import { APIResource } from '../../store/src/types/api.types'; import { CFApplicationEntitySchema, @@ -200,24 +200,24 @@ const CFUserSchema = new CFUserEntitySchema({ audited_spaces: [createUserOrgSpaceSchema(spaceEntityType, {}, CfUserRoleParams.AUDITED_SPACES)], } }, { - idAttribute: getAPIResourceGuid, - processStrategy: (user: APIResource) => { - if (user.entity.username) { - return user; - } - const entity = { - ...user.entity, - username: user.metadata.guid - }; - - return user.metadata ? { - entity, - metadata: user.metadata - } : { - entity - }; + idAttribute: getAPIResourceGuid, + processStrategy: (user: APIResource) => { + if (user.entity.username) { + return user; } - }); + const entity = { + ...user.entity, + username: user.metadata.guid + }; + + return user.metadata ? { + entity, + metadata: user.metadata + } : { + entity + }; + } +}); entityCache[cfUserEntityType] = CFUserSchema; const coreSpaceSchemaParams = { diff --git a/src/frontend/packages/cloud-foundry/src/cf-entity-generator.ts b/src/frontend/packages/cloud-foundry/src/cf-entity-generator.ts index bc6f27b556..89727e826e 100644 --- a/src/frontend/packages/cloud-foundry/src/cf-entity-generator.ts +++ b/src/frontend/packages/cloud-foundry/src/cf-entity-generator.ts @@ -6,7 +6,6 @@ import { first, map } from 'rxjs/operators'; import { BaseEndpointAuth } from '../../core/src/core/endpoint-auth'; import { urlValidationExpression } from '../../core/src/core/utils.service'; import { AppState, GeneralEntityAppState } from '../../store/src/app-state'; -import { metricEntityType } from '../../store/src/base-entity-schemas'; import { StratosBaseCatalogEntity, StratosCatalogEndpointEntity, @@ -22,6 +21,7 @@ import { } from '../../store/src/entity-request-pipeline/entity-request-base-handlers/handle-multi-endpoints.pipe'; import { ActionDispatcher, JetstreamResponse } from '../../store/src/entity-request-pipeline/entity-request-pipeline.types'; import { EntitySchema } from '../../store/src/helpers/entity-schema'; +import { metricEntityType } from '../../store/src/helpers/stratos-entity-factory'; import { RequestInfoState } from '../../store/src/reducers/api-request-reducer/types'; import { selectSessionData } from '../../store/src/reducers/auth.reducer'; import { APIResource, EntityInfo } from '../../store/src/types/api.types'; @@ -409,7 +409,9 @@ function generateCFQuotaDefinitionEntity(endpointDefinition: StratosEndpointExte const definition: IStratosEntityDefinition = { type: quotaDefinitionEntityType, schema: cfEntityFactory(quotaDefinitionEntityType), - endpoint: endpointDefinition + endpoint: endpointDefinition, + label: 'Organization Quota', + labelPlural: 'Organization Quotas', }; cfEntityCatalog.quotaDefinition = new StratosCatalogEntity< IBasicCFMetaData, @@ -451,6 +453,8 @@ function generateCFAppEnvVarEntity(endpointDefinition: StratosEndpointExtensionD } }; }, + label: 'App Env Var', + labelPlural: 'App Env Vars', }; cfEntityCatalog.appEnvVar = new StratosCatalogEntity< IBasicCFMetaData, @@ -478,6 +482,8 @@ function generateCFAppSummaryEntity(endpointDefinition: StratosEndpointExtension type: appSummaryEntityType, schema: cfEntityFactory(appSummaryEntityType), endpoint: endpointDefinition, + label: 'App Summary', + labelPlural: 'App Summaries', }; cfEntityCatalog.appSummary = new StratosCatalogEntity(definition, { dataReducers: [ @@ -500,7 +506,9 @@ function generateCFSpaceQuotaEntity(endpointDefinition: StratosEndpointExtension const definition: IStratosEntityDefinition = { type: spaceQuotaEntityType, schema: cfEntityFactory(spaceQuotaEntityType), - endpoint: endpointDefinition + endpoint: endpointDefinition, + label: 'Space Quota', + labelPlural: 'Space Quotas', }; cfEntityCatalog.spaceQuota = new StratosCatalogEntity< IBasicCFMetaData, @@ -518,7 +526,9 @@ function generateCFPrivateDomainEntity(endpointDefinition: StratosEndpointExtens const definition: IStratosEntityDefinition = { type: privateDomainsEntityType, schema: cfEntityFactory(privateDomainsEntityType), - endpoint: endpointDefinition + endpoint: endpointDefinition, + label: 'Private Domain', + labelPlural: 'Private Domains', }; cfEntityCatalog.privateDomain = new StratosCatalogEntity>(definition, { dataReducers: [ diff --git a/src/frontend/packages/cloud-foundry/src/cloud-foundry-test.module.ts b/src/frontend/packages/cloud-foundry/src/cloud-foundry-test.module.ts index 7f1d67b662..99bfc37bbd 100644 --- a/src/frontend/packages/cloud-foundry/src/cloud-foundry-test.module.ts +++ b/src/frontend/packages/cloud-foundry/src/cloud-foundry-test.module.ts @@ -5,9 +5,9 @@ import { EffectsModule } from '@ngrx/effects'; import { generateASEntities } from '../../cf-autoscaler/src/store/autoscaler-entity-generator'; import { getGitHubAPIURL, GITHUB_API_URL } from '../../core/src/core/github.helpers'; import { LoggerService } from '../../core/src/core/logger.service'; -import { generateStratosEntities } from '../../core/src/stratos-entities'; import { CATALOGUE_ENTITIES, EntityCatalogFeatureModule } from '../../store/src/entity-catalog.module'; import { entityCatalog, TestEntityCatalog } from '../../store/src/entity-catalog/entity-catalog'; +import { generateStratosEntities } from '../../store/src/stratos-entity-generator'; import { testSCFEndpointGuid } from '../../store/testing/public-api'; import { BaseCfOrgSpaceRouteMock } from '../test-framework/cloud-foundry-endpoint-service.helper'; import { generateCFEntities } from './cf-entity-generator'; diff --git a/src/frontend/packages/cloud-foundry/src/entity-relations/entity-relations-list.spec.ts b/src/frontend/packages/cloud-foundry/src/entity-relations/entity-relations-list.spec.ts index 73851810cc..35679dc510 100644 --- a/src/frontend/packages/cloud-foundry/src/entity-relations/entity-relations-list.spec.ts +++ b/src/frontend/packages/cloud-foundry/src/entity-relations/entity-relations-list.spec.ts @@ -1,6 +1,7 @@ +import { EntitySchema } from '../../../store/src/helpers/entity-schema'; import { listEntityRelations } from './entity-relations'; import { createEntityRelationKey, EntityInlineParentAction } from './entity-relations.types'; -import { EntitySchema } from '../../../store/src/helpers/entity-schema'; + const endpointType = 'endpointtype1'; describe('Entity Relations - List relations', () => { diff --git a/src/frontend/packages/cloud-foundry/src/entity-relations/entity-relations.tree.spec.ts b/src/frontend/packages/cloud-foundry/src/entity-relations/entity-relations.tree.spec.ts index 6ce1b9126a..5383e22fbe 100644 --- a/src/frontend/packages/cloud-foundry/src/entity-relations/entity-relations.tree.spec.ts +++ b/src/frontend/packages/cloud-foundry/src/entity-relations/entity-relations.tree.spec.ts @@ -1,5 +1,5 @@ -import { CF_ENDPOINT_TYPE } from '../cf-types'; import { CFEntitySchema } from '../cf-entity-schema-types'; +import { CF_ENDPOINT_TYPE } from '../cf-types'; import { fetchEntityTree } from './entity-relations.tree'; import { createEntityRelationKey, EntityInlineParentAction } from './entity-relations.types'; diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/application-delete/application-delete.component.spec.ts b/src/frontend/packages/cloud-foundry/src/features/applications/application-delete/application-delete.component.spec.ts index 7e8ac98783..52aa6ff434 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/application-delete/application-delete.component.spec.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/application-delete/application-delete.component.spec.ts @@ -1,12 +1,8 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { GetApplication } from '../../../../../cloud-foundry/src/actions/application.actions'; -import { cfEntityFactory } from '../../../../../cloud-foundry/src/cf-entity-factory'; import { TabNavService } from '../../../../../core/tab-nav.service'; -import { generateTestEntityServiceProvider } from '../../../../../core/test-framework/entity-service.helper'; import { generateTestApplicationServiceProvider } from '../../../../test-framework/application-service-helper'; import { generateCfBaseTestModules } from '../../../../test-framework/cloud-foundry-endpoint-service.helper'; -import { applicationEntityType } from '../../../cf-entity-types'; import { ApplicationsModule } from '../applications.module'; import { ApplicationDeleteComponent } from './application-delete.component'; @@ -22,11 +18,6 @@ describe('ApplicationDeleteComponent', () => { ApplicationsModule ], providers: [ - generateTestEntityServiceProvider( - appId, - cfEntityFactory(applicationEntityType), - new GetApplication(appId, cfId) - ), generateTestApplicationServiceProvider(cfId, appId), TabNavService ] diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/application-delete/delete-app-instances/app-delete-instances-routes-list-config.service.ts b/src/frontend/packages/cloud-foundry/src/features/applications/application-delete/delete-app-instances/app-delete-instances-routes-list-config.service.ts index 91f805f77c..f8b961dfba 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/application-delete/delete-app-instances/app-delete-instances-routes-list-config.service.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/application-delete/delete-app-instances/app-delete-instances-routes-list-config.service.ts @@ -12,7 +12,7 @@ import { import { CurrentUserPermissionsService } from '../../../../../../core/src/core/permissions/current-user-permissions.service'; import { RowState } from '../../../../../../core/src/shared/components/list/data-sources-controllers/list-data-source-types'; import { ListViewTypes } from '../../../../../../core/src/shared/components/list/list.component.types'; -import { endpointSchemaKey } from '../../../../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../../../../store/src/helpers/stratos-entity-factory'; import { PaginationMonitorFactory } from '../../../../../../store/src/monitors/pagination-monitor.factory'; import { APIResource } from '../../../../../../store/src/types/api.types'; import { IServiceBinding } from '../../../../cf-api-svc.types'; @@ -59,7 +59,7 @@ export class AppDeleteServiceInstancesListConfigService extends AppServiceBindin const action = cfEntityCatalog.serviceBinding.actions.getAllForServiceInstance( serviceBinding.entity.service_instance_guid, appService.cfGuid, - createEntityRelationPaginationKey(endpointSchemaKey, serviceBindingEntityType), + createEntityRelationPaginationKey(endpointEntityType, serviceBindingEntityType), { includeRelations: [], } diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/application-delete/delete-app-instances/delete-app-instances.component.spec.ts b/src/frontend/packages/cloud-foundry/src/features/applications/application-delete/delete-app-instances/delete-app-instances.component.spec.ts index cc133e9d3b..184b50070a 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/application-delete/delete-app-instances/delete-app-instances.component.spec.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/application-delete/delete-app-instances/delete-app-instances.component.spec.ts @@ -1,12 +1,8 @@ import { DatePipe } from '@angular/common'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { GetApplication } from '../../../../../../cloud-foundry/src/actions/application.actions'; -import { cfEntityFactory } from '../../../../../../cloud-foundry/src/cf-entity-factory'; -import { generateTestEntityServiceProvider } from '../../../../../../core/test-framework/entity-service.helper'; import { generateTestApplicationServiceProvider } from '../../../../../test-framework/application-service-helper'; import { generateCfBaseTestModules } from '../../../../../test-framework/cloud-foundry-endpoint-service.helper'; -import { applicationEntityType } from '../../../../cf-entity-types'; import { ServiceActionHelperService } from '../../../../shared/data-services/service-action-helper.service'; import { ApplicationEnvVarsHelper, @@ -24,11 +20,6 @@ describe('DeleteAppInstancesComponent', () => { declarations: [DeleteAppServiceInstancesComponent], imports: generateCfBaseTestModules(), providers: [ - generateTestEntityServiceProvider( - appId, - cfEntityFactory(applicationEntityType), - new GetApplication(appId, cfId) - ), generateTestApplicationServiceProvider(cfId, appId), ApplicationEnvVarsHelper, DatePipe, diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/application-delete/delete-app-routes/delete-app-routes.component.spec.ts b/src/frontend/packages/cloud-foundry/src/features/applications/application-delete/delete-app-routes/delete-app-routes.component.spec.ts index 28b04b412d..7e6b4e0ff6 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/application-delete/delete-app-routes/delete-app-routes.component.spec.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/application-delete/delete-app-routes/delete-app-routes.component.spec.ts @@ -1,12 +1,8 @@ import { DatePipe } from '@angular/common'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { GetApplication } from '../../../../../../cloud-foundry/src/actions/application.actions'; -import { cfEntityFactory } from '../../../../../../cloud-foundry/src/cf-entity-factory'; -import { generateTestEntityServiceProvider } from '../../../../../../core/test-framework/entity-service.helper'; import { generateTestApplicationServiceProvider } from '../../../../../test-framework/application-service-helper'; import { generateCfBaseTestModules } from '../../../../../test-framework/cloud-foundry-endpoint-service.helper'; -import { applicationEntityType } from '../../../../cf-entity-types'; import { ApplicationEnvVarsHelper, } from '../../application/application-tabs-base/tabs/build-tab/application-env-vars.service'; @@ -23,11 +19,6 @@ describe('DeleteAppRoutesComponent', () => { declarations: [DeleteAppRoutesComponent], imports: generateCfBaseTestModules(), providers: [ - generateTestEntityServiceProvider( - appId, - cfEntityFactory(applicationEntityType), - new GetApplication(appId, cfId) - ), generateTestApplicationServiceProvider(cfId, appId), ApplicationEnvVarsHelper, DatePipe, diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/application.service.spec.ts b/src/frontend/packages/cloud-foundry/src/features/applications/application.service.spec.ts index aba0ea3567..23282a262b 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/application.service.spec.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/application.service.spec.ts @@ -1,18 +1,14 @@ import { inject, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; -import { GetApplication } from '../../../../cloud-foundry/src/actions/application.actions'; -import { cfEntityFactory } from '../../../../cloud-foundry/src/cf-entity-factory'; import { CoreModule } from '../../../../core/src/core/core.module'; import { ExtensionService } from '../../../../core/src/core/extension/extension-service'; import { getGitHubAPIURL, GITHUB_API_URL } from '../../../../core/src/core/github.helpers'; -import { generateTestEntityServiceProvider } from '../../../../core/test-framework/entity-service.helper'; import { EntityMonitorFactory } from '../../../../store/src/monitors/entity-monitor.factory.service'; import { PaginationMonitorFactory } from '../../../../store/src/monitors/pagination-monitor.factory'; import { AppStoreModule } from '../../../../store/src/store.module'; import { generateTestApplicationServiceProvider } from '../../../test-framework/application-service-helper'; import { generateCfStoreModules } from '../../../test-framework/cloud-foundry-endpoint-service.helper'; -import { applicationEntityType } from '../../cf-entity-types'; import { LongRunningCfOperationsService } from '../../shared/data-services/long-running-cf-op.service'; import { GitSCMService } from '../../shared/data-services/scm/scm.service'; import { ApplicationStateService } from '../../shared/services/application-state.service'; @@ -33,11 +29,6 @@ describe('ApplicationService', () => { generateCfStoreModules() ], providers: [ - generateTestEntityServiceProvider( - appId, - cfEntityFactory(applicationEntityType), - new GetApplication(appId, cfId) - ), generateTestApplicationServiceProvider(cfId, appId), ApplicationStateService, ApplicationEnvVarsHelper, diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/application.service.ts b/src/frontend/packages/cloud-foundry/src/features/applications/application.service.ts index d918209f4f..628b8560a4 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/application.service.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/application.service.ts @@ -44,13 +44,13 @@ export function createGetApplicationAction(guid: string, endpointGuid: string) { return new GetApplication( guid, endpointGuid, [ - createEntityRelationKey(applicationEntityType, routeEntityType), - createEntityRelationKey(applicationEntityType, spaceEntityType), - createEntityRelationKey(applicationEntityType, stackEntityType), - createEntityRelationKey(applicationEntityType, serviceBindingEntityType), - createEntityRelationKey(routeEntityType, domainEntityType), - createEntityRelationKey(spaceEntityType, organizationEntityType), - ] + createEntityRelationKey(applicationEntityType, routeEntityType), + createEntityRelationKey(applicationEntityType, spaceEntityType), + createEntityRelationKey(applicationEntityType, stackEntityType), + createEntityRelationKey(applicationEntityType, serviceBindingEntityType), + createEntityRelationKey(routeEntityType, domainEntityType), + createEntityRelationKey(spaceEntityType, organizationEntityType), + ] ); } @@ -64,7 +64,7 @@ export interface ApplicationData { @Injectable() export class ApplicationService { - private appEntityService: EntityService>; + public entityService: EntityService>; private appSummaryEntityService: EntityService; constructor( @@ -74,7 +74,7 @@ export class ApplicationService { private appStateService: ApplicationStateService, private appEnvVarsService: ApplicationEnvVarsHelper, ) { - this.appEntityService = cfEntityCatalog.application.store.getEntityService( + this.entityService = cfEntityCatalog.application.store.getEntityService( appGuid, cfGuid, { @@ -138,7 +138,7 @@ export class ApplicationService { private constructCoreObservables() { // First set up all the base observables - this.app$ = this.appEntityService.waitForEntity$; + this.app$ = this.entityService.waitForEntity$; const moreWaiting$ = this.app$.pipe( filter(entityInfo => !!(entityInfo.entity && entityInfo.entity.entity && entityInfo.entity.entity.cfGuid)), map(entityInfo => entityInfo.entity.entity)); @@ -162,9 +162,9 @@ export class ApplicationService { filter(org => !!org) ); - this.isDeletingApp$ = this.appEntityService.isDeletingEntity$.pipe(publishReplay(1), refCount()); + this.isDeletingApp$ = this.entityService.isDeletingEntity$.pipe(publishReplay(1), refCount()); - this.waitForAppEntity$ = this.appEntityService.waitForEntity$.pipe(publishReplay(1), refCount()); + this.waitForAppEntity$ = this.entityService.waitForEntity$.pipe(publishReplay(1), refCount()); this.appSummary$ = this.waitForAppEntity$.pipe( switchMap(() => this.appSummaryEntityService.entityObs$), @@ -231,9 +231,9 @@ export class ApplicationService { } private constructStatusObservables() { - this.isFetchingApp$ = this.appEntityService.isFetchingEntity$; + this.isFetchingApp$ = this.entityService.isFetchingEntity$; - this.isUpdatingApp$ = this.appEntityService.entityObs$.pipe(map(a => { + this.isUpdatingApp$ = this.entityService.entityObs$.pipe(map(a => { const updatingRoot = a.entityRequestInfo.updating[rootUpdatingKey] || { busy: false }; const updatingSection = a.entityRequestInfo.updating[UpdateExistingApplication.updateKey] || { busy: false }; return !!updatingRoot.busy || !!updatingSection.busy; diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-base.component.ts b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-base.component.ts index a95f69f887..ba7fea321a 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-base.component.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-base.component.ts @@ -3,10 +3,9 @@ import { ActivatedRoute } from '@angular/router'; import { Store } from '@ngrx/store'; import { CFAppState } from '../../../../../cloud-foundry/src/cf-app-state'; -import { APP_GUID, CF_GUID, ENTITY_SERVICE } from '../../../../../core/src/shared/entity.tokens'; -import { EntityServiceFactory } from '../../../../../store/src/entity-service-factory.service'; +import { APP_GUID, CF_GUID } from '../../../../../core/src/shared/entity.tokens'; import { ApplicationStateService } from '../../../shared/services/application-state.service'; -import { ApplicationService, createGetApplicationAction } from '../application.service'; +import { ApplicationService } from '../application.service'; import { ApplicationEnvVarsHelper } from './application-tabs-base/tabs/build-tab/application-env-vars.service'; export function applicationServiceFactory( @@ -25,17 +24,6 @@ export function applicationServiceFactory( ); } -export function cfApplicationEntityServiceFactory( - cfId: string, - id: string, - esf: EntityServiceFactory -) { - return esf.create( - id, - createGetApplicationAction(id, cfId) - ); -} - export function getGuids(type?: string) { return (activatedRoute: ActivatedRoute) => { const { id, endpointId } = activatedRoute.snapshot.params; @@ -72,13 +60,7 @@ export function getGuids(type?: string) { ApplicationStateService, ApplicationEnvVarsHelper, ] - }, - { - provide: ENTITY_SERVICE, - useFactory: cfApplicationEntityServiceFactory, - deps: [CF_GUID, APP_GUID, EntityServiceFactory] - }, - + } ] }) export class ApplicationBaseComponent { diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/application-poll/application-poll.component.spec.ts b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/application-poll/application-poll.component.spec.ts index 096eebe3f7..d20348cc9f 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/application-poll/application-poll.component.spec.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/application-poll/application-poll.component.spec.ts @@ -1,11 +1,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { generateTestEntityServiceProvider } from '../../../../../../../core/test-framework/entity-service.helper'; import { generateTestApplicationServiceProvider } from '../../../../../../test-framework/application-service-helper'; import { generateCfBaseTestModules } from '../../../../../../test-framework/cloud-foundry-endpoint-service.helper'; -import { GetApplication } from '../../../../../actions/application.actions'; -import { cfEntityFactory } from '../../../../../cf-entity-factory'; -import { applicationEntityType } from '../../../../../cf-entity-types'; import { ApplicationPollingService } from '../application-polling.service'; import { ApplicationEnvVarsHelper } from '../tabs/build-tab/application-env-vars.service'; import { ApplicationStateService } from './../../../../../shared/services/application-state.service'; @@ -23,11 +19,6 @@ describe('ApplicationPollComponent', () => { declarations: [ApplicationPollComponent], providers: [ ApplicationPollingService, - generateTestEntityServiceProvider( - appId, - cfEntityFactory(applicationEntityType), - new GetApplication(appId, cfId) - ), generateTestApplicationServiceProvider(cfId, appId), ApplicationEnvVarsHelper, ApplicationStateService, diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/application-polling.service.ts b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/application-polling.service.ts index 39fd632931..046af5a750 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/application-polling.service.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/application-polling.service.ts @@ -1,15 +1,11 @@ -import { Inject, Injectable, NgZone } from '@angular/core'; +import { Injectable, NgZone } from '@angular/core'; import { Store } from '@ngrx/store'; import { Observable, Subscription } from 'rxjs'; import { first, map, tap } from 'rxjs/operators'; import { safeUnsubscribe } from '../../../../../../core/src/core/utils.service'; -import { ENTITY_SERVICE } from '../../../../../../core/src/shared/entity.tokens'; import { AppState } from '../../../../../../store/src/app-state'; -import { EntityService } from '../../../../../../store/src/entity-service'; import { selectDashboardState } from '../../../../../../store/src/selectors/dashboard.selectors'; -import { APIResource } from '../../../../../../store/src/types/api.types'; -import { IApp } from '../../../../cf-api.types'; import { cfEntityCatalog } from '../../../../cf-entity-catalog'; import { ApplicationService } from '../../application.service'; @@ -19,7 +15,7 @@ export class ApplicationPollingService { private pollingSub: Subscription; private autoRefreshString = 'auto-refresh'; - public isPolling$ = this.entityService.updatingSection$.pipe(map( + public isPolling$ = this.applicationService.entityService.updatingSection$.pipe(map( update => update[this.autoRefreshString] && update[this.autoRefreshString].busy )); @@ -27,7 +23,6 @@ export class ApplicationPollingService { constructor( public applicationService: ApplicationService, - @Inject(ENTITY_SERVICE) private entityService: EntityService>, private store: Store, private ngZone: NgZone, ) { @@ -54,7 +49,7 @@ export class ApplicationPollingService { // Auto refresh this.ngZone.runOutsideAngular(() => { - this.pollingSub = this.entityService + this.pollingSub = this.applicationService.entityService .poll(10000, this.autoRefreshString).pipe( tap(() => this.ngZone.run(() => this.poll(false)))) .subscribe(); @@ -69,12 +64,12 @@ export class ApplicationPollingService { const { cfGuid, appGuid } = this.applicationService; if (withApp) { const updatingApp = { - ...this.entityService.action, + ...this.applicationService.entityService.action, updatingKey: this.autoRefreshString }; this.store.dispatch(updatingApp); } - this.entityService.entityObs$.pipe( + this.applicationService.entityService.entityObs$.pipe( first(), ).subscribe(resource => { cfEntityCatalog.appSummary.api.get(appGuid, cfGuid); diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/application-tabs-base.component.spec.ts b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/application-tabs-base.component.spec.ts index 55f591b111..19c49370d4 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/application-tabs-base.component.spec.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/application-tabs-base.component.spec.ts @@ -5,17 +5,13 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { RouterTestingModule } from '@angular/router/testing'; import { StoreModule } from '@ngrx/store'; -import { GetApplication } from '../../../../../../cloud-foundry/src/actions/application.actions'; -import { cfEntityFactory } from '../../../../../../cloud-foundry/src/cf-entity-factory'; import { CoreModule } from '../../../../../../core/src/core/core.module'; import { getGitHubAPIURL, GITHUB_API_URL } from '../../../../../../core/src/core/github.helpers'; import { MDAppModule } from '../../../../../../core/src/core/md.module'; import { SharedModule } from '../../../../../../core/src/shared/shared.module'; import { TabNavService } from '../../../../../../core/tab-nav.service'; -import { generateTestEntityServiceProvider } from '../../../../../../core/test-framework/entity-service.helper'; import { generateTestApplicationServiceProvider } from '../../../../../test-framework/application-service-helper'; import { generateCfStoreModules } from '../../../../../test-framework/cloud-foundry-endpoint-service.helper'; -import { applicationEntityType } from '../../../../cf-entity-types'; import { ApplicationStateService } from '../../../../shared/services/application-state.service'; import { ApplicationTabsBaseComponent } from './application-tabs-base.component'; import { ApplicationEnvVarsHelper } from './tabs/build-tab/application-env-vars.service'; @@ -44,11 +40,6 @@ describe('ApplicationTabsBaseComponent', () => { HttpClientTestingModule ], providers: [ - generateTestEntityServiceProvider( - appId, - cfEntityFactory(applicationEntityType), - new GetApplication(appId, cfId) - ), generateTestApplicationServiceProvider(cfId, appId), ApplicationStateService, ApplicationEnvVarsHelper, diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/application-tabs-base.component.ts b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/application-tabs-base.component.ts index 7974416cac..362c6c37fd 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/application-tabs-base.component.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/application-tabs-base.component.ts @@ -1,4 +1,4 @@ -import { Component, Inject, NgZone, OnDestroy, OnInit } from '@angular/core'; +import { Component, NgZone, OnDestroy, OnInit } from '@angular/core'; import { Store } from '@ngrx/store'; import { combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs'; import { filter, first, map, startWith, switchMap, withLatestFrom } from 'rxjs/operators'; @@ -18,10 +18,8 @@ import { CurrentUserPermissionsService } from '../../../../../../core/src/core/p import { safeUnsubscribe } from '../../../../../../core/src/core/utils.service'; import { IPageSideNavTab } from '../../../../../../core/src/features/dashboard/page-side-nav/page-side-nav.component'; import { IHeaderBreadcrumb } from '../../../../../../core/src/shared/components/page-header/page-header.types'; -import { ENTITY_SERVICE } from '../../../../../../core/src/shared/entity.tokens'; import { RouterNav } from '../../../../../../store/src/actions/router.actions'; import { entityCatalog } from '../../../../../../store/src/entity-catalog/entity-catalog'; -import { EntityService } from '../../../../../../store/src/entity-service'; import { FavoritesConfigMapper } from '../../../../../../store/src/favorite-config-mapper'; import { EntitySchema } from '../../../../../../store/src/helpers/entity-schema'; import { ActionState } from '../../../../../../store/src/reducers/api-request-reducer/types'; @@ -59,7 +57,6 @@ export class ApplicationTabsBaseComponent implements OnInit, OnDestroy { constructor( public applicationService: ApplicationService, - @Inject(ENTITY_SERVICE) private entityService: EntityService, private store: Store, private endpointsService: EndpointsService, private ngZone: NgZone, @@ -244,7 +241,7 @@ export class ApplicationTabsBaseComponent implements OnInit, OnDestroy { } ngOnInit() { - this.appSub$ = this.entityService.entityMonitor.entityRequest$.subscribe(requestInfo => { + this.appSub$ = this.applicationService.entityService.entityMonitor.entityRequest$.subscribe(requestInfo => { if ( requestInfo.deleting.deleted || requestInfo.error @@ -255,7 +252,7 @@ export class ApplicationTabsBaseComponent implements OnInit, OnDestroy { this.isFetching$ = this.applicationService.isFetchingApp$; - this.isBusyUpdating$ = this.entityService.updatingSection$.pipe( + this.isBusyUpdating$ = this.applicationService.entityService.updatingSection$.pipe( map(updatingSection => { const updating = this.updatingSectionBusy(updatingSection.restaging) || this.updatingSectionBusy(updatingSection[UpdateExistingApplication.updateKey]); diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/tabs/build-tab/build-tab.component.spec.ts b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/tabs/build-tab/build-tab.component.spec.ts index 71731cb35b..58a38edbe5 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/tabs/build-tab/build-tab.component.spec.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/tabs/build-tab/build-tab.component.spec.ts @@ -6,17 +6,15 @@ import { RouterTestingModule } from '@angular/router/testing'; import { CoreModule } from '../../../../../../../../core/src/core/core.module'; import { GITHUB_API_URL } from '../../../../../../../../core/src/core/github.helpers'; -import { APP_GUID, CF_GUID, ENTITY_SERVICE } from '../../../../../../../../core/src/shared/entity.tokens'; +import { APP_GUID, CF_GUID } from '../../../../../../../../core/src/shared/entity.tokens'; import { SharedModule } from '../../../../../../../../core/src/shared/shared.module'; import { TabNavService } from '../../../../../../../../core/tab-nav.service'; -import { EntityServiceFactory } from '../../../../../../../../store/src/entity-service-factory.service'; import { AppStoreModule } from '../../../../../../../../store/src/store.module'; import { ApplicationServiceMock } from '../../../../../../../test-framework/application-service-helper'; import { generateCfStoreModules } from '../../../../../../../test-framework/cloud-foundry-endpoint-service.helper'; 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'; import { ApplicationPollComponent } from '../../application-poll/application-poll.component'; import { ApplicationPollingService } from '../../application-polling.service'; import { ApplicationEnvVarsHelper } from './application-env-vars.service'; @@ -53,11 +51,6 @@ describe('BuildTabComponent', () => { TabNavService, { provide: CF_GUID, useValue: '' }, { provide: APP_GUID, useValue: '' }, - { - provide: ENTITY_SERVICE, - useFactory: cfApplicationEntityServiceFactory, - deps: [CF_GUID, APP_GUID, EntityServiceFactory] - }, ApplicationPollingService ] }) diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/tabs/build-tab/build-tab.component.ts b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/tabs/build-tab/build-tab.component.ts index c2b6aa3ca6..26f9c2b373 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/tabs/build-tab/build-tab.component.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/tabs/build-tab/build-tab.component.ts @@ -1,4 +1,4 @@ -import { Component, Inject, OnInit } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { Store } from '@ngrx/store'; import { combineLatest as observableCombineLatest, Observable, of as observableOf, of } from 'rxjs'; @@ -12,12 +12,10 @@ import { } from '../../../../../../../../core/src/core/permissions/current-user-permissions.service'; import { ConfirmationDialogConfig } from '../../../../../../../../core/src/shared/components/confirmation-dialog.config'; import { ConfirmationDialogService } from '../../../../../../../../core/src/shared/components/confirmation-dialog.service'; -import { ENTITY_SERVICE } from '../../../../../../../../core/src/shared/entity.tokens'; import { ResetPagination } from '../../../../../../../../store/src/actions/pagination.actions'; import { getFullEndpointApiUrl } from '../../../../../../../../store/src/endpoint-utils'; -import { EntityService } from '../../../../../../../../store/src/entity-service'; import { ActionState } from '../../../../../../../../store/src/reducers/api-request-reducer/types'; -import { APIResource, EntityInfo } from '../../../../../../../../store/src/types/api.types'; +import { EntityInfo } from '../../../../../../../../store/src/types/api.types'; import { IAppSummary } from '../../../../../../cf-api.types'; import { cfEntityCatalog } from '../../../../../../cf-entity-catalog'; import { GitSCMService, GitSCMType } from '../../../../../../shared/data-services/scm/scm.service'; @@ -66,7 +64,6 @@ export class BuildTabComponent implements OnInit { public applicationService: ApplicationService, private scmService: GitSCMService, private store: Store, - @Inject(ENTITY_SERVICE) private entityService: EntityService, private route: ActivatedRoute, private router: Router, private confirmDialog: ConfirmationDialogService, @@ -92,7 +89,7 @@ export class BuildTabComponent implements OnInit { return app.fetching || appSummary.entityRequestInfo.fetching; }), distinct()); - this.isBusyUpdating$ = this.entityService.updatingSection$.pipe( + this.isBusyUpdating$ = this.applicationService.entityService.updatingSection$.pipe( map(updatingSection => { const updating = this.updatingSectionBusy(updatingSection.restaging) || this.updatingSectionBusy(updatingSection[UpdateExistingApplication.updateKey]); @@ -266,7 +263,7 @@ export class BuildTabComponent implements OnInit { } pollEntityService(state, stateString): Observable { - return this.entityService + return this.applicationService.entityService .poll(1000, state).pipe( delay(1), filter(({ resource }) => { diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/tabs/log-stream-tab/log-stream-tab.component.spec.ts b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/tabs/log-stream-tab/log-stream-tab.component.spec.ts index b300ad4f84..03b62309d1 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/tabs/log-stream-tab/log-stream-tab.component.spec.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/tabs/log-stream-tab/log-stream-tab.component.spec.ts @@ -3,18 +3,14 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { RouterTestingModule } from '@angular/router/testing'; import { StoreModule } from '@ngrx/store'; -import { GetApplication } from '../../../../../../../../cloud-foundry/src/actions/application.actions'; -import { cfEntityFactory } from '../../../../../../../../cloud-foundry/src/cf-entity-factory'; import { CoreModule } from '../../../../../../../../core/src/core/core.module'; import { MDAppModule } from '../../../../../../../../core/src/core/md.module'; import { LogViewerComponent } from '../../../../../../../../core/src/shared/components/log-viewer/log-viewer.component'; -import { generateTestEntityServiceProvider } from '../../../../../../../../core/test-framework/entity-service.helper'; import { EntityMonitorFactory } from '../../../../../../../../store/src/monitors/entity-monitor.factory.service'; import { PaginationMonitorFactory } from '../../../../../../../../store/src/monitors/pagination-monitor.factory'; import { AppStoreModule } from '../../../../../../../../store/src/store.module'; import { generateTestApplicationServiceProvider } from '../../../../../../../test-framework/application-service-helper'; import { generateCfStoreModules } from '../../../../../../../test-framework/cloud-foundry-endpoint-service.helper'; -import { applicationEntityType } from '../../../../../../cf-entity-types'; import { ApplicationStateService } from '../../../../../../shared/services/application-state.service'; import { ApplicationEnvVarsHelper } from '../build-tab/application-env-vars.service'; import { LogStreamTabComponent } from './log-stream-tab.component'; @@ -41,11 +37,6 @@ describe('LogStreamTabComponent', () => { LogStreamTabComponent ], providers: [ - generateTestEntityServiceProvider( - appId, - cfEntityFactory(applicationEntityType), - new GetApplication(appId, cfId) - ), generateTestApplicationServiceProvider(cfId, appId), AppStoreModule, ApplicationStateService, diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/tabs/metrics-tab/metrics-tab.component.spec.ts b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/tabs/metrics-tab/metrics-tab.component.spec.ts index 6bb64cb28b..42bf58fa38 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/tabs/metrics-tab/metrics-tab.component.spec.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/application/application-tabs-base/tabs/metrics-tab/metrics-tab.component.spec.ts @@ -1,14 +1,10 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { GetApplication } from '../../../../../../../../cloud-foundry/src/actions/application.actions'; -import { cfEntityFactory } from '../../../../../../../../cloud-foundry/src/cf-entity-factory'; import { MDAppModule } from '../../../../../../../../core/src/core/md.module'; import { SharedModule } from '../../../../../../../../core/src/shared/shared.module'; -import { generateTestEntityServiceProvider } from '../../../../../../../../core/test-framework/entity-service.helper'; import { generateTestApplicationServiceProvider } from '../../../../../../../test-framework/application-service-helper'; import { generateCfStoreModules } from '../../../../../../../test-framework/cloud-foundry-endpoint-service.helper'; -import { applicationEntityType } from '../../../../../../cf-entity-types'; import { ApplicationStateService } from '../../../../../../shared/services/application-state.service'; import { ApplicationEnvVarsHelper } from '../build-tab/application-env-vars.service'; import { MetricsTabComponent } from './metrics-tab.component'; @@ -30,11 +26,6 @@ describe('MetricsTabComponent', () => { providers: [ ApplicationStateService, ApplicationEnvVarsHelper, - generateTestEntityServiceProvider( - appId, - cfEntityFactory(applicationEntityType), - new GetApplication(appId, cfId) - ), generateTestApplicationServiceProvider(cfId, appId), ] }) diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/cli-info-application/cli-info-application.component.spec.ts b/src/frontend/packages/cloud-foundry/src/features/applications/cli-info-application/cli-info-application.component.spec.ts index c3ead1317a..ff36e161d2 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/cli-info-application/cli-info-application.component.spec.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/cli-info-application/cli-info-application.component.spec.ts @@ -1,16 +1,12 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; -import { GetApplication } from '../../../../../cloud-foundry/src/actions/application.actions'; -import { cfEntityFactory } from '../../../../../cloud-foundry/src/cf-entity-factory'; import { CoreModule } from '../../../../../core/src/core/core.module'; import { MDAppModule } from '../../../../../core/src/core/md.module'; import { SharedModule } from '../../../../../core/src/shared/shared.module'; import { TabNavService } from '../../../../../core/tab-nav.service'; -import { generateTestEntityServiceProvider } from '../../../../../core/test-framework/entity-service.helper'; import { generateTestApplicationServiceProvider } from '../../../../test-framework/application-service-helper'; import { generateCfStoreModules } from '../../../../test-framework/cloud-foundry-endpoint-service.helper'; -import { applicationEntityType } from '../../../cf-entity-types'; 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'; @@ -35,11 +31,6 @@ describe('CliInfoApplicationComponent', () => { CloudFoundrySharedModule ], providers: [ - generateTestEntityServiceProvider( - appId, - cfEntityFactory(applicationEntityType), - new GetApplication(appId, cfId) - ), generateTestApplicationServiceProvider(cfId, appId), ApplicationStateService, ApplicationEnvVarsHelper, diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/cli-info-application/cli-info-application.component.ts b/src/frontend/packages/cloud-foundry/src/features/applications/cli-info-application/cli-info-application.component.ts index e18ca983cf..1681bae4ad 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/cli-info-application/cli-info-application.component.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/cli-info-application/cli-info-application.component.ts @@ -3,10 +3,9 @@ import { BehaviorSubject, combineLatest, Observable } from 'rxjs'; import { filter, first, map } from 'rxjs/operators'; import { IHeaderBreadcrumb } from '../../../../../core/src/shared/components/page-header/page-header.types'; -import { GetAllEndpoints } from '../../../../../store/src/actions/endpoint.actions'; import { getFullEndpointApiUrl } from '../../../../../store/src/endpoint-utils'; import { EntityService } from '../../../../../store/src/entity-service'; -import { EntityServiceFactory } from '../../../../../store/src/entity-service-factory.service'; +import { stratosEntityCatalog } from '../../../../../store/src/stratos-entity-catalog'; import { EndpointModel } from '../../../../../store/src/types/endpoint.types'; import { CFAppCLIInfoContext } from '../../../shared/components/cli-info/cli-info.component'; import { ApplicationService } from '../application.service'; @@ -29,7 +28,6 @@ export class CliInfoApplicationComponent implements OnInit { constructor( private applicationService: ApplicationService, - private entityServiceFactory: EntityServiceFactory ) { this.breadcrumbs$ = new BehaviorSubject([]); } @@ -41,10 +39,7 @@ export class CliInfoApplicationComponent implements OnInit { } private setupObservables(cfGuid: string) { - this.cfEndpointEntityService = this.entityServiceFactory.create( - cfGuid, - new GetAllEndpoints() - ); + this.cfEndpointEntityService = stratosEntityCatalog.endpoint.store.getEntityService(cfGuid); this.context$ = combineLatest( this.applicationService.application$, diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/edit-application/edit-application.component.spec.ts b/src/frontend/packages/cloud-foundry/src/features/applications/edit-application/edit-application.component.spec.ts index f25b7fa87f..e5de781a2a 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/edit-application/edit-application.component.spec.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/edit-application/edit-application.component.spec.ts @@ -4,18 +4,14 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { RouterTestingModule } from '@angular/router/testing'; -import { GetApplication } from '../../../../../cloud-foundry/src/actions/application.actions'; -import { cfEntityFactory } from '../../../../../cloud-foundry/src/cf-entity-factory'; import { CoreModule } from '../../../../../core/src/core/core.module'; import { SharedModule } from '../../../../../core/src/shared/shared.module'; import { TabNavService } from '../../../../../core/tab-nav.service'; -import { generateTestEntityServiceProvider } from '../../../../../core/test-framework/entity-service.helper'; import { ApplicationServiceMock, generateTestApplicationServiceProvider, } from '../../../../test-framework/application-service-helper'; import { generateCfStoreModules } from '../../../../test-framework/cloud-foundry-endpoint-service.helper'; -import { applicationEntityType } from '../../../cf-entity-types'; import { ApplicationStateService } from '../../../shared/services/application-state.service'; import { ApplicationService } from '../application.service'; import { ApplicationEnvVarsHelper } from '../application/application-tabs-base/tabs/build-tab/application-env-vars.service'; @@ -42,11 +38,6 @@ describe('EditApplicationComponent', () => { ], providers: [ { provide: ApplicationService, useClass: ApplicationServiceMock }, - generateTestEntityServiceProvider( - appId, - cfEntityFactory(applicationEntityType), - new GetApplication(appId, cfId) - ), generateTestApplicationServiceProvider(cfId, appId), ApplicationStateService, ApplicationEnvVarsHelper, diff --git a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/add-organization/create-organization-step/create-organization-step.component.ts b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/add-organization/create-organization-step/create-organization-step.component.ts index c5e99f073c..acc4f55a0c 100644 --- a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/add-organization/create-organization-step/create-organization-step.component.ts +++ b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/add-organization/create-organization-step/create-organization-step.component.ts @@ -14,7 +14,7 @@ import { import { selectCfRequestInfo } from '../../../../../../cloud-foundry/src/store/selectors/api.selectors'; import { StepOnNextFunction } from '../../../../../../core/src/shared/components/stepper/step/step.component'; import { entityCatalog } from '../../../../../../store/src/entity-catalog/entity-catalog'; -import { endpointSchemaKey } from '../../../../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../../../../store/src/helpers/stratos-entity-factory'; import { PaginationMonitorFactory } from '../../../../../../store/src/monitors/pagination-monitor.factory'; import { getPaginationObservables } from '../../../../../../store/src/reducers/pagination-reducer/pagination-reducer.helper'; import { APIResource } from '../../../../../../store/src/types/api.types'; @@ -75,7 +75,7 @@ export class CreateOrganizationStepComponent implements OnInit, OnDestroy { tap((o) => this.allOrgs = o) ); - const quotaPaginationKey = createEntityRelationPaginationKey(endpointSchemaKey, this.cfGuid); + const quotaPaginationKey = createEntityRelationPaginationKey(endpointEntityType, this.cfGuid); this.quotaDefinitions$ = cfEntityCatalog.quotaDefinition.store.getPaginationService( quotaPaginationKey, this.cfGuid, { includeRelations: [] } ).entities$.pipe( diff --git a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/edit-organization/edit-organization-step/edit-organization-step.component.ts b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/edit-organization/edit-organization-step/edit-organization-step.component.ts index cc3e90927d..5a91738c56 100644 --- a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/edit-organization/edit-organization-step/edit-organization-step.component.ts +++ b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/edit-organization/edit-organization-step/edit-organization-step.component.ts @@ -11,7 +11,7 @@ import { } from '../../../../../../cloud-foundry/src/entity-relations/entity-relations.types'; import { safeUnsubscribe } from '../../../../../../core/src/core/utils.service'; import { StepOnNextFunction } from '../../../../../../core/src/shared/components/stepper/step/step.component'; -import { endpointSchemaKey } from '../../../../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../../../../store/src/helpers/stratos-entity-factory'; import { PaginationMonitorFactory } from '../../../../../../store/src/monitors/pagination-monitor.factory'; import { ActionState } from '../../../../../../store/src/reducers/api-request-reducer/types'; import { getPaginationObservables } from '../../../../../../store/src/reducers/pagination-reducer/pagination-reducer.helper'; @@ -114,7 +114,7 @@ export class EditOrganizationStepComponent implements OnInit, OnDestroy { ); this.fetchOrgsSub = this.allOrgsInEndpoint$.subscribe(); - const quotaPaginationKey = createEntityRelationPaginationKey(endpointSchemaKey, this.cfGuid); + const quotaPaginationKey = createEntityRelationPaginationKey(endpointEntityType, this.cfGuid); this.quotaDefinitions$ = cfEntityCatalog.quotaDefinition.store.getPaginationService( quotaPaginationKey, this.cfGuid, { includeRelations: [] } ).entities$.pipe( diff --git a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/quota-definition-form/quota-definition-form.component.ts b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/quota-definition-form/quota-definition-form.component.ts index f271b4ec36..d330a31aec 100644 --- a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/quota-definition-form/quota-definition-form.component.ts +++ b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/quota-definition-form/quota-definition-form.component.ts @@ -8,7 +8,7 @@ import { createEntityRelationPaginationKey } from '../../../../../cloud-foundry/ import { ActiveRouteCfOrgSpace } from '../../../../../cloud-foundry/src/features/cloud-foundry/cf-page.types'; import { getActiveRouteCfOrgSpaceProvider } from '../../../../../cloud-foundry/src/features/cloud-foundry/cf.helpers'; import { safeUnsubscribe } from '../../../../../core/src/core/utils.service'; -import { endpointSchemaKey } from '../../../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../../../store/src/helpers/stratos-entity-factory'; import { IQuotaDefinition } from '../../../cf-api.types'; export interface QuotaFormValues { @@ -71,7 +71,7 @@ export class QuotaDefinitionFormComponent implements OnInit, OnDestroy { } fetchQuotasDefinitions() { - const quotaPaginationKey = createEntityRelationPaginationKey(endpointSchemaKey, this.cfGuid); + const quotaPaginationKey = createEntityRelationPaginationKey(endpointEntityType, this.cfGuid); const quotaDefinitions$ = cfEntityCatalog.quotaDefinition.store.getPaginationService(quotaPaginationKey, this.cfGuid, {}) .entities$.pipe( filter(o => !!o), diff --git a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/services/cloud-foundry-endpoint.service.ts b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/services/cloud-foundry-endpoint.service.ts index 7f489dbfb6..eec79aba70 100644 --- a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/services/cloud-foundry-endpoint.service.ts +++ b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/services/cloud-foundry-endpoint.service.ts @@ -17,13 +17,12 @@ import { createEntityRelationPaginationKey, } from '../../../../../cloud-foundry/src/entity-relations/entity-relations.types'; import { CfApplicationState } from '../../../../../cloud-foundry/src/store/types/application.types'; -import { GetAllEndpoints } from '../../../../../store/src/actions/endpoint.actions'; import { EntityService } from '../../../../../store/src/entity-service'; -import { EntityServiceFactory } from '../../../../../store/src/entity-service-factory.service'; -import { endpointSchemaKey } from '../../../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../../../store/src/helpers/stratos-entity-factory'; import { PaginationMonitorFactory } from '../../../../../store/src/monitors/pagination-monitor.factory'; import { getPaginationObservables } from '../../../../../store/src/reducers/pagination-reducer/pagination-reducer.helper'; import { PaginationObservables } from '../../../../../store/src/reducers/pagination-reducer/pagination-reducer.types'; +import { stratosEntityCatalog } from '../../../../../store/src/stratos-entity-catalog'; import { APIResource, EntityInfo } from '../../../../../store/src/types/api.types'; import { EndpointModel, EndpointUser } from '../../../../../store/src/types/endpoint.types'; import { PaginatedAction } from '../../../../../store/src/types/pagination.types'; @@ -69,8 +68,8 @@ export class CloudFoundryEndpointService { static createGetAllOrganizations(cfGuid: string) { const paginationKey = cfGuid ? - createEntityRelationPaginationKey(endpointSchemaKey, cfGuid) - : createEntityRelationPaginationKey(endpointSchemaKey); + createEntityRelationPaginationKey(endpointEntityType, cfGuid) + : createEntityRelationPaginationKey(endpointEntityType); const getAllOrganizationsAction = cfEntityCatalog.org.actions.getMultiple(cfGuid, paginationKey, { includeRelations: [ @@ -84,8 +83,8 @@ export class CloudFoundryEndpointService { } static createGetAllOrganizationsLimitedSchema(cfGuid: string) { const paginationKey = cfGuid ? - createEntityRelationPaginationKey(endpointSchemaKey, cfGuid) - : createEntityRelationPaginationKey(endpointSchemaKey); + createEntityRelationPaginationKey(endpointEntityType, cfGuid) + : createEntityRelationPaginationKey(endpointEntityType); const getAllOrganizationsAction = cfEntityCatalog.org.actions.getMultiple(cfGuid, paginationKey, { includeRelations: [ @@ -138,16 +137,12 @@ export class CloudFoundryEndpointService { constructor( public activeRouteCfOrgSpace: ActiveRouteCfOrgSpace, private store: Store, - private entityServiceFactory: EntityServiceFactory, private cfUserService: CfUserService, private pmf: PaginationMonitorFactory, ) { this.cfGuid = activeRouteCfOrgSpace.cfGuid; - this.cfEndpointEntityService = this.entityServiceFactory.create( - this.cfGuid, - new GetAllEndpoints() - ); + this.cfEndpointEntityService = stratosEntityCatalog.endpoint.store.getEntityService(this.cfGuid); this.cfInfoEntityService = cfEntityCatalog.cfInfo.store.getEntityService(this.cfGuid) this.constructCoreObservables(); diff --git a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/space-quota-definition-form/space-quota-definition-form.component.ts b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/space-quota-definition-form/space-quota-definition-form.component.ts index a6bacfc2c6..5e648aba80 100644 --- a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/space-quota-definition-form/space-quota-definition-form.component.ts +++ b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/space-quota-definition-form/space-quota-definition-form.component.ts @@ -9,7 +9,7 @@ import { createEntityRelationPaginationKey } from '../../../../../cloud-foundry/ import { ActiveRouteCfOrgSpace } from '../../../../../cloud-foundry/src/features/cloud-foundry/cf-page.types'; import { getActiveRouteCfOrgSpaceProvider } from '../../../../../cloud-foundry/src/features/cloud-foundry/cf.helpers'; import { safeUnsubscribe } from '../../../../../core/src/core/utils.service'; -import { endpointSchemaKey } from '../../../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../../../store/src/helpers/stratos-entity-factory'; import { IQuotaDefinition } from '../../../cf-api.types'; @@ -65,7 +65,7 @@ export class SpaceQuotaDefinitionFormComponent implements OnInit, OnDestroy { this.spaceQuotaDefinitions$ = cfEntityCatalog.spaceQuota.store.getAllInOrganization.getPaginationService( this.orgGuid, this.cfGuid, - createEntityRelationPaginationKey(endpointSchemaKey, this.cfGuid) + createEntityRelationPaginationKey(endpointEntityType, this.cfGuid) ).entities$ .pipe( filter(o => !!o), diff --git a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/space-quota-definition/space-quota-definition.component.spec.ts b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/space-quota-definition/space-quota-definition.component.spec.ts index f4cf1f0ad5..ee79e073f2 100644 --- a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/space-quota-definition/space-quota-definition.component.spec.ts +++ b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/space-quota-definition/space-quota-definition.component.spec.ts @@ -4,9 +4,9 @@ import { Store } from '@ngrx/store'; import { testSCFEndpoint, testSCFEndpointGuid } from '@stratosui/store/testing'; import { TabNavService } from '../../../../../core/tab-nav.service'; -import { endpointEntitySchema } from '../../../../../store/src/base-entity-schemas'; import { EntityCatalogHelpers } from '../../../../../store/src/entity-catalog/entity-catalog.helper'; import { EntityCatalogEntityConfig } from '../../../../../store/src/entity-catalog/entity-catalog.types'; +import { endpointEntityType, stratosEntityFactory } from '../../../../../store/src/helpers/stratos-entity-factory'; import { NormalizedResponse } from '../../../../../store/src/types/api.types'; import { WrapperRequestActionSuccess } from '../../../../../store/src/types/request.types'; import { @@ -51,7 +51,7 @@ describe('SpaceQuotaDefinitionComponent', () => { .compileComponents(); - const stratosEndpointEntityConfig: EntityCatalogEntityConfig = endpointEntitySchema; + const stratosEndpointEntityConfig: EntityCatalogEntityConfig = stratosEntityFactory(endpointEntityType); const stratosEndpointEntityKey = EntityCatalogHelpers.buildEntityKey( stratosEndpointEntityConfig.entityType, stratosEndpointEntityConfig.endpointType diff --git a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/tabs/cloud-foundry-cells/cloud-foundry-cell/cloud-foundry-cell-base/cloud-foundry-cell-base.component.ts b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/tabs/cloud-foundry-cells/cloud-foundry-cell/cloud-foundry-cell-base/cloud-foundry-cell-base.component.ts index 848157a8e1..cd137d502e 100644 --- a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/tabs/cloud-foundry-cells/cloud-foundry-cell/cloud-foundry-cell-base/cloud-foundry-cell-base.component.ts +++ b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/tabs/cloud-foundry-cells/cloud-foundry-cell/cloud-foundry-cell-base/cloud-foundry-cell-base.component.ts @@ -4,7 +4,7 @@ import { first, map } from 'rxjs/operators'; import { IPageSideNavTab } from '../../../../../../../../core/src/features/dashboard/page-side-nav/page-side-nav.component'; import { IHeaderBreadcrumb } from '../../../../../../../../core/src/shared/components/page-header/page-header.types'; -import { metricEntityType } from '../../../../../../../../store/src/base-entity-schemas'; +import { metricEntityType } from '../../../../../../../../store/src/helpers/stratos-entity-factory'; import { cfEntityFactory } from '../../../../../../cf-entity-factory'; import { getActiveRouteCfCellProvider } from '../../../../cf.helpers'; import { CloudFoundryEndpointService } from '../../../../services/cloud-foundry-endpoint.service'; diff --git a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/user-invites/user-invite.service.ts b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/user-invites/user-invite.service.ts index 755128bd1b..7331193e11 100644 --- a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/user-invites/user-invite.service.ts +++ b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/user-invites/user-invite.service.ts @@ -10,7 +10,7 @@ import { CurrentUserPermissionsService } from '../../../../../core/src/core/perm import { environment } from '../../../../../core/src/environments/environment.prod'; import { ConfirmationDialogConfig } from '../../../../../core/src/shared/components/confirmation-dialog.config'; import { ConfirmationDialogService } from '../../../../../core/src/shared/components/confirmation-dialog.service'; -import { GetSystemInfo } from '../../../../../store/src/actions/system.actions'; +import { stratosEntityCatalog } from '../../../../../store/src/stratos-entity-catalog'; import { CfCurrentUserPermissions } from '../../../user-permissions/cf-user-permissions-checkers'; import { ActiveRouteCfOrgSpace } from '../cf-page.types'; import { waitForCFPermissions } from '../cf.helpers'; @@ -57,7 +57,6 @@ interface UserInviteSend { export class UserInviteConfigureService { constructor( - private store: Store, private http: HttpClient, private snackBar: MatSnackBar, private confirmDialog: ConfirmationDialogService, @@ -70,7 +69,7 @@ export class UserInviteConfigureService { const url = `/pp/${proxyAPIVersion}/invite/${cfGUID}`; const obs$ = this.http.post(url, formData).pipe( map(v => { - this.store.dispatch(new GetSystemInfo()); + stratosEntityCatalog.systemInfo.api.getSystemInfo() return { error: false }; @@ -99,7 +98,7 @@ export class UserInviteConfigureService { const url = `/pp/${proxyAPIVersion}/invite/${cfGUID}`; this.http.delete(url).pipe( map(v => { - this.store.dispatch(new GetSystemInfo()); + stratosEntityCatalog.systemInfo.api.getSystemInfo() return { error: false, errorMessage: '' diff --git a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/users/manage-users/cf-roles.service.ts b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/users/manage-users/cf-roles.service.ts index 56a88ed334..faa4668b08 100644 --- a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/users/manage-users/cf-roles.service.ts +++ b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/users/manage-users/cf-roles.service.ts @@ -18,7 +18,7 @@ import { createEntityRelationPaginationKey, } from '../../../../../../cloud-foundry/src/entity-relations/entity-relations.types'; import { CurrentUserPermissionsService } from '../../../../../../core/src/core/permissions/current-user-permissions.service'; -import { endpointSchemaKey } from '../../../../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../../../../store/src/helpers/stratos-entity-factory'; import { APIResource, EntityInfo } from '../../../../../../store/src/types/api.types'; import { UsersRolesSetChanges } from '../../../../actions/users-roles.actions'; import { IOrganization, ISpace } from '../../../../cf-api.types'; @@ -239,7 +239,7 @@ export class CfRolesService { fetchOrgs(cfGuid: string): Observable[]> { if (!this.cfOrgs[cfGuid]) { - const paginationKey = createEntityRelationPaginationKey(endpointSchemaKey, cfGuid); + const paginationKey = createEntityRelationPaginationKey(endpointEntityType, cfGuid); const orgs$ = cfEntityCatalog.org.store.getPaginationService( cfGuid, paginationKey, diff --git a/src/frontend/packages/cloud-foundry/src/features/services/services/services-wall.service.ts b/src/frontend/packages/cloud-foundry/src/features/services/services/services-wall.service.ts index c6ebd18e85..eadc97f032 100644 --- a/src/frontend/packages/cloud-foundry/src/features/services/services/services-wall.service.ts +++ b/src/frontend/packages/cloud-foundry/src/features/services/services/services-wall.service.ts @@ -3,7 +3,7 @@ import { Observable } from 'rxjs'; import { filter, map, publishReplay, refCount } from 'rxjs/operators'; import { serviceEntityType } from '../../../../../cloud-foundry/src/cf-entity-types'; -import { endpointSchemaKey } from '../../../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../../../store/src/helpers/stratos-entity-factory'; import { APIResource } from '../../../../../store/src/types/api.types'; import { IService } from '../../../cf-api-svc.types'; import { cfEntityCatalog } from '../../../cf-entity-catalog'; @@ -18,7 +18,7 @@ export class ServicesWallService { } initServicesObservable = () => { - const paginationKey = createEntityRelationPaginationKey(endpointSchemaKey); + const paginationKey = createEntityRelationPaginationKey(endpointEntityType); return cfEntityCatalog.service.store.getPaginationService(null, paginationKey, {}).entities$ } diff --git a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/app-instance/cf-app-instances-config.service.spec.ts b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/app-instance/cf-app-instances-config.service.spec.ts index dd2d9a08a4..3966e4880a 100644 --- a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/app-instance/cf-app-instances-config.service.spec.ts +++ b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/app-instance/cf-app-instances-config.service.spec.ts @@ -6,15 +6,11 @@ import { testSCFEndpointGuid } from '@stratosui/store/testing'; import { CoreModule } from '../../../../../../../core/src/core/core.module'; import { CF_GUID } from '../../../../../../../core/src/shared/entity.tokens'; import { SharedModule } from '../../../../../../../core/src/shared/shared.module'; -import { generateTestEntityServiceProvider } from '../../../../../../../core/test-framework/entity-service.helper'; import { generateTestApplicationServiceProvider } from '../../../../../../test-framework/application-service-helper'; import { generateCfStoreModules, generateTestCfEndpointServiceProvider, } from '../../../../../../test-framework/cloud-foundry-endpoint-service.helper'; -import { GetApplication } from '../../../../../actions/application.actions'; -import { cfEntityFactory } from '../../../../../cf-entity-factory'; -import { applicationEntityType } from '../../../../../cf-entity-types'; import { ApplicationsModule } from '../../../../../features/applications/applications.module'; import { CfAppInstancesConfigService } from './cf-app-instances-config.service'; @@ -27,11 +23,6 @@ describe('CfAppInstancesConfigService', () => { TestBed.configureTestingModule({ providers: [ CfAppInstancesConfigService, - generateTestEntityServiceProvider( - appGuid, - cfEntityFactory(applicationEntityType), - new GetApplication(appGuid, cfGuid) - ), generateTestApplicationServiceProvider(appGuid, cfGuid), generateTestCfEndpointServiceProvider(), { diff --git a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/app-instance/table-cell-cf-cell/table-cell-cf-cell.component.ts b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/app-instance/table-cell-cf-cell/table-cell-cf-cell.component.ts index 64ccc8b4f4..651c1b90ac 100644 --- a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/app-instance/table-cell-cf-cell/table-cell-cf-cell.component.ts +++ b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/app-instance/table-cell-cf-cell/table-cell-cf-cell.component.ts @@ -2,8 +2,8 @@ import { Component, Input, OnDestroy } from '@angular/core'; import { Observable, Subscription } from 'rxjs'; import { filter, map, tap } from 'rxjs/operators'; -import { EntityService } from '../../../../../../../../store/src/entity-service'; import { TableCellCustom } from '../../../../../../../../core/src/shared/components/list/list.types'; +import { EntityService } from '../../../../../../../../store/src/entity-service'; import { IMetricMatrixResult, IMetrics } from '../../../../../../../../store/src/types/base-metric.types'; import { IMetricCell } from '../../../../../../../../store/src/types/metric.types'; import { ListAppInstance } from '../app-instance-types'; diff --git a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/app-variables/cf-app-variables-list-config.service.spec.ts b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/app-variables/cf-app-variables-list-config.service.spec.ts index 4eea9c86fc..b2a3d64486 100644 --- a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/app-variables/cf-app-variables-list-config.service.spec.ts +++ b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/app-variables/cf-app-variables-list-config.service.spec.ts @@ -4,12 +4,8 @@ import { RouterTestingModule } from '@angular/router/testing'; import { CoreModule } from '../../../../../../../core/src/core/core.module'; import { SharedModule } from '../../../../../../../core/src/shared/shared.module'; -import { generateTestEntityServiceProvider } from '../../../../../../../core/test-framework/entity-service.helper'; import { generateTestApplicationServiceProvider } from '../../../../../../test-framework/application-service-helper'; import { generateCfStoreModules } from '../../../../../../test-framework/cloud-foundry-endpoint-service.helper'; -import { GetApplication } from '../../../../../actions/application.actions'; -import { cfEntityFactory } from '../../../../../cf-entity-factory'; -import { applicationEntityType } from '../../../../../cf-entity-types'; import { ApplicationsModule } from '../../../../../features/applications/applications.module'; import { CfAppVariablesListConfigService } from './cf-app-variables-list-config.service'; @@ -22,11 +18,6 @@ describe('CfAppVariablesListConfigService', () => { TestBed.configureTestingModule({ providers: [ CfAppVariablesListConfigService, - generateTestEntityServiceProvider( - appGuid, - cfEntityFactory(applicationEntityType), - new GetApplication(appGuid, cfGuid) - ), generateTestApplicationServiceProvider(appGuid, cfGuid) ], imports: [ diff --git a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-buildpacks/cf-buildpacks-data-source.ts b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-buildpacks/cf-buildpacks-data-source.ts index ae5065e46e..fbc40398d9 100644 --- a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-buildpacks/cf-buildpacks-data-source.ts +++ b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-buildpacks/cf-buildpacks-data-source.ts @@ -9,7 +9,7 @@ import { ListDataSource, } from '../../../../../../../core/src/shared/components/list/data-sources-controllers/list-data-source'; import { IListConfig } from '../../../../../../../core/src/shared/components/list/list.component.types'; -import { endpointSchemaKey } from '../../../../../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../../../../../store/src/helpers/stratos-entity-factory'; import { getRowMetadata } from '../../../../../../../store/src/public-api'; import { APIResource } from '../../../../../../../store/src/types/api.types'; import { cfEntityCatalog } from '../../../../../cf-entity-catalog'; @@ -17,7 +17,7 @@ import { cfEntityFactory } from '../../../../../cf-entity-factory'; export class CfBuildpacksDataSource extends ListDataSource { constructor(store: Store, cfGuid: string, listConfig?: IListConfig) { - const paginationKey = createEntityRelationPaginationKey(endpointSchemaKey, cfGuid); + const paginationKey = createEntityRelationPaginationKey(endpointEntityType, cfGuid); const action = cfEntityCatalog.buildPack.actions.getMultiple(cfGuid, paginationKey) super({ store, diff --git a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-cell-apps/cf-cell-apps-list-config.service.ts b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-cell-apps/cf-cell-apps-list-config.service.ts index 6bc5cdfb94..6d4c6d7b02 100644 --- a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-cell-apps/cf-cell-apps-list-config.service.ts +++ b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-cell-apps/cf-cell-apps-list-config.service.ts @@ -5,7 +5,6 @@ import { CFAppState } from '../../../../../../../cloud-foundry/src/cf-app-state' import { ITableColumn } from '../../../../../../../core/src/shared/components/list/list-table/table.types'; import { ListViewTypes } from '../../../../../../../core/src/shared/components/list/list.component.types'; import { ListView } from '../../../../../../../store/src/actions/list.actions'; -import { EntityServiceFactory } from '../../../../../../../store/src/entity-service-factory.service'; import { APIResource } from '../../../../../../../store/src/types/api.types'; import { IApp, ISpace } from '../../../../../cf-api.types'; import { ActiveRouteCfCell } from '../../../../../features/cloud-foundry/cf-page.types'; @@ -24,9 +23,9 @@ export class CfCellAppsListConfigService extends BaseCfListConfig { noEntries: 'There are no applications' }; - constructor(store: Store, private activeRouteCfCell: ActiveRouteCfCell, entityServiceFactory: EntityServiceFactory) { + constructor(store: Store, private activeRouteCfCell: ActiveRouteCfCell) { super(); - this.dataSource = new CfCellAppsDataSource(store, activeRouteCfCell.cfGuid, activeRouteCfCell.cellId, this, entityServiceFactory); + this.dataSource = new CfCellAppsDataSource(store, activeRouteCfCell.cfGuid, activeRouteCfCell.cellId, this); } getColumns = (): ITableColumn[] => [ diff --git a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-cell-apps/cf-cell-apps-source.ts b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-cell-apps/cf-cell-apps-source.ts index 2d12d50d6f..ba9148a902 100644 --- a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-cell-apps/cf-cell-apps-source.ts +++ b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-cell-apps/cf-cell-apps-source.ts @@ -2,7 +2,6 @@ import { Store } from '@ngrx/store'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; -import { GetApplication } from '../../../../../../../cloud-foundry/src/actions/application.actions'; import { CFAppState } from '../../../../../../../cloud-foundry/src/cf-app-state'; import { applicationEntityType, @@ -14,12 +13,12 @@ import { } from '../../../../../../../core/src/shared/components/list/data-sources-controllers/list-data-source'; import { IListConfig } from '../../../../../../../core/src/shared/components/list/list.component.types'; import { MetricQueryConfig } from '../../../../../../../store/src/actions/metrics.actions'; -import { EntityServiceFactory } from '../../../../../../../store/src/entity-service-factory.service'; import { APIResource } from '../../../../../../../store/src/types/api.types'; import { IMetrics, IMetricVectorResult } from '../../../../../../../store/src/types/base-metric.types'; import { IMetricApplication, MetricQueryType } from '../../../../../../../store/src/types/metric.types'; import { FetchCFMetricsPaginatedAction } from '../../../../../actions/cf-metrics.actions'; import { IApp } from '../../../../../cf-api.types'; +import { cfEntityCatalog } from '../../../../../cf-entity-catalog'; import { cfEntityFactory } from '../../../../../cf-entity-factory'; import { createEntityRelationKey } from '../../../../../entity-relations/entity-relations.types'; @@ -40,7 +39,6 @@ export class CfCellAppsDataSource cfGuid: string, cellId: string, listConfig: IListConfig, - entityServiceFactory: EntityServiceFactory ) { const action = new FetchCFMetricsPaginatedAction( cellId, @@ -63,7 +61,7 @@ export class CfCellAppsDataSource return response[0].data.result.map(res => ({ metric: res.metric, appGuid: res.metric.application_id, - appEntityService: this.createAppEntityService(res.metric.application_id, cfGuid, entityServiceFactory) + appEntityService: this.createAppEntityService(res.metric.application_id, cfGuid) })); }), listConfig @@ -73,15 +71,18 @@ export class CfCellAppsDataSource private createAppEntityService( appGuid: string, - cfGuid: string, - entityServiceFactory: EntityServiceFactory): Observable> { + cfGuid: string + ): Observable> { if (!this.appEntityServices[appGuid]) { - this.appEntityServices[appGuid] = entityServiceFactory.create>( + this.appEntityServices[appGuid] = cfEntityCatalog.application.store.getEntityService( appGuid, - new GetApplication(appGuid, cfGuid, [ + cfGuid, { + includeRelations: [ createEntityRelationKey(applicationEntityType, spaceEntityType), createEntityRelationKey(spaceEntityType, organizationEntityType) - ]) + ], + populateMissing: true + } ).waitForEntity$.pipe( map(entityInfo => entityInfo.entity) ); diff --git a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-endpoints/cf-endpoints-data-source.ts b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-endpoints/cf-endpoints-data-source.ts index a9e6b2856e..591c35bf58 100644 --- a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-endpoints/cf-endpoints-data-source.ts +++ b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-endpoints/cf-endpoints-data-source.ts @@ -9,7 +9,7 @@ import { IListConfig } from '../../../../../../../core/src/shared/components/lis import { EntityMonitorFactory } from '../../../../../../../store/src/monitors/entity-monitor.factory.service'; import { InternalEventMonitorFactory } from '../../../../../../../store/src/monitors/internal-event-monitor.factory'; import { PaginationMonitorFactory } from '../../../../../../../store/src/monitors/pagination-monitor.factory'; -import { GetAllEndpoints } from '../../../../../../../store/src/actions/endpoint.actions'; +import { stratosEntityCatalog } from '../../../../../../../store/src/stratos-entity-catalog'; import { EndpointModel } from '../../../../../../../store/src/types/endpoint.types'; export class CFEndpointsDataSource extends BaseEndpointsDataSource { @@ -22,7 +22,7 @@ export class CFEndpointsDataSource extends BaseEndpointsDataSource { entityMonitorFactory: EntityMonitorFactory, internalEventMonitorFactory: InternalEventMonitorFactory ) { - const action = new GetAllEndpoints(); + const action = stratosEntityCatalog.endpoint.actions.getAll(); const paginationKey = 'cf-endpoints'; // We do this here to ensure we sync up with main endpoint table data. syncPaginationSection(store, action, paginationKey); diff --git a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-quotas/cf-quotas-data-source.service.ts b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-quotas/cf-quotas-data-source.service.ts index f2bf84af31..1771755cb0 100644 --- a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-quotas/cf-quotas-data-source.service.ts +++ b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-quotas/cf-quotas-data-source.service.ts @@ -11,10 +11,10 @@ import { getDefaultRowState, } from '../../../../../../../core/src/shared/components/list/data-sources-controllers/list-data-source-types'; import { IListConfig } from '../../../../../../../core/src/shared/components/list/list.component.types'; -import { endpointSchemaKey } from '../../../../../../../store/src/helpers/entity-factory'; -import { EntityMonitor } from '../../../../../../../store/src/monitors/entity-monitor'; +import { endpointEntityType } from '../../../../../../../store/src/helpers/stratos-entity-factory'; import { APIResource } from '../../../../../../../store/src/types/api.types'; import { CFAppState } from '../../../../../cf-app-state'; +import { cfEntityCatalog } from '../../../../../cf-entity-catalog'; import { cfEntityFactory } from '../../../../../cf-entity-factory'; import { quotaDefinitionEntityType } from '../../../../../cf-entity-types'; import { createEntityRelationPaginationKey } from '../../../../../entity-relations/entity-relations.types'; @@ -22,7 +22,7 @@ import { createEntityRelationPaginationKey } from '../../../../../entity-relatio export class CfQuotasDataSourceService extends ListDataSource { constructor(store: Store, cfGuid: string, listConfig?: IListConfig) { - const quotaPaginationKey = createEntityRelationPaginationKey(endpointSchemaKey, cfGuid); + const quotaPaginationKey = createEntityRelationPaginationKey(endpointEntityType, cfGuid); const action = new GetQuotaDefinitions(quotaPaginationKey, cfGuid); super({ @@ -44,8 +44,7 @@ export class CfQuotasDataSourceService extends ListDataSource { if (!this.sourceScheme || !row) { return of(getDefaultRowState()); } - const entityMonitor = new EntityMonitor(this.store, this.getRowUniqueId(row), this.entityKey, this.sourceScheme); - return entityMonitor.entityRequest$.pipe( + return cfEntityCatalog.quotaDefinition.store.getEntityMonitor(this.getRowUniqueId(row)).entityRequest$.pipe( distinctUntilChanged(), map(requestInfo => ({ deleting: requestInfo.deleting.busy, diff --git a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-security-groups/cf-security-groups-data-source.ts b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-security-groups/cf-security-groups-data-source.ts index 42b046e9dd..2f0b04583f 100644 --- a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-security-groups/cf-security-groups-data-source.ts +++ b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-security-groups/cf-security-groups-data-source.ts @@ -10,14 +10,14 @@ import { ListDataSource, } from '../../../../../../../core/src/shared/components/list/data-sources-controllers/list-data-source'; import { IListConfig } from '../../../../../../../core/src/shared/components/list/list.component.types'; -import { endpointSchemaKey } from '../../../../../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../../../../../store/src/helpers/stratos-entity-factory'; import { APIResource } from '../../../../../../../store/src/types/api.types'; import { cfEntityCatalog } from '../../../../../cf-entity-catalog'; import { cfEntityFactory } from '../../../../../cf-entity-factory'; export class CfSecurityGroupsDataSource extends ListDataSource { constructor(store: Store, cfGuid: string, listConfig?: IListConfig) { - const paginationKey = createEntityRelationPaginationKey(endpointSchemaKey, cfGuid); + const paginationKey = createEntityRelationPaginationKey(endpointEntityType, cfGuid); const action = cfEntityCatalog.securityGroup.actions.getMultiple(cfGuid, paginationKey, {}); super({ store, diff --git a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-services/cf-services-data-source.ts b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-services/cf-services-data-source.ts index 334d992dd6..58e54ea397 100644 --- a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-services/cf-services-data-source.ts +++ b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-services/cf-services-data-source.ts @@ -11,7 +11,7 @@ import { } from '../../../../../../../core/src/shared/components/list/data-sources-controllers/list-data-source'; import { IListConfig } from '../../../../../../../core/src/shared/components/list/list.component.types'; import { entityCatalog } from '../../../../../../../store/src/entity-catalog/entity-catalog'; -import { endpointSchemaKey } from '../../../../../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../../../../../store/src/helpers/stratos-entity-factory'; import { APIResource } from '../../../../../../../store/src/types/api.types'; import { PaginationEntityState } from '../../../../../../../store/src/types/pagination.types'; import { cfEntityCatalog } from '../../../../../cf-entity-catalog'; @@ -19,7 +19,7 @@ import { CF_ENDPOINT_TYPE } from '../../../../../cf-types'; export class CfServicesDataSource extends ListDataSource { constructor(store: Store, endpointGuid: string, listConfig?: IListConfig) { - const paginationKey = createEntityRelationPaginationKey(endpointSchemaKey); + const paginationKey = createEntityRelationPaginationKey(endpointEntityType); const getServicesAction = cfEntityCatalog.service.actions.getMultiple(endpointGuid, paginationKey, {}); super({ store, diff --git a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-space-quotas/cf-space-quotas-data-source.service.ts b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-space-quotas/cf-space-quotas-data-source.service.ts index 4a880b804b..cd9e0e00c1 100644 --- a/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-space-quotas/cf-space-quotas-data-source.service.ts +++ b/src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-space-quotas/cf-space-quotas-data-source.service.ts @@ -10,11 +10,11 @@ import { getDefaultRowState, } from '../../../../../../../core/src/shared/components/list/data-sources-controllers/list-data-source-types'; import { IListConfig } from '../../../../../../../core/src/shared/components/list/list.component.types'; -import { endpointSchemaKey } from '../../../../../../../store/src/helpers/entity-factory'; -import { EntityMonitor } from '../../../../../../../store/src/monitors/entity-monitor'; +import { endpointEntityType } from '../../../../../../../store/src/helpers/stratos-entity-factory'; import { APIResource } from '../../../../../../../store/src/types/api.types'; import { GetOrganizationSpaceQuotaDefinitions } from '../../../../../actions/quota-definitions.actions'; import { CFAppState } from '../../../../../cf-app-state'; +import { cfEntityCatalog } from '../../../../../cf-entity-catalog'; import { cfEntityFactory } from '../../../../../cf-entity-factory'; import { spaceQuotaEntityType } from '../../../../../cf-entity-types'; import { createEntityRelationPaginationKey } from '../../../../../entity-relations/entity-relations.types'; @@ -22,7 +22,7 @@ import { createEntityRelationPaginationKey } from '../../../../../entity-relatio export class CfOrgSpaceQuotasDataSourceService extends ListDataSource { constructor(store: Store, orgGuid: string, cfGuid: string, listConfig?: IListConfig) { - const quotaPaginationKey = createEntityRelationPaginationKey(endpointSchemaKey, cfGuid); + const quotaPaginationKey = createEntityRelationPaginationKey(endpointEntityType, cfGuid); const action = new GetOrganizationSpaceQuotaDefinitions(quotaPaginationKey, orgGuid, cfGuid); super({ @@ -44,8 +44,8 @@ export class CfOrgSpaceQuotasDataSourceService extends ListDataSource ({ deleting: requestInfo.deleting.busy, diff --git a/src/frontend/packages/cloud-foundry/src/shared/data-services/cloud-foundry.service.ts b/src/frontend/packages/cloud-foundry/src/shared/data-services/cloud-foundry.service.ts index 45ba64f2e0..2482601268 100644 --- a/src/frontend/packages/cloud-foundry/src/shared/data-services/cloud-foundry.service.ts +++ b/src/frontend/packages/cloud-foundry/src/shared/data-services/cloud-foundry.service.ts @@ -1,13 +1,11 @@ import { Injectable } from '@angular/core'; -import { Store } from '@ngrx/store'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; -import { CFAppState } from '../../../../cloud-foundry/src/cf-app-state'; -import { endpointEntitySchema } from '../../../../store/src/base-entity-schemas'; import { PaginationMonitor } from '../../../../store/src/monitors/pagination-monitor'; +import { stratosEntityCatalog } from '../../../../store/src/stratos-entity-catalog'; import { APIResource, EntityInfo } from '../../../../store/src/types/api.types'; -import { endpointListKey, EndpointModel } from '../../../../store/src/types/endpoint.types'; +import { EndpointModel } from '../../../../store/src/types/endpoint.types'; @Injectable() export class CloudFoundryService { @@ -18,11 +16,9 @@ export class CloudFoundryService { cfEndpointsMonitor: PaginationMonitor; waitForAppEntity$: Observable>; - constructor( - store: Store - ) { + constructor() { - this.cfEndpointsMonitor = new PaginationMonitor(store, endpointListKey, endpointEntitySchema, true); + this.cfEndpointsMonitor = stratosEntityCatalog.endpoint.store.getPaginationMonitor(); this.cFEndpoints$ = this.cfEndpointsMonitor.currentPage$.pipe( map(endpoints => endpoints.filter(e => e.cnsi_type === 'cf')) diff --git a/src/frontend/packages/cloud-foundry/src/shared/data-services/long-running-cf-op.service.ts b/src/frontend/packages/cloud-foundry/src/shared/data-services/long-running-cf-op.service.ts index c6633637ec..acec511ca3 100644 --- a/src/frontend/packages/cloud-foundry/src/shared/data-services/long-running-cf-op.service.ts +++ b/src/frontend/packages/cloud-foundry/src/shared/data-services/long-running-cf-op.service.ts @@ -4,7 +4,7 @@ import { Store } from '@ngrx/store'; import { LongRunningOperationsService } from '../../../../core/src/shared/services/long-running-op.service'; import { SnackBarService } from '../../../../core/src/shared/services/snackbar.service'; import { AppState } from '../../../../store/src/app-state'; -import { GetServiceInstance } from '../../actions/service-instances.actions'; +import { cfEntityCatalog } from '../../cf-entity-catalog'; @Injectable() export class LongRunningCfOperationsService extends LongRunningOperationsService { @@ -20,14 +20,15 @@ export class LongRunningCfOperationsService extends LongRunningOperationsService const message = `The operation to create the service instance is taking a long time and will continue in the background. Please refresh the service instance list to check it's status ${bindApp ? ` and then bind the application via the Application page.` : '.'}`; - this.snackBarService.show(message, 'Dismiss'); } + this.snackBarService.show(message, 'Dismiss'); + } handleLongRunningUpdateService(serviceInstanceGuid: string, cfGuid: string) { const message = `The operation to update the service instance is taking a long time and will continue in the background. Please refresh the service instance list to check it's status`; - // Also attempt to fetch the service instance, this will update the `last operation` value to `update` and `in progress` + // Also attempt to fetch the service instance, this will update the `last operation` value to `update` and `in progress` this.snackBarService.show(message, 'Dismiss'); - this.store.dispatch(new GetServiceInstance(serviceInstanceGuid, cfGuid)); + cfEntityCatalog.serviceInstance.api.get(serviceInstanceGuid, cfGuid); } handleLongRunningDeleteService(serviceInstanceGuid: string, cfGuid: string) { @@ -35,7 +36,7 @@ export class LongRunningCfOperationsService extends LongRunningOperationsService Please refresh the service instance list to check it's status`; this.snackBarService.show(message, 'Dismiss'); // Also attempt to fetch the service instance, this will update the `last operation` value to `delete` and `in progress` - this.store.dispatch(new GetServiceInstance(serviceInstanceGuid, cfGuid)); + cfEntityCatalog.serviceInstance.api.get(serviceInstanceGuid, cfGuid); } } diff --git a/src/frontend/packages/cloud-foundry/src/shared/services/cf-org-space-label.service.ts b/src/frontend/packages/cloud-foundry/src/shared/services/cf-org-space-label.service.ts index de20b2451c..36c9cb2e38 100644 --- a/src/frontend/packages/cloud-foundry/src/shared/services/cf-org-space-label.service.ts +++ b/src/frontend/packages/cloud-foundry/src/shared/services/cf-org-space-label.service.ts @@ -2,9 +2,8 @@ import { Store } from '@ngrx/store'; import { combineLatest, Observable } from 'rxjs'; import { filter, first, map } from 'rxjs/operators'; -import { STRATOS_ENDPOINT_TYPE } from '../../../../store/src/base-entity-schemas'; import { entityCatalog } from '../../../../store/src/entity-catalog/entity-catalog'; -import { endpointSchemaKey } from '../../../../store/src/helpers/entity-factory'; +import { endpointEntityType, STRATOS_ENDPOINT_TYPE } from '../../../../store/src/helpers/stratos-entity-factory'; import { selectEntity } from '../../../../store/src/selectors/api.selectors'; import { APIResource } from '../../../../store/src/types/api.types'; import { EndpointModel } from '../../../../store/src/types/endpoint.types'; @@ -33,7 +32,7 @@ export class CfOrgSpaceLabelService { private spaceGuid?: string) { this.multipleConnectedEndpoints$ = haveMultiConnectedCfs(this.store); // FIXME: hide STRATOS_ENDPOINT_TYPE from extensions - STRAT-154 - const endpointEntityKey = entityCatalog.getEntityKey(STRATOS_ENDPOINT_TYPE, endpointSchemaKey); + const endpointEntityKey = entityCatalog.getEntityKey(STRATOS_ENDPOINT_TYPE, endpointEntityType); this.cf$ = this.store.select(selectEntity(endpointEntityKey, this.cfGuid)); diff --git a/src/frontend/packages/cloud-foundry/src/shared/services/current-user-permissions.service.spec.ts b/src/frontend/packages/cloud-foundry/src/shared/services/current-user-permissions.service.spec.ts index c3536ed8a9..ddf7d54350 100644 --- a/src/frontend/packages/cloud-foundry/src/shared/services/current-user-permissions.service.spec.ts +++ b/src/frontend/packages/cloud-foundry/src/shared/services/current-user-permissions.service.spec.ts @@ -15,12 +15,12 @@ import { import { PermissionConfig } from '../../../../core/src/core/permissions/current-user-permissions.config'; import { CurrentUserPermissionsService } from '../../../../core/src/core/permissions/current-user-permissions.service'; import { StratosScopeStrings } from '../../../../core/src/core/permissions/stratos-user-permissions.checker'; -import { generateStratosEntities } from '../../../../core/src/stratos-entities'; import { AppTestModule } from '../../../../core/test-framework/core-test.helper'; import { AppState } from '../../../../store/src/app-state'; -import { endpointEntitySchema } from '../../../../store/src/base-entity-schemas'; import { EntityCatalogTestModule, TEST_CATALOGUE_ENTITIES } from '../../../../store/src/entity-catalog-test.module'; import { EntityCatalogEntityConfig } from '../../../../store/src/entity-catalog/entity-catalog.types'; +import { endpointEntityType, stratosEntityFactory } from '../../../../store/src/helpers/stratos-entity-factory'; +import { generateStratosEntities } from '../../../../store/src/stratos-entity-generator'; import { APIResource } from '../../../../store/src/types/api.types'; import { EndpointModel } from '../../../../store/src/types/endpoint.types'; import { BaseEntityValues } from '../../../../store/src/types/entity.types'; @@ -588,7 +588,7 @@ describe('CurrentUserPermissionsService with CF checker', () => { // Create request and requestData sections const entityMap = new Map>([ [ - endpointEntitySchema, + stratosEntityFactory(endpointEntityType), endpoints.map(endpoint => ({ guid: endpoint.guid, data: endpoint diff --git a/src/frontend/packages/cloud-foundry/src/store/reducers/cf-users.reducer.ts b/src/frontend/packages/cloud-foundry/src/store/reducers/cf-users.reducer.ts index 71079d216e..2395df2ff6 100644 --- a/src/frontend/packages/cloud-foundry/src/store/reducers/cf-users.reducer.ts +++ b/src/frontend/packages/cloud-foundry/src/store/reducers/cf-users.reducer.ts @@ -12,6 +12,7 @@ import { } from '../../actions/users.actions'; import { IOrganization, ISpace } from '../../cf-api.types'; import { cfUserEntityType } from '../../cf-entity-types'; +import { CF_ENDPOINT_TYPE } from '../../cf-types'; import { CfUser, CfUserMissingOrgRoles, @@ -61,7 +62,7 @@ export function cfUserReducer(state: IRequestEntityTypeState } export function endpointDisconnectUserReducer(state: IRequestEntityTypeState>, action: DisconnectEndpoint) { - if (action.endpointType === 'cf') { + if (action.endpointType === CF_ENDPOINT_TYPE) { switch (action.type) { case DISCONNECT_ENDPOINTS_SUCCESS: const cfGuid = action.guid; diff --git a/src/frontend/packages/cloud-foundry/test-framework/application-service-helper.ts b/src/frontend/packages/cloud-foundry/test-framework/application-service-helper.ts index 6c07e9ba8f..18ed991825 100644 --- a/src/frontend/packages/cloud-foundry/test-framework/application-service-helper.ts +++ b/src/frontend/packages/cloud-foundry/test-framework/application-service-helper.ts @@ -1,7 +1,8 @@ import { Store } from '@ngrx/store'; -import { Observable, of as observableOf } from 'rxjs'; +import { Observable, of as observableOf, of } from 'rxjs'; import { map } from 'rxjs/internal/operators/map'; +import { EntityService } from '../../store/src/entity-service'; import { RequestInfoState } from '../../store/src/reducers/api-request-reducer/types'; import { APIResource, EntityInfo } from '../../store/src/types/api.types'; import { IApp, IAppSummary, IDomain, ISpace } from '../src/cf-api.types'; @@ -81,6 +82,10 @@ export class ApplicationServiceMock { appSpace$: Observable> = observableOf(createEntity({} as ISpace)); applicationRunning$: Observable = observableOf(false); orgDomains$: Observable[]> = observableOf([]); + entityService: EntityService>> = { + waitForEntity$: of({}), + updatingSection$: of({}) + } as EntityService>> } export function generateTestApplicationServiceProvider(appGuid: string, cfGuid: string) { diff --git a/src/frontend/packages/cloud-foundry/test-framework/cf-test-helper.ts b/src/frontend/packages/cloud-foundry/test-framework/cf-test-helper.ts index fda8621a50..c22514e227 100644 --- a/src/frontend/packages/cloud-foundry/test-framework/cf-test-helper.ts +++ b/src/frontend/packages/cloud-foundry/test-framework/cf-test-helper.ts @@ -1,6 +1,6 @@ -import { generateStratosEntities } from '../../core/src/stratos-entities'; import { BaseTestModules } from '../../core/test-framework/core-test.helper'; import { EntityCatalogTestModule, TEST_CATALOGUE_ENTITIES } from '../../store/src/entity-catalog-test.module'; +import { generateStratosEntities } from '../../store/src/stratos-entity-generator'; import { generateCFEntities } from '../src/cf-entity-generator'; export const CFBaseTestModules = [ diff --git a/src/frontend/packages/cloud-foundry/test-framework/cloud-foundry-endpoint-service.helper.ts b/src/frontend/packages/cloud-foundry/test-framework/cloud-foundry-endpoint-service.helper.ts index 2174658903..3fc7ed40e9 100644 --- a/src/frontend/packages/cloud-foundry/test-framework/cloud-foundry-endpoint-service.helper.ts +++ b/src/frontend/packages/cloud-foundry/test-framework/cloud-foundry-endpoint-service.helper.ts @@ -114,7 +114,7 @@ export function generateTestCfServiceProvider() { useFactory: ( store: Store, ) => { - const appService = new CloudFoundryService(store); + const appService = new CloudFoundryService(); return appService; }, deps: [Store] diff --git a/src/frontend/packages/core/src/app.module.ts b/src/frontend/packages/core/src/app.module.ts index f70ee4210e..24bfcbbe56 100644 --- a/src/frontend/packages/core/src/app.module.ts +++ b/src/frontend/packages/core/src/app.module.ts @@ -10,21 +10,19 @@ import { debounceTime, filter, withLatestFrom } from 'rxjs/operators'; import { CfAutoscalerModule } from '../../cf-autoscaler/src/cf-autoscaler.module'; import { CloudFoundryPackageModule } from '../../cloud-foundry/src/cloud-foundry-package.module'; import { SetRecentlyVisitedEntityAction } from '../../store/src/actions/recently-visited.actions'; -import { - UpdateUserFavoriteMetadataAction, -} from '../../store/src/actions/user-favourites-actions/update-user-favorite-metadata-action'; import { GeneralEntityAppState, GeneralRequestDataState } from '../../store/src/app-state'; -import { STRATOS_ENDPOINT_TYPE } from '../../store/src/base-entity-schemas'; import { EntityCatalogModule } from '../../store/src/entity-catalog.module'; import { entityCatalog } from '../../store/src/entity-catalog/entity-catalog'; import { EntityCatalogHelper } from '../../store/src/entity-catalog/entity-catalog-entity/entity-catalog.service'; import { EntityCatalogHelpers } from '../../store/src/entity-catalog/entity-catalog.helper'; import { FavoritesConfigMapper } from '../../store/src/favorite-config-mapper'; -import { endpointSchemaKey } from '../../store/src/helpers/entity-factory'; +import { endpointEntityType, STRATOS_ENDPOINT_TYPE } from '../../store/src/helpers/stratos-entity-factory'; import { getAPIRequestDataState, selectEntity } from '../../store/src/selectors/api.selectors'; import { internalEventStateSelector } from '../../store/src/selectors/internal-events.selectors'; import { recentlyVisitedSelector } from '../../store/src/selectors/recently-visitied.selectors'; import { AppStoreModule } from '../../store/src/store.module'; +import { stratosEntityCatalog } from '../../store/src/stratos-entity-catalog'; +import { generateStratosEntities } from '../../store/src/stratos-entity-generator'; import { EndpointModel } from '../../store/src/types/endpoint.types'; import { IFavoriteMetadata, UserFavorite } from '../../store/src/types/user-favorites.types'; import { UserFavoriteManager } from '../../store/src/user-favorite-manager'; @@ -51,7 +49,6 @@ import { CustomReuseStrategy } from './route-reuse-stragegy'; import { endpointEventKey, GlobalEventData, GlobalEventService } from './shared/global-events.service'; import { SidePanelService } from './shared/services/side-panel.service'; import { SharedModule } from './shared/shared.module'; -import { generateStratosEntities } from './stratos-entities'; // Create action for router navigation. See // - https://github.com/ngrx/platform/issues/68 @@ -92,7 +89,7 @@ const storeDebugImports = environment.production ? [] : [ @NgModule({ imports: storeDebugImports }) -class AppStoreDebugModule {} +class AppStoreDebugModule { } /** * `HttpXsrfTokenExtractor` which retrieves the token from a cookie. @@ -174,7 +171,7 @@ export class AppModule { if (!backendErrors.length) { return res; } - const entityConfig = entityCatalog.getEntity(STRATOS_ENDPOINT_TYPE, endpointSchemaKey); + const entityConfig = entityCatalog.getEntity(STRATOS_ENDPOINT_TYPE, endpointEntityType); res.push(new GlobalEventData(true, { endpoint: selectEntity(entityConfig.entityKey, eventId)(state), count: backendErrors.length @@ -263,7 +260,7 @@ export class AppModule { private syncFavorite(favorite: UserFavorite, entities: GeneralRequestDataState) { if (favorite) { - const isEndpoint = (favorite.entityType === endpointSchemaKey); + const isEndpoint = (favorite.entityType === endpointEntityType); // If the favorite is an endpoint ensure we look in the stratosEndpoint part of the store instead of, for example, cfEndpoint const entityKey = isEndpoint ? entityCatalog.getEntityKey({ ...favorite, @@ -273,10 +270,10 @@ export class AppModule { if (entity) { const newMetadata = this.favoritesConfigMapper.getEntityMetadata(favorite, entity); if (this.metadataHasChanged(favorite.metadata, newMetadata)) { - this.store.dispatch(new UpdateUserFavoriteMetadataAction({ + stratosEntityCatalog.userFavorite.api.updateFavorite({ ...favorite, metadata: newMetadata - })); + }); } } } diff --git a/src/frontend/packages/core/src/core/permissions/current-user-permissions.service.spec.ts b/src/frontend/packages/core/src/core/permissions/current-user-permissions.service.spec.ts index 60d39f5ace..90d5401db5 100644 --- a/src/frontend/packages/core/src/core/permissions/current-user-permissions.service.spec.ts +++ b/src/frontend/packages/core/src/core/permissions/current-user-permissions.service.spec.ts @@ -3,14 +3,14 @@ import { createBasicStoreModule, createEntityStoreState, TestStoreEntity } from import { first, tap } from 'rxjs/operators'; import { AppState } from '../../../../store/src/app-state'; -import { endpointEntitySchema } from '../../../../store/src/base-entity-schemas'; import { EntityCatalogTestModule, TEST_CATALOGUE_ENTITIES } from '../../../../store/src/entity-catalog-test.module'; import { EntityCatalogEntityConfig } from '../../../../store/src/entity-catalog/entity-catalog.types'; +import { endpointEntityType, stratosEntityFactory } from '../../../../store/src/helpers/stratos-entity-factory'; +import { generateStratosEntities } from '../../../../store/src/stratos-entity-generator'; import { EndpointModel } from '../../../../store/src/types/endpoint.types'; import { BaseEntityValues } from '../../../../store/src/types/entity.types'; import { PaginationState } from '../../../../store/src/types/pagination.types'; import { AppTestModule } from '../../../test-framework/core-test.helper'; -import { generateStratosEntities } from '../../stratos-entities'; import { PermissionConfig } from './current-user-permissions.config'; import { CurrentUserPermissionsService } from './current-user-permissions.service'; import { StratosPermissionStrings, StratosPermissionTypes, StratosScopeStrings } from './stratos-user-permissions.checker'; @@ -138,7 +138,7 @@ describe('CurrentUserPermissionsService', () => { // Create request and requestData sections const entityMap = new Map>([ [ - endpointEntitySchema, + stratosEntityFactory(endpointEntityType), endpoints.map(endpoint => ({ guid: endpoint.guid, data: endpoint diff --git a/src/frontend/packages/core/src/core/permissions/current-user-permissions.service.ts b/src/frontend/packages/core/src/core/permissions/current-user-permissions.service.ts index 95e8399c3b..4ad096b7c5 100644 --- a/src/frontend/packages/core/src/core/permissions/current-user-permissions.service.ts +++ b/src/frontend/packages/core/src/core/permissions/current-user-permissions.service.ts @@ -4,10 +4,7 @@ import { combineLatest, Observable, of } from 'rxjs'; import { distinctUntilChanged, map, switchMap } from 'rxjs/operators'; import { InternalAppState } from '../../../../store/src/app-state'; -import { ENDPOINT_TYPE, STRATOS_ENDPOINT_TYPE } from '../../../../store/src/base-entity-schemas'; -import { entityCatalog } from '../../../../store/src/entity-catalog/entity-catalog'; -import { selectEntity } from '../../../../store/src/selectors/api.selectors'; -import { EndpointModel } from '../../../../store/src/types/endpoint.types'; +import { stratosEntityCatalog } from '../../../../store/src/stratos-entity-catalog'; import { LoggerService } from '../logger.service'; import { CurrentUserPermissions, @@ -79,8 +76,7 @@ export class CurrentUserPermissionsService { } else if (actionConfig) { return this.getSimplePermission(actionConfig, endpointGuid, ...args); } else if (endpointGuid) { - const key = entityCatalog.getEntityKey(STRATOS_ENDPOINT_TYPE, ENDPOINT_TYPE); - return this.store.select(selectEntity(key, endpointGuid)).pipe( + return stratosEntityCatalog.endpoint.store.getEntityMonitor(endpointGuid).entity$.pipe( switchMap(endpoint => endpoint ? this.getFallbackPermission(endpointGuid, endpoint.cnsi_type) : of(false) diff --git a/src/frontend/packages/core/src/core/user-profile.service.ts b/src/frontend/packages/core/src/core/user-profile.service.ts index 936be6ba31..0a496d3adc 100644 --- a/src/frontend/packages/core/src/core/user-profile.service.ts +++ b/src/frontend/packages/core/src/core/user-profile.service.ts @@ -1,22 +1,13 @@ import { Injectable } from '@angular/core'; import { Store } from '@ngrx/store'; -import { combineLatest, Observable, of as observableOf, of } from 'rxjs'; +import { combineLatest, Observable, of as observableOf } from 'rxjs'; import { filter, first, map, publishReplay, refCount, switchMap } from 'rxjs/operators'; -import { - FetchUserProfileAction, - UpdateUserPasswordAction, - UpdateUserProfileAction, -} from '../../../store/src/actions/user-profile.actions'; import { AppState } from '../../../store/src/app-state'; -import { userProfileEntitySchema } from '../../../store/src/base-entity-schemas'; -import { userProfilePasswordUpdatingKey } from '../../../store/src/effects/user-profile.effects'; -import { entityCatalog } from '../../../store/src/entity-catalog/entity-catalog'; import { EntityService } from '../../../store/src/entity-service'; -import { EntityServiceFactory } from '../../../store/src/entity-service-factory.service'; -import { ActionState, getDefaultActionState, rootUpdatingKey } from '../../../store/src/reducers/api-request-reducer/types'; +import { ActionState, getDefaultActionState } from '../../../store/src/reducers/api-request-reducer/types'; import { AuthState } from '../../../store/src/reducers/auth.reducer'; -import { selectRequestInfo, selectUpdateInfo } from '../../../store/src/selectors/api.selectors'; +import { stratosEntityCatalog } from '../../../store/src/stratos-entity-catalog'; import { SessionData } from '../../../store/src/types/auth.types'; import { UserProfileInfo, UserProfileInfoEmail, UserProfileInfoUpdates } from '../../../store/src/types/user-profile.types'; @@ -32,21 +23,22 @@ export class UserProfileService { userProfile$: Observable; - private stratosUserConfig = entityCatalog.getEntity(userProfileEntitySchema.endpointType, userProfileEntitySchema.entityType); + private userGuid$: Observable; constructor( private store: Store, - esf: EntityServiceFactory ) { - if (!this.stratosUserConfig) { - console.error('Can not get user profile entity'); - this.userProfile$ = of({} as UserProfileInfo); - return; - } + this.userGuid$ = this.store.select(s => s.auth).pipe( + filter((auth: AuthState) => !!(auth && auth.sessionData)), + map((auth: AuthState) => auth.sessionData), + filter((sessionData: SessionData) => !!sessionData.user), + first(), + map(data => data.user.guid) + ); - this.entityService = this.createFetchUserAction().pipe( + this.entityService = this.userGuid$.pipe( first(), - map(action => esf.create(action.guid, action)), + map(userGuid => stratosEntityCatalog.userProfile.store.getEntityService(userGuid)), publishReplay(1), refCount() ); @@ -60,27 +52,16 @@ export class UserProfileService { switchMap(service => service.isFetchingEntity$) ); - this.isError$ = this.store.select(selectRequestInfo(this.stratosUserConfig.entityKey, FetchUserProfileAction.guid)).pipe( + this.isError$ = this.entityService.pipe( + switchMap(es => es.entityMonitor.entityRequest$), filter(requestInfo => !!requestInfo && !requestInfo.fetching), map(requestInfo => requestInfo.error) - ); - } - - private createFetchUserAction(): Observable { - return this.store.select(s => s.auth).pipe( - filter((auth: AuthState) => !!(auth && auth.sessionData)), - map((auth: AuthState) => auth.sessionData), - filter((sessionData: SessionData) => !!sessionData.user), - first(), - map(data => new FetchUserProfileAction(data.user.guid)) - ); + ) } fetchUserProfile() { // Once we have the user's guid, fetch their profile - this.createFetchUserAction().pipe(first()).subscribe(action => { - this.store.dispatch(action); - }); + this.userGuid$.pipe(first()).subscribe(userGuid => stratosEntityCatalog.userProfile.api.get(userGuid)); } getPrimaryEmailAddress(profile: UserProfileInfo): string { @@ -135,11 +116,8 @@ export class UserProfileService { if (profileChanges.emailAddress) { this.setPrimaryEmailAddress(updatedProfile, profileChanges.emailAddress); } - this.store.dispatch(new UpdateUserProfileAction(updatedProfile, profileChanges.currentPassword)); - const actionState = selectUpdateInfo(this.stratosUserConfig.entityKey, - FetchUserProfileAction.guid, - rootUpdatingKey); - return this.store.select(actionState).pipe( + + return stratosEntityCatalog.userProfile.api.updateProfile(updatedProfile, profileChanges.currentPassword).pipe( filter(item => item && !item.busy) ); } @@ -149,11 +127,7 @@ export class UserProfileService { oldPassword: profileChanges.currentPassword, password: profileChanges.newPassword }; - this.store.dispatch(new UpdateUserPasswordAction(profile.id, passwordUpdates)); - const actionState = selectUpdateInfo(this.stratosUserConfig.entityKey, - FetchUserProfileAction.guid, - userProfilePasswordUpdatingKey); - return this.store.select(actionState).pipe( + return stratosEntityCatalog.userProfile.api.updatePassword(profile.id, passwordUpdates).pipe( filter(item => item && !item.busy) ); } diff --git a/src/frontend/packages/core/src/features/dashboard/dashboard-base/dashboard-base.component.ts b/src/frontend/packages/core/src/features/dashboard/dashboard-base/dashboard-base.component.ts index a3bff217b1..8310e6723e 100644 --- a/src/frontend/packages/core/src/features/dashboard/dashboard-base/dashboard-base.component.ts +++ b/src/frontend/packages/core/src/features/dashboard/dashboard-base/dashboard-base.component.ts @@ -9,11 +9,11 @@ import { distinctUntilChanged, filter, map, startWith, withLatestFrom } from 'rx import { CloseSideNav, DisableMobileNav, EnableMobileNav } from '../../../../../store/src/actions/dashboard-actions'; import { GetCurrentUsersRelations } from '../../../../../store/src/actions/permissions.actions'; -import { GetUserFavoritesAction } from '../../../../../store/src/actions/user-favourites-actions/get-user-favorites-action'; import { DashboardOnlyAppState } from '../../../../../store/src/app-state'; import { entityCatalog } from '../../../../../store/src/entity-catalog/entity-catalog'; import { DashboardState } from '../../../../../store/src/reducers/dashboard-reducer'; import { selectDashboardState } from '../../../../../store/src/selectors/dashboard.selectors'; +import { stratosEntityCatalog } from '../../../../../store/src/stratos-entity-catalog'; import { TabNavService } from '../../../../tab-nav.service'; import { CustomizationService } from '../../../core/customizations.types'; import { EndpointsService } from '../../../core/endpoints.service'; @@ -144,7 +144,7 @@ export class DashboardBaseComponent implements OnInit, OnDestroy, AfterViewInit }); this.dispatchRelations(); - this.store.dispatch(new GetUserFavoritesAction()); + stratosEntityCatalog.userFavorite.api.getAll(); } ngOnDestroy() { diff --git a/src/frontend/packages/core/src/features/endpoints/backup-restore/backup-endpoints/backup-endpoints.component.ts b/src/frontend/packages/core/src/features/endpoints/backup-restore/backup-endpoints/backup-endpoints.component.ts index f1a2a345da..9c41ea8a3d 100644 --- a/src/frontend/packages/core/src/features/endpoints/backup-restore/backup-endpoints/backup-endpoints.component.ts +++ b/src/frontend/packages/core/src/features/endpoints/backup-restore/backup-endpoints/backup-endpoints.component.ts @@ -1,16 +1,12 @@ import { Component } from '@angular/core'; import { FormControl, FormGroup, Validators } from '@angular/forms'; -import { Store } from '@ngrx/store'; import * as moment from 'moment'; import { Observable, of, Subject } from 'rxjs'; import { filter, first, map } from 'rxjs/operators'; -import { GetAllEndpoints } from '../../../../../../store/src/actions/endpoint.actions'; -import { AppState } from '../../../../../../store/src/app-state'; import { entityCatalog } from '../../../../../../store/src/entity-catalog/entity-catalog'; import { httpErrorResponseToSafeString } from '../../../../../../store/src/jetstream'; -import { PaginationMonitorFactory } from '../../../../../../store/src/monitors/pagination-monitor.factory'; -import { getPaginationObservables } from '../../../../../../store/src/reducers/pagination-reducer/pagination-reducer.helper'; +import { stratosEntityCatalog } from '../../../../../../store/src/stratos-entity-catalog'; import { EndpointModel } from '../../../../../../store/src/types/endpoint.types'; import { ConfirmationDialogConfig } from '../../../../shared/components/confirmation-dialog.config'; import { ConfirmationDialogService } from '../../../../shared/components/confirmation-dialog.service'; @@ -74,8 +70,6 @@ export class BackupEndpointsComponent { constructor( public service: BackupEndpointsService, - private store: Store, - private paginationMonitorFactory: PaginationMonitorFactory, private confirmDialog: ConfirmationDialogService, ) { this.setupSelectStep(); @@ -84,17 +78,7 @@ export class BackupEndpointsComponent { setupSelectStep() { - const action = new GetAllEndpoints(); - const endpointObs = getPaginationObservables({ - store: this.store, - action, - paginationMonitor: this.paginationMonitorFactory.create( - action.paginationKey, - action, - true - ) - }, true); - + const endpointObs = stratosEntityCatalog.endpoint.store.getAll.getPaginationService(); const endpoints$ = endpointObs.entities$.pipe( filter(entities => !!entities), diff --git a/src/frontend/packages/core/src/features/endpoints/backup-restore/restore-endpoints/restore-endpoints.component.ts b/src/frontend/packages/core/src/features/endpoints/backup-restore/restore-endpoints/restore-endpoints.component.ts index 72e4f53b1d..3ddca26bd4 100644 --- a/src/frontend/packages/core/src/features/endpoints/backup-restore/restore-endpoints/restore-endpoints.component.ts +++ b/src/frontend/packages/core/src/features/endpoints/backup-restore/restore-endpoints/restore-endpoints.component.ts @@ -5,9 +5,9 @@ import { Store } from '@ngrx/store'; import { Observable, of, Subject } from 'rxjs'; import { first, map } from 'rxjs/operators'; -import { GetAllEndpoints } from '../../../../../../store/src/actions/endpoint.actions'; import { GeneralEntityAppState } from '../../../../../../store/src/app-state'; import { httpErrorResponseToSafeString } from '../../../../../../store/src/jetstream'; +import { stratosEntityCatalog } from '../../../../../../store/src/stratos-entity-catalog'; import { getEventFiles } from '../../../../core/browser-helper'; import { ConfirmationDialogConfig } from '../../../../shared/components/confirmation-dialog.config'; import { ConfirmationDialogService } from '../../../../shared/components/confirmation-dialog.service'; @@ -79,7 +79,7 @@ export class RestoreEndpointsComponent { }; const restoreSuccess = () => { - this.store.dispatch(new GetAllEndpoints()); + stratosEntityCatalog.endpoint.api.getAll() result.next({ success: true, redirect: true, diff --git a/src/frontend/packages/core/src/features/endpoints/connect-endpoint-dialog/connect-endpoint-dialog.component.ts b/src/frontend/packages/core/src/features/endpoints/connect-endpoint-dialog/connect-endpoint-dialog.component.ts index 75402fd26f..3a56bdbc23 100644 --- a/src/frontend/packages/core/src/features/endpoints/connect-endpoint-dialog/connect-endpoint-dialog.component.ts +++ b/src/frontend/packages/core/src/features/endpoints/connect-endpoint-dialog/connect-endpoint-dialog.component.ts @@ -1,9 +1,7 @@ import { Component, Inject, OnDestroy } from '@angular/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; -import { Store } from '@ngrx/store'; import { Subscription } from 'rxjs'; -import { EndpointOnlyAppState } from '../../../../../store/src/app-state'; import { EndpointsService } from '../../../core/endpoints.service'; import { MarkdownPreviewComponent } from '../../../shared/components/markdown-preview/markdown-preview.component'; import { SidePanelService } from '../../../shared/services/side-panel.service'; @@ -27,12 +25,11 @@ export class ConnectEndpointDialogComponent implements OnDestroy { constructor( public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: ConnectEndpointConfig, - private store: Store, endpointsService: EndpointsService, private sidePanelService: SidePanelService, private snackBarService: SnackBarService, ) { - this.connectService = new ConnectEndpointService(store, endpointsService, data); + this.connectService = new ConnectEndpointService(endpointsService, data); this.hasConnected = this.connectService.hasConnected$.subscribe(() => { this.snackBarService.show(`Connected endpoint '${this.data.name}'`); diff --git a/src/frontend/packages/core/src/features/endpoints/connect.service.ts b/src/frontend/packages/core/src/features/endpoints/connect.service.ts index 678abf483e..76504957f7 100644 --- a/src/frontend/packages/core/src/features/endpoints/connect.service.ts +++ b/src/frontend/packages/core/src/features/endpoints/connect.service.ts @@ -1,28 +1,11 @@ -import { Store } from '@ngrx/store'; import { combineLatest, Observable, of, Subject, Subscription } from 'rxjs'; -import { - delay, - distinctUntilChanged, - filter, - map, - pairwise, - startWith, - switchMap, - tap, - withLatestFrom, -} from 'rxjs/operators'; +import { delay, distinctUntilChanged, filter, map, pairwise, startWith, switchMap, tap } from 'rxjs/operators'; import { AuthParams, ConnectEndpoint } from '../../../../store/src/actions/endpoint.actions'; -import { GetSystemInfo } from '../../../../store/src/actions/system.actions'; -import { EndpointOnlyAppState } from '../../../../store/src/app-state'; -import { STRATOS_ENDPOINT_TYPE } from '../../../../store/src/base-entity-schemas'; -import { EndpointsEffect } from '../../../../store/src/effects/endpoint.effects'; -import { SystemEffects } from '../../../../store/src/effects/system.effects'; import { entityCatalog } from '../../../../store/src/entity-catalog/entity-catalog'; import { EndpointType } from '../../../../store/src/extension-types'; -import { endpointSchemaKey } from '../../../../store/src/helpers/entity-factory'; import { ActionState } from '../../../../store/src/reducers/api-request-reducer/types'; -import { selectEntity, selectRequestInfo, selectUpdateInfo } from '../../../../store/src/selectors/api.selectors'; +import { stratosEntityCatalog } from '../../../../store/src/stratos-entity-catalog'; import { EndpointModel } from '../../../../store/src/types/endpoint.types'; import { EndpointsService } from '../../core/endpoints.service'; import { safeUnsubscribe } from '../../core/utils.service'; @@ -65,15 +48,12 @@ export class ConnectEndpointService { private hasAttemptedConnect: boolean; private pData: ConnectEndpointData; - private endpointEntityKey = entityCatalog.getEntityKey(STRATOS_ENDPOINT_TYPE, endpointSchemaKey); - // We need a delay to ensure the BE has finished registering the endpoint. // If we don't do this and if we're quick enough, we can navigate to the application page // and end up with an empty list where we should have results. private connectDelay = 1000; constructor( - private store: Store, private endpointsService: EndpointsService, public config: ConnectEndpointConfig, ) { @@ -87,33 +67,29 @@ export class ConnectEndpointService { ).subscribe(([oldVal, newVal]) => { if (!newVal.error && (oldVal.busy && !newVal.busy)) { // Has finished fetching - this.store.dispatch(new GetSystemInfo()); + stratosEntityCatalog.endpoint.api.get(this.config.guid); } })); this.subs.push(this.connected$.pipe( - filter(([connected]) => connected), + filter(([isConnected]) => isConnected), delay(this.connectDelay), tap(() => this.hasConnected.next(true)), - distinctUntilChanged(([connected], [oldConnected]) => connected && oldConnected), - ).subscribe(([connected, endpoint]) => this.endpointsService.checkEndpoint(endpoint)) + distinctUntilChanged(([isConnected], [oldIsConnected]) => isConnected && oldIsConnected), + ).subscribe(([, endpoint]) => this.endpointsService.checkEndpoint(endpoint)) ); } private setupObservables() { - this.update$ = this.store.select( - this.getUpdateSelector() - ).pipe(filter(update => !!update)); + this.update$ = stratosEntityCatalog.endpoint.store.getEntityMonitor(this.config.guid).getUpdatingSection(ConnectEndpoint.UpdatingKey) + .pipe(filter(update => !!update)); - this.fetchingInfo$ = this.store.select( - this.getRequestSelector() - ).pipe( + this.fetchingInfo$ = stratosEntityCatalog.endpoint.store.getEntityMonitor(this.config.guid).entityRequest$.pipe( filter(request => !!request), - map(request => request.fetching)); + map(request => request.fetching) + ); - this.connected$ = this.store.select( - this.getEntitySelector() - ).pipe( + this.connected$ = stratosEntityCatalog.endpoint.store.getEntityMonitor(this.config.guid).entity$.pipe( map(endpoint => { const isConnected = !!(endpoint && endpoint.api_endpoint && endpoint.user); return [isConnected, endpoint] as [boolean, EndpointModel]; @@ -149,28 +125,6 @@ export class ConnectEndpointService { ); } - private getUpdateSelector() { - return selectUpdateInfo( - this.endpointEntityKey, - this.config.guid, - EndpointsEffect.connectingKey - ); - } - - private getRequestSelector() { - return selectRequestInfo( - this.endpointEntityKey, - SystemEffects.guid - ); - } - - private getEntitySelector() { - return selectEntity( - this.endpointEntityKey, - this.config.guid, - ); - } - public setData(data: ConnectEndpointData) { this.pData = data; } @@ -179,25 +133,21 @@ export class ConnectEndpointService { this.hasAttemptedConnect = true; const { authType, authVal, systemShared, bodyContent } = this.pData; - this.store.dispatch(new ConnectEndpoint( + return stratosEntityCatalog.endpoint.api.connect( this.config.guid, this.config.type, authType, authVal, systemShared, bodyContent, - )); - - return this.isBusy$.pipe( + ).pipe( pairwise(), - filter(([oldBusy, newBusy]) => { - return !(oldBusy === true && newBusy === false); - }), - withLatestFrom(this.update$), - map(([, updateSection]) => ({ + filter(([oldV, newV]) => oldV.busy && !newV.busy), + map(([, newV]) => newV), + map(updateSection => ({ success: !updateSection.error, errorMessage: updateSection.message - })) + })), ); } diff --git a/src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-cf-step-1/create-endpoint-cf-step-1.component.ts b/src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-cf-step-1/create-endpoint-cf-step-1.component.ts index c14286bdc8..96bca56f21 100644 --- a/src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-cf-step-1/create-endpoint-cf-step-1.component.ts +++ b/src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-cf-step-1/create-endpoint-cf-step-1.component.ts @@ -1,23 +1,16 @@ import { AfterContentInit, Component, Input, ViewChild } from '@angular/core'; import { NgForm, NgModel } from '@angular/forms'; import { ActivatedRoute } from '@angular/router'; -import { Store } from '@ngrx/store'; -import { denormalize } from 'normalizr'; import { Observable } from 'rxjs'; -import { filter, map, pairwise, withLatestFrom } from 'rxjs/operators'; +import { filter, map, pairwise } from 'rxjs/operators'; -import { GetAllEndpoints, RegisterEndpoint } from '../../../../../../store/src/actions/endpoint.actions'; -import { GeneralEntityAppState } from '../../../../../../store/src/app-state'; -import { endpointEntitySchema, STRATOS_ENDPOINT_TYPE } from '../../../../../../store/src/base-entity-schemas'; -import { EndpointsEffect } from '../../../../../../store/src/effects/endpoint.effects'; import { getFullEndpointApiUrl } from '../../../../../../store/src/endpoint-utils'; import { entityCatalog } from '../../../../../../store/src/entity-catalog/entity-catalog'; import { StratosCatalogEndpointEntity, } from '../../../../../../store/src/entity-catalog/entity-catalog-entity/entity-catalog-entity'; -import { endpointSchemaKey } from '../../../../../../store/src/helpers/entity-factory'; -import { getAPIRequestDataState, selectUpdateInfo } from '../../../../../../store/src/selectors/api.selectors'; -import { selectPaginationState } from '../../../../../../store/src/selectors/pagination.selectors'; +import { ActionState } from '../../../../../../store/src/reducers/api-request-reducer/types'; +import { stratosEntityCatalog } from '../../../../../../store/src/stratos-entity-catalog'; import { getIdFromRoute } from '../../../../core/utils.service'; import { IStepperStep, StepOnNextFunction } from '../../../../shared/components/stepper/step/step.component'; import { SnackBarService } from '../../../../shared/services/snackbar.service'; @@ -59,27 +52,16 @@ export class CreateEndpointCfStep1Component implements IStepperStep, AfterConten endpointTypeSupportsSSO = false; endpoint: StratosCatalogEndpointEntity; - private endpointEntityKey = entityCatalog.getEntityKey(STRATOS_ENDPOINT_TYPE, endpointSchemaKey); - constructor( - private store: Store, activatedRoute: ActivatedRoute, - private snackBarService: SnackBarService, + private snackBarService: SnackBarService ) { - - this.existingEndpoints = store.select(selectPaginationState(this.endpointEntityKey, GetAllEndpoints.storeKey)) - .pipe( - withLatestFrom(store.select(getAPIRequestDataState)), - map(([pagination, entities]) => { - const pages = Object.values(pagination.ids); - const page = [].concat.apply([], pages); - const endpoints = page.length ? denormalize(page, [endpointEntitySchema], entities) : []; - return { - names: endpoints.map(ep => ep.name), - urls: endpoints.map(ep => getFullEndpointApiUrl(ep)), - }; - }) - ); + this.existingEndpoints = stratosEntityCatalog.endpoint.store.getAll.getPaginationMonitor().currentPage$.pipe( + map(endpoints => ({ + names: endpoints.map(ep => ep.name), + urls: endpoints.map(ep => getFullEndpointApiUrl(ep)), + })) + ); const epType = getIdFromRoute(activatedRoute, 'type'); const epSubType = getIdFromRoute(activatedRoute, 'subtype'); @@ -92,7 +74,7 @@ export class CreateEndpointCfStep1Component implements IStepperStep, AfterConten onNext: StepOnNextFunction = () => { const { subType, type } = this.endpoint.getTypeAndSubtype(); - const action = new RegisterEndpoint( + return stratosEntityCatalog.endpoint.api.register( type, subType, this.nameField.value, @@ -101,15 +83,8 @@ export class CreateEndpointCfStep1Component implements IStepperStep, AfterConten this.clientIDField ? this.clientIDField.value : '', this.clientSecretField ? this.clientSecretField.value : '', this.ssoAllowedField ? !!this.ssoAllowedField.value : false, - ); - - this.store.dispatch(action); - - const update$ = this.store.select( - this.getUpdateSelector(action.guid()) - ).pipe(filter(update => !!update)); - - return update$.pipe(pairwise(), + ).pipe( + pairwise(), filter(([oldVal, newVal]) => (oldVal.busy && !newVal.busy)), map(([oldVal, newVal]) => newVal), map(result => { @@ -134,13 +109,6 @@ export class CreateEndpointCfStep1Component implements IStepperStep, AfterConten ); } - private getUpdateSelector(guid) { - return selectUpdateInfo( - this.endpointEntityKey, - guid, - EndpointsEffect.registeringKey, - ); - } ngAfterContentInit() { this.validate = this.form.statusChanges.pipe( diff --git a/src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-connect/create-endpoint-connect.component.ts b/src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-connect/create-endpoint-connect.component.ts index 9fc5b74dee..7be71e52aa 100644 --- a/src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-connect/create-endpoint-connect.component.ts +++ b/src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-connect/create-endpoint-connect.component.ts @@ -1,9 +1,7 @@ import { Component, OnDestroy } from '@angular/core'; -import { Store } from '@ngrx/store'; import { Observable, of } from 'rxjs'; import { map } from 'rxjs/operators'; -import { EndpointOnlyAppState } from '../../../../../../store/src/app-state'; import { EndpointsService } from '../../../../core/endpoints.service'; import { MarkdownPreviewComponent } from '../../../../shared/components/markdown-preview/markdown-preview.component'; import { IStepperStep, StepOnNextResult } from '../../../../shared/components/stepper/step/step.component'; @@ -26,7 +24,6 @@ export class CreateEndpointConnectComponent implements OnDestroy, IStepperStep { public doConnect = false; constructor( - private store: Store, private endpointsService: EndpointsService, private sidePanelService: SidePanelService, ) { @@ -37,7 +34,7 @@ export class CreateEndpointConnectComponent implements OnDestroy, IStepperStep { } onEnter = (data: ConnectEndpointConfig) => { - this.connectService = new ConnectEndpointService(this.store, this.endpointsService, data); + this.connectService = new ConnectEndpointService(this.endpointsService, data); } onNext = (): Observable => this.doConnect ? this.connectService.submit().pipe( diff --git a/src/frontend/packages/core/src/features/endpoints/edit-endpoint/edit-endpoint-step/edit-endpoint-step.component.ts b/src/frontend/packages/core/src/features/endpoints/edit-endpoint/edit-endpoint-step/edit-endpoint-step.component.ts index bae73a9c0f..cb6120b12e 100644 --- a/src/frontend/packages/core/src/features/endpoints/edit-endpoint/edit-endpoint-step/edit-endpoint-step.component.ts +++ b/src/frontend/packages/core/src/features/endpoints/edit-endpoint/edit-endpoint-step/edit-endpoint-step.component.ts @@ -1,22 +1,19 @@ import { Component, OnDestroy } from '@angular/core'; import { FormControl, FormGroup, Validators } from '@angular/forms'; import { ActivatedRoute } from '@angular/router'; -import { Store } from '@ngrx/store'; import { Observable, Subscription } from 'rxjs'; import { filter, first, map, pairwise, switchMap } from 'rxjs/operators'; -import { AppState } from '../../../../../../store/src/app-state'; import { getFullEndpointApiUrl } from '../../../../../../store/src/endpoint-utils'; import { entityCatalog } from '../../../../../../store/src/entity-catalog/entity-catalog'; -import { selectUpdateInfo } from '../../../../../../store/src/selectors/api.selectors'; +import { ActionState } from '../../../../../../store/src/reducers/api-request-reducer/types'; +import { stratosEntityCatalog } from '../../../../../../store/src/stratos-entity-catalog'; import { StepOnNextFunction } from '../../../../shared/components/stepper/step/step.component'; import { getSSOClientRedirectURI } from '../../endpoint-helpers'; -import { UpdateEndpoint } from './../../../../../../store/src/actions/endpoint.actions'; import { EntityCatalogSchemas, IStratosEndpointDefinition, } from './../../../../../../store/src/entity-catalog/entity-catalog.types'; -import { endpointEntitiesSelector } from './../../../../../../store/src/selectors/endpoint.selectors'; import { EndpointModel } from './../../../../../../store/src/types/endpoint.types'; import { getIdFromRoute, safeUnsubscribe } from './../../../../core/utils.service'; import { IStepperStep } from './../../../../shared/components/stepper/step/step.component'; @@ -42,12 +39,11 @@ export class EditEndpointStepComponent implements OnDestroy, IStepperStep { existingEndpoints: Observable; endpoint$: Observable; definition$: Observable>; - existingEndpoinNames$: Observable; + existingEndpointNames$: Observable; formChangeSub: Subscription; setClientInfo = false; constructor( - private store: Store, activatedRoute: ActivatedRoute, ) { this.editEndpoint = new FormGroup({ @@ -66,9 +62,14 @@ export class EditEndpointStepComponent implements OnDestroy, IStepperStep { this.endpointID = getIdFromRoute(activatedRoute, 'id'); - this.existingEndpoints = this.store.select(endpointEntitiesSelector); + this.existingEndpoints = stratosEntityCatalog.endpoint.store.getAll.getPaginationMonitor().currentPage$.pipe( + map(endpoints => endpoints.reduce((res, endpoint) => { + res[endpoint.guid] = endpoint; + return res; + }, {})) + ); - this.existingEndpoinNames$ = this.existingEndpoints.pipe( + this.existingEndpointNames$ = this.existingEndpoints.pipe( map(endpoints => Object.values(endpoints).filter((ep: EndpointModel) => ep.guid !== this.endpointID)), map((endpoints: EndpointModel[]) => endpoints.map(ep => ep.name)) ); @@ -128,20 +129,19 @@ export class EditEndpointStepComponent implements OnDestroy, IStepperStep { return this.endpoint$.pipe( first(), switchMap(endpoint => { - const action = new UpdateEndpoint( - endpoint.cnsi_type, + return stratosEntityCatalog.endpoint.api.update( this.endpointID, - this.editEndpoint.value.name, - this.editEndpoint.value.skipSSL, - this.editEndpoint.value.setClientInfo, - this.editEndpoint.value.clientID, - this.editEndpoint.value.clientSecret, - this.editEndpoint.value.allowSSO, - ); - - this.store.dispatch(action); - - return this.store.select(selectUpdateInfo('stratosEndpoint', this.endpointID, 'updating')).pipe( + this.endpointID, { + endpointType: endpoint.cnsi_type, + id: this.endpointID, + name: this.editEndpoint.value.name, + skipSSL: this.editEndpoint.value.skipSSL, + setClientInfo: this.editEndpoint.value.setClientInfo, + clientID: this.editEndpoint.value.clientID, + clientSecret: this.editEndpoint.value.clientSecret, + allowSSO: this.editEndpoint.value.allowSSO, + } + ).pipe( pairwise(), filter(([oldV, newV]) => oldV.busy && !newV.busy), map(([, newV]) => newV), diff --git a/src/frontend/packages/core/src/features/error-page/error-page/error-page.component.ts b/src/frontend/packages/core/src/features/error-page/error-page/error-page.component.ts index b21a8b228a..a404433a5e 100644 --- a/src/frontend/packages/core/src/features/error-page/error-page/error-page.component.ts +++ b/src/frontend/packages/core/src/features/error-page/error-page/error-page.component.ts @@ -7,10 +7,9 @@ import { first, map, withLatestFrom } from 'rxjs/operators'; import { SendClearEndpointEventsAction } from '../../../../../store/src/actions/internal-events.actions'; import { AppState } from '../../../../../store/src/app-state'; -import { endpointEntitySchema } from '../../../../../store/src/base-entity-schemas'; -import { endpointSchemaKey } from '../../../../../store/src/helpers/entity-factory'; -import { EntityMonitor } from '../../../../../store/src/monitors/entity-monitor'; +import { endpointEntityType } from '../../../../../store/src/helpers/stratos-entity-factory'; import { InternalEventMonitorFactory } from '../../../../../store/src/monitors/internal-event-monitor.factory'; +import { stratosEntityCatalog } from '../../../../../store/src/stratos-entity-catalog'; import { EndpointModel } from '../../../../../store/src/types/endpoint.types'; import { InternalEventState } from '../../../../../store/src/types/internal-events.types'; import { getPreviousRoutingState } from '../../../../../store/src/types/routing.type'; @@ -36,13 +35,8 @@ export class ErrorPageComponent implements OnInit { ngOnInit() { const endpointId = this.activatedRoute.snapshot.params.endpointId; if (endpointId) { - const endpointMonitor = new EntityMonitor( - this.store, - endpointId, - endpointEntitySchema.key, - endpointEntitySchema - ); - const cfEndpointEventMonitor = this.internalEventMonitorFactory.getMonitor(endpointSchemaKey, of([endpointId])); + const endpointMonitor = stratosEntityCatalog.endpoint.store.getEntityMonitor(endpointId); + const cfEndpointEventMonitor = this.internalEventMonitorFactory.getMonitor(endpointEntityType, of([endpointId])); this.errorDetails$ = cfEndpointEventMonitor.hasErroredOverTimeNoPoll(30).pipe( withLatestFrom(endpointMonitor.entity$), map(([errors, endpoint]) => { diff --git a/src/frontend/packages/core/src/features/metrics/services/metrics-service.ts b/src/frontend/packages/core/src/features/metrics/services/metrics-service.ts index 52b3db2e88..e9391d7fae 100644 --- a/src/frontend/packages/core/src/features/metrics/services/metrics-service.ts +++ b/src/frontend/packages/core/src/features/metrics/services/metrics-service.ts @@ -2,12 +2,11 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { map, publishReplay, refCount } from 'rxjs/operators'; -import { endpointEntitySchema } from '../../../../../store/src/base-entity-schemas'; import { getFullEndpointApiUrl } from '../../../../../store/src/endpoint-utils'; import { PaginationMonitor } from '../../../../../store/src/monitors/pagination-monitor'; -import { PaginationMonitorFactory } from '../../../../../store/src/monitors/pagination-monitor.factory'; +import { stratosEntityCatalog } from '../../../../../store/src/stratos-entity-catalog'; import { APIResource, EntityInfo } from '../../../../../store/src/types/api.types'; -import { endpointListKey, EndpointModel } from '../../../../../store/src/types/endpoint.types'; +import { EndpointModel } from '../../../../../store/src/types/endpoint.types'; export interface MetricsEndpointProvider { provider: EndpointModel; @@ -22,14 +21,8 @@ export class MetricsService { haveNoMetricsEndpoints$: Observable; haveNoConnectedMetricsEndpoints$: Observable; - constructor( - private paginationMonitorFactory: PaginationMonitorFactory - ) { - this.endpointsMonitor = this.paginationMonitorFactory.create( - endpointListKey, - endpointEntitySchema, - true - ); + constructor() { + this.endpointsMonitor = stratosEntityCatalog.endpoint.store.getPaginationMonitor() this.setupObservables(); } diff --git a/src/frontend/packages/core/src/features/user-profile/edit-profile-info/edit-profile-info.component.ts b/src/frontend/packages/core/src/features/user-profile/edit-profile-info/edit-profile-info.component.ts index 54194241ee..75aa2b69bf 100644 --- a/src/frontend/packages/core/src/features/user-profile/edit-profile-info/edit-profile-info.component.ts +++ b/src/frontend/packages/core/src/features/user-profile/edit-profile-info/edit-profile-info.component.ts @@ -2,7 +2,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; import { AbstractControl, FormBuilder, FormGroup, ValidatorFn, Validators } from '@angular/forms'; import { ErrorStateMatcher, ShowOnDirtyErrorStateMatcher } from '@angular/material/core'; import { Subscription } from 'rxjs'; -import { first, map, take, tap } from 'rxjs/operators'; +import { delay, first, map, take, tap } from 'rxjs/operators'; import { UserProfileInfo, UserProfileInfoUpdates } from '../../../../../store/src/types/user-profile.types'; import { CurrentUserPermissionsService } from '../../../core/permissions/current-user-permissions.service'; @@ -119,8 +119,7 @@ export class EditProfileInfoComponent implements OnInit, OnDestroy { updates[key] = this.editProfileForm.value[key]; } } - const obs$ = this.userProfileService.updateProfile(this.profile, updates); - return obs$.pipe( + return this.userProfileService.updateProfile(this.profile, updates).pipe( take(1), map(([profileResult, passwordResult]) => { const okay = !profileResult.error && !passwordResult.error; @@ -131,6 +130,7 @@ export class EditProfileInfoComponent implements OnInit, OnDestroy { message: okay ? '' : `An error occurred whilst updating your profile: ${message}` }; }), + delay(300), // Ensure that the profile is updated before fetching to refresh local copy tap(() => this.userProfileService.fetchUserProfile()) ); } diff --git a/src/frontend/packages/core/src/shared/components/app-action-monitor-icon/app-action-monitor-icon.component.spec.ts b/src/frontend/packages/core/src/shared/components/app-action-monitor-icon/app-action-monitor-icon.component.spec.ts index 06860cf718..571f14e1ee 100644 --- a/src/frontend/packages/core/src/shared/components/app-action-monitor-icon/app-action-monitor-icon.component.spec.ts +++ b/src/frontend/packages/core/src/shared/components/app-action-monitor-icon/app-action-monitor-icon.component.spec.ts @@ -1,6 +1,6 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { endpointEntitySchema } from '../../../../../store/src/base-entity-schemas'; +import { endpointEntityType, stratosEntityFactory } from '../../../../../store/src/helpers/stratos-entity-factory'; import { BaseTestModules } from '../../../../test-framework/core-test.helper'; import { AppActionMonitorIconComponent } from './app-action-monitor-icon.component'; @@ -21,7 +21,7 @@ describe('AppActionMonitorIconComponent', () => { fixture = TestBed.createComponent(AppActionMonitorIconComponent); component = fixture.componentInstance; component.id = '1'; - component.schema = endpointEntitySchema; + component.schema = stratosEntityFactory(endpointEntityType); fixture.detectChanges(); }); diff --git a/src/frontend/packages/core/src/shared/components/favorites-meta-card/favorites-meta-card.component.ts b/src/frontend/packages/core/src/shared/components/favorites-meta-card/favorites-meta-card.component.ts index 44948e8559..40d15028a1 100644 --- a/src/frontend/packages/core/src/shared/components/favorites-meta-card/favorites-meta-card.component.ts +++ b/src/frontend/packages/core/src/shared/components/favorites-meta-card/favorites-meta-card.component.ts @@ -1,16 +1,11 @@ import { Component, Input } from '@angular/core'; -import { Store } from '@ngrx/store'; import { isObservable, Observable, of as observableOf } from 'rxjs'; import { map } from 'rxjs/operators'; -import { - RemoveUserFavoriteAction, -} from '../../../../../store/src/actions/user-favourites-actions/remove-user-favorite-action'; -import { AppState } from '../../../../../store/src/app-state'; -import { userFavoritesEntitySchema } from '../../../../../store/src/base-entity-schemas'; import { entityCatalog } from '../../../../../store/src/entity-catalog/entity-catalog'; import { IFavoritesMetaCardConfig } from '../../../../../store/src/favorite-config-mapper'; -import { endpointEntitiesSelector } from '../../../../../store/src/selectors/endpoint.selectors'; +import { stratosEntityFactory, userFavouritesEntityType } from '../../../../../store/src/helpers/stratos-entity-factory'; +import { stratosEntityCatalog } from '../../../../../store/src/stratos-entity-catalog'; import { MenuItem } from '../../../../../store/src/types/menu-item.types'; import { ComponentEntityMonitorConfig, StratosStatus } from '../../../../../store/src/types/shared.types'; import { IFavoriteEntity } from '../../../../../store/src/types/user-favorite-manager.types'; @@ -72,9 +67,7 @@ export class FavoritesMetaCardComponent { @Input() set favoriteEntity(favoriteEntity: IFavoriteEntity) { if (!this.placeholder && favoriteEntity) { - const endpoint$ = this.store.select(endpointEntitiesSelector).pipe( - map(endpoints => endpoints[favoriteEntity.favorite.endpointId]) - ); + const endpoint$ = stratosEntityCatalog.endpoint.store.getEntityMonitor(favoriteEntity.favorite.endpointId).entity$; this.endpointConnected$ = endpoint$.pipe(map(endpoint => isEndpointConnected(endpoint))); this.actions$ = this.endpointConnected$.pipe( map(connected => connected ? this.config.menuItems : []) @@ -83,7 +76,7 @@ export class FavoritesMetaCardComponent { this.favorite = favorite; this.metaFavorite = !this.endpoint || (this.endpoint && !this.endpointHasEntities) ? favorite : null; this.prettyName = prettyName || 'Unknown'; - this.entityConfig = new ComponentEntityMonitorConfig(favorite.guid, userFavoritesEntitySchema); + this.entityConfig = new ComponentEntityMonitorConfig(favorite.guid, stratosEntityFactory(userFavouritesEntityType)); // If this favorite is an endpoint, lookup the image for it from the entitiy catalog if (this.favorite.entityType === 'endpoint') { @@ -113,7 +106,6 @@ export class FavoritesMetaCardComponent { } constructor( - private store: Store, private confirmDialog: ConfirmationDialogService ) { } @@ -131,7 +123,7 @@ export class FavoritesMetaCardComponent { } private removeFavorite = () => { - this.store.dispatch(new RemoveUserFavoriteAction(this.favorite)); + stratosEntityCatalog.userFavorite.api.delete(this.favorite); } public toggleMoreError() { diff --git a/src/frontend/packages/core/src/shared/components/list/list-table/table-cell-request-monitor-icon/table-cell-request-monitor-icon.component.spec.ts b/src/frontend/packages/core/src/shared/components/list/list-table/table-cell-request-monitor-icon/table-cell-request-monitor-icon.component.spec.ts index 8a69e57ded..8dac64962b 100644 --- a/src/frontend/packages/core/src/shared/components/list/list-table/table-cell-request-monitor-icon/table-cell-request-monitor-icon.component.spec.ts +++ b/src/frontend/packages/core/src/shared/components/list/list-table/table-cell-request-monitor-icon/table-cell-request-monitor-icon.component.spec.ts @@ -1,6 +1,6 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { endpointEntitySchema } from '../../../../../../../store/src/base-entity-schemas'; +import { endpointEntityType, stratosEntityFactory } from '../../../../../../../store/src/helpers/stratos-entity-factory'; import { BaseTestModules } from '../../../../../../test-framework/core-test.helper'; import { AppMonitorComponentTypes } from '../../../app-action-monitor-icon/app-action-monitor-icon.component'; import { TableCellRequestMonitorIconComponent } from './table-cell-request-monitor-icon.component'; @@ -24,7 +24,7 @@ describe('TableCellRequestMonitorIconComponent', () => { component.id = '1'; component.config = () => ({ entityKey: '', - schema: endpointEntitySchema, + schema: stratosEntityFactory(endpointEntityType), monitorState: AppMonitorComponentTypes.DELETE }); component.row = { diff --git a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/base-endpoints-data-source.ts b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/base-endpoints-data-source.ts index 6eb5dc16f6..afacea4130 100644 --- a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/base-endpoints-data-source.ts +++ b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/base-endpoints-data-source.ts @@ -5,14 +5,14 @@ import { map, pairwise, tap, withLatestFrom } from 'rxjs/operators'; import { GetAllEndpoints } from '../../../../../../../store/src/actions/endpoint.actions'; import { CreatePagination } from '../../../../../../../store/src/actions/pagination.actions'; import { AppState } from '../../../../../../../store/src/app-state'; -import { endpointEntitySchema } from '../../../../../../../store/src/base-entity-schemas'; -import { endpointSchemaKey } from '../../../../../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../../../../../store/src/helpers/stratos-entity-factory'; import { EntityMonitorFactory } from '../../../../../../../store/src/monitors/entity-monitor.factory.service'; import { InternalEventMonitorFactory } from '../../../../../../../store/src/monitors/internal-event-monitor.factory'; import { PaginationMonitorFactory } from '../../../../../../../store/src/monitors/pagination-monitor.factory'; import { endpointEntitiesSelector } from '../../../../../../../store/src/selectors/endpoint.selectors'; import { EndpointModel } from '../../../../../../../store/src/types/endpoint.types'; -import { DataFunctionDefinition, ListDataSource } from '../../data-sources-controllers/list-data-source'; +import { ListDataSource } from '../../data-sources-controllers/list-data-source'; +import { IListDataSourceConfig } from '../../data-sources-controllers/list-data-source-config'; import { RowsState } from '../../data-sources-controllers/list-data-source-types'; import { TableRowStateManager } from '../../list-table/table-row/table-row-state-manager'; import { IListConfig } from '../../list.component.types'; @@ -55,7 +55,7 @@ export class BaseEndpointsDataSource extends ListDataSource { const { rowStateManager, sub } = rowStateHelper.getRowStateManager( paginationMonitorFactory, entityMonitorFactory, - GetAllEndpoints.storeKey, + action.paginationKey, action, EndpointRowStateSetUpManager, false @@ -99,26 +99,26 @@ export class BaseEndpointsDataSource extends ListDataSource { rowsState: Observable, destroy: () => void, refresh: () => void - ) { + ): IListDataSourceConfig { return { store, action, - schema: endpointEntitySchema, - getRowUniqueId: object => object.guid, + schema: action.entity[0], + getRowUniqueId: (object) => action.entity[0].getId(object), getEmptyType: () => ({ name: '', system_shared_token: false, metricsAvailable: false, sso_allowed: false, }), - paginationKey: GetAllEndpoints.storeKey, + paginationKey: action.paginationKey, isLocal: true, transformEntities: [ { type: 'filter', field: 'name' }, - ] as DataFunctionDefinition[], + ], listConfig, rowsState, destroy, @@ -130,7 +130,7 @@ export class BaseEndpointsDataSource extends ListDataSource { rowStateManager: TableRowStateManager, store: Store ) { - const eventMonitor = internalEventMonitorFactory.getMonitor(endpointSchemaKey); + const eventMonitor = internalEventMonitorFactory.getMonitor(endpointEntityType); return eventMonitor.hasErroredOverTime().pipe( withLatestFrom(store.select(endpointEntitiesSelector)), tap(([errored, endpoints]) => Object.keys(errored).forEach(id => { diff --git a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoint-card/endpoint-card.component.ts b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoint-card/endpoint-card.component.ts index f275f03966..dfdd1548a2 100644 --- a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoint-card/endpoint-card.component.ts +++ b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoint-card/endpoint-card.component.ts @@ -9,7 +9,6 @@ import { ViewContainerRef, } from '@angular/core'; import { Store } from '@ngrx/store'; -import { CurrentUserPermissionsService } from 'frontend/packages/core/src/core/permissions/current-user-permissions.service'; import { AppState } from 'frontend/packages/store/src/app-state'; import { Observable, of, ReplaySubject, Subscription } from 'rxjs'; import { map, startWith } from 'rxjs/operators'; @@ -122,7 +121,6 @@ export class EndpointCardComponent extends CardCell implements On private endpointListHelper: EndpointListHelper, private componentFactoryResolver: ComponentFactoryResolver, private favoritesConfigMapper: FavoritesConfigMapper, - private currentUserPermissionsService: CurrentUserPermissionsService, ) { super(); this.endpointIds$ = this.endpointIds.asObservable(); diff --git a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoint-data-source.helpers.ts b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoint-data-source.helpers.ts index 3c9cc0c03e..e5862804f9 100644 --- a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoint-data-source.helpers.ts +++ b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoint-data-source.helpers.ts @@ -1,12 +1,12 @@ - import { combineLatest } from 'rxjs'; import { distinctUntilChanged, map, mergeMap, switchMap, tap } from 'rxjs/operators'; +import { DisconnectEndpoint } from '../../../../../../../store/src/actions/endpoint.actions'; import { EntityMonitorFactory } from '../../../../../../../store/src/monitors/entity-monitor.factory.service'; import { PaginationMonitor } from '../../../../../../../store/src/monitors/pagination-monitor'; -import { TableRowStateManager } from '../../list-table/table-row/table-row-state-manager'; import { EndpointModel } from '../../../../../../../store/src/types/endpoint.types'; -import { EndpointsEffect } from '../../../../../../../store/src/effects/endpoint.effects'; +import { TableRowStateManager } from '../../list-table/table-row/table-row-state-manager'; + export function EndpointRowStateSetUpManager( paginationMonitor: PaginationMonitor, @@ -21,7 +21,7 @@ export function EndpointRowStateSetUpManager( .create(entity.guid, paginationMonitor.entityConfig); const request$ = entityMonitor.entityRequest$.pipe( map(request => { - const disconnect = request.updating[EndpointsEffect.disconnectingKey] || { busy: false }; + const disconnect = request.updating[DisconnectEndpoint.UpdatingKey] || { busy: false }; const unregister = request.deleting || { busy: false }; const busy = disconnect.busy || unregister.busy; const blocked = unregister.busy; diff --git a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoint-list.helpers.ts b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoint-list.helpers.ts index 25f9131be8..e1ebaabf50 100644 --- a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoint-list.helpers.ts +++ b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoint-list.helpers.ts @@ -4,15 +4,11 @@ import { Store } from '@ngrx/store'; import { combineLatest, Observable } from 'rxjs'; import { map, pairwise } from 'rxjs/operators'; -import { DisconnectEndpoint, UnregisterEndpoint } from '../../../../../../../store/src/actions/endpoint.actions'; import { RouterNav } from '../../../../../../../store/src/actions/router.actions'; -import { GetSystemInfo } from '../../../../../../../store/src/actions/system.actions'; import { AppState } from '../../../../../../../store/src/app-state'; -import { STRATOS_ENDPOINT_TYPE } from '../../../../../../../store/src/base-entity-schemas'; -import { EndpointsEffect } from '../../../../../../../store/src/effects/endpoint.effects'; import { entityCatalog } from '../../../../../../../store/src/entity-catalog/entity-catalog'; -import { endpointSchemaKey } from '../../../../../../../store/src/helpers/entity-factory'; -import { selectDeletionInfo, selectUpdateInfo } from '../../../../../../../store/src/selectors/api.selectors'; +import { ActionState } from '../../../../../../../store/src/reducers/api-request-reducer/types'; +import { stratosEntityCatalog } from '../../../../../../../store/src/stratos-entity-catalog'; import { EndpointModel } from '../../../../../../../store/src/types/endpoint.types'; import { LoggerService } from '../../../../../core/logger.service'; import { CurrentUserPermissionsService } from '../../../../../core/permissions/current-user-permissions.service'; @@ -43,7 +39,6 @@ function isEndpointListDetailsComponent(obj: any): EndpointListDetailsComponent @Injectable() export class EndpointListHelper { - private endpointEntityKey = entityCatalog.getEntityKey(STRATOS_ENDPOINT_TYPE, endpointSchemaKey); constructor( private store: Store, private dialog: MatDialog, @@ -64,10 +59,10 @@ export class EndpointListHelper { false ); this.confirmDialog.open(confirmation, () => { - this.store.dispatch(new DisconnectEndpoint(item.guid, item.cnsi_type)); - this.handleUpdateAction(item, EndpointsEffect.disconnectingKey, ([oldVal, newVal]) => { + const obs$ = stratosEntityCatalog.endpoint.api.disconnect(item.guid, item.cnsi_type); + this.handleAction(obs$, () => { this.snackBarService.show(`Disconnected endpoint '${item.name}'`); - this.store.dispatch(new GetSystemInfo()); + stratosEntityCatalog.systemInfo.api.getSystemInfo(); }); }); }, @@ -113,8 +108,8 @@ export class EndpointListHelper { true ); this.confirmDialog.open(confirmation, () => { - this.store.dispatch(new UnregisterEndpoint(item.guid, item.cnsi_type)); - this.handleDeleteAction(item, ([oldVal, newVal]) => { + const obs$ = stratosEntityCatalog.endpoint.api.unregister(item.guid, item.cnsi_type); + this.handleAction(obs$, () => { this.snackBarService.show(`Unregistered ${item.name}`); }); }); @@ -135,31 +130,16 @@ export class EndpointListHelper { ]; } - private handleUpdateAction(item, effectKey, handleChange) { - this.handleAction(selectUpdateInfo( - this.endpointEntityKey, - item.guid, - effectKey, - ), handleChange); - } - - private handleDeleteAction(item, handleChange) { - this.handleAction(selectDeletionInfo( - this.endpointEntityKey, - item.guid, - ), handleChange); - } - - private handleAction(storeSelect, handleChange) { - const disSub = this.store.select(storeSelect).pipe( - pairwise()) - .subscribe(([oldVal, newVal]) => { - // https://github.com/SUSE/stratos/issues/29 Generic way to handle errors ('Failed to disconnect X') - if (!newVal.error && (oldVal.busy && !newVal.busy)) { - handleChange([oldVal, newVal]); - disSub.unsubscribe(); - } - }); + private handleAction(obs$: Observable, handleChange: ([o, n]: [ActionState, ActionState]) => void) { + const disSub = obs$.pipe( + pairwise() + ).subscribe(([oldVal, newVal]) => { + // https://github.com/SUSE/stratos/issues/29 Generic way to handle errors ('Failed to disconnect X') + if (!newVal.error && (oldVal.busy && !newVal.busy)) { + handleChange([oldVal, newVal]); + disSub.unsubscribe(); + } + }); } createEndpointDetails(listDetailsComponent: any, container: ViewContainerRef, componentFactoryResolver: ComponentFactoryResolver): diff --git a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoints-data-source.ts b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoints-data-source.ts index 1f2999e41b..cdb066f099 100644 --- a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoints-data-source.ts +++ b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoints-data-source.ts @@ -1,10 +1,10 @@ import { Store } from '@ngrx/store'; -import { GetAllEndpoints } from '../../../../../../../store/src/actions/endpoint.actions'; import { AppState } from '../../../../../../../store/src/app-state'; import { EntityMonitorFactory } from '../../../../../../../store/src/monitors/entity-monitor.factory.service'; import { InternalEventMonitorFactory } from '../../../../../../../store/src/monitors/internal-event-monitor.factory'; import { PaginationMonitorFactory } from '../../../../../../../store/src/monitors/pagination-monitor.factory'; +import { stratosEntityCatalog } from '../../../../../../../store/src/stratos-entity-catalog'; import { EndpointModel } from '../../../../../../../store/src/types/endpoint.types'; import { IListConfig } from '../../list.component.types'; import { BaseEndpointsDataSource } from './base-endpoints-data-source'; @@ -23,7 +23,7 @@ export class EndpointsDataSource extends BaseEndpointsDataSource { super( store, listConfig, - new GetAllEndpoints(), + stratosEntityCatalog.endpoint.actions.getAll(), null, paginationMonitorFactory, entityMonitorFactory, diff --git a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/table-cell-endpoint-address/table-cell-endpoint-address.component.ts b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/table-cell-endpoint-address/table-cell-endpoint-address.component.ts index 206f52ca40..0eb0e7d08b 100644 --- a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/table-cell-endpoint-address/table-cell-endpoint-address.component.ts +++ b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/table-cell-endpoint-address/table-cell-endpoint-address.component.ts @@ -2,9 +2,8 @@ import { Component, Input } from '@angular/core'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; -import { GetAllEndpoints } from '../../../../../../../../store/src/actions/endpoint.actions'; import { getFullEndpointApiUrl } from '../../../../../../../../store/src/endpoint-utils'; -import { EntityServiceFactory } from '../../../../../../../../store/src/entity-service-factory.service'; +import { stratosEntityCatalog } from '../../../../../../../../store/src/stratos-entity-catalog'; import { EndpointModel } from '../../../../../../../../store/src/types/endpoint.types'; import { TableCellCustom } from '../../../list.types'; import { RowWithEndpointId } from '../table-cell-endpoint-name/table-cell-endpoint-name.component'; @@ -17,15 +16,11 @@ import { RowWithEndpointId } from '../table-cell-endpoint-name/table-cell-endpoi export class TableCellEndpointAddressComponent extends TableCellCustom { public endpointAddress$: Observable; - constructor(private entityServiceFactory: EntityServiceFactory) { - super(); - } - @Input('row') set row(row: EndpointModel | RowWithEndpointId) { /* tslint:disable-next-line:no-string-literal */ const id = row['endpointId'] || row['guid']; - this.endpointAddress$ = this.entityServiceFactory.create(id, new GetAllEndpoints()).waitForEntity$.pipe( + this.endpointAddress$ = stratosEntityCatalog.endpoint.store.getEntityService(id).waitForEntity$.pipe( map(data => data.entity), map((data: any) => getFullEndpointApiUrl(data)) ); diff --git a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/table-cell-endpoint-name/table-cell-endpoint-name.component.spec.ts b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/table-cell-endpoint-name/table-cell-endpoint-name.component.spec.ts index 02c3cb866a..6813bb19d8 100644 --- a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/table-cell-endpoint-name/table-cell-endpoint-name.component.spec.ts +++ b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/table-cell-endpoint-name/table-cell-endpoint-name.component.spec.ts @@ -26,7 +26,9 @@ describe('TableCellEndpointNameComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(TableCellEndpointNameComponent); component = fixture.componentInstance; - component.row = {} as EndpointModel; + component.row = { + guid: '' + } as EndpointModel; fixture.detectChanges(); }); diff --git a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/table-cell-endpoint-name/table-cell-endpoint-name.component.ts b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/table-cell-endpoint-name/table-cell-endpoint-name.component.ts index 62928cef55..d3c9c5940a 100644 --- a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/table-cell-endpoint-name/table-cell-endpoint-name.component.ts +++ b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/table-cell-endpoint-name/table-cell-endpoint-name.component.ts @@ -1,10 +1,10 @@ import { Component, Input } from '@angular/core'; import { Observable } from 'rxjs'; import { map } from 'rxjs/internal/operators/map'; +import { filter } from 'rxjs/operators'; -import { GetAllEndpoints } from '../../../../../../../../store/src/actions/endpoint.actions'; import { entityCatalog } from '../../../../../../../../store/src/entity-catalog/entity-catalog'; -import { EntityServiceFactory } from '../../../../../../../../store/src/entity-service-factory.service'; +import { stratosEntityCatalog } from '../../../../../../../../store/src/stratos-entity-catalog'; import { EndpointModel } from '../../../../../../../../store/src/types/endpoint.types'; import { EndpointsService } from '../../../../../../core/endpoints.service'; import { TableCellCustom } from '../../../list.types'; @@ -22,27 +22,19 @@ export class TableCellEndpointNameComponent extends TableCellCustom; - constructor( - private entityServiceFactory: EntityServiceFactory, - - ) { - super(); - } - @Input('row') set row(row: EndpointModel | RowWithEndpointId) { /* tslint:disable-next-line:no-string-literal */ const id = row['endpointId'] || row['guid']; - this.endpoint$ = this.entityServiceFactory.create( - id, - new GetAllEndpoints() - ).waitForEntity$.pipe( - map(data => data.entity), - map((data: any) => { + this.endpoint$ = stratosEntityCatalog.endpoint.store.getEntityMonitor(id).entity$.pipe( + filter(data => !!data), + map(data => { const ep = entityCatalog.getEndpoint(data.cnsi_type, data.sub_type).definition; - data.canShowLink = data.connectionStatus === 'connected' || ep.unConnectable; - data.link = EndpointsService.getLinkForEndpoint(data); - return data; + return { + ...data, + canShowLink: data.connectionStatus === 'connected' || ep.unConnectable, + link: EndpointsService.getLinkForEndpoint(data) + }; }) ); } diff --git a/src/frontend/packages/core/src/shared/components/recent-entities/recent-entities.component.ts b/src/frontend/packages/core/src/shared/components/recent-entities/recent-entities.component.ts index fcd86c1dc6..86af699f5c 100644 --- a/src/frontend/packages/core/src/shared/components/recent-entities/recent-entities.component.ts +++ b/src/frontend/packages/core/src/shared/components/recent-entities/recent-entities.component.ts @@ -5,7 +5,7 @@ import { Observable, of as observableOf } from 'rxjs'; import { filter, map } from 'rxjs/operators'; import { AppState } from '../../../../../store/src/app-state'; -import { endpointSchemaKey } from '../../../../../store/src/helpers/entity-factory'; +import { endpointEntityType } from '../../../../../store/src/helpers/stratos-entity-factory'; import { endpointEntitiesSelector } from '../../../../../store/src/selectors/endpoint.selectors'; import { recentlyVisitedSelector } from '../../../../../store/src/selectors/recently-visitied.selectors'; import { @@ -29,7 +29,7 @@ class RenderableRecent { public mostRecentHit: moment.Moment; public subText$: Observable; constructor(readonly entity: IRecentlyVisitedEntity, private store: Store) { - if (entity.entityType === endpointSchemaKey) { + if (entity.entityType === endpointEntityType) { this.subText$ = observableOf(entity.prettyType); } else { this.subText$ = this.store.select(endpointEntitiesSelector).pipe( diff --git a/src/frontend/packages/core/src/shared/entity.tokens.ts b/src/frontend/packages/core/src/shared/entity.tokens.ts index 76df701c07..0a4b9da0e9 100644 --- a/src/frontend/packages/core/src/shared/entity.tokens.ts +++ b/src/frontend/packages/core/src/shared/entity.tokens.ts @@ -1,6 +1,4 @@ -import { InjectionToken, Injectable } from '@angular/core'; -import { EntityService } from '../../../store/src/entity-service'; +import { InjectionToken } from '@angular/core'; + export const CF_GUID = new InjectionToken('cfGuid'); export const APP_GUID = new InjectionToken('appGuid'); - -export const ENTITY_SERVICE = new InjectionToken(null); diff --git a/src/frontend/packages/core/src/stratos-entities.ts b/src/frontend/packages/core/src/stratos-entities.ts deleted file mode 100644 index 539aec7e4c..0000000000 --- a/src/frontend/packages/core/src/stratos-entities.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { - DefaultEndpointCatalogEntity, - SystemInfoCatalogEntity, - UserFavoriteCatalogEntity, - UserProfileCatalogEntity, -} from '../../store/src/base-entity-types'; -import { StratosCatalogEndpointEntity } from '../../store/src/entity-catalog/entity-catalog-entity/entity-catalog-entity'; -import { BaseEndpointAuth } from './core/endpoint-auth'; -import { - MetricsEndpointDetailsComponent, -} from './features/metrics/metrics-endpoint-details/metrics-endpoint-details.component'; - -export function generateStratosEntities() { - return [ - new DefaultEndpointCatalogEntity(), - new SystemInfoCatalogEntity(), - new UserFavoriteCatalogEntity(), - new UserProfileCatalogEntity(), - // TODO: metrics location to be sorted - STRAT-152 - new StratosCatalogEndpointEntity({ - type: 'metrics', - label: 'Metrics', - labelPlural: 'Metrics', - tokenSharing: true, - logoUrl: '/core/assets/endpoint-icons/metrics.svg', - authTypes: [BaseEndpointAuth.UsernamePassword, BaseEndpointAuth.None], - renderPriority: 1, - listDetailsComponent: MetricsEndpointDetailsComponent, - }, - metadata => `/endpoints/metrics/${metadata.guid}` - ) - ]; -} diff --git a/src/frontend/packages/core/test-framework/core-test.modules.ts b/src/frontend/packages/core/test-framework/core-test.modules.ts index d38e89193a..0110b5e1d5 100644 --- a/src/frontend/packages/core/test-framework/core-test.modules.ts +++ b/src/frontend/packages/core/test-framework/core-test.modules.ts @@ -2,7 +2,7 @@ import { NgModule } from '@angular/core'; import { CATALOGUE_ENTITIES, EntityCatalogFeatureModule } from '../../store/src/entity-catalog.module'; import { entityCatalog, TestEntityCatalog } from '../../store/src/entity-catalog/entity-catalog'; -import { generateStratosEntities } from '../src/stratos-entities'; +import { generateStratosEntities } from '../../store/src/stratos-entity-generator'; @NgModule({ imports: [ diff --git a/src/frontend/packages/core/test-framework/entity-service.helper.ts b/src/frontend/packages/core/test-framework/entity-service.helper.ts deleted file mode 100644 index f01fb32974..0000000000 --- a/src/frontend/packages/core/test-framework/entity-service.helper.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Store } from '@ngrx/store'; -import { schema as normalizrSchema } from 'normalizr'; -import { EntityRequestAction } from '../../store/src/types/request.types'; -import { EntityServiceFactory } from '../../store/src/entity-service-factory.service'; -import { ENTITY_SERVICE } from '../src/shared/entity.tokens'; -import { AppState } from '../../store/src/app-state'; - -export function generateTestEntityServiceProvider( - guid: string, - schema: normalizrSchema.Entity, - action: EntityRequestAction -) { - function useFactory( - store: Store, - entityServiceFactory: EntityServiceFactory - ) { - return entityServiceFactory.create( - guid, - action - ); - } - - return { - provide: ENTITY_SERVICE, - useFactory, - deps: [Store, EntityServiceFactory] - }; -} diff --git a/src/frontend/packages/store/src/actions/endpoint.actions.ts b/src/frontend/packages/store/src/actions/endpoint.actions.ts index c5ea0fd519..2e4b8404ed 100644 --- a/src/frontend/packages/store/src/actions/endpoint.actions.ts +++ b/src/frontend/packages/store/src/actions/endpoint.actions.ts @@ -1,18 +1,20 @@ import { Action } from '@ngrx/store'; import { EndpointType } from '../extension-types'; -import { STRATOS_ENDPOINT_TYPE } from '../base-entity-schemas'; -import { endpointSchemaKey } from '../helpers/entity-factory'; +import { endpointEntityType, STRATOS_ENDPOINT_TYPE, stratosEntityFactory } from '../helpers/stratos-entity-factory'; import { NormalizedResponse } from '../types/api.types'; import { endpointListKey, EndpointModel, INewlyConnectedEndpointInfo } from '../types/endpoint.types'; import { PaginatedAction } from '../types/pagination.types'; +import { EntityRequestAction } from '../types/request.types'; export const GET_ENDPOINTS = '[Endpoints] Get all'; -export const GET_ENDPOINTS_START = '[Endpoints] Get all start'; -export const GET_ENDPOINTS_LOGIN = '[Endpoints] Get all at login'; export const GET_ENDPOINTS_SUCCESS = '[Endpoints] Get all success'; export const GET_ENDPOINTS_FAILED = '[Endpoints] Get all failed'; +export const GET_ENDPOINT = '[Endpoints] Get'; +export const GET_ENDPOINT_SUCCESS = '[Endpoints] Get success'; +export const GET_ENDPOINT_FAILED = '[Endpoints] Get failed'; + export const CONNECT_ENDPOINTS = '[Endpoints] Connect'; export const CONNECT_ENDPOINTS_SUCCESS = '[Endpoints] Connect succeed'; export const CONNECT_ENDPOINTS_FAILED = '[Endpoints] Connect failed'; @@ -37,14 +39,45 @@ export class EndpointActionComplete implements Action { constructor( public type: string, public guid: string, + /** + * Note - The underlying endpoints type (_cf_Endpoint, not _stratos_Endpoint) + */ public endpointType: EndpointType, public endpoint: EndpointModel | INewlyConnectedEndpointInfo ) { } } -export class EndpointAction implements Action { - type: string; - endpointType: EndpointType; +export abstract class BaseEndpointAction implements EntityRequestAction { + public entityType = endpointEntityType; + public endpointType = STRATOS_ENDPOINT_TYPE; + public subType = ''; + public entity = [stratosEntityFactory(endpointEntityType)] + constructor(public type: string) { } + actions: string[]; +} + +export abstract class SingleBaseEndpointAction extends BaseEndpointAction { + constructor( + actionType: string, + public guid: string, + /** + * The endpoint type of the endpoint + * endpointType = stratos endpoint type... where it will be stored + * endpointsType = specific type of the endpoint type... for instance 'metrics' + */ + public endpointsType?: string + ) { + super(actionType); + } +} + +abstract class MultipleBaseEndpointAction extends BaseEndpointAction implements PaginatedAction { + constructor( + actionType: string, + public paginationKey: string + ) { + super(actionType); + } } // Different Auth Type support for connecting to Endpoints @@ -60,15 +93,34 @@ export interface AuthParamsToken { // All supported auth params types export type AuthParams = AuthParamsUsernamePassword | AuthParamsToken; -export class GetAllEndpoints implements PaginatedAction { +export class GetEndpoint extends SingleBaseEndpointAction { + constructor( + guid: string, + ) { + super( + GET_ENDPOINT, + guid + ) + } + actions = [ + GET_ENDPOINT, + GET_ENDPOINT_SUCCESS, + GET_ENDPOINT_FAILED + ]; +} + +export class GetAllEndpoints extends MultipleBaseEndpointAction { public static storeKey = endpointListKey; - constructor(public login = false) { } - entityType = endpointSchemaKey; - endpointType = STRATOS_ENDPOINT_TYPE; - paginationKey = GetAllEndpoints.storeKey; - type = GET_ENDPOINTS; + constructor( + public login = false + ) { + super( + GET_ENDPOINTS, + GetAllEndpoints.storeKey + ) + } actions = [ - GET_ENDPOINTS_START, + GET_ENDPOINTS, GET_ENDPOINTS_SUCCESS, GET_ENDPOINTS_FAILED ]; @@ -80,53 +132,82 @@ export class GetAllEndpoints implements PaginatedAction { }; } -export class GetAllEndpointsSuccess implements Action { - constructor(public payload: NormalizedResponse, public login = false) { } +export class GetAllEndpointsSuccess extends GetAllEndpoints { + constructor(public payload: NormalizedResponse, public login = false) { + super(login) + } type = GET_ENDPOINTS_SUCCESS; } -export class GetAllEndpointsFailed implements Action { - constructor(public message: string, public login = false) { } - type = GET_ENDPOINTS_FAILED; -} - -export class ConnectEndpoint extends EndpointAction { +export class ConnectEndpoint extends SingleBaseEndpointAction { + static UpdatingKey = 'connectingKey' constructor( - public guid: string, - public endpointType: EndpointType, + guid: string, + // Note - should not be called endpointType + connectEndpointType: EndpointType, public authType: string, public authValues: AuthParams, public systemShared: boolean, public body: string, ) { - super(); + super( + CONNECT_ENDPOINTS, + guid, + connectEndpointType + ); } - type = CONNECT_ENDPOINTS; + updatingKey = ConnectEndpoint.UpdatingKey; + actions = [ + CONNECT_ENDPOINTS, + CONNECT_ENDPOINTS_SUCCESS, + CONNECT_ENDPOINTS_FAILED + ] } -export class DisconnectEndpoint extends EndpointAction { +export class DisconnectEndpoint extends SingleBaseEndpointAction { + static UpdatingKey = 'disconnecting' constructor( - public guid: string, - public endpointType: EndpointType, + guid: string, + // Note - should not be called endpointType + disconnectEndpointType: EndpointType, ) { - super(); + super( + DISCONNECT_ENDPOINTS, + guid, + disconnectEndpointType + ); } - type = DISCONNECT_ENDPOINTS; + updatingKey = DisconnectEndpoint.UpdatingKey; + actions = [ + DISCONNECT_ENDPOINTS, + DISCONNECT_ENDPOINTS_SUCCESS, + DISCONNECT_ENDPOINTS_FAILED + ]; } -export class UnregisterEndpoint extends EndpointAction { +export class UnregisterEndpoint extends SingleBaseEndpointAction { constructor( - public guid: string, - public endpointType: EndpointType, + guid: string, + // Note - should not be called endpointType + unregisterEndpointType: EndpointType, ) { - super(); + super( + UNREGISTER_ENDPOINTS, + guid, + unregisterEndpointType + ); } - type = UNREGISTER_ENDPOINTS; + actions = [ + UNREGISTER_ENDPOINTS, + UNREGISTER_ENDPOINTS_SUCCESS, + UNREGISTER_ENDPOINTS_FAILED + ]; } -export class RegisterEndpoint extends EndpointAction { +export class RegisterEndpoint extends SingleBaseEndpointAction { constructor( - public endpointType: EndpointType, + // Note - should not be called endpointType + registerEndpointType: EndpointType, public endpointSubType: string = null, public name: string, public endpoint: string, @@ -135,21 +216,24 @@ export class RegisterEndpoint extends EndpointAction { public clientSecret = '', public ssoAllowed: boolean, ) { - super(); - } - type = REGISTER_ENDPOINTS; - - public guid(): string { - return '' + this.name; + super( + REGISTER_ENDPOINTS, + '' + name, + registerEndpointType + ); } + updatingKey = 'registering' + actions = [ + REGISTER_ENDPOINTS, + REGISTER_ENDPOINTS_SUCCESS, + REGISTER_ENDPOINTS_FAILED + ]; } -export class UpdateEndpoint extends EndpointAction { - - type = UPDATE_ENDPOINT; - +export class UpdateEndpoint extends SingleBaseEndpointAction { constructor( - public endpointType: EndpointType, + // Note - should not be called endpointType + updateEndpointType: EndpointType, public id: string, public name: string, public skipSSL: boolean, @@ -158,6 +242,16 @@ export class UpdateEndpoint extends EndpointAction { public clientSecret: string, public allowSSO: boolean, ) { - super(); + super( + UPDATE_ENDPOINT, + id, + updateEndpointType + ); } + updatingKey = 'updating' + actions = [ + UPDATE_ENDPOINT, + UPDATE_ENDPOINT_SUCCESS, + UPDATE_ENDPOINT_FAILED + ]; } diff --git a/src/frontend/packages/store/src/actions/metrics.actions.ts b/src/frontend/packages/store/src/actions/metrics.actions.ts index 1cbcc786f3..ac62831049 100644 --- a/src/frontend/packages/store/src/actions/metrics.actions.ts +++ b/src/frontend/packages/store/src/actions/metrics.actions.ts @@ -1,4 +1,4 @@ -import { metricEntityType } from '../base-entity-schemas'; +import { metricEntityType } from '../helpers/stratos-entity-factory'; import { proxyAPIVersion } from '../jetstream'; import { MetricQueryType } from '../types/metric.types'; import { EntityRequestAction } from '../types/request.types'; diff --git a/src/frontend/packages/store/src/actions/system.actions.ts b/src/frontend/packages/store/src/actions/system.actions.ts index c916b62398..29c9f9410d 100644 --- a/src/frontend/packages/store/src/actions/system.actions.ts +++ b/src/frontend/packages/store/src/actions/system.actions.ts @@ -1,27 +1,35 @@ import { Action } from '@ngrx/store'; +import { STRATOS_ENDPOINT_TYPE, stratosEntityFactory, systemInfoEntityType } from '../helpers/stratos-entity-factory'; +import { EntityRequestAction } from '../types/request.types'; import { SystemInfo } from '../types/system.types'; -import { GetAllEndpoints } from './endpoint.actions'; +import { BaseEndpointAction, GetAllEndpoints } from './endpoint.actions'; export const GET_SYSTEM_INFO = '[System] Get info'; export const GET_SYSTEM_INFO_SUCCESS = '[System] Get info success'; export const GET_SYSTEM_INFO_FAILED = '[System] Get info failed'; -export class GetSystemInfo implements Action { - constructor(public login = false, public associatedAction?: GetAllEndpoints) { - if (!associatedAction) { +export class GetSystemInfo implements EntityRequestAction { + static guid = 'info'; + guid = GetSystemInfo.guid; + constructor(public login = false, public associatedAction?: BaseEndpointAction) { + if (!this.associatedAction) { this.associatedAction = new GetAllEndpoints(login); } } + schemaKey = systemInfoEntityType; + entity = [stratosEntityFactory(systemInfoEntityType)] + entityType = systemInfoEntityType; + endpointType = STRATOS_ENDPOINT_TYPE; type = GET_SYSTEM_INFO; + actions = [ + GET_SYSTEM_INFO, + GET_SYSTEM_INFO_SUCCESS, + GET_SYSTEM_INFO_FAILED + ] } export class GetSystemSuccess implements Action { - constructor(public payload: SystemInfo, public login = false, public associatedAction: GetAllEndpoints) { } + constructor(public payload: SystemInfo, public login = false, public associatedAction: BaseEndpointAction) { } type = GET_SYSTEM_INFO_SUCCESS; } - -export class GetSystemFailed implements Action { - type = GET_SYSTEM_INFO_FAILED; -} - diff --git a/src/frontend/packages/store/src/actions/user-favourites-actions/base-user-favorites-action.ts b/src/frontend/packages/store/src/actions/user-favourites-actions/base-user-favorites-action.ts deleted file mode 100644 index c7bfabd239..0000000000 --- a/src/frontend/packages/store/src/actions/user-favourites-actions/base-user-favorites-action.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Action } from '@ngrx/store'; - -export class BaseUserFavoritesAction implements Action { - constructor( - actionType: string, - ) { - this.type = actionType; - } - public type: string; - public url = '/user-favorites'; -} diff --git a/src/frontend/packages/store/src/actions/user-favourites-actions/get-user-favorites-action.ts b/src/frontend/packages/store/src/actions/user-favourites-actions/get-user-favorites-action.ts deleted file mode 100644 index b0b3eed95b..0000000000 --- a/src/frontend/packages/store/src/actions/user-favourites-actions/get-user-favorites-action.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { BaseUserFavoritesAction } from './base-user-favorites-action'; -import { UserFavorite, IFavoriteMetadata } from '../../types/user-favorites.types'; - -export class GetUserFavoritesAction extends BaseUserFavoritesAction { - static ACTION_TYPE = 'GET_USER_FAVORITES'; - constructor() { - super( - GetUserFavoritesAction.ACTION_TYPE - ); - } -} - -export class GetUserFavoritesSuccessAction extends BaseUserFavoritesAction { - static ACTION_TYPE = 'GET_USER_FAVORITES_SUCCESS'; - constructor(public favorites: UserFavorite[]) { - super( - GetUserFavoritesSuccessAction.ACTION_TYPE - ); - } -} - -export class GetUserFavoritesFailedAction extends BaseUserFavoritesAction { - static ACTION_TYPE = 'GET_USER_FAVORITES_FAILED'; - constructor() { - super( - GetUserFavoritesFailedAction.ACTION_TYPE - ); - } -} - diff --git a/src/frontend/packages/store/src/actions/user-favourites-actions/remove-user-favorite-action.ts b/src/frontend/packages/store/src/actions/user-favourites-actions/remove-user-favorite-action.ts deleted file mode 100644 index 89bcd7d47e..0000000000 --- a/src/frontend/packages/store/src/actions/user-favourites-actions/remove-user-favorite-action.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { BaseUserFavoritesAction } from './base-user-favorites-action'; -import { UserFavorite, IFavoriteMetadata } from '../../types/user-favorites.types'; - -export class RemoveUserFavoriteAction extends BaseUserFavoritesAction { - static ACTION_TYPE = 'REMOVE_USER_FAVORITE'; - constructor(public favorite: UserFavorite) { - super( - RemoveUserFavoriteAction.ACTION_TYPE - ); - } -} - -export class RemoveUserFavoriteSuccessAction extends BaseUserFavoritesAction { - static ACTION_TYPE = 'REMOVE_USER_FAVORITE_SUCCESS'; - constructor(public favorite: UserFavorite) { - super( - RemoveUserFavoriteSuccessAction.ACTION_TYPE - ); - } -} - diff --git a/src/frontend/packages/store/src/actions/user-favourites-actions/save-user-favorite-action.ts b/src/frontend/packages/store/src/actions/user-favourites-actions/save-user-favorite-action.ts deleted file mode 100644 index b38c8199de..0000000000 --- a/src/frontend/packages/store/src/actions/user-favourites-actions/save-user-favorite-action.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { IFavoriteMetadata } from './../../types/user-favorites.types'; -import { BaseUserFavoritesAction } from './base-user-favorites-action'; -import { UserFavorite } from '../../types/user-favorites.types'; - -export class SaveUserFavoriteAction extends BaseUserFavoritesAction { - static ACTION_TYPE = 'SAVE_USER_FAVORITE'; - constructor( - public favorite: UserFavorite - ) { - super( - SaveUserFavoriteAction.ACTION_TYPE - ); - } -} - -export class SaveUserFavoriteSuccessAction extends BaseUserFavoritesAction { - static ACTION_TYPE = 'SAVE_USER_FAVORITE_SUCCESS'; - constructor( - public favorite: UserFavorite - ) { - super( - SaveUserFavoriteSuccessAction.ACTION_TYPE - ); - } -} diff --git a/src/frontend/packages/store/src/actions/user-favourites-actions/toggle-user-favorite-action.ts b/src/frontend/packages/store/src/actions/user-favourites-actions/toggle-user-favorite-action.ts deleted file mode 100644 index 03a6100d31..0000000000 --- a/src/frontend/packages/store/src/actions/user-favourites-actions/toggle-user-favorite-action.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { BaseUserFavoritesAction } from './base-user-favorites-action'; -import { UserFavorite, IFavoriteMetadata } from '../../types/user-favorites.types'; - -export class ToggleUserFavoriteAction extends BaseUserFavoritesAction { - static ACTION_TYPE = 'TOGGLE_USER_FAVORITE'; - constructor( - public favorite: UserFavorite - ) { - super( - ToggleUserFavoriteAction.ACTION_TYPE - ); - } -} diff --git a/src/frontend/packages/store/src/actions/user-favourites-actions/update-user-favorite-metadata-action.ts b/src/frontend/packages/store/src/actions/user-favourites-actions/update-user-favorite-metadata-action.ts deleted file mode 100644 index 3707f615f1..0000000000 --- a/src/frontend/packages/store/src/actions/user-favourites-actions/update-user-favorite-metadata-action.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { UserFavorite, IFavoriteMetadata } from '../../types/user-favorites.types'; -import { BaseUserFavoritesAction } from './base-user-favorites-action'; - -export class UpdateUserFavoriteMetadataAction extends BaseUserFavoritesAction { - static ACTION_TYPE = 'UPDATE_FAVORITE_METADATA'; - constructor(public favorite: UserFavorite) { - super( - UpdateUserFavoriteMetadataAction.ACTION_TYPE - ); - } -} - -export class UpdateUserFavoriteMetadataSuccessAction extends BaseUserFavoritesAction { - static ACTION_TYPE = 'UPDATE_FAVORITE_METADATA_SUCCESS'; - constructor(public favorite: UserFavorite) { - super( - UpdateUserFavoriteMetadataSuccessAction.ACTION_TYPE - ); - } -} - diff --git a/src/frontend/packages/store/src/actions/user-favourites.actions.ts b/src/frontend/packages/store/src/actions/user-favourites.actions.ts new file mode 100644 index 0000000000..c4fcfdf744 --- /dev/null +++ b/src/frontend/packages/store/src/actions/user-favourites.actions.ts @@ -0,0 +1,145 @@ +import { STRATOS_ENDPOINT_TYPE, stratosEntityFactory, userFavouritesEntityType } from '../helpers/stratos-entity-factory'; +import { PaginatedAction } from '../types/pagination.types'; +import { EntityRequestAction } from '../types/request.types'; +import { IFavoriteMetadata, UserFavorite } from '../types/user-favorites.types'; + +abstract class BaseUserFavoritesAction implements EntityRequestAction { + constructor( + actionType: string, + ) { + this.type = actionType; + } + public type: string; + public url = '/user-favorites'; + + public entity = [stratosEntityFactory(userFavouritesEntityType)] + public entityType = userFavouritesEntityType; + public endpointType = STRATOS_ENDPOINT_TYPE; +} + + +abstract class BaseSingleUserFavouritesAction extends BaseUserFavoritesAction { + constructor(actionType: string, public guid: string) { + super(actionType); + } +} + +abstract class BaseMultipleUserFavouritesAction extends BaseUserFavoritesAction implements PaginatedAction { + guid: string; + constructor(actionType: string, public paginationKey: string) { + super(actionType); + } +} + + +abstract class BaseSuccessFavouritesAction extends BaseMultipleUserFavouritesAction { + constructor( + type: string, + public favorites: UserFavorite[], + paginationKey: string, + ) { + super(type, paginationKey); + } +} + +abstract class BaseSuccessFavouriteAction extends BaseSingleUserFavouritesAction { + constructor( + type: string, + public favorite: UserFavorite, + ) { + super(type, favorite.guid); + } +} + +// --------- + +export class GetUserFavoritesAction extends BaseMultipleUserFavouritesAction { + static PAGINATION_KEY = 'user_favourites'; + static ACTION_TYPE = '[Favorite] Get Favorites'; + constructor() { + super( + GetUserFavoritesAction.ACTION_TYPE, + GetUserFavoritesAction.PAGINATION_KEY + ); + } +} + +export class GetUserFavoritesSuccessAction extends BaseSuccessFavouritesAction { + static ACTION_TYPE = '[Favorite] Get Favorites Success'; + constructor(favorites: UserFavorite[]) { + super( + GetUserFavoritesSuccessAction.ACTION_TYPE, + favorites, + GetUserFavoritesAction.PAGINATION_KEY, + ); + } +} + +export class GetUserFavoritesFailedAction extends BaseMultipleUserFavouritesAction { + static ACTION_TYPE = '[Favorite] Get Favorites Failed'; + constructor() { + super( + GetUserFavoritesFailedAction.ACTION_TYPE, + GetUserFavoritesAction.PAGINATION_KEY + ); + } +} + +// --------- + +export class RemoveUserFavoriteAction extends BaseSingleUserFavouritesAction { + static ACTION_TYPE = '[Favorite] Remove Favorite'; + constructor(public favorite: UserFavorite) { + super( + RemoveUserFavoriteAction.ACTION_TYPE, + favorite.guid, + ); + } +} + +export class RemoveUserFavoriteSuccessAction extends BaseSuccessFavouriteAction { + static ACTION_TYPE = '[Favorite] Remove Favorite Success'; + constructor(favorite: UserFavorite) { + super(RemoveUserFavoriteSuccessAction.ACTION_TYPE, favorite) + } +} + +// --------- + +export class SaveUserFavoriteAction extends BaseSingleUserFavouritesAction { + static ACTION_TYPE = '[Favorite] Save Favorite'; + constructor(public favorite: UserFavorite) { + super(SaveUserFavoriteAction.ACTION_TYPE, favorite.guid); + } +} + +export class SaveUserFavoriteSuccessAction extends BaseSuccessFavouriteAction { + static ACTION_TYPE = '[Favorite] Save Favorite Success'; + constructor(favorite: UserFavorite) { + super(SaveUserFavoriteSuccessAction.ACTION_TYPE, favorite); + } +} + +// --------- + +export class ToggleUserFavoriteAction extends BaseSingleUserFavouritesAction { + static ACTION_TYPE = '[Favorite] Toggle Favorite'; + constructor(public favorite: UserFavorite) { + super(ToggleUserFavoriteAction.ACTION_TYPE, favorite.guid); + } +} + +// --------- +export class UpdateUserFavoriteMetadataAction extends BaseSingleUserFavouritesAction { + static ACTION_TYPE = '[Favorite] Update Favorite Metadata'; + constructor(public favorite: UserFavorite) { + super(UpdateUserFavoriteMetadataAction.ACTION_TYPE, favorite.guid); + } +} + +export class UpdateUserFavoriteMetadataSuccessAction extends BaseSuccessFavouriteAction { + static ACTION_TYPE = '[Favorite] Update Favorite Metadata Success'; + constructor(public favorite: UserFavorite) { + super(UpdateUserFavoriteMetadataSuccessAction.ACTION_TYPE, favorite); + } +} diff --git a/src/frontend/packages/store/src/actions/user-profile.actions.ts b/src/frontend/packages/store/src/actions/user-profile.actions.ts index 73b7b09523..c4e25f1eb6 100644 --- a/src/frontend/packages/store/src/actions/user-profile.actions.ts +++ b/src/frontend/packages/store/src/actions/user-profile.actions.ts @@ -1,6 +1,5 @@ -import { Action } from '@ngrx/store'; - -import { userProfileEntitySchema } from '../base-entity-schemas'; +import { STRATOS_ENDPOINT_TYPE, stratosEntityFactory, userProfileEntityType } from '../helpers/stratos-entity-factory'; +import { rootUpdatingKey } from '../reducers/api-request-reducer/types'; import { EntityRequestAction } from '../types/request.types'; import { UserProfileInfo, UserProfilePasswordUpdate } from '../types/user-profile.types'; @@ -8,21 +7,31 @@ export const GET_USERPROFILE = '[UserProfile] Get'; export const UPDATE_USERPROFILE = '[UserProfile] Update'; export const UPDATE_USERPASSWORD = '[UserPassword] Update'; -export class FetchUserProfileAction implements EntityRequestAction { +abstract class BaseProfileAction implements EntityRequestAction { static guid = 'userProfile'; - type = GET_USERPROFILE; - constructor(public userGuid: string) { } - entityType = userProfileEntitySchema.entityType; - endpointType = userProfileEntitySchema.endpointType; - guid = FetchUserProfileAction.guid; + guid = BaseProfileAction.guid; + entityType = userProfileEntityType; + endpointType = STRATOS_ENDPOINT_TYPE; + entity = [stratosEntityFactory(userProfileEntityType)] + constructor(public type: string) { } +} + +export class FetchUserProfileAction extends BaseProfileAction { + constructor(public userGuid: string) { + super(GET_USERPROFILE); + } } -export class UpdateUserProfileAction implements Action { - type = UPDATE_USERPROFILE; - constructor(public profile: UserProfileInfo, public password: string) { } +export class UpdateUserProfileAction extends BaseProfileAction { + constructor(public profile: UserProfileInfo, public password: string) { + super(UPDATE_USERPROFILE) + } + updatingKey = rootUpdatingKey } -export class UpdateUserPasswordAction implements Action { - type = UPDATE_USERPASSWORD; - constructor(public id: string, public passwordChanges: UserProfilePasswordUpdate) { } +export class UpdateUserPasswordAction extends BaseProfileAction { + constructor(public id: string, public passwordChanges: UserProfilePasswordUpdate) { + super(UPDATE_USERPASSWORD); + } + updatingKey = 'password' } diff --git a/src/frontend/packages/store/src/base-entity-schemas.ts b/src/frontend/packages/store/src/base-entity-schemas.ts deleted file mode 100644 index f819325d8f..0000000000 --- a/src/frontend/packages/store/src/base-entity-schemas.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { - endpointSchemaKey, - entityFactory, - systemInfoSchemaKey, - userFavouritesSchemaKey, - userProfileSchemaKey, -} from './helpers/entity-factory'; -import { EntitySchema } from './helpers/entity-schema'; - -export const metricEntityType = 'metrics'; - -export const STRATOS_ENDPOINT_TYPE = 'stratos'; -export const ENDPOINT_TYPE = 'endpoint'; - -class StratosEntitySchema extends EntitySchema { - constructor(entityType: string) { - super(entityType, STRATOS_ENDPOINT_TYPE); - } -} - -export const userFavoritesEntitySchema = new StratosEntitySchema(entityFactory(userFavouritesSchemaKey).entityType); -export const endpointEntitySchema = new StratosEntitySchema(entityFactory(endpointSchemaKey).entityType); -export const userProfileEntitySchema = new StratosEntitySchema(entityFactory(userProfileSchemaKey).entityType); -export const systemInfoEntitySchema = new StratosEntitySchema(entityFactory(systemInfoSchemaKey).entityType); diff --git a/src/frontend/packages/store/src/base-entity-types.ts b/src/frontend/packages/store/src/base-entity-types.ts deleted file mode 100644 index 1d034152c2..0000000000 --- a/src/frontend/packages/store/src/base-entity-types.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { - endpointEntitySchema, - STRATOS_ENDPOINT_TYPE, - systemInfoEntitySchema, - userFavoritesEntitySchema, - userProfileEntitySchema, -} from './base-entity-schemas'; -import { StratosCatalogEntity } from './entity-catalog/entity-catalog-entity/entity-catalog-entity'; -import { addOrUpdateUserFavoriteMetadataReducer, deleteUserFavoriteMetadataReducer } from './reducers/favorite.reducer'; -import { systemEndpointsReducer } from './reducers/system-endpoints.reducer'; - -// -// These types are used to represent the base stratos types. -// - -/** - * This is used as a fake endpoint type to allow the store to be initiated correctly - */ -const stratosType = { - logoUrl: '', - authTypes: [], - type: STRATOS_ENDPOINT_TYPE, - schema: null -}; - -/** - * DefaultEndpointEntityType is used to represent a general endpoint - * This should not be used to actually attempt to render an endpoint and is instead used as a way to fill the - */ -export class DefaultEndpointCatalogEntity extends StratosCatalogEntity { - constructor() { - super({ - schema: endpointEntitySchema, - type: endpointEntitySchema.entityType, - endpoint: stratosType, - }, { - dataReducers: [ - systemEndpointsReducer - ] - }); - } -} - -export class UserFavoriteCatalogEntity extends StratosCatalogEntity { - constructor() { - super({ - schema: userFavoritesEntitySchema, - type: userFavoritesEntitySchema.entityType, - endpoint: stratosType, - }, { - dataReducers: [ - addOrUpdateUserFavoriteMetadataReducer, - deleteUserFavoriteMetadataReducer, - ] - }); - } -} - -export class UserProfileCatalogEntity extends StratosCatalogEntity { - constructor() { - super({ - schema: userProfileEntitySchema, - type: userProfileEntitySchema.entityType, - endpoint: stratosType, - }); - } -} - -export class SystemInfoCatalogEntity extends StratosCatalogEntity { - constructor() { - super({ - schema: systemInfoEntitySchema, - type: systemInfoEntitySchema.entityType, - endpoint: stratosType, - }); - } -} - - diff --git a/src/frontend/packages/store/src/effects/auth.effects.ts b/src/frontend/packages/store/src/effects/auth.effects.ts index 086c791cea..70f117622a 100644 --- a/src/frontend/packages/store/src/effects/auth.effects.ts +++ b/src/frontend/packages/store/src/effects/auth.effects.ts @@ -25,10 +25,10 @@ import { } from '../actions/auth.actions'; import { HydrateDashboardStateAction } from '../actions/dashboard-actions'; import { GET_ENDPOINTS_SUCCESS, GetAllEndpointsSuccess } from '../actions/endpoint.actions'; -import { GetSystemInfo } from '../actions/system.actions'; import { DispatchOnlyAppState } from '../app-state'; import { BrowserStandardEncoder } from '../browser-encoder'; import { getDashboardStateSessionId } from '../helpers/store-helpers'; +import { stratosEntityCatalog } from '../stratos-entity-catalog'; import { SessionData } from '../types/auth.types'; const SETUP_HEADER = 'stratos-setup-required'; @@ -82,7 +82,10 @@ export class AuthEffect { const sessionData = response.body; sessionData.sessionExpiresOn = parseInt(response.headers.get('x-cap-session-expires-on'), 10) * 1000; this.rehydrateDashboardState(this.store, sessionData); - return [new GetSystemInfo(true), new VerifiedSession(sessionData, action.updateEndpoints)]; + return [ + stratosEntityCatalog.systemInfo.actions.getSystemInfo(true), + new VerifiedSession(sessionData, action.updateEndpoints) + ]; }), catchError((err, caught) => { let setupMode = false; diff --git a/src/frontend/packages/store/src/effects/endpoint-api-errors.effects.ts b/src/frontend/packages/store/src/effects/endpoint-api-errors.effects.ts index 8aa64ed80f..118abe2282 100644 --- a/src/frontend/packages/store/src/effects/endpoint-api-errors.effects.ts +++ b/src/frontend/packages/store/src/effects/endpoint-api-errors.effects.ts @@ -6,7 +6,7 @@ import { map } from 'rxjs/operators'; import { SendEventAction } from '../actions/internal-events.actions'; import { RequestTypes } from '../actions/request.actions'; import { InternalAppState } from '../app-state'; -import { endpointSchemaKey } from '../helpers/entity-factory'; +import { endpointEntityType } from '../helpers/stratos-entity-factory'; import { InternalEventSeverity } from '../types/internal-events.types'; import { WrapperRequestActionFailed } from '../types/request.types'; @@ -26,7 +26,7 @@ export class EndpointApiError { const { eventCode, message, error, url } = internalEndpointError; internalEndpointError.endpointIds.forEach(endpoint => this.store.dispatch( - new SendEventAction(endpointSchemaKey, endpoint, { + new SendEventAction(endpointEntityType, endpoint, { eventCode, severity: InternalEventSeverity.ERROR, message, diff --git a/src/frontend/packages/store/src/effects/endpoint.effects.ts b/src/frontend/packages/store/src/effects/endpoint.effects.ts index 0a7f25fcae..6925c05e5c 100644 --- a/src/frontend/packages/store/src/effects/endpoint.effects.ts +++ b/src/frontend/packages/store/src/effects/endpoint.effects.ts @@ -6,37 +6,29 @@ import { catchError, mergeMap } from 'rxjs/operators'; import { CONNECT_ENDPOINTS, - CONNECT_ENDPOINTS_FAILED, - CONNECT_ENDPOINTS_SUCCESS, ConnectEndpoint, DISCONNECT_ENDPOINTS, - DISCONNECT_ENDPOINTS_FAILED, - DISCONNECT_ENDPOINTS_SUCCESS, DisconnectEndpoint, EndpointActionComplete, + GET_ENDPOINT, GET_ENDPOINTS, GetAllEndpoints, GetAllEndpointsSuccess, + GetEndpoint, REGISTER_ENDPOINTS, - REGISTER_ENDPOINTS_FAILED, - REGISTER_ENDPOINTS_SUCCESS, RegisterEndpoint, UNREGISTER_ENDPOINTS, - UNREGISTER_ENDPOINTS_FAILED, - UNREGISTER_ENDPOINTS_SUCCESS, UnregisterEndpoint, } from '../actions/endpoint.actions'; import { SendClearEventAction } from '../actions/internal-events.actions'; import { ClearPaginationOfEntity } from '../actions/pagination.actions'; -import { GET_SYSTEM_INFO_SUCCESS, GetSystemInfo, GetSystemSuccess } from '../actions/system.actions'; -import { GetUserFavoritesAction } from '../actions/user-favourites-actions/get-user-favorites-action'; +import { GET_SYSTEM_INFO_SUCCESS, GetSystemSuccess } from '../actions/system.actions'; import { DispatchOnlyAppState } from '../app-state'; -import { STRATOS_ENDPOINT_TYPE } from '../base-entity-schemas'; import { BrowserStandardEncoder } from '../browser-encoder'; import { entityCatalog } from '../entity-catalog/entity-catalog'; import { EndpointType } from '../extension-types'; -import { endpointSchemaKey } from '../helpers/entity-factory'; import { ApiRequestTypes } from '../reducers/api-request-reducer/request-helpers'; +import { stratosEntityCatalog } from '../stratos-entity-catalog'; import { NormalizedResponse } from '../types/api.types'; import { EndpointModel } from '../types/endpoint.types'; import { @@ -45,53 +37,51 @@ import { WrapperRequestActionFailed, WrapperRequestActionSuccess, } from '../types/request.types'; -import { - UPDATE_ENDPOINT, - UPDATE_ENDPOINT_FAILED, - UPDATE_ENDPOINT_SUCCESS, - UpdateEndpoint, -} from './../actions/endpoint.actions'; +import { UPDATE_ENDPOINT, UpdateEndpoint } from './../actions/endpoint.actions'; import { PaginatedAction } from './../types/pagination.types'; @Injectable() export class EndpointsEffect { - static connectingKey = 'connecting'; - static disconnectingKey = 'disconnecting'; - static registeringKey = 'registering'; - static updatingKey = 'updating'; - constructor( private http: HttpClient, private actions$: Actions, private store: Store ) { } + @Effect() getEndpoint$ = this.actions$.pipe( + ofType(GET_ENDPOINT), + mergeMap((action: GetEndpoint) => [ + stratosEntityCatalog.systemInfo.actions.getSystemInfo(false, action) + ]) + ); + @Effect() getAllEndpointsBySystemInfo$ = this.actions$.pipe( ofType(GET_ENDPOINTS), - mergeMap((action: GetAllEndpoints) => [new GetSystemInfo(false, action)]) + mergeMap((action: GetAllEndpoints) => [ + stratosEntityCatalog.systemInfo.actions.getSystemInfo(false, action) + ]) ); @Effect() getAllEndpoints$ = this.actions$.pipe( ofType(GET_SYSTEM_INFO_SUCCESS), mergeMap(action => { - const endpointEntityKey = entityCatalog.getEntityKey(STRATOS_ENDPOINT_TYPE, endpointSchemaKey); const { associatedAction } = action; - const actionType = 'fetch'; + const entityKey = entityCatalog.getEntityKey(associatedAction); const endpoints = action.payload.endpoints; // Data is an array of endpoints - const mappedData = { + const mappedData: NormalizedResponse = { entities: { - [endpointEntityKey]: {} + [entityKey]: {} }, result: [] - } as NormalizedResponse; + }; Object.keys(endpoints).forEach((type: string) => { const endpointsForType = endpoints[type]; Object.values(endpointsForType).forEach(endpointInfo => { - mappedData.entities[endpointEntityKey][endpointInfo.guid] = { + mappedData.entities[entityKey][endpointInfo.guid] = { ...endpointInfo, connectionStatus: endpointInfo.user ? 'connected' : 'disconnected', }; @@ -102,8 +92,8 @@ export class EndpointsEffect { // Order is important. Need to ensure data is written (none cf action success) before we notify everything is loaded // (endpoint success) return [ - new WrapperRequestActionSuccess(mappedData, associatedAction, actionType), - new GetAllEndpointsSuccess(mappedData, associatedAction.login), + new WrapperRequestActionSuccess(mappedData, associatedAction, 'fetch'), + new GetAllEndpointsSuccess(mappedData, associatedAction['login']), ]; })); @@ -119,8 +109,6 @@ export class EndpointsEffect { return []; } - const apiAction = this.getEndpointUpdateAction(action.guid, action.type, EndpointsEffect.connectingKey); - let fromObject: any; let body = action.body as any; @@ -152,12 +140,11 @@ export class EndpointsEffect { }); return this.doEndpointAction( - apiAction, + action, '/pp/v1/auth/login/cnsi', params, null, - [CONNECT_ENDPOINTS_SUCCESS, CONNECT_ENDPOINTS_FAILED], - action.endpointType, + action.endpointsType, body, response => response && response.error && response.error.error ? response.error.error : 'Could not connect, please try again' ); @@ -166,8 +153,6 @@ export class EndpointsEffect { @Effect() disconnect$ = this.actions$.pipe( ofType(DISCONNECT_ENDPOINTS), mergeMap(action => { - - const apiAction = this.getEndpointUpdateAction(action.guid, action.type, EndpointsEffect.disconnectingKey); const params: HttpParams = new HttpParams({ fromObject: { cnsi_guid: action.guid @@ -175,20 +160,17 @@ export class EndpointsEffect { }); return this.doEndpointAction( - apiAction, + action, '/pp/v1/auth/logout/cnsi', params, null, - [DISCONNECT_ENDPOINTS_SUCCESS, DISCONNECT_ENDPOINTS_FAILED], - action.endpointType + action.endpointsType ); })); @Effect() unregister$ = this.actions$.pipe( ofType(UNREGISTER_ENDPOINTS), mergeMap(action => { - - const apiAction = this.getEndpointDeleteAction(action.guid, action.type); const params: HttpParams = new HttpParams({ fromObject: { cnsi_guid: action.guid @@ -196,12 +178,11 @@ export class EndpointsEffect { }); return this.doEndpointAction( - apiAction, + action, '/pp/v1/unregister', params, 'delete', - [UNREGISTER_ENDPOINTS_SUCCESS, UNREGISTER_ENDPOINTS_FAILED], - action.endpointType + action.endpointsType ); })); @@ -209,7 +190,6 @@ export class EndpointsEffect { ofType(REGISTER_ENDPOINTS), mergeMap(action => { - const apiAction = this.getEndpointUpdateAction(action.guid(), action.type, EndpointsEffect.registeringKey); const paramsObj = { cnsi_name: action.name, api_endpoint: action.endpoint, @@ -230,12 +210,11 @@ export class EndpointsEffect { }); return this.doEndpointAction( - apiAction, - '/pp/v1/register/' + action.endpointType, + action, + '/pp/v1/register/' + action.endpointsType, new HttpParams({}), 'create', - [REGISTER_ENDPOINTS_SUCCESS, REGISTER_ENDPOINTS_FAILED], - action.endpointType, + action.endpointsType, body, this.processRegisterError ); @@ -243,8 +222,7 @@ export class EndpointsEffect { @Effect() updateEndpoint$ = this.actions$.pipe( ofType(UPDATE_ENDPOINT), - mergeMap(action => { - const apiAction = this.getEndpointUpdateAction(action.id, action.type, EndpointsEffect.updatingKey); + mergeMap((action: UpdateEndpoint) => { const paramsObj = { name: action.name, skipSSL: action.skipSSL, @@ -261,12 +239,11 @@ export class EndpointsEffect { }); return this.doEndpointAction( - apiAction, + action, '/pp/v1/endpoint/' + action.id, new HttpParams({}), 'update', - [UPDATE_ENDPOINT_SUCCESS, UPDATE_ENDPOINT_FAILED], - action.endpointType, + action.endpointsType, body, this.processUpdateError ); @@ -291,35 +268,20 @@ export class EndpointsEffect { } return message; } - private getEndpointUpdateAction(guid: string, type: string, updatingKey: string) { - const entityType = entityCatalog.getEntityKey(STRATOS_ENDPOINT_TYPE, endpointSchemaKey); - return { - entityType, - guid, - type, - updatingKey, - } as EntityRequestAction; - } - - private getEndpointDeleteAction(guid, type) { - const entityType = entityCatalog.getEntityKey(STRATOS_ENDPOINT_TYPE, endpointSchemaKey); - return { - entityType, - guid, - type, - } as EntityRequestAction; - } + /** + * @param endpointType The underlying endpoints type (_cf_Endpoint, not _stratos_Endpoint) + */ private doEndpointAction( apiAction: EntityRequestAction | PaginatedAction, url: string, params: HttpParams, apiActionType: ApiRequestTypes = 'update', - actionStrings: [string, string] = [null, null], - endpointType: EndpointType = 'cf', + endpointType: EndpointType, body?: string, errorMessageHandler?: (e: any) => string, ) { + const endpointEntityKey = entityCatalog.getEntityKey(apiAction); this.store.dispatch(new StartRequestAction(apiAction, apiActionType)); return this.http.post(url, body || {}, { @@ -328,17 +290,17 @@ export class EndpointsEffect { mergeMap((endpoint: EndpointModel) => { const actions = []; let response: NormalizedResponse; - if (actionStrings[0]) { - actions.push(new EndpointActionComplete(actionStrings[0], apiAction.guid, endpointType, endpoint)); + if (apiAction.actions[1]) { + actions.push(new EndpointActionComplete(apiAction.actions[1], apiAction.guid, endpointType, endpoint)); } if (apiActionType === 'delete') { actions.push(new ClearPaginationOfEntity(apiAction, apiAction.guid)); - actions.push(new GetUserFavoritesAction()); + actions.push(stratosEntityCatalog.userFavorite.actions.getAll()); } if (apiActionType === 'create') { - actions.push(new GetSystemInfo()); + actions.push(stratosEntityCatalog.systemInfo.actions.getSystemInfo()); response = { entities: { [endpointEntityKey]: { @@ -350,10 +312,10 @@ export class EndpointsEffect { } if (apiActionType === 'update') { - actions.push(new GetSystemInfo()); + actions.push(stratosEntityCatalog.systemInfo.actions.getSystemInfo()); } - if (apiAction.updatingKey === EndpointsEffect.disconnectingKey || apiActionType === 'create' || apiActionType === 'delete' + if (apiAction.updatingKey === DisconnectEndpoint.UpdatingKey || apiActionType === 'create' || apiActionType === 'delete' || apiActionType === 'update') { actions.push(this.clearEndpointInternalEvents(apiAction.guid, endpointEntityKey)); } @@ -364,8 +326,8 @@ export class EndpointsEffect { ), catchError(e => { const actions = []; - if (actionStrings[1]) { - actions.push({ type: actionStrings[1], guid: apiAction.guid }); + if (apiAction.actions[2]) { + actions.push({ type: apiAction.actions[2], guid: apiAction.guid }); } const errorMessage = errorMessageHandler ? errorMessageHandler(e) : 'Could not perform action'; actions.push(new WrapperRequestActionFailed(errorMessage, apiAction, apiActionType)); diff --git a/src/frontend/packages/store/src/effects/system.effects.ts b/src/frontend/packages/store/src/effects/system.effects.ts index b02c7cc365..07eb09bdf5 100644 --- a/src/frontend/packages/store/src/effects/system.effects.ts +++ b/src/frontend/packages/store/src/effects/system.effects.ts @@ -4,16 +4,11 @@ import { Actions, Effect, ofType } from '@ngrx/effects'; import { Store } from '@ngrx/store'; import { catchError, mergeMap } from 'rxjs/operators'; -import { GET_SYSTEM_INFO, GetSystemFailed, GetSystemInfo, GetSystemSuccess } from '../actions/system.actions'; +import { GET_SYSTEM_INFO, GetSystemInfo, GetSystemSuccess } from '../actions/system.actions'; import { InternalAppState } from '../app-state'; -import { STRATOS_ENDPOINT_TYPE } from '../base-entity-schemas'; -import { - EntityRequestAction, - StartRequestAction, - WrapperRequestActionFailed, - WrapperRequestActionSuccess, -} from '../types/request.types'; -import { SystemInfo, systemStoreNames } from '../types/system.types'; +import { StartRequestAction, WrapperRequestActionFailed, WrapperRequestActionSuccess } from '../types/request.types'; +import { SystemInfo } from '../types/system.types'; + @Injectable() export class SystemEffects { @@ -23,32 +18,25 @@ export class SystemEffects { private store: Store ) { } - static guid = 'info'; - @Effect() getInfo$ = this.actions$.pipe( ofType(GET_SYSTEM_INFO), mergeMap(action => { - const apiAction = { - entityType: systemStoreNames.type, - endpointType: STRATOS_ENDPOINT_TYPE, - guid: SystemEffects.guid, - type: action.type, - } as EntityRequestAction; - this.store.dispatch(new StartRequestAction(apiAction)); + // Associated action with be either get endpoint or get all endpoints/ + // Start action for those two are dispatched here, as well as error handling + // Success actions are handling in the effect associated with GetSystemSuccess + this.store.dispatch(new StartRequestAction(action)); const { associatedAction } = action; - const actionType = 'fetch'; - this.store.dispatch(new StartRequestAction(associatedAction, actionType)); + this.store.dispatch(new StartRequestAction(associatedAction, 'fetch')); return this.httpClient.get('/pp/v1/info').pipe( mergeMap((info: SystemInfo) => { return [ new GetSystemSuccess(info, action.login, associatedAction), - new WrapperRequestActionSuccess({ entities: {}, result: [] }, apiAction) + new WrapperRequestActionSuccess({ entities: {}, result: [] }, action) ]; }), catchError((e) => { return [ - new GetSystemFailed(), - new WrapperRequestActionFailed('Could not get system endpoints', associatedAction), - new WrapperRequestActionFailed('Could not fetch system info', apiAction) + { type: action.actions[2] }, + new WrapperRequestActionFailed('Could not fetch system info', action) ]; })); })); diff --git a/src/frontend/packages/store/src/effects/user-favorites-effect.ts b/src/frontend/packages/store/src/effects/user-favorites-effect.ts index be235e1b03..02240e52af 100644 --- a/src/frontend/packages/store/src/effects/user-favorites-effect.ts +++ b/src/frontend/packages/store/src/effects/user-favorites-effect.ts @@ -2,34 +2,26 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Actions, Effect, ofType } from '@ngrx/effects'; import { Store } from '@ngrx/store'; -import { catchError, first, map, mergeMap, switchMap } from 'rxjs/operators'; +import { catchError, first, mergeMap, switchMap } from 'rxjs/operators'; import { ClearPaginationOfEntity } from '../actions/pagination.actions'; import { GetUserFavoritesAction, GetUserFavoritesFailedAction, GetUserFavoritesSuccessAction, -} from '../actions/user-favourites-actions/get-user-favorites-action'; -import { RemoveUserFavoriteAction, RemoveUserFavoriteSuccessAction, -} from '../actions/user-favourites-actions/remove-user-favorite-action'; -import { SaveUserFavoriteAction, SaveUserFavoriteSuccessAction, -} from '../actions/user-favourites-actions/save-user-favorite-action'; -import { ToggleUserFavoriteAction } from '../actions/user-favourites-actions/toggle-user-favorite-action'; -import { + ToggleUserFavoriteAction, UpdateUserFavoriteMetadataAction, UpdateUserFavoriteMetadataSuccessAction, -} from '../actions/user-favourites-actions/update-user-favorite-metadata-action'; +} from '../actions/user-favourites.actions'; import { DispatchOnlyAppState } from '../app-state'; -import { userFavoritesEntitySchema } from '../base-entity-schemas'; 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 { StartRequestAction, WrapperRequestActionFailed, WrapperRequestActionSuccess } from '../types/request.types'; import { IFavoriteMetadata, UserFavorite, userFavoritesPaginationKey } from '../types/user-favorites.types'; import { UserFavoriteManager } from '../user-favorite-manager'; @@ -50,11 +42,17 @@ export class UserFavoritesEffect { @Effect() saveFavorite = this.actions$.pipe( ofType(SaveUserFavoriteAction.ACTION_TYPE), mergeMap(action => { + const actionType = 'update'; + this.store.dispatch(new StartRequestAction(action, actionType)) return this.http.post>(favoriteUrlPath, action.favorite).pipe( - mergeMap(newFavorite => { - return [ - new SaveUserFavoriteSuccessAction(newFavorite) - ]; + switchMap(newFavorite => { + this.store.dispatch(new WrapperRequestActionSuccess(null, action, actionType)); + this.store.dispatch(new SaveUserFavoriteSuccessAction(newFavorite)); + return []; + }), + catchError(() => { + this.store.dispatch(new WrapperRequestActionFailed('Failed to update user favorite', action, actionType)); + return []; }) ); }) @@ -63,14 +61,11 @@ export class UserFavoritesEffect { @Effect({ dispatch: false }) getFavorite$ = this.actions$.pipe( ofType(GetUserFavoritesAction.ACTION_TYPE), switchMap((action: GetUserFavoritesAction) => { - const apiAction = { - entityType: userFavoritesEntitySchema.entityType, - endpointType: userFavoritesEntitySchema.endpointType, - type: action.type - } as PaginatedAction; - const favEntityKey = entityCatalog.getEntityKey(apiAction); + const favEntityKey = entityCatalog.getEntityKey(action); + const actionType = 'fetch'; + this.store.dispatch(new StartRequestAction(action, actionType)) return this.http.get[]>(favoriteUrlPath).pipe( - map(favorites => { + switchMap(favorites => { const mappedData = favorites.reduce>>((data, favorite) => { const { guid } = favorite; if (guid) { @@ -79,12 +74,14 @@ export class UserFavoritesEffect { } return data; }, { entities: { [favEntityKey]: {} }, result: [] }); - this.store.dispatch(new WrapperRequestActionSuccess(mappedData, apiAction)); + this.store.dispatch(new WrapperRequestActionSuccess(mappedData, action, actionType, mappedData.result.length, 1)); this.store.dispatch(new GetUserFavoritesSuccessAction(favorites)); + return []; }), - catchError(e => { - this.store.dispatch(new GetUserFavoritesFailedAction()); - throw e; + catchError(() => { + this.store.dispatch(new GetUserFavoritesFailedAction()) + this.store.dispatch(new WrapperRequestActionFailed('Failed to fetch user favorites', action, actionType)) + return []; }) ); }) @@ -95,11 +92,11 @@ export class UserFavoritesEffect { mergeMap(action => this.userFavoriteManager.getIsFavoriteObservable(action.favorite).pipe( first(), - map(isFav => { + switchMap(isFav => { if (isFav) { - return new RemoveUserFavoriteAction(action.favorite); + return [new RemoveUserFavoriteAction(action.favorite)]; } else { - return new SaveUserFavoriteAction(action.favorite); + return [new SaveUserFavoriteAction(action.favorite)]; } }) ) @@ -108,22 +105,42 @@ export class UserFavoritesEffect { @Effect({ dispatch: false }) removeFavorite$ = this.actions$.pipe( ofType(RemoveUserFavoriteAction.ACTION_TYPE), - switchMap((action: RemoveUserFavoriteAction) => { - const { guid } = action.favorite; - this.store.dispatch(new RemoveUserFavoriteSuccessAction(action.favorite)); - this.store.dispatch(new ClearPaginationOfEntity(userFavoritesEntitySchema, guid, userFavoritesPaginationKey)); - return this.http.delete>(`${favoriteUrlPath}/${guid}`); + mergeMap((action: RemoveUserFavoriteAction) => { + const actionType = 'update'; + this.store.dispatch(new StartRequestAction(action, actionType)) + return this.http.delete>(`${favoriteUrlPath}/${action.guid}`).pipe( + switchMap(() => { + this.store.dispatch(new WrapperRequestActionSuccess(null, action)); + this.store.dispatch(new RemoveUserFavoriteSuccessAction(action.favorite)); + this.store.dispatch(new ClearPaginationOfEntity(action.entity[0], action.guid, userFavoritesPaginationKey)); + return []; + }), + catchError(() => { + this.store.dispatch(new WrapperRequestActionFailed('Failed to remove user favorite', action, actionType)); + return []; + }) + ); }) ); @Effect() updateMetadata$ = this.actions$.pipe( ofType(UpdateUserFavoriteMetadataAction.ACTION_TYPE), mergeMap((action: UpdateUserFavoriteMetadataAction) => { + const actionType = 'update'; + this.store.dispatch(new StartRequestAction(action, actionType)) return this.http.post>( `${favoriteUrlPath}/${action.favorite.guid}/metadata`, action.favorite.metadata ).pipe( - map(() => new UpdateUserFavoriteMetadataSuccessAction(action.favorite)) + switchMap(() => { + this.store.dispatch(new WrapperRequestActionSuccess(null, action)); + this.store.dispatch(new UpdateUserFavoriteMetadataSuccessAction(action.favorite)); + return []; + }), + catchError(() => { + this.store.dispatch(new WrapperRequestActionFailed('Failed to update user favorite', action, actionType)); + return []; + }) ); }) ); diff --git a/src/frontend/packages/store/src/effects/user-profile.effects.ts b/src/frontend/packages/store/src/effects/user-profile.effects.ts index e273e9de17..9c010fee57 100644 --- a/src/frontend/packages/store/src/effects/user-profile.effects.ts +++ b/src/frontend/packages/store/src/effects/user-profile.effects.ts @@ -12,29 +12,16 @@ import { UpdateUserPasswordAction, UpdateUserProfileAction, } from '../actions/user-profile.actions'; -import { userProfileEntitySchema } from '../base-entity-schemas'; 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'; -import { - EntityRequestAction, - StartRequestAction, - WrapperRequestActionFailed, - WrapperRequestActionSuccess, -} from './../types/request.types'; - +import { StartRequestAction, WrapperRequestActionFailed, WrapperRequestActionSuccess } from './../types/request.types'; -export const userProfilePasswordUpdatingKey = 'password'; @Injectable() export class UserProfileEffect { - stratosUserConfig = entityCatalog.getEntity(userProfileEntitySchema.endpointType, userProfileEntitySchema.entityType); - private stratosUserEntityType = userProfileEntitySchema.entityType; - private stratosUserEndpointType = userProfileEntitySchema.endpointType; - constructor( private actions$: Actions, private store: Store, @@ -45,85 +32,66 @@ export class UserProfileEffect { ofType(GET_USERPROFILE), mergeMap(action => { this.store.dispatch(new StartRequestAction(action)); + const entityKey = entityCatalog.getEntityKey(action); return this.httpClient.get(`/pp/${proxyAPIVersion}/users/${action.userGuid}`).pipe( - mergeMap((info: UserProfileInfo) => { - return [ - new WrapperRequestActionSuccess({ - entities: { [this.stratosUserConfig.entityKey]: { [action.guid]: info } }, - result: [action.guid] - }, action) - ]; - }), catchError((e) => { - return [ - new WrapperRequestActionFailed('Could not get User Profile Info', action), - ]; - })); + mergeMap((info: UserProfileInfo) => [ + new WrapperRequestActionSuccess({ + entities: { [entityKey]: { [action.guid]: info } }, + result: [action.guid] + }, action) + ]), + catchError((e) => [ + new WrapperRequestActionFailed('Could not get User Profile Info', action), + ]) + ); })); @Effect() updateUserProfileInfo$ = this.actions$.pipe( ofType(UPDATE_USERPROFILE), - mergeMap(action => { - const apiAction = { - entityType: this.stratosUserEntityType, - endpointType: this.stratosUserEndpointType, - guid: FetchUserProfileAction.guid, - type: action.type, - updatingKey: rootUpdatingKey - } as EntityRequestAction; - const actionType = 'update'; - this.store.dispatch(new StartRequestAction(apiAction, actionType)); - const guid = action.profile.id; + mergeMap((action: UpdateUserProfileAction) => { + this.store.dispatch(new StartRequestAction(action, 'update')); + const userGuid = action.profile.id; const version = action.profile.meta.version; const headers = { 'If-Match': version.toString() }; if (action.password) { headers['x-stratos-password'] = action.password; } - return this.httpClient.put(`/pp/${proxyAPIVersion}/users/${guid}`, action.profile, { headers }).pipe( + return this.httpClient.put(`/pp/${proxyAPIVersion}/users/${userGuid}`, action.profile, { headers }).pipe( mergeMap((info: UserProfileInfo) => { return [ new WrapperRequestActionSuccess({ entities: {}, result: [] - }, apiAction), - ]; - }), catchError((e) => { - return [ - new WrapperRequestActionFailed('Could not update User Profile Info', apiAction), + }, action), ]; - })); + }), + catchError((e) => [ + new WrapperRequestActionFailed('Could not update User Profile Info', action), + ])); })); @Effect() updateUserPassword$ = this.actions$.pipe( ofType(UPDATE_USERPASSWORD), - mergeMap(action => { - const apiAction = { - entityType: this.stratosUserEntityType, - endpointType: this.stratosUserEndpointType, - guid: FetchUserProfileAction.guid, - type: action.type, - updatingKey: userProfilePasswordUpdatingKey - } as EntityRequestAction; - // Use the creating action for password change - const actionType = 'update'; - this.store.dispatch(new StartRequestAction(apiAction, actionType)); - const guid = action.id; + mergeMap((action: UpdateUserPasswordAction) => { + this.store.dispatch(new StartRequestAction(action, 'update')); + const userGuid = action.id; const headers = { 'x-stratos-password': action.passwordChanges.oldPassword, 'x-stratos-password-new': action.passwordChanges.password }; - return this.httpClient.put(`/pp/${proxyAPIVersion}/users/${guid}/password`, action.passwordChanges, { headers }).pipe( + return this.httpClient.put(`/pp/${proxyAPIVersion}/users/${userGuid}/password`, action.passwordChanges, { headers }).pipe( switchMap((info: UserProfileInfo) => { return [ new WrapperRequestActionSuccess({ entities: {}, result: [] - }, apiAction) - ]; - }), catchError((e) => { - return [ - new WrapperRequestActionFailed('Could not update User Password', apiAction), + }, action) ]; - })); + }), + catchError((e) => [ + new WrapperRequestActionFailed('Could not update User Password', action), + ]) + ); })); } diff --git a/src/frontend/packages/store/src/entity-catalog/entity-catalog-entity/entity-catalog-entity-store-helpers.ts b/src/frontend/packages/store/src/entity-catalog/entity-catalog-entity/entity-catalog-entity-store-helpers.ts index 2e88c4f518..0ad7cc9d67 100644 --- a/src/frontend/packages/store/src/entity-catalog/entity-catalog-entity/entity-catalog-entity-store-helpers.ts +++ b/src/frontend/packages/store/src/entity-catalog/entity-catalog-entity/entity-catalog-entity-store-helpers.ts @@ -122,6 +122,7 @@ export class EntityCatalogEntityStoreHelpers { if (!rAction.guid) { throw new Error(`\`${actionKey}\` action for entity \`${rAction.entityType}\` has no guid`); } + const entityMonitor = es.getEntityMonitor( rAction.guid, { @@ -147,9 +148,9 @@ export class EntityCatalogEntityStoreHelpers { schemaKey: '', startWithNull: false } - ): EntityMonitor => - new EntityMonitor(EntityCatalogHelpers.GetEntityCatalogHelper().store, entityId, entityKey, getSchema(params.schemaKey), params.startWithNull) - , + ): EntityMonitor => new EntityMonitor( + EntityCatalogHelpers.GetEntityCatalogHelper().store, entityId, entityKey, getSchema(params.schemaKey), params.startWithNull + ), getEntityService: ( ...args: Parameters ): EntityService => { diff --git a/src/frontend/packages/store/src/entity-catalog/entity-catalog-entity/entity-catalog-entity.ts b/src/frontend/packages/store/src/entity-catalog/entity-catalog-entity/entity-catalog-entity.ts index 08f5a882df..61bbc7883e 100644 --- a/src/frontend/packages/store/src/entity-catalog/entity-catalog-entity/entity-catalog-entity.ts +++ b/src/frontend/packages/store/src/entity-catalog/entity-catalog-entity/entity-catalog-entity.ts @@ -1,7 +1,6 @@ import { ActionReducer } from '@ngrx/store'; import { IRequestEntityTypeState } from '../../app-state'; -import { endpointEntitySchema, STRATOS_ENDPOINT_TYPE } from '../../base-entity-schemas'; import { getFullEndpointApiUrl } from '../../endpoint-utils'; import { EntitiesFetchHandler, @@ -14,6 +13,7 @@ import { } from '../../entity-request-pipeline/pagination-request-base-handlers/pagination-iterator.pipe'; import { EntityPipelineEntity, stratosEndpointGuidKey } from '../../entity-request-pipeline/pipeline.types'; import { EntitySchema } from '../../helpers/entity-schema'; +import { endpointEntityType, STRATOS_ENDPOINT_TYPE, stratosEntityFactory } from '../../helpers/stratos-entity-factory'; import { EndpointModel } from '../../types/endpoint.types'; import { APISuccessOrFailedAction, EntityRequestAction } from '../../types/request.types'; import { IEndpointFavMetadata } from '../../types/user-favorites.types'; @@ -316,7 +316,7 @@ export class StratosCatalogEntity< } export class StratosCatalogEndpointEntity extends StratosBaseCatalogEntity { - static readonly baseEndpointRender = { + static readonly baseEndpointRender: IStratosEntityBuilder = { getMetadata: endpoint => ({ name: endpoint.name, guid: endpoint.guid, @@ -332,19 +332,19 @@ export class StratosCatalogEndpointEntity extends StratosBaseCatalogEntity metadata.user], ['Admin', (metadata) => metadata.admin] ] - } as IStratosEntityBuilder; + }; // This is needed here for typing public definition: IStratosEndpointDefinition; constructor( entity: StratosEndpointExtensionDefinition | IStratosEndpointDefinition, getLink?: (metadata: IEndpointFavMetadata) => string ) { - const fullEntity = { + const fullEntity: IStratosEndpointDefinition = { ...entity, schema: { - default: endpointEntitySchema + default: stratosEntityFactory(endpointEntityType) } - } as IStratosEndpointDefinition; + }; super(fullEntity, { entityBuilder: { ...StratosCatalogEndpointEntity.baseEndpointRender, diff --git a/src/frontend/packages/store/src/entity-catalog/entity-catalog.spec.ts b/src/frontend/packages/store/src/entity-catalog/entity-catalog.spec.ts index bea826fdf0..7b2a0f4c5a 100644 --- a/src/frontend/packages/store/src/entity-catalog/entity-catalog.spec.ts +++ b/src/frontend/packages/store/src/entity-catalog/entity-catalog.spec.ts @@ -1,8 +1,8 @@ import { EndpointListDetailsComponent, } from '../../../core/src/shared/components/list/list-types/endpoint/endpoint-list.helpers'; -import { endpointEntitySchema } from '../base-entity-schemas'; import { EntitySchema } from '../helpers/entity-schema'; +import { endpointEntityType, stratosEntityFactory } from '../helpers/stratos-entity-factory'; import { TestEntityCatalog } from './entity-catalog'; import { StratosCatalogEndpointEntity, StratosCatalogEntity } from './entity-catalog-entity/entity-catalog-entity'; import { EntityCatalogSchemas, IStratosEndpointDefinition } from './entity-catalog.types'; @@ -106,7 +106,7 @@ fdescribe('EntityCatalogService', () => { expect(catalogEntity.definition).toEqual({ ...endpoint, schema: { - default: endpointEntitySchema + default: stratosEntityFactory(endpointEntityType) } }); }); @@ -138,7 +138,7 @@ fdescribe('EntityCatalogService', () => { iconFont: 'stratos-icons', listDetailsComponent: EndpointListDetailsComponent, schema: { - default: endpointEntitySchema + default: stratosEntityFactory(endpointEntityType) }, parentType: endpoint.type }; diff --git a/src/frontend/packages/store/src/entity-catalog/entity-catalog.ts b/src/frontend/packages/store/src/entity-catalog/entity-catalog.ts index 40665ba7af..5565256852 100644 --- a/src/frontend/packages/store/src/entity-catalog/entity-catalog.ts +++ b/src/frontend/packages/store/src/entity-catalog/entity-catalog.ts @@ -1,7 +1,7 @@ import { Action } from '@ngrx/store'; import { IRequestEntityTypeState } from '../app-state'; -import { STRATOS_ENDPOINT_TYPE } from '../base-entity-schemas'; +import { STRATOS_ENDPOINT_TYPE } from '../helpers/stratos-entity-factory'; import { ExtraApiReducers } from '../reducers/api-request-reducers.generator.helpers'; import { ICurrentUserRolesState } from '../types/current-user-roles.types'; import { OrchestratedActionBuilders } from './action-orchestrator/action-orchestrator'; diff --git a/src/frontend/packages/store/src/entity-request-pipeline/entity-request-base-handlers/endpoint-errors.handler.ts b/src/frontend/packages/store/src/entity-request-pipeline/entity-request-base-handlers/endpoint-errors.handler.ts index 8b6fc07532..3f335ec3c5 100644 --- a/src/frontend/packages/store/src/entity-request-pipeline/entity-request-base-handlers/endpoint-errors.handler.ts +++ b/src/frontend/packages/store/src/entity-request-pipeline/entity-request-base-handlers/endpoint-errors.handler.ts @@ -1,6 +1,6 @@ import { SendEventAction } from '../../actions/internal-events.actions'; import { StratosBaseCatalogEntity } from '../../entity-catalog/entity-catalog-entity/entity-catalog-entity'; -import { endpointSchemaKey } from '../../helpers/entity-factory'; +import { endpointEntityType } from '../../helpers/stratos-entity-factory'; import { ApiRequestTypes } from '../../reducers/api-request-reducer/request-helpers'; import { InternalEventSeverity, InternalEventStateMetadata } from '../../types/internal-events.types'; import { APISuccessOrFailedAction, EntityRequestAction } from '../../types/request.types'; @@ -28,7 +28,7 @@ export const endpointErrorsHandlerFactory = (actionDispatcher: ActionDispatcher) ) ); actionDispatcher( - new SendEventAction(endpointSchemaKey, error.guid, { + new SendEventAction(endpointEntityType, error.guid, { eventCode: error.errorCode, severity: InternalEventSeverity.ERROR, message: errorMessage, diff --git a/src/frontend/packages/store/src/entity-request-pipeline/entity-request-base-handlers/jetstream-error.handler.ts b/src/frontend/packages/store/src/entity-request-pipeline/entity-request-base-handlers/jetstream-error.handler.ts index d68ddd27ab..5b504a93fa 100644 --- a/src/frontend/packages/store/src/entity-request-pipeline/entity-request-base-handlers/jetstream-error.handler.ts +++ b/src/frontend/packages/store/src/entity-request-pipeline/entity-request-base-handlers/jetstream-error.handler.ts @@ -1,7 +1,7 @@ import { SendEventAction } from '../../actions/internal-events.actions'; import { RecursiveDeleteFailed } from '../../effects/recursive-entity-delete.effect'; import { StratosBaseCatalogEntity } from '../../entity-catalog/entity-catalog-entity/entity-catalog-entity'; -import { endpointSchemaKey } from '../../helpers/entity-factory'; +import { endpointEntityType } from '../../helpers/stratos-entity-factory'; import { ApiRequestTypes, getFailApiRequestActions } from '../../reducers/api-request-reducer/request-helpers'; import { GLOBAL_EVENT, InternalEventSeverity, InternalEventStateMetadata } from '../../types/internal-events.types'; import { EntityRequestAction } from '../../types/request.types'; @@ -26,7 +26,7 @@ export function jetstreamErrorHandler( if (endpointString) { endpointIds.forEach(endpoint => actionDispatcher( - new SendEventAction(endpointSchemaKey, endpoint, { + new SendEventAction(endpointEntityType, endpoint, { eventCode: error.status ? error.status + '' : '500', severity: InternalEventSeverity.ERROR, message: 'Jetstream API request error', diff --git a/src/frontend/packages/store/src/entity-service.spec.ts b/src/frontend/packages/store/src/entity-service.spec.ts index 8a754fbaae..ad52aab1fb 100644 --- a/src/frontend/packages/store/src/entity-service.spec.ts +++ b/src/frontend/packages/store/src/entity-service.spec.ts @@ -4,12 +4,9 @@ import { inject, TestBed } from '@angular/core/testing'; import { Action, Store } from '@ngrx/store'; import { filter, first, map, pairwise, tap } from 'rxjs/operators'; -import { ENTITY_SERVICE } from '../../core/src/shared/entity.tokens'; -import { generateTestEntityServiceProvider } from '../../core/test-framework/entity-service.helper'; import { createEntityStore, TestStoreEntity } from '../testing/src/store-test-helper'; import { APIResponse } from './actions/request.actions'; import { GeneralAppState } from './app-state'; -import { STRATOS_ENDPOINT_TYPE } from './base-entity-schemas'; import { EntityCatalogTestModule, TEST_CATALOGUE_ENTITIES } from './entity-catalog-test.module'; import { StratosBaseCatalogEntity } from './entity-catalog/entity-catalog-entity/entity-catalog-entity'; import { EntityCatalogEntityConfig, IStratosEndpointDefinition } from './entity-catalog/entity-catalog.types'; @@ -18,6 +15,7 @@ import { PipelineResult } from './entity-request-pipeline/entity-request-pipelin import { EntityService } from './entity-service'; import { EntityServiceFactory } from './entity-service-factory.service'; import { EntitySchema } from './helpers/entity-schema'; +import { STRATOS_ENDPOINT_TYPE } from './helpers/stratos-entity-factory'; import { EntityMonitor } from './monitors/entity-monitor'; import { EntityMonitorFactory } from './monitors/entity-monitor.factory.service'; import { completeApiRequest, startApiRequest } from './reducers/api-request-reducer/request-helpers'; @@ -143,11 +141,6 @@ describe('EntityServiceService', () => { providers: [ EntityServiceFactory, EntityMonitorFactory, - generateTestEntityServiceProvider( - action.guid, - entitySchema, - action - ), { provide: HttpXhrBackend, useClass: HttpTestingController @@ -170,20 +163,6 @@ describe('EntityServiceService', () => { }); }); - it('should be created', inject([ENTITY_SERVICE], (service: EntityService) => { - expect(service).toBeTruthy(); - })); - - it('should poll', (done) => { - inject([ENTITY_SERVICE, HttpXhrBackend], (service: EntityService, mockBackend: HttpTestingController) => { - const sub = service.poll(1, '_root_').subscribe(a => { - sub.unsubscribe(); - expect('polled once').toEqual('polled once'); - done(); - }); - })(); - }); - it('should get application', (done) => { inject([Store], (store: Store) => { const guid = 'GUID123456789x'; diff --git a/src/frontend/packages/store/src/favorite-config-mapper.ts b/src/frontend/packages/store/src/favorite-config-mapper.ts index 76b8a8e2b2..8fa3cd6890 100644 --- a/src/frontend/packages/store/src/favorite-config-mapper.ts +++ b/src/frontend/packages/store/src/favorite-config-mapper.ts @@ -160,13 +160,13 @@ export class FavoritesConfigMapper { public getFavoriteEndpointFromEntity( endpoint: EndpointModel - ) { + ): UserFavoriteEndpoint { return this.getFavoriteFromEntity( EntityCatalogHelpers.endpointType, endpoint.cnsi_type, endpoint.guid, endpoint - ) as UserFavoriteEndpoint; + ); } } diff --git a/src/frontend/packages/store/src/helpers/entity-factory.ts b/src/frontend/packages/store/src/helpers/entity-factory.ts deleted file mode 100644 index c10311c3de..0000000000 --- a/src/frontend/packages/store/src/helpers/entity-factory.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { EntitySchema } from './entity-schema'; - -export const userFavouritesSchemaKey = 'userFavorites'; -export const endpointSchemaKey = 'endpoint'; -export const userProfileSchemaKey = 'userProfile'; -export const systemInfoSchemaKey = 'system'; - -const entityCache: { - [key: string]: EntitySchema -} = {}; - -// Note - The cache entry is added as a secondary step. This helps keep the child entity definition's clear and easier to spot circular -// dependencies which would otherwise be hidden (if we assigned directly to entityCache and references via entityCache in other entities) -const UserFavouritesSchema = new EntitySchema(userFavouritesSchemaKey, null, {}, { idAttribute: 'id' }); -entityCache[userFavouritesSchemaKey] = UserFavouritesSchema; - -const SystemInfoSchema = new EntitySchema(systemInfoSchemaKey, null, {}, { idAttribute: 'id' }); -entityCache[systemInfoSchemaKey] = SystemInfoSchema; - -const EndpointSchema = new EntitySchema(endpointSchemaKey, null, {}, { idAttribute: 'guid' }); -entityCache[endpointSchemaKey] = EndpointSchema; - -const UserProfileInfoSchema = new EntitySchema(userProfileSchemaKey, null, {}, { idAttribute: 'id' }); -entityCache[userProfileSchemaKey] = UserProfileInfoSchema; - -export function entityFactory(key: string): EntitySchema { - const entity = entityCache[key]; - if (!entity) { - throw new Error(`Unknown entity schema type: ${key}`); - } - return entity; -} diff --git a/src/frontend/packages/store/src/helpers/stratos-entity-factory.ts b/src/frontend/packages/store/src/helpers/stratos-entity-factory.ts new file mode 100644 index 0000000000..1182c576a3 --- /dev/null +++ b/src/frontend/packages/store/src/helpers/stratos-entity-factory.ts @@ -0,0 +1,40 @@ +import { EntitySchema } from './entity-schema'; + +export const userFavouritesEntityType = 'userFavorites'; +export const endpointEntityType = 'endpoint'; +export const userProfileEntityType = 'userProfile'; +export const systemInfoEntityType = 'systemInfo'; + +export const metricEntityType = 'metrics'; + +export const STRATOS_ENDPOINT_TYPE = 'stratos'; + +const entityCache: { + [key: string]: EntitySchema +} = {}; + +class StratosEntitySchema extends EntitySchema { + constructor(entityType: string, idAttribute: string) { + super(entityType, STRATOS_ENDPOINT_TYPE, {}, { idAttribute }); + } +} + +const UserFavouritesSchema = new StratosEntitySchema(userFavouritesEntityType, 'guid'); +entityCache[userFavouritesEntityType] = UserFavouritesSchema; + +const SystemInfoSchema = new StratosEntitySchema(systemInfoEntityType, 'guid'); +entityCache[systemInfoEntityType] = SystemInfoSchema; + +const EndpointSchema = new StratosEntitySchema(endpointEntityType, 'guid'); +entityCache[endpointEntityType] = EndpointSchema; + +const UserProfileInfoSchema = new StratosEntitySchema(userProfileEntityType, 'id'); +entityCache[userProfileEntityType] = UserProfileInfoSchema; + +export function stratosEntityFactory(key: string): EntitySchema { + const entity = entityCache[key]; + if (!entity) { + throw new Error(`Unknown entity schema type: ${key}`); + } + return entity; +} \ No newline at end of file diff --git a/src/frontend/packages/store/src/reducers/current-user-roles-reducer/recently-visited.reducer.ts b/src/frontend/packages/store/src/reducers/current-user-roles-reducer/recently-visited.reducer.ts index b69b7779aa..ead7fd092e 100644 --- a/src/frontend/packages/store/src/reducers/current-user-roles-reducer/recently-visited.reducer.ts +++ b/src/frontend/packages/store/src/reducers/current-user-roles-reducer/recently-visited.reducer.ts @@ -8,9 +8,8 @@ import { UNREGISTER_ENDPOINTS_SUCCESS, } from '../../actions/endpoint.actions'; import { AddRecentlyVisitedEntityAction, SetRecentlyVisitedEntityAction } from '../../actions/recently-visited.actions'; -import { STRATOS_ENDPOINT_TYPE } from '../../base-entity-schemas'; import { entityCatalog } from '../../entity-catalog/entity-catalog'; -import { endpointSchemaKey } from '../../helpers/entity-factory'; +import { endpointEntityType, STRATOS_ENDPOINT_TYPE } from '../../helpers/stratos-entity-factory'; import { IRecentlyVisitedState } from '../../types/recently-visited.types'; import { addNewHit, cleanRecentsList, getDefaultRecentState } from './recently-visited.reducer.helpers'; @@ -36,7 +35,7 @@ export function recentlyVisitedReducer( return cleanRecentsList(state, [removeEndpointAction.guid]); case GET_ENDPOINTS_SUCCESS: const getAllAction = action as GetAllEndpointsSuccess; - const endpointKey = entityCatalog.getEntityKey(STRATOS_ENDPOINT_TYPE, endpointSchemaKey); + const endpointKey = entityCatalog.getEntityKey(STRATOS_ENDPOINT_TYPE, endpointEntityType); const connectedIds = Object.values(getAllAction.payload.entities[endpointKey]).reduce((ids, endpoint) => { if (endpoint.user) { ids.push(endpoint.guid); diff --git a/src/frontend/packages/store/src/reducers/current-user-roles-reducer/user-favorites-groups.reducer.spec.ts b/src/frontend/packages/store/src/reducers/current-user-roles-reducer/user-favorites-groups.reducer.spec.ts index 2d64c4610c..3afec96484 100644 --- a/src/frontend/packages/store/src/reducers/current-user-roles-reducer/user-favorites-groups.reducer.spec.ts +++ b/src/frontend/packages/store/src/reducers/current-user-roles-reducer/user-favorites-groups.reducer.spec.ts @@ -2,9 +2,9 @@ import { GetUserFavoritesAction, GetUserFavoritesFailedAction, GetUserFavoritesSuccessAction, -} from '../../actions/user-favourites-actions/get-user-favorites-action'; -import { RemoveUserFavoriteSuccessAction } from '../../actions/user-favourites-actions/remove-user-favorite-action'; -import { SaveUserFavoriteSuccessAction } from '../../actions/user-favourites-actions/save-user-favorite-action'; + RemoveUserFavoriteSuccessAction, + SaveUserFavoriteSuccessAction, +} from '../../actions/user-favourites.actions'; import { getDefaultFavoriteGroupsState, IUserFavoritesGroupsState } from '../../types/favorite-groups.types'; import { IEndpointFavMetadata, UserFavorite } from '../../types/user-favorites.types'; import { deriveEndpointFavoriteFromFavorite } from '../../user-favorite-helpers'; diff --git a/src/frontend/packages/store/src/reducers/current-user-roles-reducer/user-favorites-groups.reducer.ts b/src/frontend/packages/store/src/reducers/current-user-roles-reducer/user-favorites-groups.reducer.ts index 30e33e8c01..463b41c655 100644 --- a/src/frontend/packages/store/src/reducers/current-user-roles-reducer/user-favorites-groups.reducer.ts +++ b/src/frontend/packages/store/src/reducers/current-user-roles-reducer/user-favorites-groups.reducer.ts @@ -4,9 +4,9 @@ import { GetUserFavoritesAction, GetUserFavoritesFailedAction, GetUserFavoritesSuccessAction, -} from '../../actions/user-favourites-actions/get-user-favorites-action'; -import { RemoveUserFavoriteSuccessAction } from '../../actions/user-favourites-actions/remove-user-favorite-action'; -import { SaveUserFavoriteSuccessAction } from '../../actions/user-favourites-actions/save-user-favorite-action'; + RemoveUserFavoriteSuccessAction, + SaveUserFavoriteSuccessAction, +} from '../../actions/user-favourites.actions'; import { getDefaultFavoriteGroup, getDefaultFavoriteGroupsState, diff --git a/src/frontend/packages/store/src/reducers/endpoints.reducer.ts b/src/frontend/packages/store/src/reducers/endpoints.reducer.ts index 1a5796c694..662f1c0ebb 100644 --- a/src/frontend/packages/store/src/reducers/endpoints.reducer.ts +++ b/src/frontend/packages/store/src/reducers/endpoints.reducer.ts @@ -1,11 +1,14 @@ import { GET_ENDPOINTS, GET_ENDPOINTS_FAILED, GET_ENDPOINTS_SUCCESS } from '../actions/endpoint.actions'; import { EndpointState } from '../types/endpoint.types'; -export function endpointsReducer(state: EndpointState = { - loading: false, - error: false, - message: '' -}, action): EndpointState { +export function endpointsReducer( + state: EndpointState = { + loading: false, + error: false, + message: '' + }, + action +): EndpointState { switch (action.type) { case GET_ENDPOINTS: return { ...state, loading: true, message: '', error: false }; diff --git a/src/frontend/packages/store/src/reducers/favorite.reducer.ts b/src/frontend/packages/store/src/reducers/favorite.reducer.ts index 31165eb6bd..04a98983be 100644 --- a/src/frontend/packages/store/src/reducers/favorite.reducer.ts +++ b/src/frontend/packages/store/src/reducers/favorite.reducer.ts @@ -1,8 +1,8 @@ -import { RemoveUserFavoriteSuccessAction } from '../actions/user-favourites-actions/remove-user-favorite-action'; -import { SaveUserFavoriteSuccessAction } from '../actions/user-favourites-actions/save-user-favorite-action'; import { + RemoveUserFavoriteSuccessAction, + SaveUserFavoriteSuccessAction, UpdateUserFavoriteMetadataSuccessAction, -} from '../actions/user-favourites-actions/update-user-favorite-metadata-action'; +} from '../actions/user-favourites.actions'; import { IRequestEntityTypeState } from '../app-state'; import { IFavoriteMetadata, UserFavorite } from '../types/user-favorites.types'; @@ -27,7 +27,7 @@ export function deleteUserFavoriteMetadataReducer( ): IRequestEntityTypeState> { if (action.type === RemoveUserFavoriteSuccessAction.ACTION_TYPE) { const { - [action.favorite.guid]: deletedFavorite, + [action.guid]: deletedFavorite, ...newState } = state; return newState; diff --git a/src/frontend/packages/store/src/reducers/internal-events.reducer.ts b/src/frontend/packages/store/src/reducers/internal-events.reducer.ts index c6b2a9ec59..277e067439 100644 --- a/src/frontend/packages/store/src/reducers/internal-events.reducer.ts +++ b/src/frontend/packages/store/src/reducers/internal-events.reducer.ts @@ -1,27 +1,27 @@ -import { UPDATE_ENDPOINT_SUCCESS } from './../actions/endpoint.actions'; import { Action } from '@ngrx/store'; +import { + CONNECT_ENDPOINTS_SUCCESS, + DISCONNECT_ENDPOINTS_SUCCESS, + DisconnectEndpoint, + UNREGISTER_ENDPOINTS_SUCCESS, +} from '../actions/endpoint.actions'; import { SendClearEndpointEventsAction, SendClearEventAction, SendEventAction } from '../actions/internal-events.actions'; +import { endpointEntityType } from '../helpers/stratos-entity-factory'; import { + CLEAR_ENDPOINT_ERROR_EVENTS, CLEAR_EVENTS, GLOBAL_EVENT, InternalEventsState, InternalEventState, SEND_EVENT, - CLEAR_ENDPOINT_ERROR_EVENTS, } from '../types/internal-events.types'; -import { endpointSchemaKey } from './../helpers/entity-factory'; -import { - DISCONNECT_ENDPOINTS_SUCCESS, - DisconnectEndpoint, - UNREGISTER_ENDPOINTS_SUCCESS, - CONNECT_ENDPOINTS_SUCCESS -} from '../actions/endpoint.actions'; +import { UPDATE_ENDPOINT_SUCCESS } from './../actions/endpoint.actions'; const defaultState: InternalEventsState = { types: { [GLOBAL_EVENT]: {}, - [endpointSchemaKey]: {} + [endpointEntityType]: {} } }; diff --git a/src/frontend/packages/store/src/reducers/pagination-reducer/pagination-reducer-clear-pagination-type.ts b/src/frontend/packages/store/src/reducers/pagination-reducer/pagination-reducer-clear-pagination-type.ts index 61cc841a8a..aaf5dafbaf 100644 --- a/src/frontend/packages/store/src/reducers/pagination-reducer/pagination-reducer-clear-pagination-type.ts +++ b/src/frontend/packages/store/src/reducers/pagination-reducer/pagination-reducer-clear-pagination-type.ts @@ -1,4 +1,4 @@ -import { EndpointAction } from '../../actions/endpoint.actions'; +import { EndpointActionComplete } from '../../actions/endpoint.actions'; import { entityCatalog } from '../../entity-catalog/entity-catalog'; import { PaginationState } from '../../types/pagination.types'; import { getDefaultPaginationEntityState } from './pagination-reducer-reset-pagination'; @@ -23,7 +23,7 @@ export function paginationClearAllTypes(state: PaginationState, entityKeys: stri }, state); } -export function clearEndpointEntities(state: PaginationState, action: EndpointAction) { +export function clearEndpointEntities(state: PaginationState, action: EndpointActionComplete) { const entityKeys = entityCatalog.getAllEntitiesForEndpointType(action.endpointType).map(entity => entity.entityKey); if (entityKeys.length > 0) { return paginationClearAllTypes( diff --git a/src/frontend/packages/store/src/reducers/pagination-reducer/pagination-reducer-create-pagination.spec.ts b/src/frontend/packages/store/src/reducers/pagination-reducer/pagination-reducer-create-pagination.spec.ts index d9c0465284..047f677ad6 100644 --- a/src/frontend/packages/store/src/reducers/pagination-reducer/pagination-reducer-create-pagination.spec.ts +++ b/src/frontend/packages/store/src/reducers/pagination-reducer/pagination-reducer-create-pagination.spec.ts @@ -1,5 +1,5 @@ -import { entityCatalog } from '../../entity-catalog/entity-catalog'; import { CreatePagination } from '../../actions/pagination.actions'; +import { entityCatalog } from '../../entity-catalog/entity-catalog'; import { PaginationState } from '../../types/pagination.types'; import { createNewPaginationSection } from './pagination-reducer-create-pagination'; import { getDefaultPaginationEntityState } from './pagination-reducer-reset-pagination'; diff --git a/src/frontend/packages/store/src/reducers/pagination-reducer/pagination.reducer.spec.ts b/src/frontend/packages/store/src/reducers/pagination-reducer/pagination.reducer.spec.ts index 95d840e19d..cd0fe5bc3b 100644 --- a/src/frontend/packages/store/src/reducers/pagination-reducer/pagination.reducer.spec.ts +++ b/src/frontend/packages/store/src/reducers/pagination-reducer/pagination.reducer.spec.ts @@ -1,10 +1,10 @@ import { HttpRequest } from '@angular/common/http'; import { RequestTypes } from '../../actions/request.actions'; -import { ENDPOINT_TYPE, endpointEntitySchema, STRATOS_ENDPOINT_TYPE } from '../../base-entity-schemas'; import { entityCatalog } from '../../entity-catalog/entity-catalog'; import { EntityCatalogHelpers } from '../../entity-catalog/entity-catalog.helper'; import { EntitySchema } from '../../helpers/entity-schema'; +import { endpointEntityType, STRATOS_ENDPOINT_TYPE, stratosEntityFactory } from '../../helpers/stratos-entity-factory'; import { PaginatedAction } from '../../types/pagination.types'; import { StartRequestAction, WrapperRequestActionFailed, WrapperRequestActionSuccess } from '../../types/request.types'; import { createPaginationReducer } from './pagination.reducer'; @@ -20,8 +20,8 @@ function getReducer() { class MockPagAction implements PaginatedAction { actions = ['ONE', 'TWO', 'THREE']; options = new HttpRequest('GET', 'fake123'); - entity = endpointEntitySchema; - entityType = ENDPOINT_TYPE; + entity = stratosEntityFactory(endpointEntityType); + entityType = endpointEntityType; endpointType = STRATOS_ENDPOINT_TYPE; paginationKey = 'PaginationKey'; type = RequestTypes.START; diff --git a/src/frontend/packages/store/src/selectors/api.selectors.ts b/src/frontend/packages/store/src/selectors/api.selectors.ts index 4aecb698d7..ed793c7678 100644 --- a/src/frontend/packages/store/src/selectors/api.selectors.ts +++ b/src/frontend/packages/store/src/selectors/api.selectors.ts @@ -1,8 +1,8 @@ import { compose } from '@ngrx/store'; +import { GeneralEntityAppState, IRequestEntityTypeState as IRequestEntityKeyState, IRequestTypeState } from '../app-state'; import { EntityCatalogHelpers } from '../entity-catalog/entity-catalog.helper'; import { EntityCatalogEntityConfig } from '../entity-catalog/entity-catalog.types'; -import { GeneralEntityAppState, IRequestEntityTypeState as IRequestEntityKeyState, IRequestTypeState } from '../app-state'; import { ActionState, RequestInfoState, UpdatingSection } from '../reducers/api-request-reducer/types'; import { APIResource } from '../types/api.types'; diff --git a/src/frontend/packages/store/src/selectors/endpoint.selectors.ts b/src/frontend/packages/store/src/selectors/endpoint.selectors.ts index 59c191d9c9..a77a92e217 100644 --- a/src/frontend/packages/store/src/selectors/endpoint.selectors.ts +++ b/src/frontend/packages/store/src/selectors/endpoint.selectors.ts @@ -1,9 +1,8 @@ import { compose } from '@ngrx/store'; import { InternalAppState, IRequestEntityTypeState } from '../app-state'; -import { STRATOS_ENDPOINT_TYPE } from '../base-entity-schemas'; import { EntityCatalogHelpers } from '../entity-catalog/entity-catalog.helper'; -import { endpointSchemaKey } from '../helpers/entity-factory'; +import { endpointEntityType, STRATOS_ENDPOINT_TYPE } from '../helpers/stratos-entity-factory'; import { EndpointModel, EndpointState } from '../types/endpoint.types'; import { selectEntities, selectEntity, selectRequestInfo } from './api.selectors'; @@ -12,10 +11,10 @@ export const endpointStatusSelector = (state: InternalAppState): EndpointState = // All endpoint request data // Note - Replacing `buildEntityKey` with `entityCatalog.getEntityKey` will cause circular dependency -const endpointEntityKey = EntityCatalogHelpers.buildEntityKey(endpointSchemaKey, STRATOS_ENDPOINT_TYPE); +const endpointEntityKey = EntityCatalogHelpers.buildEntityKey(endpointEntityType, STRATOS_ENDPOINT_TYPE); export const endpointEntitiesSelector = selectEntities(endpointEntityKey); -export const endpointOfType = (type: string) => +const endpointOfType = (type: string) => (endpoints: IRequestEntityTypeState): IRequestEntityTypeState => { return Object.values(endpoints || {}).reduce((endpointsOfType, endpoint) => { if (endpoint.cnsi_type === type) { diff --git a/src/frontend/packages/store/src/selectors/favorite-groups.selectors.ts b/src/frontend/packages/store/src/selectors/favorite-groups.selectors.ts index 25fb934666..12139d6f78 100644 --- a/src/frontend/packages/store/src/selectors/favorite-groups.selectors.ts +++ b/src/frontend/packages/store/src/selectors/favorite-groups.selectors.ts @@ -1,13 +1,13 @@ import { compose } from '@ngrx/store'; import { InternalAppState, IRequestEntityTypeState } from '../app-state'; -import { STRATOS_ENDPOINT_TYPE, userFavoritesEntitySchema } from '../base-entity-schemas'; import { entityCatalog } from '../entity-catalog/entity-catalog'; +import { STRATOS_ENDPOINT_TYPE, userFavouritesEntityType } from '../helpers/stratos-entity-factory'; import { IUserFavoriteGroup, IUserFavoritesGroups, IUserFavoritesGroupsState } from '../types/favorite-groups.types'; import { IFavoriteMetadata, UserFavorite } from '../types/user-favorites.types'; import { deriveEndpointFavoriteFromFavorite } from '../user-favorite-helpers'; -const favoritesEntityKey = entityCatalog.getEntityKey(STRATOS_ENDPOINT_TYPE, userFavoritesEntitySchema.entityType); +const favoritesEntityKey = entityCatalog.getEntityKey(STRATOS_ENDPOINT_TYPE, userFavouritesEntityType); export const favoriteEntitiesSelector = (state: InternalAppState): IRequestEntityTypeState> => state.requestData[favoritesEntityKey]; diff --git a/src/frontend/packages/store/src/stratos-action-builders.ts b/src/frontend/packages/store/src/stratos-action-builders.ts new file mode 100644 index 0000000000..c64a95cd01 --- /dev/null +++ b/src/frontend/packages/store/src/stratos-action-builders.ts @@ -0,0 +1,198 @@ +import { + AuthParams, + BaseEndpointAction, + ConnectEndpoint, + DisconnectEndpoint, + GetAllEndpoints, + GetEndpoint, + RegisterEndpoint, + UnregisterEndpoint, + UpdateEndpoint, +} from './actions/endpoint.actions'; +import { GetSystemInfo } from './actions/system.actions'; +import { + GetUserFavoritesAction, + RemoveUserFavoriteAction, + SaveUserFavoriteAction, + ToggleUserFavoriteAction, + UpdateUserFavoriteMetadataAction, +} from './actions/user-favourites.actions'; +import { FetchUserProfileAction, UpdateUserPasswordAction, UpdateUserProfileAction } from './actions/user-profile.actions'; +import { OrchestratedActionBuilders } from './entity-catalog/action-orchestrator/action-orchestrator'; +import { EndpointType } from './extension-types'; +import { IFavoriteMetadata, UserFavorite } from './types/user-favorites.types'; +import { UserProfileInfo, UserProfilePasswordUpdate } from './types/user-profile.types'; + +export interface EndpointActionBuilder extends OrchestratedActionBuilders { + get: ( + guid: string, + ) => GetEndpoint, + getAll: ( + login?: boolean, + ) => GetAllEndpoints, + getMultiple: ( + endpointGuid?: string, + paginationKey?: string, + args?: { login: boolean } + ) => GetAllEndpoints, + connect: ( + guid: string, + endpointType: EndpointType, + authType: string, + authValues: AuthParams, + systemShared: boolean, + body: string, + ) => ConnectEndpoint, + disconnect: ( + guid: string, + endpointType: EndpointType, + ) => DisconnectEndpoint, + unregister: ( + guid: string, + endpointType: EndpointType, + ) => UnregisterEndpoint, + register: ( + endpointType: EndpointType, + endpointSubType: string, + name: string, + endpoint: string, + skipSslValidation: boolean, + clientID?: string, + clientSecret?: string, + ssoAllowed?: boolean, + ) => RegisterEndpoint, + update: ( + guid: string, + endpointGuid: string, + args: { + endpointType: EndpointType, + id: string, + name: string, + skipSSL: boolean, + setClientInfo: boolean, + clientID: string, + clientSecret: string, + allowSSO: boolean, + } + ) => UpdateEndpoint, +} + +export const endpointActionBuilder: EndpointActionBuilder = { + get: (guid: string) => new GetEndpoint(guid), + getAll: (login: boolean) => new GetAllEndpoints(login), + getMultiple: ( + endpointGuid?: string, + paginationKey?: string, + args?: { login: boolean } + ) => new GetAllEndpoints(args ? args.login : false), + connect: ( + guid: string, + endpointType: EndpointType, + authType: string, + authValues: AuthParams, + systemShared: boolean, + body: string, + ) => new ConnectEndpoint(guid, endpointType, authType, authValues, systemShared, body), + disconnect: (guid: string, endpointType: EndpointType) => new DisconnectEndpoint(guid, endpointType), + unregister: (guid: string, endpointType: EndpointType) => new UnregisterEndpoint(guid, endpointType), + register: ( + endpointType: EndpointType, + endpointSubType: string, + name: string, + endpoint: string, + skipSslValidation: boolean, + clientID?: string, + clientSecret?: string, + ssoAllowed?: boolean, + ) => new RegisterEndpoint( + endpointType, + endpointSubType, + name, + endpoint, + skipSslValidation, + clientID, + clientSecret, + ssoAllowed, + ), + update: ( + guid: string, + endpointGuid: string, + args: { + endpointType: EndpointType, + // id: string, + name: string, + skipSSL: boolean, + setClientInfo: boolean, + clientID: string, + clientSecret: string, + allowSSO: boolean, + } + ) => new UpdateEndpoint( + args.endpointType, + guid, + args.name, + args.skipSSL, + args.setClientInfo, + args.clientID, + args.clientSecret, + args.allowSSO + ), +} + +export interface SystemInfoActionBuilder extends OrchestratedActionBuilders { + getSystemInfo: ( + login?: boolean, + associatedAction?: BaseEndpointAction + ) => GetSystemInfo +} +export const systemInfoActionBuilder: SystemInfoActionBuilder = { + getSystemInfo: ( + login?: false, + associatedAction?: BaseEndpointAction + ) => new GetSystemInfo(login, associatedAction) +} + +export interface UserFavoriteActionBuilder extends OrchestratedActionBuilders { + getMultiple: () => GetUserFavoritesAction, + getAll: () => GetUserFavoritesAction, + delete: ( + favorite: UserFavorite + ) => RemoveUserFavoriteAction, + save: ( + favorite: UserFavorite + ) => SaveUserFavoriteAction, + toggle: ( + favorite: UserFavorite + ) => ToggleUserFavoriteAction + updateFavorite: ( + favorite: UserFavorite + ) => UpdateUserFavoriteMetadataAction +} + +export const userFavoriteActionBuilder: UserFavoriteActionBuilder = { + getMultiple: () => new GetUserFavoritesAction(), + getAll: () => new GetUserFavoritesAction(), + delete: (favorite: UserFavorite) => new RemoveUserFavoriteAction(favorite), + save: (favorite: UserFavorite) => new SaveUserFavoriteAction(favorite), + toggle: (favorite: UserFavorite) => new ToggleUserFavoriteAction(favorite), + updateFavorite: (favorite: UserFavorite) => new UpdateUserFavoriteMetadataAction(favorite) +} + +export interface UserProfileActionBuilder extends OrchestratedActionBuilders { + get: ( + userGuid: string + ) => FetchUserProfileAction + updateProfile: ( + profile: UserProfileInfo, + password: string + ) => UpdateUserProfileAction + updatePassword: ( + guid: string, + passwordChanges: UserProfilePasswordUpdate + ) => UpdateUserPasswordAction +} +export const userProfileActionBuilder: UserProfileActionBuilder = { + get: (userGuid: string) => new FetchUserProfileAction(userGuid), + updateProfile: (profile: UserProfileInfo, password: string) => new UpdateUserProfileAction(profile, password), + updatePassword: (guid: string, passwordChanges: UserProfilePasswordUpdate) => new UpdateUserPasswordAction(guid, passwordChanges) +} \ No newline at end of file diff --git a/src/frontend/packages/store/src/stratos-entity-catalog.ts b/src/frontend/packages/store/src/stratos-entity-catalog.ts new file mode 100644 index 0000000000..9237a16978 --- /dev/null +++ b/src/frontend/packages/store/src/stratos-entity-catalog.ts @@ -0,0 +1,45 @@ +import { + StratosCatalogEndpointEntity, + StratosCatalogEntity, +} from './entity-catalog/entity-catalog-entity/entity-catalog-entity'; +import { + EndpointActionBuilder, + SystemInfoActionBuilder, + UserFavoriteActionBuilder, + UserProfileActionBuilder, +} from './stratos-action-builders'; +import { EndpointModel } from './types/endpoint.types'; +import { SystemInfo } from './types/system.types'; +import { UserFavorite } from './types/user-favorites.types'; +import { UserProfileInfo } from './types/user-profile.types'; + +export class StratosEntityCatalog { + endpoint: StratosCatalogEntity< + undefined, + EndpointModel, + EndpointActionBuilder + > + + systemInfo: StratosCatalogEntity< + undefined, + SystemInfo, + SystemInfoActionBuilder + > + + userFavorite: StratosCatalogEntity< + undefined, + UserFavorite, + UserFavoriteActionBuilder + > + + userProfile: StratosCatalogEntity< + undefined, + UserProfileInfo, + UserProfileActionBuilder + > + + metricsEndpoint: StratosCatalogEndpointEntity; +} + +export const stratosEntityCatalog = new StratosEntityCatalog(); + diff --git a/src/frontend/packages/store/src/stratos-entity-generator.ts b/src/frontend/packages/store/src/stratos-entity-generator.ts new file mode 100644 index 0000000000..0062f4fc4a --- /dev/null +++ b/src/frontend/packages/store/src/stratos-entity-generator.ts @@ -0,0 +1,161 @@ +import { BaseEndpointAuth } from '../../core/src/core/endpoint-auth'; +import { + MetricsEndpointDetailsComponent, +} from '../../core/src/features/metrics/metrics-endpoint-details/metrics-endpoint-details.component'; +import { + StratosBaseCatalogEntity, + StratosCatalogEndpointEntity, + StratosCatalogEntity, +} from '../../store/src/entity-catalog/entity-catalog-entity/entity-catalog-entity'; +import { + endpointEntityType, + STRATOS_ENDPOINT_TYPE, + stratosEntityFactory, + systemInfoEntityType, + userFavouritesEntityType, + userProfileEntityType, +} from '../../store/src/helpers/stratos-entity-factory'; +import { + addOrUpdateUserFavoriteMetadataReducer, + deleteUserFavoriteMetadataReducer, +} from '../../store/src/reducers/favorite.reducer'; +import { systemEndpointsReducer } from '../../store/src/reducers/system-endpoints.reducer'; +import { EndpointModel } from '../../store/src/types/endpoint.types'; +import { IStratosEntityDefinition } from './entity-catalog/entity-catalog.types'; +import { + EndpointActionBuilder, + endpointActionBuilder, + SystemInfoActionBuilder, + systemInfoActionBuilder, + UserFavoriteActionBuilder, + userFavoriteActionBuilder, + UserProfileActionBuilder, + userProfileActionBuilder, +} from './stratos-action-builders'; +import { stratosEntityCatalog } from './stratos-entity-catalog'; +import { SystemInfo } from './types/system.types'; +import { UserFavorite } from './types/user-favorites.types'; +import { UserProfileInfo } from './types/user-profile.types'; + +export function generateStratosEntities(): StratosBaseCatalogEntity[] { + /** + * This is used as a fake endpoint type to allow the store to be initiated correctly + */ + const stratosType = { + logoUrl: '', + authTypes: [], + type: STRATOS_ENDPOINT_TYPE, + schema: null + } + return [ + generateEndpoint(stratosType), + generateSystemInfo(stratosType), + generateUserFavorite(stratosType), + generateUserProfile(stratosType), + generateMetricsEndpoint() + ] +} + +/** + * DefaultEndpointEntityType is used to represent a general endpoint + * This should not be used to actually attempt to render an endpoint and is instead used as a way to fill the + */ +function generateEndpoint(stratosType) { + const definition: IStratosEntityDefinition = { + schema: stratosEntityFactory(endpointEntityType), + type: endpointEntityType, + endpoint: stratosType, + } + stratosEntityCatalog.endpoint = new StratosCatalogEntity< + undefined, + EndpointModel, + EndpointActionBuilder + >( + definition, + { + dataReducers: [ + systemEndpointsReducer + ], + actionBuilders: endpointActionBuilder + } + ) + return stratosEntityCatalog.endpoint; +} + +function generateSystemInfo(stratosType) { + const definition: IStratosEntityDefinition = { + schema: stratosEntityFactory(systemInfoEntityType), + type: systemInfoEntityType, + endpoint: stratosType, + } + stratosEntityCatalog.systemInfo = new StratosCatalogEntity< + undefined, + SystemInfo, + SystemInfoActionBuilder + >( + definition, + { + actionBuilders: systemInfoActionBuilder + } + ) + return stratosEntityCatalog.systemInfo; +} + +function generateUserFavorite(stratosType) { + const definition: IStratosEntityDefinition = { + schema: stratosEntityFactory(userFavouritesEntityType), + type: userFavouritesEntityType, + endpoint: stratosType, + } + stratosEntityCatalog.userFavorite = new StratosCatalogEntity< + undefined, + UserFavorite, + UserFavoriteActionBuilder + >( + definition, + { + dataReducers: [ + addOrUpdateUserFavoriteMetadataReducer, + deleteUserFavoriteMetadataReducer, + ], + actionBuilders: userFavoriteActionBuilder + } + ) + return stratosEntityCatalog.userFavorite; +} + +function generateUserProfile(stratosType) { + const definition: IStratosEntityDefinition = { + schema: stratosEntityFactory(userProfileEntityType), + type: userProfileEntityType, + endpoint: stratosType, + } + stratosEntityCatalog.userProfile = new StratosCatalogEntity< + undefined, + UserProfileInfo, + UserProfileActionBuilder + >( + definition, + { + actionBuilders: userProfileActionBuilder + } + ) + return stratosEntityCatalog.userProfile; +} + +function generateMetricsEndpoint() { + // TODO: metrics location to be sorted - STRAT-152 + stratosEntityCatalog.metricsEndpoint = new StratosCatalogEndpointEntity({ + type: 'metrics', + label: 'Metrics', + labelPlural: 'Metrics', + tokenSharing: true, + logoUrl: '/core/assets/endpoint-icons/metrics.svg', + authTypes: [BaseEndpointAuth.UsernamePassword, BaseEndpointAuth.None], + renderPriority: 1, + listDetailsComponent: MetricsEndpointDetailsComponent, + }, + metadata => `/endpoints/metrics/${metadata.guid}` + ) + return stratosEntityCatalog.metricsEndpoint; +} diff --git a/src/frontend/packages/store/src/types/endpoint.types.ts b/src/frontend/packages/store/src/types/endpoint.types.ts index 779b7cabbd..0cf7a86a6a 100644 --- a/src/frontend/packages/store/src/types/endpoint.types.ts +++ b/src/frontend/packages/store/src/types/endpoint.types.ts @@ -1,7 +1,5 @@ import { MetricsAPITargets, MetricsStratosInfo } from '../actions/metrics-api.actions'; import { EndpointType } from '../extension-types'; -import { endpointSchemaKey } from '../helpers/entity-factory'; -import { RequestSectionKeys, TRequestTypeKeys } from '../reducers/api-request-reducer/types'; export const endpointListKey = 'endpoint-list'; export interface INewlyConnectedEndpointInfo { @@ -12,14 +10,6 @@ export interface INewlyConnectedEndpointInfo { user: EndpointUser; } -export const endpointStoreNames: { - section: TRequestTypeKeys, - type: string -} = { - section: RequestSectionKeys.Other, - type: endpointSchemaKey -}; - export interface IApiEndpointInfo { ForceQuery: boolean; Fragment: string; diff --git a/src/frontend/packages/store/src/types/system.types.ts b/src/frontend/packages/store/src/types/system.types.ts index 2e66f11a2f..a369b88217 100644 --- a/src/frontend/packages/store/src/types/system.types.ts +++ b/src/frontend/packages/store/src/types/system.types.ts @@ -1,6 +1,5 @@ -import { RequestSectionKeys, TRequestTypeKeys } from '../reducers/api-request-reducer/types'; -import { EndpointUser, EndpointModel } from './endpoint.types'; -import { entityFactory, systemInfoSchemaKey } from '../helpers/entity-factory'; +import { EndpointModel, EndpointUser } from './endpoint.types'; + export interface SystemInfo { version: { proxy_version: string, @@ -13,11 +12,3 @@ export interface SystemInfo { } }; } - -export const systemStoreNames: { - section: TRequestTypeKeys, - type: string -} = { - section: RequestSectionKeys.Other, - type: entityFactory(systemInfoSchemaKey).entityType -}; diff --git a/src/frontend/packages/store/src/user-favorite-manager.ts b/src/frontend/packages/store/src/user-favorite-manager.ts index b3fae3896c..a1e0d211e6 100644 --- a/src/frontend/packages/store/src/user-favorite-manager.ts +++ b/src/frontend/packages/store/src/user-favorite-manager.ts @@ -3,7 +3,6 @@ import { Store } from '@ngrx/store'; import { combineLatest, Observable, of } from 'rxjs'; import { filter, map, switchMap, tap } from 'rxjs/operators'; -import { ToggleUserFavoriteAction } from './actions/user-favourites-actions/toggle-user-favorite-action'; import { GeneralEntityAppState, IRequestEntityTypeState } from './app-state'; import { entityCatalog } from './entity-catalog/entity-catalog'; import { FavoritesConfigMapper } from './favorite-config-mapper'; @@ -15,6 +14,7 @@ import { fetchingFavoritesSelector, } from './selectors/favorite-groups.selectors'; import { isFavorite } from './selectors/favorite.selectors'; +import { stratosEntityCatalog } from './stratos-entity-catalog'; import { IUserFavoritesGroups } from './types/favorite-groups.types'; import { IGroupedFavorites, IHydrationResults } from './types/user-favorite-manager.types'; import { IEndpointFavMetadata, IFavoriteMetadata, UserFavorite } from './types/user-favorites.types'; @@ -128,6 +128,6 @@ export class UserFavoriteManager { } public toggleFavorite(favorite: UserFavorite) { - this.store.dispatch(new ToggleUserFavoriteAction(favorite)); + stratosEntityCatalog.userFavorite.api.toggle(favorite); } } diff --git a/src/frontend/packages/store/testing/src/store-test-helper.ts b/src/frontend/packages/store/testing/src/store-test-helper.ts index 44b01d7eb7..98731e61fe 100644 --- a/src/frontend/packages/store/testing/src/store-test-helper.ts +++ b/src/frontend/packages/store/testing/src/store-test-helper.ts @@ -3,9 +3,9 @@ import { TestBed } from '@angular/core/testing'; import { Store, StoreModule } from '@ngrx/store'; import { AppState } from '../../src/app-state'; -import { endpointEntitySchema } from '../../src/base-entity-schemas'; import { entityCatalog } from '../../src/entity-catalog/entity-catalog'; import { EntityCatalogEntityConfig } from '../../src/entity-catalog/entity-catalog.types'; +import { endpointEntityType, stratosEntityFactory } from '../../src/helpers/stratos-entity-factory'; import { appReducers } from '../../src/reducers.module'; import { getDefaultRequestState, rootUpdatingKey } from '../../src/reducers/api-request-reducer/types'; import { getDefaultPaginationEntityState } from '../../src/reducers/pagination-reducer/pagination-reducer-reset-pagination'; @@ -396,7 +396,7 @@ export function createEntityStore(entityMap: Map