Skip to content

Commit

Permalink
Tidy up code
Browse files Browse the repository at this point in the history
  • Loading branch information
thsparks committed Sep 11, 2024
1 parent 201f520 commit 3856fe2
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions teachertool/src/transforms/loadCatalogAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,24 @@ export async function loadCatalogAsync() {
const { dispatch } = stateAndDispatch();
const fullCatalog = await loadTestableCollectionFromDocsAsync<CatalogCriteria>(prodFiles, "criteria");

// Re-instantiate catalog parameters into their more specific types
for (const criteria of fullCatalog) {
for (let i = 0; i < (criteria.params?.length ?? 0); i++) {
const param = criteria.params![i];
criteria.params![i] = createSpecificParameter(param, criteria.id);
}
}
// Re-instantiate parameter into its more specific type.
// If we don't do this, parameters will all have the base CriteriaParameter
// validate function instead of their more specific overloads.
const newParam = createSpecificParameter(criteria.params![i], criteria.id);

fullCatalog.forEach(c => {
// Convert parameter names to lower-case for case-insensitive matching
c.params?.forEach(p => {
p.name = p.name.toLocaleLowerCase();
});
// Convert to lower-case for case-insensitive matching
newParam.name = newParam.name.toLocaleLowerCase();

criteria.params![i] = newParam;
}

// Add default tag if none are present
if (!c.tags || c.tags.length === 0) {
c.tags = [Strings.Other];
if (!criteria.tags || criteria.tags.length === 0) {
criteria.tags = [Strings.Other];
}
});
}

dispatch(Actions.setCatalog(fullCatalog));
}

0 comments on commit 3856fe2

Please sign in to comment.