chore: filter out non-app extensions and log
Signed-off-by: benjdlambert <ben@blam.sh>
This commit is contained in:
@@ -37,18 +37,32 @@ export const SwappableComponentsApi = ApiBlueprint.makeWithOverrides({
|
||||
defineParams({
|
||||
api: swappableComponentsApiRef,
|
||||
deps: {},
|
||||
factory: () =>
|
||||
DefaultSwappableComponentsApi.fromComponents(
|
||||
inputs.components.map(i => {
|
||||
if (i.node.spec.plugin?.id !== 'app') {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
`SwappableComponents should only be installed as an extension in the app plugin. You can either use appPlugin.override(), or provide a module for the app-plugin with the extension there instead. id={${i.node.spec.id}}`,
|
||||
);
|
||||
}
|
||||
return i.get(SwappableComponentBlueprint.dataRefs.component);
|
||||
}),
|
||||
),
|
||||
factory: () => {
|
||||
const nonAppExtensions = inputs.components.filter(
|
||||
i => i.node.spec.plugin?.id !== 'app',
|
||||
);
|
||||
|
||||
if (nonAppExtensions.length > 0) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
`SwappableComponents should only be installed as an extension in the app plugin.
|
||||
You can either use appPlugin.override(), or provide a module for the app-plugin with the extension there instead.
|
||||
Invalid extensions: ${nonAppExtensions
|
||||
.map(i => i.node.spec.id)
|
||||
.join(', ')}`,
|
||||
);
|
||||
}
|
||||
|
||||
const appExtensions = inputs.components.filter(
|
||||
i => i.node.spec.plugin?.id === 'app',
|
||||
);
|
||||
|
||||
return DefaultSwappableComponentsApi.fromComponents(
|
||||
appExtensions.map(i =>
|
||||
i.get(SwappableComponentBlueprint.dataRefs.component),
|
||||
),
|
||||
);
|
||||
},
|
||||
}),
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user