Skip to content

Commit

Permalink
Merge pull request #5295 from jinjunoh/SWC-6668
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgros authored Feb 20, 2024
2 parents a2e680c + 01d3437 commit 5c5458a
Show file tree
Hide file tree
Showing 10 changed files with 325 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,8 @@
import org.sagebionetworks.web.client.widget.docker.modal.AddExternalRepoModal;
import org.sagebionetworks.web.client.widget.doi.CreateOrUpdateDoiModal;
import org.sagebionetworks.web.client.widget.doi.DoiWidgetV2;
import org.sagebionetworks.web.client.widget.entity.ChallengeBadge;
import org.sagebionetworks.web.client.widget.entity.EditFileMetadataModalWidget;
import org.sagebionetworks.web.client.widget.entity.EditProjectMetadataModalWidget;
import org.sagebionetworks.web.client.widget.entity.EntityListRowBadge;
import org.sagebionetworks.web.client.widget.entity.EntityMetadata;
import org.sagebionetworks.web.client.widget.entity.EntityTreeItem;
import org.sagebionetworks.web.client.widget.entity.MarkdownWidget;
import org.sagebionetworks.web.client.widget.entity.ModifiedCreatedByWidget;
import org.sagebionetworks.web.client.widget.entity.MoreTreeItem;
import org.sagebionetworks.web.client.widget.entity.PreviewWidget;
import org.sagebionetworks.web.client.widget.entity.ProjectBadge;
import org.sagebionetworks.web.client.widget.entity.PromptForValuesModalView;
import org.sagebionetworks.web.client.widget.entity.RegisterTeamDialog;
import org.sagebionetworks.web.client.widget.entity.RenameEntityModalWidget;
import org.sagebionetworks.web.client.widget.entity.TutorialWizard;
import org.sagebionetworks.web.client.widget.entity.VersionHistoryRowView;
import org.sagebionetworks.web.client.widget.entity.VersionHistoryWidget;
import org.sagebionetworks.web.client.widget.entity.WikiMarkdownEditor;
import org.sagebionetworks.web.client.widget.entity.WikiPageDeleteConfirmationDialog;
import org.sagebionetworks.web.client.widget.entity.WikiPageWidget;
import org.sagebionetworks.web.client.widget.entity.WikiVersionAnchorListItem;
import org.sagebionetworks.web.client.widget.entity.*;
import org.sagebionetworks.web.client.widget.entity.SqlDefinedEditorModalWidget;
import org.sagebionetworks.web.client.widget.entity.act.ApproveUserAccessModal;
import org.sagebionetworks.web.client.widget.entity.act.RejectReasonWidget;
import org.sagebionetworks.web.client.widget.entity.act.UserBadgeItem;
Expand Down Expand Up @@ -786,6 +767,8 @@ public interface PortalGinInjector extends Ginjector {

UploadTableModalWidget getUploadTableModalWidget();

SqlDefinedEditorModalWidget getSqlDefinedEditorModalWidget();

AddExternalRepoModal getAddExternalRepoModal();

PDFPreviewWidget getPDFPreviewWidget();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@
import org.sagebionetworks.web.client.widget.entity.RenameEntityModalWidgetImpl;
import org.sagebionetworks.web.client.widget.entity.SharingAndDataUseConditionWidgetView;
import org.sagebionetworks.web.client.widget.entity.SharingAndDataUseConditionWidgetViewImpl;
import org.sagebionetworks.web.client.widget.entity.SqlDefinedEditorModalWidgetView;
import org.sagebionetworks.web.client.widget.entity.SqlDefinedEditorModalWidgetViewImpl;
import org.sagebionetworks.web.client.widget.entity.TutorialWizardView;
import org.sagebionetworks.web.client.widget.entity.TutorialWizardViewImpl;
import org.sagebionetworks.web.client.widget.entity.VersionHistoryRowView;
Expand Down Expand Up @@ -1446,6 +1448,8 @@ protected void configure() {
bind(FileDownloadMenuItemView.class).to(FileDownloadMenuItemViewImpl.class);
bind(SqlDefinedTableEditorView.class)
.to(SqlDefinedTableEditorViewImpl.class);
bind(SqlDefinedEditorModalWidgetView.class)
.to(SqlDefinedEditorModalWidgetViewImpl.class);
bind(ChallengeWidgetView.class).to(ChallengeWidgetViewImpl.class);
bind(SelectTeamModalView.class).to(SelectTeamModalViewImpl.class);
bind(ApproveUserAccessModalView.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public static class SynapseComponents {
public static ReactComponentType<EntityHeaderTableProps> EntityHeaderTable;
public static ReactComponentType<AccessRequirementRelatedProjectsListProps> AccessRequirementRelatedProjectsList;
public static ReactComponentType<CreateTableViewWizardProps> CreateTableViewWizard;
public static ReactComponentType<SqlDefinedTableEditorModalProps> SqlDefinedTableEditorModal;

/**
* Pushes a global toast message. In SWC, you should use {@link DisplayUtils#notify}, rather than calling this method directly.
Expand Down
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;
}
}
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();
}
}
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);
}
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
import org.sagebionetworks.web.client.widget.entity.EntityBadge;
import org.sagebionetworks.web.client.widget.entity.PromptForValuesModalView;
import org.sagebionetworks.web.client.widget.entity.RenameEntityModalWidget;
import org.sagebionetworks.web.client.widget.entity.SqlDefinedEditorModalWidget;
import org.sagebionetworks.web.client.widget.entity.WikiMarkdownEditor;
import org.sagebionetworks.web.client.widget.entity.WikiPageDeleteConfirmationDialog;
import org.sagebionetworks.web.client.widget.entity.act.ApproveUserAccessModal;
Expand Down Expand Up @@ -276,6 +277,7 @@ public class EntityActionControllerImpl
CreateTableViewWizard createTableViewWizard;
CreateDatasetOrCollection createDatasetOrCollection;
SqlDefinedTableEditor sqlDefinedTableEditor;
SqlDefinedEditorModalWidget sqlDefinedEditorModalWidget;
boolean isShowingVersion = false;
WizardCallback entityUpdatedWizardCallback;
UploadTableModalWidget uploadTableModalWidget;
Expand Down Expand Up @@ -469,6 +471,15 @@ private UploadTableModalWidget getUploadTableModalWidget() {
return uploadTableModalWidget;
}

private SqlDefinedEditorModalWidget getSqlDefinedEditorModalWidget() {
if (sqlDefinedEditorModalWidget == null) {
sqlDefinedEditorModalWidget =
ginInjector.getSqlDefinedEditorModalWidget();
view.addWidget(sqlDefinedEditorModalWidget);
}
return sqlDefinedEditorModalWidget;
}

private AddExternalRepoModal getAddExternalRepoModal() {
if (addExternalRepoModal == null) {
addExternalRepoModal = ginInjector.getAddExternalRepoModal();
Expand Down Expand Up @@ -2709,13 +2720,19 @@ private void postCheckEditProjectMetadata() {
}

private void postCheckEditDefiningSql() {
// prompt for defining sql
view.showPromptDialog(
"Update SQL",
((HasDefiningSql) entity).getDefiningSQL(),
getUpdateDefiningSqlCallback(),
PromptForValuesModalView.InputType.TEXTAREA
);
String entityId = entity.getId();
getSqlDefinedEditorModalWidget()
.configure(
entityId,
() -> {
getSqlDefinedEditorModalWidget().setOpen(false);
eventBus.fireEvent(new EntityUpdatedEvent(entity.getId()));
},
() -> {
getSqlDefinedEditorModalWidget().setOpen(false);
}
);
getSqlDefinedEditorModalWidget().setOpen(true);
}

private void onViewDefiningSql() {
Expand Down
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();
}
}
Loading

0 comments on commit 5c5458a

Please sign in to comment.