-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[ViewAPI] implement initial view API #1642
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
Conversation
|
TODO: Need to handle editable / separate views for edit mode. |
|
TODO: need to address container sizing. If someone wants to inject a view that is 100% of the width and height of the container, they need to intentionally add the "abs" class to the container. Either we document this as a thing view developers need to do, or we add this class to the container so they don't have to worry about it. |
I think we should add this class at a container level from the platform whenever that layout behavior is desired. Simpler, meets principle of least surprise (I do not expect to need to worry about the layouts of container elements when I'm writing a view plugin), reduces our effective API surface (insofar as CSS classes are "APIs") and gives us more implementation flexibility in the future. |
Running through some options:
I'm leaning toward Option 2 given current status. Feels clean and straightforward. The many-to-one problem makes it a little difficult, but view-as-object should entirely mitigate that. |
|
@VWoeltjen I like editors as a separate extension point. It makes it super clear to developers how to add a new editing view of an object. It also doesn't actually stop you from using the same view if you want to, you could just check on view initialization whether the object is currently being edited, which avoids the need to listen to event changes. |
akhenry
left a comment
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.
Looks good. Excited to start using the new view API! A couple of comments inline.
| // be defaults by returning priority less than 100. | ||
| }; | ||
| if (v.provider) { | ||
| vd.priority = v.provider.canView(newDomainObject); |
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.
I'm not so sure about canView returning priority. It's kind of nice in that you can treat anything non-zero as boolean true if you don't care about its priority, but it will inevitably lead to type checking in client code.
Also it doesn't seem obvious to me that it's going to return priority, and it feels like it's violating the "Do One Thing" rule.
Separating out priority will complicate the view provider interface, but will improve clarity I think.
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.
per discussion:
- canview returns boolean
- priority function is optional, when present takes object and returns priority (number)
| * @name objectViews | ||
| */ | ||
| this.mainViews = new ViewRegistry(); | ||
| this.objectViews = new ViewRegistry(); |
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.
Noice
src/ui/ViewRegistry.js
Outdated
| * views. | ||
| * @private | ||
| */ | ||
| ViewRegistry.prototype._getByVPID = function (vpid) { |
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.
I've been tempted in the past to use the _ prefix, but decided against it in lieu of better JSDocs. Since we're potentially moving our API docs away from JSDoc this might be a good convention to use, so long as we use it consistently. The danger is that anything not prefixed with an _ is considered fair game by developers. Eg. .get() is also marked private but doesn't have an underscore.
src/ui/ViewRegistry.js
Outdated
| * @returns {boolean} true if this domain object can be viewed using | ||
| * this provider | ||
| * @returns {Number|boolean} if this returns `false`, then the view does | ||
| * not apply to the object. If it returns true or any number, then |
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.
See above comments about canView vs priority.
src/ui/ViewRegistry.js
Outdated
| * @memberof module:openmct.ViewRegistry# | ||
| */ | ||
| ViewRegistry.prototype.addProvider = function (provider) { | ||
| provider._vpid = this._next_id++; |
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.
Maybe view providers should just have keys? Or is the vpid just internal wiring for compatibility with legacy views? My jetlag addled brain is having trouble understanding vpid
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.
per discussion, yes view providers should have keys.
|
Pushed two commits. The first separates out priority and canView. Not sure priority is being used properly at the moment in the new view API, The second commit replaces vpid with a view provider key. Need to do some testing and sanity-checking tomorrow to ensure that what I've committed is not the lunatic ravings of a jetlagged mind, and is at least up to the standard of my usual drivel. Also, still need to fix those code style errors. |
|
@larkin I'm done with this if you want to take a look. @VWoeltjen Since this impacts your work on the heatmap view I'm assigning you reviewer :) @dtailor90 This also affects summary widgets and rover view as view providers now require a 'key' and openmct.objectViews.addProvider({
key: 'my-view',
name: 'my view',
canView: function (d) {
return d.type === 'folder';
},
priority: function (d) {
return 1000;
},
view: function (domainObject) {
return {
show: function (container) {
container.innerHTML = '<div> Congratulations, this is a view of: ' + domainObject.name + '</div>';
},
destroy: function (container) {
}
}
}
}); |
src/MCT.js
Outdated
|
|
||
| this.objectViews.getAllProviders().forEach(function (p) { | ||
| this.legacyExtension('views', { | ||
| key: 'provider-namespace-' + p.key, |
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.
per discussion: don't prefix
src/ui/ViewRegistry.js
Outdated
| throw "View providers must have a unique 'key' defined"; | ||
| } | ||
| if (this.providers[key] !== undefined) { | ||
| throw "Provider already defined for key '" + key + "'. Keys must be unique."; |
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.
per discussion; make this a warning at most, allow overrides.
|
Writing this post so I can link a few developers to it. Can also integrate into API docs later. changes for existing usersFor anyone currently using the view API, the following changes need to be made to your usage of the view API after this pull request (#1642) is merged:
For a more complete listing of supported properties, look no further than this handy dandy table. Object View Provider properties
|
4623fd7 to
d7b44f8
Compare
|
I've squished all the commits for this branch into one. |
|
Leaving an author checklist as a partial author, @akhenry can post review and author checklists as the other partial author. Author Checklist
|
Author Checklist
|
Reviewer Checklist (For Andrew's authorship)
|
akhenry
left a comment
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.
Reviewer Checklist
- Changes appear to address issue? Y
- Appropriate unit tests included? N/A
- Code style and in-line documentation are appropriate? Y
- Commit messages meet standards? Y
This is a discussion / develop branch for finalizing the view API.
openmct.mainViewstoopenmct.objectViews. I think this is more clear that these are views of an object, and separates them from "indicators" and the soon-to-be "inspector view".For testing, you can define a view by adding the following to index.html:
@VWoeltjen et all, feedback appreciated. (@luisschubert you may also be interested).