-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5515 from jay-hodgson/PORTALS-3204
PORTALS-3204: Use SynapseChat from SRC (when available)
- Loading branch information
Showing
10 changed files
with
198 additions
and
0 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
38 changes: 38 additions & 0 deletions
38
src/main/java/org/sagebionetworks/web/client/jsinterop/SynapseChatProps.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,38 @@ | ||
package org.sagebionetworks.web.client.jsinterop; | ||
|
||
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 SynapseChatProps extends ReactComponentProps { | ||
|
||
@JsNullable | ||
public String initialMessage; | ||
|
||
@JsNullable | ||
public String agentId; | ||
|
||
@JsNullable | ||
public String chatbotName; | ||
|
||
@JsOverlay | ||
public static SynapseChatProps create( | ||
String initialMessage, | ||
String agentId, | ||
String chatbotName | ||
) { | ||
SynapseChatProps props = new SynapseChatProps(); | ||
if (initialMessage != null) { | ||
props.initialMessage = initialMessage; | ||
} | ||
if (agentId != null) { | ||
props.agentId = agentId; | ||
} | ||
if (chatbotName != null) { | ||
props.chatbotName = chatbotName; | ||
} | ||
return props; | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
src/main/java/org/sagebionetworks/web/client/place/ChatPlace.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,29 @@ | ||
package org.sagebionetworks.web.client.place; | ||
|
||
import com.google.gwt.place.shared.PlaceTokenizer; | ||
import com.google.gwt.place.shared.Prefix; | ||
|
||
public class ChatPlace extends ParameterizedPlace { | ||
|
||
public static final String INITIAL_MESSAGE = "initialMessage"; | ||
public static final String AGENT_ID = "agentId"; | ||
public static final String CHATBOT_NAME = "chatbotName"; | ||
|
||
public ChatPlace(String token) { | ||
super(token); | ||
} | ||
|
||
@Prefix("Chat") | ||
public static class Tokenizer implements PlaceTokenizer<ChatPlace> { | ||
|
||
@Override | ||
public String getToken(ChatPlace place) { | ||
return place.toToken(); | ||
} | ||
|
||
@Override | ||
public ChatPlace getPlace(String token) { | ||
return new ChatPlace(token); | ||
} | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
src/main/java/org/sagebionetworks/web/client/presenter/ChatPresenter.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,38 @@ | ||
package org.sagebionetworks.web.client.presenter; | ||
|
||
import com.google.gwt.activity.shared.AbstractActivity; | ||
import com.google.gwt.event.shared.EventBus; | ||
import com.google.gwt.user.client.ui.AcceptsOneWidget; | ||
import com.google.inject.Inject; | ||
import org.sagebionetworks.web.client.place.ChatPlace; | ||
import org.sagebionetworks.web.client.view.ChatView; | ||
|
||
public class ChatPresenter | ||
extends AbstractActivity | ||
implements Presenter<ChatPlace> { | ||
|
||
private ChatPlace place; | ||
private ChatView view; | ||
|
||
@Inject | ||
public ChatPresenter(ChatView view) { | ||
this.view = view; | ||
view.scrollToTop(); | ||
} | ||
|
||
@Override | ||
public void start(AcceptsOneWidget panel, EventBus eventBus) { | ||
// Install the view | ||
panel.setWidget(view); | ||
} | ||
|
||
@Override | ||
public void setPlace(ChatPlace place) { | ||
this.place = place; | ||
String initialMessage = place.getParam(ChatPlace.INITIAL_MESSAGE); | ||
String agentId = place.getParam(ChatPlace.AGENT_ID); | ||
String chatbotName = place.getParam(ChatPlace.CHATBOT_NAME); | ||
|
||
view.render(initialMessage, agentId, chatbotName); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/org/sagebionetworks/web/client/view/ChatView.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.view; | ||
|
||
import com.google.gwt.user.client.ui.IsWidget; | ||
|
||
public interface ChatView extends IsWidget { | ||
void render(String initMessage, String agentId, String chatbotName); | ||
void scrollToTop(); | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/org/sagebionetworks/web/client/view/ChatViewImpl.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,61 @@ | ||
package org.sagebionetworks.web.client.view; | ||
|
||
import com.google.gwt.user.client.Window; | ||
import com.google.gwt.user.client.ui.Composite; | ||
import com.google.inject.Inject; | ||
import org.sagebionetworks.web.client.GlobalApplicationState; | ||
import org.sagebionetworks.web.client.context.SynapseReactClientFullContextPropsProvider; | ||
import org.sagebionetworks.web.client.jsinterop.React; | ||
import org.sagebionetworks.web.client.jsinterop.ReactElement; | ||
import org.sagebionetworks.web.client.jsinterop.SRC; | ||
import org.sagebionetworks.web.client.jsinterop.SynapseChatProps; | ||
import org.sagebionetworks.web.client.jsinterop.SynapseHomepageV2Props; | ||
import org.sagebionetworks.web.client.widget.ReactComponent; | ||
import org.sagebionetworks.web.client.widget.header.Header; | ||
|
||
public class ChatViewImpl extends Composite implements ChatView { | ||
|
||
ReactComponent container; | ||
|
||
private Header headerWidget; | ||
private SynapseReactClientFullContextPropsProvider propsProvider; | ||
private GlobalApplicationState globalAppState; | ||
|
||
@Inject | ||
public ChatViewImpl( | ||
Header headerWidget, | ||
final SynapseReactClientFullContextPropsProvider propsProvider, | ||
GlobalApplicationState globalAppState | ||
) { | ||
this.headerWidget = headerWidget; | ||
this.propsProvider = propsProvider; | ||
this.globalAppState = globalAppState; | ||
headerWidget.configure(); | ||
container = new ReactComponent(); | ||
initWidget(container); | ||
} | ||
|
||
@Override | ||
public void render(String initMessage, String agentId, String chatbotName) { | ||
headerWidget.configure(); | ||
headerWidget.refresh(); | ||
scrollToTop(); | ||
SynapseChatProps props = SynapseChatProps.create( | ||
initMessage, | ||
agentId, | ||
chatbotName | ||
); | ||
ReactElement component = React.createElementWithSynapseContext( | ||
SRC.SynapseComponents.SynapseChat, | ||
props, | ||
propsProvider.getJsInteropContextProps() | ||
); | ||
|
||
container.render(component); | ||
} | ||
|
||
@Override | ||
public void scrollToTop() { | ||
Window.scrollTo(0, 0); | ||
} | ||
} |