Skip to content

Commit

Permalink
Merge pull request #2515 from cloudfoundry-incubator/fix-org-refresh
Browse files Browse the repository at this point in the history
Fixes state reset issue when creating a service instance from different modes
  • Loading branch information
KlapTrap authored Jun 26, 2018
2 parents bb0bd97 + 8c5922d commit f6ea4a3
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
SetCreateServiceInstanceCFDetails,
SetCreateServiceInstanceServiceGuid,
SetServiceInstanceGuid,
ResetCreateServiceInstanceOrgAndSpaceState,
} from '../../../../store/actions/create-service-instance.actions';
import { GetServiceInstance } from '../../../../store/actions/service-instances.actions';
import { GetAllAppsInSpace, GetSpace } from '../../../../store/actions/space.actions';
Expand Down Expand Up @@ -81,7 +82,6 @@ export class AddServiceInstanceComponent implements OnDestroy, AfterContentInit
this.inMarketplaceMode = this.modeService.isMarketplaceMode();
}
ngAfterContentInit(): void {

// Check if wizard has been initiated from the Services Marketplace
if (this.inMarketplaceMode) {
this.initialisedService$ = this.initialiseForMarketplaceMode();
Expand All @@ -102,18 +102,15 @@ export class AddServiceInstanceComponent implements OnDestroy, AfterContentInit
this.skipApps$ = this.store.select(selectCreateServiceInstance).pipe(
filter(p => !!p && !!p.spaceGuid && !!p.cfGuid),
switchMap(createServiceInstance => {
const paginationKey = createEntityRelationPaginationKey(spaceSchemaKey, createServiceInstance.spaceGuid);
return getPaginationObservables<APIResource<IApp>>({
store: this.store,
action: new GetAllAppsInSpace(createServiceInstance.cfGuid, createServiceInstance.spaceGuid, paginationKey),
paginationMonitor: this.paginationMonitorFactory.create(
paginationKey,
entityFactory(applicationSchemaKey)
)
}, true).entities$;
}),
map(apps => apps.length === 0)
);
const paginationKey = createEntityRelationPaginationKey(spaceSchemaKey, createServiceInstance.spaceGuid);
return getPaginationObservables<APIResource<IApp>>({
store: this.store,
action: new GetAllAppsInSpace(createServiceInstance.cfGuid, createServiceInstance.spaceGuid, paginationKey),
paginationMonitor: this.paginationMonitorFactory.create(paginationKey, entityFactory(applicationSchemaKey))
}, true).entities$;
}),
map(apps => apps.length === 0)
);
}

onNext = () => {
Expand All @@ -126,7 +123,11 @@ export class AddServiceInstanceComponent implements OnDestroy, AfterContentInit
}

resetStoreData = () => {
this.store.dispatch(new ResetCreateServiceInstanceState());
if (this.inMarketplaceMode) {
this.store.dispatch(new ResetCreateServiceInstanceOrgAndSpaceState());
} else if (this.modeService.isServicesWallMode()) {
this.store.dispatch(new ResetCreateServiceInstanceState());
}
}

