-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
SWC-6610 - Add ColumnModelsEditorV2Widget
- Loading branch information
Showing
23 changed files
with
794 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/org/sagebionetworks/web/client/jsinterop/JSONEntityUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.sagebionetworks.web.client.jsinterop; | ||
|
||
import org.sagebionetworks.gwt.client.schema.adapter.JSONObjectGwt; | ||
import org.sagebionetworks.schema.adapter.JSONEntity; | ||
import org.sagebionetworks.schema.adapter.JSONObjectAdapter; | ||
import org.sagebionetworks.schema.adapter.JSONObjectAdapterException; | ||
|
||
public interface JSONEntityUtils { | ||
/** | ||
* Converts a JSONEntity to a JsInterop compatible object. | ||
* @param entity | ||
* @return a JsInterop compatible object that represents the passed entity. | ||
*/ | ||
public static Object toJsInteropCompatibleObject(JSONEntity entity) { | ||
JSONObjectAdapter adapter = new JSONObjectGwt(); | ||
try { | ||
entity.writeToJSONObject(adapter); | ||
} catch (JSONObjectAdapterException e) { | ||
throw new RuntimeException(e); | ||
} | ||
// This is a quick-and-dirty implementation--serialize the object to a string and use JSON.parse to deserialize it | ||
// It would be more efficient to update the JSONObjectGwt instance to directly create and return a native object. | ||
return JSON.parse(adapter.toJSONString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/org/sagebionetworks/web/client/jsinterop/ReactRef.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.sagebionetworks.web.client.jsinterop; | ||
|
||
import jsinterop.annotations.JsPackage; | ||
import jsinterop.annotations.JsType; | ||
|
||
@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") | ||
public class ReactRef<T> { | ||
|
||
public T current; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/org/sagebionetworks/web/client/jsinterop/TableColumnSchemaFormProps.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.sagebionetworks.web.client.jsinterop; | ||
|
||
import java.util.List; | ||
import jsinterop.annotations.JsNullable; | ||
import jsinterop.annotations.JsOverlay; | ||
import jsinterop.annotations.JsPackage; | ||
import jsinterop.annotations.JsType; | ||
import org.sagebionetworks.repo.model.EntityType; | ||
import org.sagebionetworks.repo.model.table.ColumnModel; | ||
import org.sagebionetworks.repo.model.table.ViewScope; | ||
|
||
@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") | ||
public class TableColumnSchemaFormProps extends ReactComponentProps { | ||
|
||
String entityType; | ||
|
||
@JsNullable | ||
Object viewScope; | ||
|
||
Object[] initialData; | ||
ReactRef<TableColumnSchemaFormRef> ref; | ||
|
||
@JsOverlay | ||
public static TableColumnSchemaFormProps create( | ||
EntityType entityType, | ||
ViewScope viewScope, | ||
List<ColumnModel> initialData, | ||
ReactRef<TableColumnSchemaFormRef> ref | ||
) { | ||
TableColumnSchemaFormProps props = new TableColumnSchemaFormProps(); | ||
props.entityType = entityType.name(); | ||
if (viewScope != null) { | ||
props.viewScope = JSONEntityUtils.toJsInteropCompatibleObject(viewScope); | ||
} | ||
props.initialData = | ||
initialData | ||
.stream() | ||
.map(JSONEntityUtils::toJsInteropCompatibleObject) | ||
.toArray(); | ||
props.ref = ref; | ||
return props; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/sagebionetworks/web/client/jsinterop/TableColumnSchemaFormRef.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.sagebionetworks.web.client.jsinterop; | ||
|
||
import jsinterop.annotations.JsPackage; | ||
import jsinterop.annotations.JsType; | ||
|
||
@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") | ||
public class TableColumnSchemaFormRef { | ||
|
||
/** | ||
* The TableColumnSchemaForm component exposes an imperative handle to get the current state of the form's ColumnModels | ||
* | ||
* @return JSON representations of ColumnModel objects | ||
*/ | ||
public native Object[] getEditedColumnModels(); | ||
|
||
/** | ||
* Returns true iff the form is valid | ||
*/ | ||
public native boolean validate(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.