Skip to content

Commit

Permalink
fix(#55): address feedback part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpascal committed Mar 27, 2024
1 parent 85ac414 commit c464dff
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 49 deletions.
12 changes: 10 additions & 2 deletions src/config/chis-tg/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@
{
"friendly_name": "Gender",
"property_name": "sex",
"type": "gender",
"type": "select_one",
"parameter": {
"male": "Masculin",
"female": "Feminin"
},
"required": true
},
{
Expand Down Expand Up @@ -157,7 +161,11 @@
{
"friendly_name": "Sex",
"property_name": "sex",
"type": "gender",
"type": "select_one",
"parameter": {
"male": "Masculin",
"female": "Feminin"
},
"required": true
},
{
Expand Down
2 changes: 0 additions & 2 deletions src/lib/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import ValidatorSkip from './validator-skip';
import ValidatorString from './validator-string';
import ValidatorSelectMultiple from './validator-select_multiple';
import ValidatorSelectOne from './validator-select_one';
import ValidatorRole from './validator-role';

export type ValidationError = {
property_name: string;
Expand All @@ -38,7 +37,6 @@ const TypeValidatorMap: ValidatorMap = {
phone: new ValidatorPhone(),
regex: new ValidatorRegex(),
string: new ValidatorString(),
select_role: new ValidatorRole(),
select_one: new ValidatorSelectOne(),
select_multiple: new ValidatorSelectMultiple(),
};
Expand Down
33 changes: 0 additions & 33 deletions src/lib/validator-role.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/lib/validator-select_multiple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export default class ValidatorSelectMultiple implements IValidator {
return input;
}

// If input is a string, split it by delimiter
return input
.split(this.DELIMITER)
.map(value => stringValidator.format(value))
Expand Down
4 changes: 2 additions & 2 deletions src/lib/validator-select_one.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {IValidator} from './validation';
import ValidatorString from './validator-string';

export default class ValidatorSelectOne implements IValidator {
isValid(input: string, property: ContactProperty): boolean {
isValid(input: string, property: ContactProperty): boolean|string {
const stringValidator = new ValidatorString();
const trimmedInput = stringValidator.format(input);

if (trimmedInput.length === 0 && property.required) {
throw new Error('Value is required');
return `Value is required`;
}
// Verify property.parameter is an object
if (!property?.parameter || typeof property.parameter !== 'object') {
Expand Down
8 changes: 0 additions & 8 deletions src/liquid/components/list_cell.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
<a href="https://{{ session.authInfo.domain }}/#/contacts/{{ include.linkTo.id }}" target="_blank">
{{ include.values[include.property.property_name] }}
</a>
{% elsif include.property.type == 'select_one' %}
{% assign valueKey = include.values[include.property.property_name] %}
{{ include.property.parameter[valueKey] }}
{% elsif include.property.type == 'select_multiple' %}
{% assign values = include.values[include.property.property_name] | split: " " %}
{% for value in values %}
{{include.property.parameter[value]}}
{% endfor %}
{% else %}
{{ include.values[include.property.property_name] }}
{% endif %}
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 @@ -192,7 +192,7 @@ describe('lib/validation.ts', () => {

expect(Validation.getValidationErrors(place)).to.deep.eq([{
property_name: 'user_role',
description: 'Error in isValid for \'select_multiple\': Error: Invalid values: stockmanager'
description: 'Invalid values: stockmanager'
}]);
});
});
Expand Down

0 comments on commit c464dff

Please sign in to comment.