Skip to content

Albert persistent autofills - #1041

Closed
MysteriousChallenger wants to merge 22 commits into
masterfrom
Albert-persistent-autofills
Closed

MysteriousChallenger wants to merge 22 commits into
masterfrom
Albert-persistent-autofills

Conversation

@MysteriousChallenger

@MysteriousChallenger MysteriousChallenger commented Feb 20, 2021 •

Copy link
Copy Markdown
Contributor
  • description
  • code comments
  • tests

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:

  • stores presets in a user-dictionary table
    • each row is a tuple(int uid, varchar key, json value). The user-id and key must be a unique pair (users may not have multiple dictionary entries for a key)
    • all values are enclosed in an array, so that you can store string values in a json column (e.g (1, "lang", ["en/us"]))
  • read/write access is provided by the java webserver at /users/dictionary/?key="key"&value="value"
  • client must be logged on (have valid session cookie) to access api

frontend:

  • DictionaryService provides read/write access to the dictionary of the logged in user (or a blank, temporary dictionary if not logged in)

    • get/set/delete/get_all public functions
    • event stream for all get/set/delete/get_all operations (no real use for this yet, but it's there)
    • synchronized dictionary proxy objects.
      • ex: dict.lang == "en/us" (should match what's stored in backend)
      • ex: dict.indent_spaces = 4 (causes a post request that sets indent_spaces = 4 in the backend)
      • "get requests" on the dictionary proxies return the locally stored value without sending a get request, but since all assignment and deletion operations are mirrored, the local and remote copies should match
  • 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.
    • Preset service listens to it's own event stream and validates/applies operator preset via workflow action service
  • 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

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
@Yicong-Huang

Copy link
Copy Markdown
Contributor

@MysteriousChallenger please let me know once you finish todo (description) and fix the failed tests.

@Yicong-Huang Yicong-Huang added the ddl-change Changes to the TexeraDB DDL label Feb 25, 2021
refactored preset service to depend on workflowActionService instead of the other way around. This fixes tests because workflowActionService no longer needs ngMessageModule to display message whenever a preset is applied.
@MysteriousChallenger
MysteriousChallenger force-pushed the Albert-persistent-autofills branch from abd1724 to b3dd540 Compare April 2, 2021 02:13
@Yicong-Huang
Yicong-Huang marked this pull request as draft April 23, 2021 21:39
@MysteriousChallenger
MysteriousChallenger marked this pull request as ready for review May 3, 2021 09:16
@MysteriousChallenger

Copy link
Copy Markdown
Contributor Author

Wrote all the front-end tests, finally!

@Yicong-Huang

Copy link
Copy Markdown
Contributor

Thanks for this detailed PR! Will review it during the weekend.

@Yicong-Huang Yicong-Huang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 name dictionary. It does not sound accurate and also it is not matching the frontend name preset. 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.

Comment thread core/.gitignore
Comment on lines +28 to +31
**/.bloop/
**/.bsp/
**/.metals/
**/project/metals.sbt

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are those changes necessary, can you explain what are those directories/files for?

@MysteriousChallenger MysteriousChallenger May 25, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are some folders generated by a vscode plugin. I'll see about only applying these changes only on my local repo

Comment thread core/.vscode/tasks.json
Comment on lines +20 to +29
},
{
"label": "build ts",
"type": "shell",
"command": "cd new-gui && npm install"
},
{
"label": "run ts",
"type": "shell",
"command": "cd new-gui && ng serve --watch"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those are IDE-related changes, ideally we should keep it local and ignore the changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

Comment on lines +54 to +56
return getAllValues(user)
} else {
return getValueByKey(user, key)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the return keywords seem to be redundant here.

@@ -0,0 +1,226 @@
package edu.uci.ics.texera.web.resource.dashboard

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the package does not match the directory?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.getOrElse(null) you can just use .orNull

Comment on lines +104 to +107
if (e instanceof SyntaxError) { // result was not json
this.dictionaryEventSubject.next({type: EVENT_TYPE.GET, key: key, value: result});
return result;
} else {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when will this happen?

Comment on lines +100 to +101
result = JSON.parse(result);
this.dictionaryEventSubject.next({type: EVENT_TYPE.GET, key: key, value: result});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. you are parsing the result in a promise and then forward it to a subject. can't we simply to use observable directly?
  2. what is the type of result variable? it seems being changed during runtime.

Comment on lines +114 to +121
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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment on lines +241 to +257
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;
}
};
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the purpose of this proxy?

Yicong-Huang added a commit that referenced this pull request Jun 19, 2021
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]>
@Yicong-Huang

Copy link
Copy Markdown
Contributor

separated into #1147 #1162 #1164.

zuozhiw added a commit that referenced this pull request Jun 27, 2021
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]>
zuozhiw added a commit that referenced this pull request Jan 14, 2022
Final feature demo:

![Kapture 2022-01-13 at 23 36 00](https://user-images.githubusercontent.com/12578068/149469927-b62bfa43-4701-4498-a489-565aea36da2c.gif)

---------------------------

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]>
@aglinxinyuan
aglinxinyuan deleted the Albert-persistent-autofills branch May 25, 2023 21:05
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
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]>
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
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]>
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
Final feature demo:

![Kapture 2022-01-13 at 23 36 00](https://user-images.githubusercontent.com/12578068/149469927-b62bfa43-4701-4498-a489-565aea36da2c.gif)

---------------------------

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ddl-change Changes to the TexeraDB DDL feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants