Browse Source

feat: handle typeahead in object extensions state utils

pull/6405/head
Arman Ozak 6 years ago
parent
commit
e3ebd07175
  1. 12
      npm/ng-packs/packages/theme-shared/extensions/src/lib/utils/state.util.ts
  2. 88
      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

@ -1,4 +1,9 @@
import { ABP, ApplicationLocalizationConfigurationDto, ConfigStateService } from '@abp/ng.core';
import {
ABP,
ApplicationLocalizationConfigurationDto,
ConfigStateService,
ExtensionPropertyUiDto,
} from '@abp/ng.core';
import { Observable, pipe, zip } from 'rxjs';
import { filter, map, switchMap, take } from 'rxjs/operators';
import { ePropType } from '../enums/props.enum';
@ -9,6 +14,7 @@ import { PropCallback } from '../models/props';
import { createEnum, createEnumOptions, createEnumValueResolver } from './enum.util';
import { createDisplayNameLocalizationPipeKeyGenerator } from './localization.util';
import { createExtraPropertyValueResolver } from './props.util';
import { createTypeaheadOptions, getTypeaheadType } from './typeahead.util';
import { getValidatorsFromProperty } from './validation.util';
function selectObjectExtensions(
@ -115,7 +121,8 @@ function createPropertiesToContributorsMapper<T = any>(
Object.keys(properties).forEach((name: string) => {
const property = properties[name];
const type = getTypeFromProperty(property);
const lookup = property.ui || ({} as ExtensionPropertyUiDto);
const type = getTypeaheadType(lookup, name) || getTypeFromProperty(property);
const displayName = generateDisplayName(property.displayName, { name, resource });
if (property.ui.onTable.isVisible) {
@ -148,6 +155,7 @@ function createPropertiesToContributorsMapper<T = any>(
const validators = () => getValidatorsFromProperty(property);
let options: PropCallback<any, Observable<ABP.Option<any>[]>>;
if (type === ePropType.Enum) options = createEnumOptions(name, enums[property.type]);
else if (type === ePropType.Typeahead) options = createTypeaheadOptions(lookup);
const formProp = new FormProp({
type,

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

@ -50,24 +50,29 @@ describe('State Utils', () => {
const propList = new EntityPropList();
contributors.prop.Role.forEach(callback => callback(propList));
expect(propList.length).toBe(3);
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');
const createFormList = new FormPropList();
contributors.createForm.Role.forEach(callback => callback(createFormList));
expect(createFormList.length).toBe(2);
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');
const editFormList = new FormPropList();
contributors.editForm.Role.forEach(callback => callback(editFormList));
expect(editFormList.length).toBe(2);
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');
});
});
});
@ -275,6 +280,83 @@ function createMockEntities(): Record<string, ObjectExtensions.EntityExtensionDt
configuration: {},
defaultValue: 2,
},
Foo: {
type: 'System.String',
typeSimple: ePropType.String,
displayName: null,
api: {
onGet: {
isAvailable: false,
},
onCreate: {
isAvailable: true,
},
onUpdate: {
isAvailable: true,
},
},
ui: {
onTable: {
isVisible: false,
},
onCreateForm: {
isVisible: true,
},
onEditForm: {
isVisible: true,
},
lookup: {
url: '/api/identity/roles',
resultListPropertyName: 'items',
displayPropertyName: 'text',
valuePropertyName: 'id',
filterParamName: 'filter',
},
},
attributes: [],
configuration: {},
defaultValue: null,
},
Foo_Text: {
type: 'System.String',
typeSimple: ePropType.String,
displayName: {
name: 'Foo',
resource: '_',
},
api: {
onGet: {
isAvailable: true,
},
onCreate: {
isAvailable: true,
},
onUpdate: {
isAvailable: true,
},
},
ui: {
onTable: {
isVisible: true,
},
onCreateForm: {
isVisible: true,
},
onEditForm: {
isVisible: true,
},
lookup: {
url: null,
resultListPropertyName: 'items',
displayPropertyName: 'text',
valuePropertyName: 'id',
filterParamName: 'filter',
},
},
attributes: [],
configuration: {},
defaultValue: null,
},
},
configuration: {},
},

Loading…
Cancel
Save