[CORD-1652] Fixed links to related models in table visualization
Change-Id: Ibb5cb3b433e690d2752f188d51a734ddc5f1cfd0
diff --git a/src/app/core/services/helpers/config.helpers.spec.ts b/src/app/core/services/helpers/config.helpers.spec.ts
index 4245b81..14e2bd3 100644
--- a/src/app/core/services/helpers/config.helpers.spec.ts
+++ b/src/app/core/services/helpers/config.helpers.spec.ts
@@ -155,10 +155,18 @@
it('should return the state for a given model', () => {
expect(service.stateFromCoreModel('Test')).toBe('xos.core.tests');
});
-
+ });
+ describe('stateWithParams', () => {
it('should return the state with params for a given model', () => {
expect(service.stateWithParams('Test', {id: 1})).toBe('xos.core.tests({id: 1})');
});
+ it('should return the state with params for a given relation', () => {
+ expect(service.relatedStateWithParams('Test', '1')).toBe('xos.core.tests({id: 1})');
+ });
+
+ it('should return the state with params for usage in js', () => {
+ expect(service.stateWithParamsForJs('Test', {id: 1})).toEqual({ name: 'xos.core.tests', params: Object({ id: 1 }) });
+ });
});
});
diff --git a/src/app/core/services/helpers/config.helpers.ts b/src/app/core/services/helpers/config.helpers.ts
index 85039fe..2dc8e46 100644
--- a/src/app/core/services/helpers/config.helpers.ts
+++ b/src/app/core/services/helpers/config.helpers.ts
@@ -36,6 +36,7 @@
toLabels(string: string[], pluralize?: boolean): string[];
stateFromCoreModel(name: string): string;
stateWithParams(name: string, model: any): string;
+ relatedStateWithParams(name: string, id: string): string;
stateWithParamsForJs(name: string, model: any): any;
}
@@ -175,9 +176,7 @@
this.populateRelated(item, item[f.name], f);
return item[f.name];
};
- col.link = item => {
- return this.stateWithParams(f.relation.model, item);
- };
+ col.link = item => this.relatedStateWithParams(f.relation.model, item[col.prop]);
}
if (f.name === 'backend_status' || f.name === 'policy_status') {
@@ -220,8 +219,12 @@
return `${state}({id: ${model['id']}})`;
}
+ public relatedStateWithParams(name: string, id: string): string {
+ const state = this.stateFromCoreModel(name);
+ return `${state}({id: ${id}})`;
+ }
+
public stateWithParamsForJs(name: string, model: any): any {
- // TODO test and interface
const state = this.stateFromCoreModel(name);
return {name: state, params: {id: model.id}};
}