Skip to content

Commit

Permalink
Fixing regression bug where default modules weren't shown in list.
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldenning committed Nov 5, 2019
1 parent b33efd6 commit 4ae7019
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
60 changes: 32 additions & 28 deletions src/ui/list/list.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,35 +62,33 @@ export default class List extends Component {
defaultModules = [];

const overrideMap = window.importMapOverrides.getOverrideMap().imports;
const filteredSearchModuleNames = Object.keys(overrideMap).filter(
moduleName =>
this.state.searchVal.trim().length > 0
? moduleName.includes(this.state.searchVal)
: true
);

filteredSearchModuleNames.forEach(moduleName => {
const mod = {
moduleName,
defaultUrl: this.state.notOverriddenMap.imports[moduleName],
overrideUrl: overrideMap[moduleName]
};
if (overrideMap[moduleName]) {
overriddenModules.push(mod);
} else {
defaultModules.push(mod);
}
});

filteredSearchModuleNames.forEach(overrideKey => {
if (!overriddenModules.some(m => m.moduleName === overrideKey)) {
overriddenModules.push({
moduleName: overrideKey,
defaultUrl: null,
overrideUrl: overrideMap[overrideKey]
});
}
});
Object.keys(this.state.notOverriddenMap.imports)
.filter(this.filterModuleNames)
.forEach(moduleName => {
const mod = {
moduleName,
defaultUrl: this.state.notOverriddenMap.imports[moduleName],
overrideUrl: overrideMap[moduleName]
};
if (overrideMap[moduleName]) {
overriddenModules.push(mod);
} else {
defaultModules.push(mod);
}
});

Object.keys(overrideMap)
.filter(this.filterModuleNames)
.forEach(overrideKey => {
if (!overriddenModules.some(m => m.moduleName === overrideKey)) {
overriddenModules.push({
moduleName: overrideKey,
defaultUrl: null,
overrideUrl: overrideMap[overrideKey]
});
}
});

overriddenModules.sort(sorter);
defaultModules.sort(sorter);
Expand Down Expand Up @@ -185,6 +183,12 @@ export default class List extends Component {
}
this.setState({ dialogModule: null });
};

filterModuleNames = moduleName => {
return this.state.searchVal.trim().length > 0
? moduleName.includes(this.state.searchVal)
: true;
};
}

function mergeImportMap(originalMap, newMap) {
Expand Down
7 changes: 7 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Import Map Overrides test</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script type="importmap">
{
"imports": {
"a": "./a.js"
}
}
</script>
<script src="/import-map-overrides.js"></script>
</head>
<body>
Expand Down

0 comments on commit 4ae7019

Please sign in to comment.