Skip to content

Commit

Permalink
Revert: "fix(picker): respect allow multiple false for picker fields (#…
Browse files Browse the repository at this point in the history
…846)" (#869)

This reverts commit 7124173.
  • Loading branch information
adrianossi authored and akurtovic committed Dec 7, 2018
1 parent 07feb74 commit 66d7e1f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 73 deletions.
12 changes: 0 additions & 12 deletions projects/novo-elements/src/elements/form/FormInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,3 @@ export interface IFieldInteractionEvent {
prop: string;
value: any;
}

export interface FormField {
dataSpecialization: string;
inputType: string;
options: string;
multiValue: boolean;
dataType: string;
type: string;
associatedEntity?: { entity: string };
optionsUrl?: string;
optionsType?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export interface NovoControlConfig {
interactions?: Array<Object>;
dataSpecialization?: string;
dataType?: string;
metaType?: string;
appendToBody?: boolean; // Deprecated
parentScrollSelector?: string;
description?: string;
Expand Down Expand Up @@ -107,7 +106,6 @@ export class BaseControl {
encrypted: boolean;
sortOrder: number;
controlType: string;
metaType: string;
placeholder: string;
config: any;
dirty: boolean;
Expand Down Expand Up @@ -182,7 +180,6 @@ export class BaseControl {
this.encrypted = !!config.encrypted;
this.sortOrder = config.sortOrder === undefined ? 1 : config.sortOrder;
this.controlType = config.controlType || '';
this.metaType = config.metaType;
this.placeholder = config.placeholder || '';
this.config = config.config || null;
this.dirty = !!config.value;
Expand Down
33 changes: 0 additions & 33 deletions projects/novo-elements/src/utils/form-utils/FormUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { FormUtils } from './FormUtils';
import { NovoFormControl } from '../../elements/form/NovoFormControl';
import { NovoLabelService } from '../../services/novo-label-service';
import { OptionsService } from '../../services/options/OptionsService';
import { FormField } from '../../elements/form/FormTypes';

/**
* Creates a mock address
Expand Down Expand Up @@ -193,38 +192,6 @@ describe('Utils: FormUtils', () => {
expect(formUtils.determineInputType).toBeDefined();
expect(formUtils.determineInputType({ type: 'file' })).toBe('file');
});
describe('TO_MANY field types', () => {
const toManyField: FormField = {
type: 'TO_MANY',
multiValue: null,
dataType: 'fake',
options: 'fake',
inputType: 'fake',
dataSpecialization: 'fake',
};

describe('without associated field types', () => {
it('should return type \'picker\' if no \'Allow Multiple\' property', () => {
expect(formUtils.determineInputType({ ...toManyField, multiValue: false })).toBe('picker');
});
it('should return type \'chips\' with \'Allow Multiple\' property', () => {
expect(formUtils.determineInputType({ ...toManyField, multiValue: true })).toBe('chips');
});
});
describe('with associated entities', () => {
beforeEach(() => {
jest.spyOn(formUtils, 'hasAssociatedEntity').mockImplementation(() => true);
});
it('should return type \'entitypicker\' with no \'Allow Multiple\' property', () => {
const field: FormField = { ...toManyField, multiValue: false };
expect(formUtils.determineInputType(field)).toBe('entitypicker');
});
it('should return type \'entitychips\' with \'Allow Multiple\' property', () => {
const field: FormField = { ...toManyField, multiValue: true };
expect(formUtils.determineInputType(field)).toBe('entitychips');
});
});
});
xit('should throw an error when a type doesn\'t exist for the field.', () => {
expect(formUtils.determineInputType).toBeDefined();
expect(() => {
Expand Down
43 changes: 18 additions & 25 deletions projects/novo-elements/src/utils/form-utils/FormUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from '../../elements/form/FormControls';
import { EntityPickerResult, EntityPickerResults } from '../../elements/picker/extras/entity-picker-results/EntityPickerResults';
import { Helpers } from '../Helpers';
import { NovoFieldset, FormField } from '../../elements/form/FormInterfaces';
import { NovoFieldset } from '../../elements/form/FormInterfaces';
import { NovoFormControl, NovoFormGroup } from '../../elements/form/NovoFormControl';
import { NovoLabelService } from '../../services/novo-label-service';
import { OptionsService } from './../../services/options/OptionsService';
Expand All @@ -41,7 +41,7 @@ export class FormUtils {
'Person',
'Placement',
];
PICKER_TEXT_LIST: string[] = [
PICKER_TEST_LIST: string[] = [
'CandidateText',
'ClientText',
'ClientContactText',
Expand Down Expand Up @@ -88,19 +88,21 @@ export class FormUtils {
return this.toFormGroup(controls);
}

/**
* @name hasAssociatedEntity
* @param field
*/
hasAssociatedEntity(field: FormField): boolean {
return !!(field.associatedEntity && ~this.ASSOCIATED_ENTITY_LIST.indexOf(field.associatedEntity.entity));
}

/**
* @name determineInputType
* @param field
*/
determineInputType(field: FormField): string {
determineInputType(field: {
dataSpecialization: string;
inputType: string;
options: string;
multiValue: boolean;
dataType: string;
type: string;
associatedEntity?: any;
optionsUrl?: string;
optionsType?: string;
}): string {
let type: string;
let dataSpecializationTypeMap = {
DATETIME: 'datetime',
Expand Down Expand Up @@ -137,27 +139,19 @@ export class FormUtils {
Integer: 'number',
};
if (field.type === 'TO_MANY') {
if (this.hasAssociatedEntity(field)) {
if (field.multiValue === false) {
type = 'entitypicker';
} else {
type = 'entitychips';
}
if (field.associatedEntity && ~this.ASSOCIATED_ENTITY_LIST.indexOf(field.associatedEntity.entity)) {
type = 'entitychips'; // TODO!
} else {
if (field.multiValue === false) {
type = 'picker';
} else {
type = 'chips';
}
type = 'chips';
}
} else if (field.type === 'TO_ONE') {
if (this.hasAssociatedEntity(field)) {
if (field.associatedEntity && ~this.ASSOCIATED_ENTITY_LIST.indexOf(field.associatedEntity.entity)) {
type = 'entitypicker'; // TODO!
} else {
type = 'picker';
}
} else if (field.optionsUrl && field.inputType === 'SELECT') {
if (field.optionsType && ~this.PICKER_TEXT_LIST.indexOf(field.optionsType)) {
if (field.optionsType && ~this.PICKER_TEST_LIST.indexOf(field.optionsType)) {
type = 'entitypicker'; // TODO!
} else {
type = 'picker';
Expand Down Expand Up @@ -198,7 +192,6 @@ export class FormUtils {
let type: string = this.determineInputType(field) || field.type;
let control: any;
let controlConfig: NovoControlConfig = {
metaType: field.type,
type: type,
key: field.name,
label: field.label,
Expand Down

0 comments on commit 66d7e1f

Please sign in to comment.