-
Notifications
You must be signed in to change notification settings - Fork 37
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
- Loading branch information
Showing
10 changed files
with
325 additions
and
52 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
42 changes: 42 additions & 0 deletions
42
src/main/java/org/sagebionetworks/web/client/jsinterop/SqlDefinedTableEditorModalProps.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,42 @@ | ||
package org.sagebionetworks.web.client.jsinterop; | ||
|
||
import jsinterop.annotations.JsFunction; | ||
import jsinterop.annotations.JsNullable; | ||
import jsinterop.annotations.JsOverlay; | ||
import jsinterop.annotations.JsPackage; | ||
import jsinterop.annotations.JsType; | ||
|
||
@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") | ||
public class SqlDefinedTableEditorModalProps extends ReactComponentProps { | ||
|
||
@FunctionalInterface | ||
@JsFunction | ||
public interface Callback { | ||
void run(); | ||
} | ||
|
||
public String entityId; | ||
public boolean open; | ||
|
||
@JsNullable | ||
public Callback onUpdate; | ||
|
||
@JsNullable | ||
public Callback onCancel; | ||
|
||
@JsOverlay | ||
public static SqlDefinedTableEditorModalProps create( | ||
String entityId, | ||
boolean open, | ||
Callback onUpdate, | ||
Callback onCancel | ||
) { | ||
SqlDefinedTableEditorModalProps props = | ||
new SqlDefinedTableEditorModalProps(); | ||
props.entityId = entityId; | ||
props.open = open; | ||
props.onUpdate = onUpdate; | ||
props.onCancel = onCancel; | ||
return props; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/org/sagebionetworks/web/client/widget/entity/SqlDefinedEditorModalWidget.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,64 @@ | ||
package org.sagebionetworks.web.client.widget.entity; | ||
|
||
import com.google.gwt.user.client.ui.IsWidget; | ||
import com.google.gwt.user.client.ui.Widget; | ||
import com.google.inject.Inject; | ||
import org.sagebionetworks.web.client.GlobalApplicationState; | ||
import org.sagebionetworks.web.client.jsinterop.SqlDefinedTableEditorModalProps; | ||
|
||
public class SqlDefinedEditorModalWidget implements IsWidget { | ||
|
||
private final GlobalApplicationState globalApplicationState; | ||
private final SqlDefinedEditorModalWidgetView view; | ||
|
||
private boolean open; | ||
|
||
private String entityId; | ||
private SqlDefinedTableEditorModalProps.Callback onCancel; | ||
private SqlDefinedTableEditorModalProps.Callback onUpdate; | ||
|
||
@Inject | ||
public SqlDefinedEditorModalWidget( | ||
SqlDefinedEditorModalWidgetView view, | ||
GlobalApplicationState globalApplicationState | ||
) { | ||
super(); | ||
this.view = view; | ||
this.globalApplicationState = globalApplicationState; | ||
} | ||
|
||
public void configure( | ||
String entityId, | ||
SqlDefinedTableEditorModalProps.Callback onUpdate, | ||
SqlDefinedTableEditorModalProps.Callback onCancel | ||
) { | ||
this.entityId = entityId; | ||
this.onUpdate = onUpdate; | ||
this.onCancel = onCancel; | ||
SqlDefinedTableEditorModalProps props = | ||
SqlDefinedTableEditorModalProps.create( | ||
entityId, | ||
false, | ||
onUpdate, | ||
onCancel | ||
); | ||
view.renderComponent(props); | ||
} | ||
|
||
public void setOpen(boolean open) { | ||
globalApplicationState.setIsEditing(open); | ||
SqlDefinedTableEditorModalProps props = | ||
SqlDefinedTableEditorModalProps.create( | ||
entityId, | ||
open, | ||
onUpdate, | ||
onCancel | ||
); | ||
view.renderComponent(props); | ||
} | ||
|
||
@Override | ||
public Widget asWidget() { | ||
return view.asWidget(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...in/java/org/sagebionetworks/web/client/widget/entity/SqlDefinedEditorModalWidgetView.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,8 @@ | ||
package org.sagebionetworks.web.client.widget.entity; | ||
|
||
import com.google.gwt.user.client.ui.IsWidget; | ||
import org.sagebionetworks.web.client.jsinterop.SqlDefinedTableEditorModalProps; | ||
|
||
public interface SqlDefinedEditorModalWidgetView extends IsWidget { | ||
void renderComponent(SqlDefinedTableEditorModalProps props); | ||
} |
41 changes: 41 additions & 0 deletions
41
...ava/org/sagebionetworks/web/client/widget/entity/SqlDefinedEditorModalWidgetViewImpl.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,41 @@ | ||
package org.sagebionetworks.web.client.widget.entity; | ||
|
||
import com.google.gwt.user.client.ui.Widget; | ||
import com.google.inject.Inject; | ||
import org.sagebionetworks.web.client.context.SynapseReactClientFullContextPropsProvider; | ||
import org.sagebionetworks.web.client.jsinterop.React; | ||
import org.sagebionetworks.web.client.jsinterop.ReactNode; | ||
import org.sagebionetworks.web.client.jsinterop.SRC; | ||
import org.sagebionetworks.web.client.jsinterop.SqlDefinedTableEditorModalProps; | ||
import org.sagebionetworks.web.client.widget.ReactComponentDiv; | ||
|
||
public class SqlDefinedEditorModalWidgetViewImpl | ||
implements SqlDefinedEditorModalWidgetView { | ||
|
||
private final SynapseReactClientFullContextPropsProvider propsProvider; | ||
private final ReactComponentDiv reactComponentDiv; | ||
|
||
@Inject | ||
public SqlDefinedEditorModalWidgetViewImpl( | ||
SynapseReactClientFullContextPropsProvider propsProvider | ||
) { | ||
super(); | ||
this.propsProvider = propsProvider; | ||
reactComponentDiv = new ReactComponentDiv(); | ||
} | ||
|
||
@Override | ||
public void renderComponent(SqlDefinedTableEditorModalProps props) { | ||
ReactNode reactNode = React.createElementWithSynapseContext( | ||
SRC.SynapseComponents.SqlDefinedTableEditorModal, | ||
props, | ||
propsProvider.getJsInteropContextProps() | ||
); | ||
reactComponentDiv.render(reactNode); | ||
} | ||
|
||
@Override | ||
public Widget asWidget() { | ||
return reactComponentDiv.asWidget(); | ||
} | ||
} |
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
82 changes: 82 additions & 0 deletions
82
...st/java/org/sagebionetworks/web/client/widget/entity/SqlDefinedEditorModalWidgetTest.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,82 @@ | ||
package org.sagebionetworks.web.client.widget.entity; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Captor; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
import org.sagebionetworks.web.client.GlobalApplicationState; | ||
import org.sagebionetworks.web.client.PlaceChanger; | ||
import org.sagebionetworks.web.client.jsinterop.SqlDefinedTableEditorModalProps; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class SqlDefinedEditorModalWidgetTest { | ||
|
||
@Mock | ||
SqlDefinedEditorModalWidgetView mockView; | ||
|
||
@Mock | ||
SqlDefinedTableEditorModalProps.Callback mockOnUpdate; | ||
|
||
@Mock | ||
SqlDefinedTableEditorModalProps.Callback mockOnCancel; | ||
|
||
@Mock | ||
GlobalApplicationState mockGlobalAppState; | ||
|
||
@Mock | ||
PlaceChanger mockPlaceChanger; | ||
|
||
@Captor | ||
ArgumentCaptor<SqlDefinedTableEditorModalProps> propsCaptor; | ||
|
||
SqlDefinedEditorModalWidget widget; | ||
|
||
public static final String ENTITY_ID = "syn42"; | ||
|
||
@Before | ||
public void before() { | ||
widget = new SqlDefinedEditorModalWidget(mockView, mockGlobalAppState); | ||
when(mockGlobalAppState.getPlaceChanger()).thenReturn(mockPlaceChanger); | ||
} | ||
|
||
@After | ||
public void validate() { | ||
validateMockitoUsage(); | ||
} | ||
|
||
@Test | ||
public void testConstruction() { | ||
widget.configure(ENTITY_ID, mockOnUpdate, mockOnCancel); | ||
verify(mockView).renderComponent(propsCaptor.capture()); | ||
SqlDefinedTableEditorModalProps capturedProps = propsCaptor.getValue(); | ||
|
||
assertEquals(ENTITY_ID, capturedProps.entityId); | ||
assertEquals(mockOnUpdate, capturedProps.onUpdate); | ||
assertEquals(mockOnCancel, capturedProps.onCancel); | ||
} | ||
|
||
@Test | ||
public void testSetOpen() { | ||
widget.setOpen(true); | ||
verify(mockGlobalAppState).setIsEditing(true); | ||
verify(mockView).renderComponent(propsCaptor.capture()); | ||
assertTrue(propsCaptor.getValue().open); | ||
widget.setOpen(false); | ||
verify(mockGlobalAppState).setIsEditing(false); | ||
verify(mockView, times(2)).renderComponent(propsCaptor.capture()); | ||
assertFalse(propsCaptor.getValue().open); | ||
} | ||
|
||
@Test | ||
public void testAsWidget() { | ||
widget.asWidget(); | ||
verify(mockView).asWidget(); | ||
} | ||
} |
Oops, something went wrong.