Skip to content
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

SWC-7064, SWC-7092 - Use Elemental2 for JsInterop models #5559

Merged
merged 3 commits into from
Oct 24, 2024

Conversation

nickgros
Copy link
Contributor

@nickgros nickgros commented Oct 22, 2024

To support SWC-7064, SWC-7092, we will have to update logic related to File uploads. Instead of manipulating JSNI code, I opted to

  • pull in Elemental2, which provides JsInterop-compatible models for native JavaScript functionality (such as FileList, File, Blob)
  • Replace our custom models with Elemental2 implementations (JSON, JsObject, Promise)
  • Remove some basic JSNI code related to Blobs that could be replaced with basic JsInterop code

@nickgros nickgros changed the title SWC-7064, SWC-7092 - view only SWC-7064, SWC-7092 - Use Elemental2 for JsInterop models Oct 24, 2024
@@ -43,10 +43,6 @@ public LayoutResult nChartlayout(

public void setPageDescription(String newDescription);

public JavaScriptObject getFileList(String fileFieldId);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved these to a new SynapseJsInteropUtils interface & class

import jsinterop.base.Js;
import org.sagebionetworks.web.client.callback.MD5Callback;

public class SynapseJsInteropUtilsImpl implements SynapseJsInteropUtils {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewrote all of these from JSNI to JsInterop using the Elemental2 classes

Comment on lines +43 to +48
@Override
public String getWebkitRelativePath(FileList fileList, double index) {
return (String) Js
.asPropertyMap(fileList.item(index))
.get("webkitRelativePath");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Elemental2's File model does not surface the webkitRelativePath field, but we can easily get it with Js.asPropertyMap(obj).get("key")

Comment on lines +573 to +574
File blob = fileList.item(this.currIndex);
long fileSize = blob.size;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In many cases where it was more simple, I just replaced calls on utils methods with direct calls to the new JsInterop methods

@nickgros nickgros marked this pull request as ready for review October 24, 2024 16:38
Comment on lines +956 to +965
<dependency>
<groupId>com.google.elemental2</groupId>
<artifactId>elemental2-core</artifactId>
<version>1.2.2</version>
</dependency>

<dependency>
<groupId>com.google.elemental2</groupId>
<artifactId>elemental2-dom</artifactId>
<version>1.2.2</version>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Elemental2 provides JsInterop bindings for browser APIs.

@nickgros nickgros merged commit 1bfd5b0 into Sage-Bionetworks:develop Oct 24, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants