Browse Source

fix: use jsonNetCamelCase on extra properties

pull/6405/head
Arman Ozak 6 years ago
parent
commit
d090a5460f
  1. 12
      npm/ng-packs/packages/theme-shared/extensions/src/lib/utils/state.util.ts
  2. 24
      npm/ng-packs/packages/theme-shared/extensions/src/tests/state.util.spec.ts

12
npm/ng-packs/packages/theme-shared/extensions/src/lib/utils/state.util.ts

@ -11,6 +11,7 @@ import { EntityProp, EntityPropList } from '../models/entity-props';
import { FormProp, FormPropList } from '../models/form-props';
import { ObjectExtensions } from '../models/object-extensions';
import { PropCallback } from '../models/props';
import { jsonNetCamelCase } from './case.util';
import { createEnum, createEnumOptions, createEnumValueResolver } from './enum.util';
import { createDisplayNameLocalizationPipeKeyGenerator } from './localization.util';
import { createExtraPropertyValueResolver } from './props.util';
@ -121,6 +122,7 @@ function createPropertiesToContributorsMapper<T = any>(
Object.keys(properties).forEach((name: string) => {
const property = properties[name];
const propName = jsonNetCamelCase(name);
const lookup = property.ui.lookup || ({} as ExtensionPropertyUiLookupDto);
const type = getTypeaheadType(lookup, name) || getTypeFromProperty(property);
const displayName = generateDisplayName(property.displayName, { name, resource });
@ -130,12 +132,12 @@ function createPropertiesToContributorsMapper<T = any>(
const columnWidth = type === ePropType.Boolean ? 150 : 250;
const valueResolver =
type === ePropType.Enum
? createEnumValueResolver(property.type, enums[property.type], name)
: createExtraPropertyValueResolver<T>(name);
? createEnumValueResolver(property.type, enums[property.type], propName)
: createExtraPropertyValueResolver<T>(propName);
const entityProp = new EntityProp<T>({
type,
name,
name: propName,
displayName,
sortable,
columnWidth,
@ -154,12 +156,12 @@ function createPropertiesToContributorsMapper<T = any>(
const defaultValue = property.defaultValue;
const validators = () => getValidatorsFromProperty(property);
let options: PropCallback<any, Observable<ABP.Option<any>[]>>;
if (type === ePropType.Enum) options = createEnumOptions(name, enums[property.type]);
if (type === ePropType.Enum) options = createEnumOptions(propName, enums[property.type]);
else if (type === ePropType.Typeahead) options = createTypeaheadOptions(lookup);
const formProp = new FormProp({
type,
name,
name: propName,
displayName,
options,
defaultValue,

24
npm/ng-packs/packages/theme-shared/extensions/src/tests/state.util.spec.ts

@ -51,28 +51,28 @@ describe('State Utils', () => {
contributors.prop.Role.forEach(callback => callback(propList));
expect(propList.length).toBe(4);
expect(propList.head.value.name).toBe('Title');
expect(propList.head.next.value.name).toBe('IsHero');
expect(propList.head.next.next.value.name).toBe('MyEnum');
expect(propList.head.next.next.next.value.name).toBe('Foo_Text');
expect(propList.head.value.name).toBe('title');
expect(propList.head.next.value.name).toBe('isHero');
expect(propList.head.next.next.value.name).toBe('myEnum');
expect(propList.head.next.next.next.value.name).toBe('foo_Text');
const createFormList = new FormPropList();
contributors.createForm.Role.forEach(callback => callback(createFormList));
expect(createFormList.length).toBe(4);
expect(createFormList.head.value.name).toBe('Title');
expect(createFormList.head.next.value.name).toBe('MyEnum');
expect(createFormList.head.next.next.value.name).toBe('Foo');
expect(createFormList.head.next.next.next.value.name).toBe('Foo_Text');
expect(createFormList.head.value.name).toBe('title');
expect(createFormList.head.next.value.name).toBe('myEnum');
expect(createFormList.head.next.next.value.name).toBe('foo');
expect(createFormList.head.next.next.next.value.name).toBe('foo_Text');
const editFormList = new FormPropList();
contributors.editForm.Role.forEach(callback => callback(editFormList));
expect(editFormList.length).toBe(4);
expect(editFormList.head.value.name).toBe('Title');
expect(editFormList.head.next.value.name).toBe('IsHero');
expect(editFormList.head.next.next.value.name).toBe('Foo');
expect(editFormList.head.next.next.next.value.name).toBe('Foo_Text');
expect(editFormList.head.value.name).toBe('title');
expect(editFormList.head.next.value.name).toBe('isHero');
expect(editFormList.head.next.next.value.name).toBe('foo');
expect(editFormList.head.next.next.next.value.name).toBe('foo_Text');
});
});
});

Loading…
Cancel
Save