Skip to content

Commit

Permalink
fix(#55): address final feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpascal committed Mar 29, 2024
1 parent 9d4a9ba commit 16998e2
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 13 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion src/config/chis-tg/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
"required": true
},
{
"friendly_name": "Sex",
"friendly_name": "Gender",
"property_name": "sex",
"type": "select_one",
"parameter": {
Expand Down
2 changes: 1 addition & 1 deletion src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class Config {
);

return {
friendly_name: 'Role(s)',
friendly_name: 'Roles',
property_name: 'role',
type: 'select_multiple',
required: true,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/validator-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -46,9 +47,8 @@ export default class ValidatorSelectMultiple implements IValidator {
}

return input
.split(this.DELIMITER)
.split(DELIMITER)
.map(value => stringValidator.format(value))
.filter(Boolean);
}
}

File renamed without changes.
2 changes: 1 addition & 1 deletion src/liquid/components/contact_type_property.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{%
include "components/contact_type_select.html"
prop_name=prop_name
prop=prop
prop=include.prop
data=data
%}
{% else %}
Expand Down
2 changes: 1 addition & 1 deletion test/lib/validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
}]);
});
});

0 comments on commit 16998e2

Please sign in to comment.