Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Entity catalogue: Service Instance Wall Fix #1 #3670

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/frontend/packages/cloud-foundry/src/cf-entity-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const serviceBrokerEntityType = 'serviceBroker';
export const userProvidedServiceInstanceEntityType = 'userProvidedServiceInstance';

export const spaceWithOrgEntityType = 'spaceWithOrg';
export const serviceInstancesWithspaceEntityType = 'serviceInstancesWithSpace';
export const serviceInstancesWithSpaceEntityType = 'serviceInstancesWithSpace';
export const serviceInstancesWithNoBindingsEntityType = 'serviceInstanceWithNoBindings';
export const serviceBindingNoBindingsEntityType = 'serviceBindingNoBindings';

Expand Down Expand Up @@ -272,7 +272,7 @@ const ServiceInstancesWithSpaceSchema = new CFEntitySchema(serviceInstancesEntit
service: ServiceSchema
}
}, { idAttribute: getAPIResourceGuid });
entityCache[serviceInstancesWithspaceEntityType] = ServiceInstancesWithSpaceSchema;
entityCache[serviceInstancesWithSpaceEntityType] = ServiceInstancesWithSpaceSchema;

const ServiceInstancesWithNoBindingsSchema = new CFEntitySchema(serviceInstancesEntityType, {
entity: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
serviceEntityType,
serviceInstancesEntityType,
serviceInstancesWithNoBindingsEntityType,
serviceInstancesWithspaceEntityType,
serviceInstancesWithSpaceEntityType,
servicePlanEntityType,
servicePlanVisibilityEntityType,
spaceEntityType,
Expand Down Expand Up @@ -301,7 +301,7 @@ function generateCFServiceInstanceEntity(endpointDefinition: IStratosEndpointDef
type: serviceInstancesEntityType,
schema: {
default: cfEntityFactory(serviceInstancesEntityType),
[serviceInstancesWithspaceEntityType]: cfEntityFactory(serviceInstancesWithspaceEntityType),
[serviceInstancesWithSpaceEntityType]: cfEntityFactory(serviceInstancesWithSpaceEntityType),
[serviceInstancesWithNoBindingsEntityType]: cfEntityFactory(serviceInstancesWithNoBindingsEntityType),
},
label: 'Marketplace Service Instance',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { Store } from '@ngrx/store';

import { AppState } from '../../../../store/src/app-state';
import { EntitySchema } from '../../../../store/src/helpers/entity-schema';
import { EndpointModel } from '../../../../store/src/types/endpoint.types';
import { IEndpointFavMetadata } from '../../../../store/src/types/user-favorites.types';
import { endpointEntitySchema } from '../../base-entity-schemas';
import { getFullEndpointApiUrl } from '../../features/endpoints/endpoint-helpers';
import { EntityMonitor } from '../../shared/monitors/entity-monitor';
import { EntityCatalogueHelpers } from './entity-catalogue.helper';
import {
IEntityMetadata,
IStratosEntityDefinition,
EntityCatalogueSchemas,
IEntityMetadata,
IStratosBaseEntityDefinition,
IStratosEndpointDefinition,
IStratosEntityBuilder,
IStratosEndpointWithoutSchemaDefinition,
IStratosBaseEntityDefinition
IStratosEntityBuilder,
IStratosEntityDefinition,
} from './entity-catalogue.types';
import { Store } from '@ngrx/store';
import { GeneralEntityAppState, AppState } from '../../../../store/src/app-state';
import { EntityCatalogueHelpers } from './entity-catalogue.helper';
import { IEndpointFavMetadata } from '../../../../store/src/types/user-favorites.types';
import { EndpointModel } from '../../../../store/src/types/endpoint.types';
import { getFullEndpointApiUrl } from '../../features/endpoints/endpoint-helpers';
import { endpointEntitySchema } from '../../base-entity-schemas';
import { EntitySchema } from '../../../../store/src/helpers/entity-schema';
import { EntityMonitor } from '../../shared/monitors/entity-monitor';

export class StratosBaseCatalogueEntity<T extends IEntityMetadata = IEntityMetadata, Y = any> {
public readonly entityKey: string;
Expand Down Expand Up @@ -56,6 +57,8 @@ export class StratosBaseCatalogueEntity<T extends IEntityMetadata = IEntityMetad
* If no schemaKey is provided then the default schema will be returned
*/
public getSchema(schemaKey?: string) {
// TODO: schemaKey - ensure wherever this is called it contains the correct schemaKey (with respect to any config
// EntityCatalogueEntityConfig that may use a schemeKey different than that provided by entityCatalogue.getEntity's)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to run through usages and check that the correct schemaKey is used. Think is most cases this should come from an EntityCatalogueEntityConfig object (whether the schema key is populated or not). We then need to ensure that this has the correct schema key when different from the default one (for service instances schemas with/without space, everything related to this issue is marked with a // TODO: schemaKey).

// TODO(NJ) We should do a better job at typeing schemax
// schema always gets changed to a EntityCatalogueSchamas.
const catalogueSchema = (this.definition.schema as EntityCatalogueSchemas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import { ServicePlanAccessibility } from './services.service';


export const getSvcAvailability = (servicePlan: APIResource<IServicePlan>,
serviceBroker: APIResource<IServiceBroker>,
allServicePlanVisibilities: APIResource<IServicePlanVisibility>[]) => {
serviceBroker: APIResource<IServiceBroker>,
allServicePlanVisibilities: APIResource<IServicePlanVisibility>[]) => {
const svcAvailability = {
isPublic: false, spaceScoped: false, hasVisibilities: false, guid: servicePlan.metadata.guid, spaceGuid: null
};
Expand Down Expand Up @@ -79,6 +79,8 @@ export const isEditServiceInstanceMode = (activatedRoute: ActivatedRoute) => {

export const getServiceInstancesInCf = (cfGuid: string, store: Store<CFAppState>, paginationMonitorFactory: PaginationMonitorFactory) => {
const paginationKey = createEntityRelationPaginationKey(serviceInstancesEntityType, cfGuid);
// TODO: schemaKey - Dispatches the action which has the correct schema key (SI with space), however uses incorrect schema to denormalise
// so entities$ does not contain space
return getPaginationObservables<APIResource<IServiceInstance>>({
store,
action: new GetServiceInstances(cfGuid, paginationKey),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ import { ListFilter, ListSort } from '../../../../../../store/src/actions/list.a
import { MetricsAction } from '../../../../../../store/src/actions/metrics.actions';
import { SetResultCount } from '../../../../../../store/src/actions/pagination.actions';
import { CFAppState } from '../../../../../../store/src/app-state';
import { EntitySchema } from '../../../../../../store/src/helpers/entity-schema';
import { getPaginationObservables } from '../../../../../../store/src/reducers/pagination-reducer/pagination-reducer.helper';
import {
PaginatedAction,
PaginationEntityState,
PaginationParam,
QParam,
} from '../../../../../../store/src/types/pagination.types';
import { entityCatalogue } from '../../../../core/entity-catalogue/entity-catalogue.service';
import { PaginationMonitor } from '../../../monitors/pagination-monitor';
import { IListDataSourceConfig, MultiActionConfig } from './list-data-source-config';
import {
Expand All @@ -49,8 +51,6 @@ import {
import { getDataFunctionList } from './local-filtering-sorting';
import { LocalListController } from './local-list-controller';
import { LocalPaginationHelpers } from './local-list.helpers';
import { entityCatalogue } from '../../../../core/entity-catalogue/entity-catalogue.service';
import { EntitySchema } from '../../../../../../store/src/helpers/entity-schema';

export class DataFunctionDefinition {
type: 'sort' | 'filter';
Expand Down Expand Up @@ -309,6 +309,7 @@ export abstract class ListDataSource<T, A = T> extends DataSource<T> implements
private getSourceSchema(schema: EntitySchema | MultiActionConfig) {
if (schema instanceof MultiActionConfig) {
const { paginationAction } = schema.schemaConfigs[0];
// TODO: schemaKey - getSchema needs to accept an EntityCatalogueEntityConfig with the correct schemaKey
const catalogueEntity = entityCatalogue.getEntity(paginationAction.endpointType, paginationAction.entityType);
return catalogueEntity.getSchema(paginationAction.schemaKey);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
serviceBindingEntityType,
serviceEntityType,
serviceInstancesEntityType,
serviceInstancesWithspaceEntityType,
serviceInstancesWithSpaceEntityType,
servicePlanEntityType,
spaceEntityType,
} from '../../../../../../../cloud-foundry/src/cf-entity-factory';
Expand All @@ -31,11 +31,11 @@ export class CfSpacesServiceInstancesDataSource extends ListDataSource<APIResour
createEntityRelationKey(serviceInstancesEntityType, spaceEntityType),
createEntityRelationKey(serviceBindingEntityType, applicationEntityType),
], true, false);
action.entity = [cfEntityFactory(serviceInstancesWithspaceEntityType)];
action.entity = [cfEntityFactory(serviceInstancesWithSpaceEntityType)];
super({
store,
action,
schema: cfEntityFactory(serviceInstancesWithspaceEntityType),
schema: cfEntityFactory(serviceInstancesWithSpaceEntityType),
getRowUniqueId: getRowMetadata,
paginationKey,
// This would normally be fetched inline, however some of the SI's children will be missing if the SI was fetched by the org
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ export class ServiceInstanceCardComponent extends CardCell<APIResource<IServiceI
this.cfOrgSpace = new CfOrgSpaceLabelService(
this.store,
this.cfGuid,
row.entity.space.entity.organization_guid,
// TODO: schemaKey - `space` is null due to the incorrect schema used when fetching the service instance
// (see service instance wall data source)
// row.entity.space.entity.organization_guid,
'junk',
row.entity.space_guid);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
serviceInstancesEntityType,
userProvidedServiceInstanceEntityType,
} from '../../../../../../../cloud-foundry/src/cf-entity-factory';
import { getCFEntityKey } from '../../../../../../../cloud-foundry/src/cf-entity-helpers';
import { ListView } from '../../../../../../../store/src/actions/list.actions';
import { CFAppState } from '../../../../../../../store/src/app-state';
import { CurrentUserPermissionsService } from '../../../../../core/current-user-permissions.service';
Expand Down Expand Up @@ -38,8 +39,8 @@ export class ServiceInstancesWallListConfigService extends CfServiceInstancesLis
enableTextFilter = true;
defaultView = 'cards' as ListView;
cardComponent = new CardMultiActionComponents({
[serviceInstancesEntityType]: ServiceInstanceCardComponent,
[userProvidedServiceInstanceEntityType]: UserProvidedServiceInstanceCardComponent
[getCFEntityKey(serviceInstancesEntityType)]: ServiceInstanceCardComponent,
[getCFEntityKey(userProvidedServiceInstanceEntityType)]: UserProvidedServiceInstanceCardComponent
});
viewType = ListViewTypes.BOTH;
pageSizeOptions = defaultPaginationPageSizeOptionsCards;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ import {
withLatestFrom,
} from 'rxjs/operators';

import { GeneralEntityAppState, AppState, GeneralRequestDataState } from '../../../../store/src/app-state';
import { AppState, GeneralEntityAppState, GeneralRequestDataState } from '../../../../store/src/app-state';
import { EntitySchema } from '../../../../store/src/helpers/entity-schema';
import { ActionState, ListActionState } from '../../../../store/src/reducers/api-request-reducer/types';
import { getAPIRequestDataState, selectEntities } from '../../../../store/src/selectors/api.selectors';
import { selectPaginationState } from '../../../../store/src/selectors/pagination.selectors';
import { BaseRequestDataState } from '../../../../store/src/types/entity.types';
import { PaginationEntityState } from '../../../../store/src/types/pagination.types';
import { LocalPaginationHelpers } from '../components/list/data-sources-controllers/local-list.helpers';
import { EntitySchema } from '../../../../store/src/helpers/entity-schema';
import { EntityCatalogueHelpers } from '../../core/entity-catalogue/entity-catalogue.helper';
import { StratosBaseCatalogueEntity } from '../../core/entity-catalogue/entity-catalogue-entity';
import { EntityCatalogueHelpers } from '../../core/entity-catalogue/entity-catalogue.helper';
import { entityCatalogue } from '../../core/entity-catalogue/entity-catalogue.service';
import { EntityCatalogueEntityConfig } from '../../core/entity-catalogue/entity-catalogue.types';
import { LocalPaginationHelpers } from '../components/list/data-sources-controllers/local-list.helpers';

export class MultiActionListEntity {
static getEntity(entity: MultiActionListEntity | any) {
Expand Down Expand Up @@ -79,7 +78,7 @@ export class PaginationMonitor<T = any, Y extends AppState = GeneralEntityAppSta
schemaKey = ''
}: any
) {
// This is a static on the pagintion monitor rather than a member of StratosBaseCatalogueEntity due to
// This is a static on the pagintion monitor rather than a member of StratosBaseCatalogueEntity due to
// a circular dependency on entityFactory from the getPageInfo function below.
const schema = catalogueEntity.getSchema(schemaKey);
return new PaginationMonitor(store, paginationKey, schema, isLocal);
Expand Down Expand Up @@ -294,6 +293,7 @@ export class PaginationMonitor<T = any, Y extends AppState = GeneralEntityAppSta
}

private denormalizePage(page: string[], schema: normalizrSchema.Entity, allEntities: GeneralRequestDataState) {
// TODO: schemaKey - the schema passed must come from a correct EntityCatalogueEntityConfig with schemaKey populated
return page.length
? denormalize(page, [schema], allEntities).filter(ent => !!ent)
: [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
serviceBindingNoBindingsEntityType,
serviceEntityType,
serviceInstancesEntityType,
serviceInstancesWithspaceEntityType,
serviceInstancesWithSpaceEntityType,
servicePlanEntityType,
spaceEntityType,
} from '../../../cloud-foundry/src/cf-entity-factory';
Expand Down Expand Up @@ -43,7 +43,7 @@ export class GetServiceInstances
this.options.params = new URLSearchParams();
}
actions = getActions('Service Instances', 'Get all');
entity = [cfEntityFactory(serviceInstancesWithspaceEntityType)];
entity = [cfEntityFactory(serviceInstancesWithSpaceEntityType)];
entityType = serviceInstancesEntityType;
options: RequestOptions;
initialParams = {
Expand All @@ -70,7 +70,7 @@ export class GetServiceInstance
this.options.params = new URLSearchParams();
}
actions = getActions('Service Instances', 'Get particular instance');
entity = [cfEntityFactory(serviceInstancesWithspaceEntityType)];
entity = [cfEntityFactory(serviceInstancesWithSpaceEntityType)];
entityType = serviceInstancesEntityType;
options: RequestOptions;
}
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/packages/store/src/actions/space.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
routeEntityType,
serviceEntityType,
serviceInstancesEntityType,
serviceInstancesWithspaceEntityType,
serviceInstancesWithSpaceEntityType,
servicePlanEntityType,
spaceEntityType,
spaceWithOrgEntityType,
Expand Down Expand Up @@ -273,7 +273,7 @@ export class GetServiceInstancesForSpace
this.parentGuid = spaceGuid;
}
actions = getActions('Space', 'Get all service instances');
entity = [cfEntityFactory(serviceInstancesWithspaceEntityType)];
entity = [cfEntityFactory(serviceInstancesWithSpaceEntityType)];
entityType = serviceInstancesEntityType;
options: RequestOptions;
initialParams = {
Expand Down