From 16998e2963f1d29de138093ab4e9e0c1fa03d791 Mon Sep 17 00:00:00 2001 From: paulpascal Date: Fri, 29 Mar 2024 17:47:47 +0000 Subject: [PATCH] fix(#55): address final feedback --- README.md | 1 - src/config/chis-tg/config.json | 2 +- src/config/index.ts | 2 +- src/lib/validation.ts | 4 ++-- src/lib/validator-name.ts | 2 +- ...select_multiple.ts => validator-select-multiple.ts} | 10 +++++----- ...validator-select_one.ts => validator-select-one.ts} | 0 src/liquid/components/contact_type_property.html | 2 +- test/lib/validation.spec.ts | 2 +- 9 files changed, 12 insertions(+), 13 deletions(-) rename src/lib/{validator-select_multiple.ts => validator-select-multiple.ts} (89%) rename src/lib/{validator-select_one.ts => validator-select-one.ts} (100%) diff --git a/README.md b/README.md index b3090d31..960799bb 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,6 @@ The `ConfigPropertyType` defines a property's validation rules and auto-formatti | name | Must be defined | Same as string + title case + `parameter` behavior | One or more regexes which are removed from the value when matched (eg. `"parameter": ["\\sCHU"]` will format `this CHU` into `This`) | | regex | Must match the `regex` captured by `parameter` | Same as `string` | A regex which must be matched to pass validation (eg. `"parameter": "^\\d{6}$"` will accept only 6 digit numbers) | | phone | A valid phone number for the specified locality | Auto formatting provided by [libphonenumber](https://github.com/google/libphonenumber) | Two letter country code specifying the locality of phone number (eg. `"parameter": "KE"`) | -None | | generated | None. No user inputs. | Uses [LiquidJS](https://liquidjs.com) templates to generate data | None | [Details](#The-Generated-ConfigPropertyType) | select_one | Single choice from a list of options | Same as `string` | None | Dictionary where the keys are the option values and the values are the corresponding labels | | select_multiple | Multiple choice from a list of options | Same as `string` | None | Same as `select_one` diff --git a/src/config/chis-tg/config.json b/src/config/chis-tg/config.json index c54c683d..b86d7428 100644 --- a/src/config/chis-tg/config.json +++ b/src/config/chis-tg/config.json @@ -159,7 +159,7 @@ "required": true }, { - "friendly_name": "Sex", + "friendly_name": "Gender", "property_name": "sex", "type": "select_one", "parameter": { diff --git a/src/config/index.ts b/src/config/index.ts index f6c81648..9a9ab1e6 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -111,7 +111,7 @@ export class Config { ); return { - friendly_name: 'Role(s)', + friendly_name: 'Roles', property_name: 'role', type: 'select_multiple', required: true, diff --git a/src/lib/validation.ts b/src/lib/validation.ts index 8acaa1fc..e00dde22 100644 --- a/src/lib/validation.ts +++ b/src/lib/validation.ts @@ -9,8 +9,8 @@ import ValidatorGenerated from './validator-generated'; import ValidatorName from './validator-name'; import ValidatorPhone from './validator-phone'; import ValidatorRegex from './validator-regex'; -import ValidatorSelectMultiple from './validator-select_multiple'; -import ValidatorSelectOne from './validator-select_one'; +import ValidatorSelectMultiple from './validator-select-multiple'; +import ValidatorSelectOne from './validator-select-one'; import ValidatorSkip from './validator-skip'; import ValidatorString from './validator-string'; diff --git a/src/lib/validator-name.ts b/src/lib/validator-name.ts index 4d1c6fa8..f4668acd 100644 --- a/src/lib/validator-name.ts +++ b/src/lib/validator-name.ts @@ -6,7 +6,7 @@ export default class ValidatorName implements IValidator { isValid(input: string, property : ContactProperty) : boolean | string { // Verify property.parameter is always array if (property.parameter && !Array.isArray(property.parameter)) { - throw Error(`property '${property.friendly_name}' of type 'regex' expects 'parameter' to be an array.`); + throw Error(`Property '${property.friendly_name}' of type 'name' expects 'parameter' to be an array.`); } return !!input; diff --git a/src/lib/validator-select_multiple.ts b/src/lib/validator-select-multiple.ts similarity index 89% rename from src/lib/validator-select_multiple.ts rename to src/lib/validator-select-multiple.ts index dc0d8224..a423c240 100644 --- a/src/lib/validator-select_multiple.ts +++ b/src/lib/validator-select-multiple.ts @@ -1,10 +1,11 @@ import {ContactProperty} from '../config'; import {IValidator} from './validation'; import ValidatorString from './validator-string'; -import ValidatorSelectOne from './validator-select_one'; +import ValidatorSelectOne from './validator-select-one'; + +const DELIMITER = ' '; export default class ValidatorSelectMultiple implements IValidator { - DELIMITER = ' '; isValid(input: string, property: ContactProperty): boolean | string { // Verify property.parameter is an object and is not null @@ -33,7 +34,7 @@ export default class ValidatorSelectMultiple implements IValidator { } format(input: string): string { - return Array.isArray(input) ? input.join(this.DELIMITER) : input; + return Array.isArray(input) ? input.join(DELIMITER) : input; } get defaultError(): string { @@ -46,9 +47,8 @@ export default class ValidatorSelectMultiple implements IValidator { } return input - .split(this.DELIMITER) + .split(DELIMITER) .map(value => stringValidator.format(value)) .filter(Boolean); } } - diff --git a/src/lib/validator-select_one.ts b/src/lib/validator-select-one.ts similarity index 100% rename from src/lib/validator-select_one.ts rename to src/lib/validator-select-one.ts diff --git a/src/liquid/components/contact_type_property.html b/src/liquid/components/contact_type_property.html index baa5e356..f89d119e 100644 --- a/src/liquid/components/contact_type_property.html +++ b/src/liquid/components/contact_type_property.html @@ -9,7 +9,7 @@ {% include "components/contact_type_select.html" prop_name=prop_name - prop=prop + prop=include.prop data=data %} {% else %} diff --git a/test/lib/validation.spec.ts b/test/lib/validation.spec.ts index 551584d8..f71b7a67 100644 --- a/test/lib/validation.spec.ts +++ b/test/lib/validation.spec.ts @@ -195,7 +195,7 @@ describe('lib/validation.ts', () => { expect(Validation.getValidationErrors(place)).to.deep.eq([{ property_name: 'user_role', - description: `Invalid values for property "Role(s)": stockmanager` + description: `Invalid values for property "Roles": stockmanager` }]); }); });