Repository navigation
Albert persistent autofills - #1041
MysteriousChallenger wants to merge 22 commits into
Conversation
adds user_dictionary database table and JOOQ generated DAOs and POJOs user_dictionary stores uid+key -> json-value pairs, storing arbitrary json data for each user
adds api for r/w access for the user dictionary table
the @autofill annotation causes the annotated property to be marked as autofillable when serialized into a json schema. In addition to each @autofill property having a "type" property in the json schema, they will also have an "autofill" property which is always set to true. If the property is not annotated with @autofill, it will not have the property "autofill" at all
the dictionary service provides the frontend with observable event streams and w/r functions for the user dictionary resource. It also provides userDictionary objects that are proxies to the user dictionary resource: - get operations yield values from the user dictionary resource, - set operations post values to the user dictionary resource
dropdowns show presets for applicable operators in the operator property editor
|
@MysteriousChallenger please let me know once you finish todo (description) and fix the failed tests. |
abd1724 to
b3dd540
Compare
|
Wrote all the front-end tests, finally! |
|
Thanks for this detailed PR! Will review it during the weekend. |
Yicong-Huang
left a comment
There was a problem hiding this comment.
Sorry for the late reply. TBH, the PR is too large to view.. I could not finish reading everything in this round, so I stopped in the mid-way. I left some comments in the code, please take care of them.
On a high level,
- is it possible to break down those changes into small PRs for easier reviews?
- can we change the backend table/service name to something different from
user dictionary? Especially I don't feel good about the namedictionary. It does not sound accurate and also it is not matching the frontend namepreset. We can talk about namings offline. - I am having a hard time understanding frontend tests. It will be good to add comments or let's have an offline discussion.
- In general please add more comments for readability.
Please take care of the comments and request another round of review. I will do the test then.
| **/.bloop/ | ||
| **/.bsp/ | ||
| **/.metals/ | ||
| **/project/metals.sbt |
There was a problem hiding this comment.
are those changes necessary, can you explain what are those directories/files for?
There was a problem hiding this comment.
Those are some folders generated by a vscode plugin. I'll see about only applying these changes only on my local repo
| }, | ||
| { | ||
| "label": "build ts", | ||
| "type": "shell", | ||
| "command": "cd new-gui && npm install" | ||
| }, | ||
| { | ||
| "label": "run ts", | ||
| "type": "shell", | ||
| "command": "cd new-gui && ng serve --watch" |
There was a problem hiding this comment.
those are IDE-related changes, ideally we should keep it local and ignore the changes.
There was a problem hiding this comment.
agreed
| return getAllValues(user) | ||
| } else { | ||
| return getValueByKey(user, key) |
There was a problem hiding this comment.
the return keywords seem to be redundant here.
| @@ -0,0 +1,226 @@ | |||
| package edu.uci.ics.texera.web.resource.dashboard | |||
There was a problem hiding this comment.
the package does not match the directory?
There was a problem hiding this comment.
yep. whoops
| def getValue(@Session session: HttpSession, @QueryParam("key") key: String): Response = { | ||
|
|
||
| // check that user is logged in and authorized | ||
| val user = UserResource.getUser(session).getOrElse(null); |
There was a problem hiding this comment.
.getOrElse(null) you can just use .orNull
| if (e instanceof SyntaxError) { // result was not json | ||
| this.dictionaryEventSubject.next({type: EVENT_TYPE.GET, key: key, value: result}); | ||
| return result; | ||
| } else { |
There was a problem hiding this comment.
when will this happen?
| result = JSON.parse(result); | ||
| this.dictionaryEventSubject.next({type: EVENT_TYPE.GET, key: key, value: result}); |
There was a problem hiding this comment.
- you are parsing the result in a promise and then forward it to a subject. can't we simply to use observable directly?
- what is the type of
resultvariable? it seems being changed during runtime.
| case 401: | ||
| this.dictionaryEventSubject.next({type: EVENT_TYPE.GET, key: key, value: undefined as any}); | ||
| return undefined as any; | ||
| default: | ||
| this.dictionaryEventSubject.next({type: EVENT_TYPE.GET, key: key, value: undefined as any}); | ||
| console.warn(reason); | ||
| return undefined as any; | ||
| } |
There was a problem hiding this comment.
is the only difference between those two cases is on the console.warn? can we simplify duplicate code?
| public static readonly USER_DICTIONARY_ENDPOINT = 'users/dictionary'; | ||
|
|
||
| private dictionaryEventSubject = new Subject<USER_DICT_EVENT>(); | ||
| private localUserDictionary: UserDictionary = {}; // asynchronously initialized after construction (see initLocalDict) |
There was a problem hiding this comment.
I am worried about having a local copy of user dictionary. this could cause unsynced issues. why not we remove the local cache, and each time fetch the latest dictionary from the backend?
| private generateProxyHandler(): ProxyHandler<UserDictionary> { | ||
| const _this = this; | ||
| return { | ||
| set(localUserDictionary: Readonly<UserDictionary>, key: string, value: JSONValue) { | ||
| _this.set(key, value); | ||
| return true; | ||
| }, | ||
| deleteProperty: function(localUserDictionary: Readonly<UserDictionary>, key: string) { | ||
| _this.delete(key); | ||
| return true; | ||
| }, | ||
| defineProperty(localUserDictionary: Readonly<UserDictionary>, key: string, value: JSONValue) { | ||
| _this.set(key, value); | ||
| return true; | ||
| } | ||
| }; | ||
| } |
There was a problem hiding this comment.
what's the purpose of this proxy?
This PR is extracted from #1041 as step 1 of the User Preset feature. rebase of picked commits pertaining to UserDictionaryResource onto master UserDictionaryResource provides a "_dictionary_", a persistent collection of string (key, value) pairs for each user. Its API is located at /api/users/dictionary. functionality includes get/set/delete, mapped to the GET/POST/DELETE HTTP methods. Changes from last review (for Yicong) - now only consumes and produces application/json - CODE 422 Unprocessable Entity replaces 400 bad request if user provides well formed request that cannot be fulfilled - I.E well-formed DELETE request when there is nothing to delete - No more confusing json validation: key/values are always strings (previously was trying to store them in MySQL json column, now using text column) - user/login check first - Unused imports removed - using orNull instead of getOrElse(null) - removed extraneous _return_ Co-authored-by: Yicong Huang <[email protected]>
This PR is extracted from #1041 as step 2 of the User Preset feature. rebase of picked commits pertaining to UserDictionaryService onto Albert-UserDictionaryResource UserDictionaryService provides a "dictionary", a persistent collection of string (key, value) pairs for clients that are logged in Changes from last review (for Yicong) - Much more code comments - using new API from User Presets Step 1 - Get/Set/Delete methods return Observables instead of Promises now - Code should be much more readable because error handling and validation are separated into individual function definitions Co-authored-by: Yicong Huang <[email protected]> Co-authored-by: Zuozhi Wang <[email protected]>
Final feature demo:  --------------------------- This PR is extracted from #1041 as step 2 of the User Preset feature. rebase of picked commits pertaining to PresetServiceService onto Albert-UserDictionaryService PresetService provides the ability to save and "apply" collections of settings (represented by objects) that a user might find convenient to save and apply as a group. These groups are called Presets. PresetService uses DictionaryService to store presets (it creates kind of a *view* in the database sense, of the user dictionary, that only includes Presets) Changes from last review (for Yicong) - Code comments - fixed subscription memory leak by using takeUntil(observable), where said observable completes on NgOndestroy - DictionaryService now attempts to init whenever client logs in (sorry, you'll have to re-review my changes to DictionaryService) - PresetService now has public ready promise/value member - This indicates that its init isn't complete until DictionaryService's init is complete (which is async, and cant be awaited in the constructor) - DeletePreset now built into PresetService (don't know why I ever didn't have that) - Revert Changes to Styles.scss to fix Karma test runner interface (I originally changed them as a workaround for an ng-zorro component that's no longer used) Note: for this step, I had less time and more complex code to test. I'm not sure I caught all the bugs, but it passes unit tests. The quality of the code in this pr is lesser, in my opinion, so You'll have to be a little more careful on my behalf. Co-authored-by: Zuozhi Wang <[email protected]> Co-authored-by: Yicong Huang <[email protected]>
This PR is extracted from apache#1041 as step 1 of the User Preset feature. rebase of picked commits pertaining to UserDictionaryResource onto master UserDictionaryResource provides a "_dictionary_", a persistent collection of string (key, value) pairs for each user. Its API is located at /api/users/dictionary. functionality includes get/set/delete, mapped to the GET/POST/DELETE HTTP methods. Changes from last review (for Yicong) - now only consumes and produces application/json - CODE 422 Unprocessable Entity replaces 400 bad request if user provides well formed request that cannot be fulfilled - I.E well-formed DELETE request when there is nothing to delete - No more confusing json validation: key/values are always strings (previously was trying to store them in MySQL json column, now using text column) - user/login check first - Unused imports removed - using orNull instead of getOrElse(null) - removed extraneous _return_ Co-authored-by: Yicong Huang <[email protected]>
This PR is extracted from apache#1041 as step 2 of the User Preset feature. rebase of picked commits pertaining to UserDictionaryService onto Albert-UserDictionaryResource UserDictionaryService provides a "dictionary", a persistent collection of string (key, value) pairs for clients that are logged in Changes from last review (for Yicong) - Much more code comments - using new API from User Presets Step 1 - Get/Set/Delete methods return Observables instead of Promises now - Code should be much more readable because error handling and validation are separated into individual function definitions Co-authored-by: Yicong Huang <[email protected]> Co-authored-by: Zuozhi Wang <[email protected]>
Final feature demo:  --------------------------- This PR is extracted from apache#1041 as step 2 of the User Preset feature. rebase of picked commits pertaining to PresetServiceService onto Albert-UserDictionaryService PresetService provides the ability to save and "apply" collections of settings (represented by objects) that a user might find convenient to save and apply as a group. These groups are called Presets. PresetService uses DictionaryService to store presets (it creates kind of a *view* in the database sense, of the user dictionary, that only includes Presets) Changes from last review (for Yicong) - Code comments - fixed subscription memory leak by using takeUntil(observable), where said observable completes on NgOndestroy - DictionaryService now attempts to init whenever client logs in (sorry, you'll have to re-review my changes to DictionaryService) - PresetService now has public ready promise/value member - This indicates that its init isn't complete until DictionaryService's init is complete (which is async, and cant be awaited in the constructor) - DeletePreset now built into PresetService (don't know why I ever didn't have that) - Revert Changes to Styles.scss to fix Karma test runner interface (I originally changed them as a workaround for an ng-zorro component that's no longer used) Note: for this step, I had less time and more complex code to test. I'm not sure I caught all the bugs, but it passes unit tests. The quality of the code in this pr is lesser, in my opinion, so You'll have to be a little more careful on my behalf. Co-authored-by: Zuozhi Wang <[email protected]> Co-authored-by: Yicong Huang <[email protected]>
IMPORTANT: this branch requires reinstalling the mysql user dashboard tables because I added a new table.
currently soliciting reviews of the user interface and the general architecture
A brief description of the architecture:
backend:
frontend:
DictionaryService provides read/write access to the dictionary of the logged in user (or a blank, temporary dictionary if not logged in)
PresetService uses DictionaryService to read/write presets and provides event streams representing applying a preset.
the workflow action service listens for when an operator preset is applied, and then actually applies the preset by merging the existing operator properties and the given preset.Property Editor component handles wrapping form fields in a special Preset-wrapper component that adds the preset dropdowns
Setting up a preset enabled field (see preset-wrapper component) is non-trivial, it involves some very opaque code: I wrote a static method that sets up the formly field template options correctly.
Property Editor component also handles saving operator presets when a user edits operator properties