-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Adding List 'track' option (replaces #490) #523
Adding List 'track' option (replaces #490) #523
Conversation
changed; "standard meta" pattern now enables list "track" option added; "standard meta" pattern displays deprecation warning
added; helper functions for commonly used code
@JohnnyEstilles Thanks for this PR, that's some genius work. Simple and effective. |
@Globegitter You're quite welcome! I aim to please. :-) I'm not sure about the genius part, but I appreciate the compliment. :-) |
This looks great, nice work @JohnnyEstilles! |
…-option Adding List 'track' option (replaces #490)
Just a quick comment that I just updated to 0.2.26 and get the following warning (as expected) but the link to the List Options does not explain anything about this (as far as I can tell)--the documentation team should take note of this: KeystoneJS: Deprecation Warning: Use of List.addPattern("standard meta") is now deprecated and will be removed See http://keystonejs.com/docs/database/#lists-options for more information. |
@webteckie, I submitted changes to the docs in my PR, but it looks like the website is still one build behind (on 0.2.25). Thanks for pointing that out. |
@webteckie @JohnnyEstilles sorry about that, I forgot to push the new docs build when I released 0.2.26 to npm. It's up now :) |
@JedWatson, cool! Thanks! I mean, I already new how to use it, but I guess we should let the rest of the world. :-) |
As promised, here's my PR for the List
track
option, which adds plugin that automatically tracks when and who created and last updated an item. This PR replaces #490.The feature can be enabled for all tracking fields, with all their default names, by setting
track
totrue
.I added this as a shortcut to setting
track
to{ createdAt: true, createdBy: true, updatedAt: true, updatedBy: true}
, which I thought was a bit verbose and probably the most common use case.You can selectively enabled each tracking field by setting
track
anobject
containing the keys for the desired fields set totrue
. When using this method, fields will default tofalse
, so any omitted fields will not be enabled.You can also selective specify custom field names by setting the desired field keys to a string representing the desired name.
As we agreed in #490, using
List.addPattern('standard meta')
enables thetrack
option and mapscreatedOn
andupdatedOn
tocreatedAt
andupdatedAt
respectively. It also displays a message warning the developer that the feature is now deprecated.I've also updated the Keystone docs with documentation for the
track
option. I included a caveat pointing out thatcreatedBy
andupdatedBy
are only updated when adding/updating items via the Admin UI (which uses theupdateHandler()
). I further explained that if developers wish to add/modify items from their own apps they must manually store the currently logged on user in the item prior to calling.save()
. I used the following example:This addresses the issue of
._req_user
not being available topre
andpost
save hooks when using.save()
.Finally, I included a unit test for the feature. I refactored some common code into helper functions and updated the test for the
._req_user
feature to use them as well.That's it! Comments, suggestions and modifications are always welcome!