Skip to content

Commit

Permalink
fix: use first option to fetch projection for secondary fields
Browse files Browse the repository at this point in the history
  • Loading branch information
friedjoff committed Apr 14, 2020
1 parent ff0ca72 commit a7e358b
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/src/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const fields = [
'silverFirArea',
'relief',
];
const fieldsConcat = ['slope', 'additional', 'silverFirArea', 'relief'];
const secondaryFields = ['slope', 'additional', 'silverFirArea', 'relief'];
const concat = (x, y) =>
Array.from(new Set((x || []).concat(y))).sort((a, b) => a - b);

Expand Down Expand Up @@ -40,7 +40,7 @@ function projectionReducer(location, targetAltitudePointer, result) {
const { field, value, values } = getField(fields[i], location);
validate(field, value, values);

options[field] = fieldsConcat.includes(field)
options[field] = secondaryFields.includes(field)
? concat(options[field], Object.keys(projection))
: options[field] || Object.keys(projection);

Expand All @@ -52,10 +52,9 @@ function projectionReducer(location, targetAltitudePointer, result) {
} else if (valueNotInOptions(value, options[field])) {
// Do not return location values if no projection was found.
return { ...result, options };
} else if (fieldsConcat.includes(field)) {
} else if (secondaryFields.includes(field)) {
// Fall back to first projection for secondary fields.
const first = Object.keys(projection)[0];
projection = projection[first];
projection = projection[options[field][0]];
} else {
// Location does not provide any more values for conditions.
break;
Expand Down Expand Up @@ -117,7 +116,7 @@ function project(location = {}, targetAltitude, previousResult) {
const transition = project(tl, targetAltitude);
const tp = transition.projections || [];
Object.entries(transition.options).forEach(([k, v]) => {
if (fieldsConcat.includes(k)) {
if (secondaryFields.includes(k)) {
result.options[k] = concat(result.options[k], v);
}
});
Expand Down

0 comments on commit a7e358b

Please # to comment.