private getIdsFromRoute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ describe('ServiceInstanceCardComponent', () => {
updated_at: '',
created_at: ''
},
service: {
entity: {
label: '',
description: '',
active: 1,
bindable: 1,
unique_id: '',
extra: '',
tags: [''],
requires: [''],
service_broker_guid: '',
plan_updateable: 1,
service_plans_url: '',
service_plans: [],
},
metadata: null
},
service_plan: {
entity: {
name: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class ServiceInstanceCardComponent extends CardCell<APIResource<IServiceI
)

getServiceName = () => {
const serviceEntity = this.serviceInstanceEntity.entity.service_plan.entity.service;
const serviceEntity = this.serviceInstanceEntity.entity.service;
let extraInfo: IServiceExtra = null;
try {
extraInfo = serviceEntity.entity.extra ? JSON.parse(serviceEntity.entity.extra) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const SET_SERVICE_INSTANCE_SPACE_SCOPED = '[Create SI] Set Service Instan
export const SET_SERVICE_INSTANCE_SVC_GUID = '[Create SI] Set Service Instance Service Guid';
export const SET_SERVICE_INSTANCE_APP = '[Create SI] Set Service Instance App';
export const RESET_CREATE_SERVICE_INSTANCE_STATE = '[Create SI] Reset State';
export const RESET_CREATE_SERVICE_INSTANCE_STATE_ORG_SPACE = '[Create SI] Reset Partial Org Space State';

export class SetServicePlan implements Action {
constructor(public servicePlanGuid: string) { }
Expand Down Expand Up @@ -61,6 +62,10 @@ export class ResetCreateServiceInstanceState implements Action {
constructor() { }
type = RESET_CREATE_SERVICE_INSTANCE_STATE;
}
export class ResetCreateServiceInstanceOrgAndSpaceState implements Action {
constructor() { }
type = RESET_CREATE_SERVICE_INSTANCE_STATE_ORG_SPACE;
}
export class SetCreateServiceInstanceCFDetails implements Action {
constructor(
public cfGuid: string,
Expand Down
24 changes: 11 additions & 13 deletions src/frontend/app/store/actions/service-instances.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@ import { getActions } from './action.helper';

export const DELETE_SERVICE_BINDING = '[Service Instances] Delete service binding';
export const UPDATE_SERVICE_INSTANCE_SUCCESS = getActions('Service Instances', 'Update Service Instance')[1];
export const getServiceInstanceRelations = [
createEntityRelationKey(serviceInstancesSchemaKey, serviceBindingSchemaKey),
createEntityRelationKey(serviceInstancesSchemaKey, servicePlanSchemaKey),
createEntityRelationKey(serviceInstancesSchemaKey, spaceSchemaKey),
createEntityRelationKey(serviceInstancesSchemaKey, serviceSchemaKey),
createEntityRelationKey(spaceSchemaKey, organizationSchemaKey),
createEntityRelationKey(serviceBindingSchemaKey, applicationSchemaKey)
];

export class GetServiceInstances
extends CFStartAction implements PaginationAction, EntityInlineParentAction {
constructor(
public endpointGuid: string,
public paginationKey: string,
public includeRelations: string[] = [
createEntityRelationKey(serviceInstancesSchemaKey, serviceBindingSchemaKey),
createEntityRelationKey(serviceInstancesSchemaKey, servicePlanSchemaKey),
createEntityRelationKey(serviceInstancesSchemaKey, spaceSchemaKey),
createEntityRelationKey(spaceSchemaKey, organizationSchemaKey),
createEntityRelationKey(servicePlanSchemaKey, serviceSchemaKey),
createEntityRelationKey(serviceBindingSchemaKey, applicationSchemaKey)
],
public includeRelations: string[] = getServiceInstanceRelations,
public populateMissing = true
) {
super();
Expand All @@ -62,10 +63,7 @@ export class GetServiceInstance
constructor(
public guid: string,
public endpointGuid: string,
public includeRelations: string[] = [
createEntityRelationKey(serviceInstancesSchemaKey, serviceBindingSchemaKey),
createEntityRelationKey(serviceInstancesSchemaKey, servicePlanSchemaKey)
],
public includeRelations: string[] = getServiceInstanceRelations,
public populateMissing = true
) {
super();
Expand All @@ -75,7 +73,7 @@ export class GetServiceInstance
this.options.params = new URLSearchParams();
}
actions = getActions('Service Instances', 'Get particular instance');
entity = [entityFactory(serviceInstancesSchemaKey)];
entity = [entityFactory(serviceInstancesWithSpaceSchemaKey)];
entityKey = serviceInstancesSchemaKey;
options: RequestOptions;
}
Expand Down
10 changes: 2 additions & 8 deletions src/frontend/app/store/actions/space.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { CFStartAction, ICFAction } from '../types/request.types';
import { getActions } from './action.helper';
import { RouteEvents } from './route.actions';
import { GetAllOrgUsers } from './organization.actions';
import { getServiceInstanceRelations } from './service-instances.actions';

export const GET_SPACES = '[Space] Get all';
export const GET_SPACES_SUCCESS = '[Space] Get all success';
Expand Down Expand Up @@ -266,14 +267,7 @@ export class GetServiceInstancesForSpace
public endpointGuid: string,
public paginationKey: string,
public q: QParam[] = null,
public includeRelations: string[] = [
createEntityRelationKey(serviceInstancesSchemaKey, serviceBindingSchemaKey),
createEntityRelationKey(serviceInstancesSchemaKey, servicePlanSchemaKey),
createEntityRelationKey(serviceInstancesSchemaKey, spaceSchemaKey),
createEntityRelationKey(spaceSchemaKey, organizationSchemaKey),
createEntityRelationKey(servicePlanSchemaKey, serviceSchemaKey),
createEntityRelationKey(serviceBindingSchemaKey, applicationSchemaKey)
],
public includeRelations: string[] = getServiceInstanceRelations,
public populateMissing = true,
public flattenPagination = true
) {
Expand Down
6 changes: 4 additions & 2 deletions src/frontend/app/store/helpers/entity-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ entityCache[serviceBindingNoBindingsSchemaKey] = ServiceBindingsNoBindingsSchema
const ServiceInstancesSchema = new EntitySchema(serviceInstancesSchemaKey, {
entity: {
service_plan: ServicePlanSchema,
service_bindings: [ServiceBindingsSchema]
service_bindings: [ServiceBindingsSchema],
service: ServiceSchema
}
}, { idAttribute: getAPIResourceGuid });
entityCache[serviceInstancesSchemaKey] = ServiceInstancesSchema;
Expand Down Expand Up @@ -271,7 +272,8 @@ const ServiceInstancesWithSpaceSchema = new EntitySchema(serviceInstancesSchemaK
entity: {
service_plan: ServicePlanSchema,
service_bindings: [ServiceBindingsSchema],
space: SpaceSchema.withEmptyDefinition()
space: SpaceSchema.withEmptyDefinition(),
service: ServiceSchema
}
}, { idAttribute: getAPIResourceGuid });
entityCache[serviceInstancesWithSpaceSchemaKey] = ServiceInstancesWithSpaceSchema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SET_SERVICE_INSTANCE_SVC_GUID,
SET_SERVICE_INSTANCE_APP,
RESET_CREATE_SERVICE_INSTANCE_STATE,
RESET_CREATE_SERVICE_INSTANCE_STATE_ORG_SPACE,
} from '../actions/create-service-instance.actions';
import { CreateServiceInstanceState } from '../types/create-service-instance.types';

Expand Down Expand Up @@ -64,6 +65,12 @@ export function createServiceInstanceReducer(state: CreateServiceInstanceState =
return setCreateServiceInstanceCfDetails(state, action);
case RESET_CREATE_SERVICE_INSTANCE_STATE:
return defaultState;
case RESET_CREATE_SERVICE_INSTANCE_STATE_ORG_SPACE:
return {
...state,
spaceGuid: null,
orgGuid: null
};
default:
return state;
}
Expand Down

0 comments on commit f6ea4a3

Please sign in to comment.