-
Notifications
You must be signed in to change notification settings - Fork 613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support models declared by plugins #1586
Support models declared by plugins #1586
Conversation
@jtomasek This should fix the error you've had regarding Console not picking up your custom models, e.g. |
The first two commits are from other un-merged PRs, please review the last one. |
models = [ ...models, ext.properties.model ]; | ||
}); | ||
|
||
return _.uniqWith(models, (a, b) => referenceForModel(a) === referenceForModel(b)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we expect multiple plugins to define the same model? I feel like we should at least print a warning, particularly if the models aren't exactly the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point.
A plugin should not re-define existing static models, this includes both core Console models (definitions in public/models/index.ts
) and models contributed by other plugins (e.g. BaremetalHostModel
from Metal3 plugin).
I feel like we should at least print a warning, particularly if the models aren't exactly the same.
Agreed, I'll adapt the code accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR updated, conflicting models will be discarded along with a console log warning.
446ecaf
to
14e98fe
Compare
@spadgett Please check out PR description for an overview of recent changes. As discussed earlier, the concept of plugin registry module will go away in favor of HOC to connect relevant React components to extensions they're interested in. |
@@ -1,61 +1,86 @@ | |||
/* eslint-env node */ | |||
|
|||
// eslint-disable-next-line no-restricted-imports |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note - this is an implication of eslint-env node
above.
|
||
export function isValidPluginPackage(pkg: Package): pkg is PluginPackage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed earlier, I've adapted function
declarations to const
since the latter form seems to be preferred.
@vojtechszocs I do not understand why |
My motivation was to establish a convention where each plugin has a module ( But you're right. Models are just another type of Console extension and shouldn't be treated differently. I'll change the export type ActivePlugin = {
name: string; // = pkg.name
extensions: Extension<any>[]; // = pkg.consolePlugin.entry
}; and introduce new extension type for models. Plugins can still have |
124a117
to
397eaaa
Compare
PR updated according to @christianvogt's comment. |
/lgtm This looks much better now @vojtechszocs |
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: christianvogt, jtomasek, spadgett, vojtechszocs The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
No such policy that I'm aware of, it's a good point for discussion, cc @spadgett. Production builds could have some ( |
This PR ensures that Console is aware of any additional static models declared by plugins.
Overview
Plugins are encouraged to keep all of their model definitions in a single module, e.g.
models.ts
placed next toplugin.ts
.To add these models, use the new
ModelDefinition
extension:Browser console log:
The
@console/active-plugins
module codegen has been modified to exportActivePlugin[]
, i.e. the list of extensions enhanced with additional data:Any future metadata (e.g. plugin order) can be part of the
ActivePlugin
representation.Note: from plugin author perspective, a plugin remains to be a list of
Extension
objects.Handling model conflicts
A plugin cannot redefine existing models, this includes both Console base models and models declared previously by other plugins.
The conflicting models will be reported in browser console log:
@mareklibra @jtomasek YAML template extension will be done in a separate PR.