-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
103 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { SYSTEM_PREFIX } from '../combination/dimensions.js' | ||
|
||
// Some logic updates `rawResult.combinations[*].dimensions[*].id`. | ||
// System ids are persisted in two places: `rawResult.system.dimensions` and | ||
// `rawResult.combinations[*].dimensions`. | ||
// We need to update the former. | ||
export const renameAllSystemIds = function (rawResults) { | ||
return rawResults.map(renameSystemIds) | ||
} | ||
|
||
const renameSystemIds = function (rawResult) { | ||
const [{ dimensions }] = rawResult.combinations | ||
return Object.entries(dimensions) | ||
.filter(isSystemDimension) | ||
.reduce(renameSystemId, rawResult) | ||
} | ||
|
||
const isSystemDimension = function ([propName]) { | ||
return propName.startsWith(SYSTEM_PREFIX) | ||
} | ||
|
||
const renameSystemId = function (rawResult, [propName, { id }]) { | ||
const propNameA = unprefixPropName(propName) | ||
return rawResult.system.dimensions[propNameA] === id | ||
? rawResult | ||
: { | ||
...rawResult, | ||
system: { | ||
...rawResult.system, | ||
dimensions: { ...rawResult.system.dimensions, [propNameA]: id }, | ||
}, | ||
} | ||
} | ||
|
||
const unprefixPropName = function (propName) { | ||
return propName.slice(SYSTEM_PREFIX.length) | ||
} |