Skip to content

Commit

Permalink
Make capacity handling more flexible (#111)
Browse files Browse the repository at this point in the history
TPAC 2024 introduces new labels for room capacity in issue template. This
update makes the code more flexible when it comes to handling capacity
options. Mapping between new labels and actual room capacity values still
needs to be hardcoded somehow.
  • Loading branch information
tidoust authored Apr 24, 2024
1 parent 719fbfe commit 16cd08a
Showing 1 changed file with 35 additions and 34 deletions.
69 changes: 35 additions & 34 deletions tools/lib/session.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ export async function initSectionHandlers(project) {
serialize: value => value
};
if (section.type === 'dropdown') {
handler.options = section.attributes.options.map(o => o.toLowerCase());
handler.validate = value => handler.options.includes(value.toLowerCase());
handler.options = section.attributes.options.map(o => Object.assign({
label: o,
llabel: o.toLowerCase()
}));
handler.validate = value => !!handler.options.find(o => o.llabel === value.toLowerCase());
}
else if (section.type === 'input') {
handler.validate = value => !value.match(/\n/)
Expand Down Expand Up @@ -227,47 +230,45 @@ export async function initSectionHandlers(project) {
break;

case 'capacity':
if (project.metadata.type === 'groups') {
handler.parse = value => {
switch (value.toLowerCase()) {
for (const option of handler.options) {
option.value = (function (label) {
switch (label) {
case 'don\'t know': return 0;
case 'don\'t know (default)': return 0;

// Labels used for TPAC 2023
case 'less than 15': return 10;
case '16-30': return 20;
case '31-50': return 40;
case 'more than 50': return 50;
default: throw new Error(`Unexpected capacity value "${value}"`);
};
};
handler.serialize = value => {
switch (value) {
case 10: return 'Less than 15';
case 20: return '16-30';
case 40: return '31-50';
case 50: return 'More than 50';
default: throw new Error(`Unexpected capacity value "${value}"`);
}
}
}
else {
handler.parse = value => {
switch (value.toLowerCase()) {
case 'don\'t know': return 0;
case 'don\'t know (default)': return 0;

// Labels used for TPAC 2024
case 'less than 20': return 15;
case '20 to 29': return 25;
case '30 to 39': return 35;
case 'more than 40': return 40;

// Labels used for breakouts day 2024
case 'fewer than 20 people': return 15;
case '20-45 people': return 30;
case 'more than 45 people': return 50;
default: throw new Error(`Unexpected capacity value "${value}"`);
};
};
handler.serialize = value => {
switch (value) {
case 0: return 'Don\'t know (Default)';
case 15: return 'Fewer than 20 people';
case 30: return '20-45 people';
case 50: return 'More than 45 people';
default: throw new Error(`Unexpected capacity value "${value}"`);
}
}
})(option.llabel);
}
handler.parse = value => {
const option = handler.options.find(o => o.llabel === value.toLowerCase());
if (!option) {
throw new Error(`Unexpected capacity value "${value}"`);
}
return option.value;
};
handler.serialize = value => {
const option = handler.options.find(o => o.value === value);
if (!option) {
throw new Error(`Unexpected capacity value "${value}"`);
}
return option.label;
};
break;

case 'times':
Expand Down

0 comments on commit 16cd08a

Please sign in to comment.