Skip to content

Commit

Permalink
Merge pull request #5253 from hallieswan/SWC-6638
Browse files Browse the repository at this point in the history
SWC-6638: show both certification and validation badges on profile pages
  • Loading branch information
hallieswan committed Jan 12, 2024
2 parents d6815ce + 23b2cbd commit ae24da7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import jsinterop.annotations.JsType;

@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
public class AccountLevelBadgeProps extends ReactComponentProps {
public class AccountLevelBadgesProps extends ReactComponentProps {

String userId;

@JsOverlay
public static AccountLevelBadgeProps create(String userId) {
AccountLevelBadgeProps props = new AccountLevelBadgeProps();
public static AccountLevelBadgesProps create(String userId) {
AccountLevelBadgesProps props = new AccountLevelBadgesProps();
props.userId = userId;
return props;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static class SynapseComponents {
public static ReactComponentType<LoginPageProps> LoginPage;
public static ReactComponentType<HasAccessProps> HasAccess;
public static ReactComponentType<UserCardProps> UserCard;
public static ReactComponentType<AccountLevelBadgeProps> AccountLevelBadge;
public static ReactComponentType<AccountLevelBadgesProps> AccountLevelBadges;
public static ReactComponentType<PageProgressProps> PageProgress;
public static ReactComponentType<TermsAndConditionsProps> TermsAndConditions;
public static ReactComponentType<IDUReportProps> IDUReport;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.sagebionetworks.web.client.widget.profile;

import static org.sagebionetworks.web.client.presenter.ProfilePresenter.IS_CERTIFIED;
import static org.sagebionetworks.web.client.presenter.ProfilePresenter.IS_VERIFIED;

import com.google.gwt.event.dom.client.KeyDownHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.SuggestBox;
Expand All @@ -20,12 +24,14 @@
import org.gwtbootstrap3.client.ui.constants.ValidationState;
import org.gwtbootstrap3.client.ui.html.Div;
import org.gwtbootstrap3.client.ui.html.Paragraph;
import org.sagebionetworks.repo.model.UserBundle;
import org.sagebionetworks.web.client.DisplayUtils;
import org.sagebionetworks.web.client.GlobalApplicationState;
import org.sagebionetworks.web.client.SynapseJSNIUtils;
import org.sagebionetworks.web.client.SynapseJavascriptClient;
import org.sagebionetworks.web.client.context.SynapseReactClientFullContextPropsProvider;
import org.sagebionetworks.web.client.cookie.CookieProvider;
import org.sagebionetworks.web.client.jsinterop.AccountLevelBadgeProps;
import org.sagebionetworks.web.client.jsinterop.AccountLevelBadgesProps;
import org.sagebionetworks.web.client.jsinterop.React;
import org.sagebionetworks.web.client.jsinterop.ReactNode;
import org.sagebionetworks.web.client.jsinterop.SRC;
Expand Down Expand Up @@ -120,7 +126,10 @@ public interface Binder
Anchor orcIdLink;

@UiField
ReactComponentDiv accountLevelBadgeContainer;
Column accountTypeContainer;

@UiField
ReactComponentDiv accountLevelBadgesContainer;

@UiField
Div userProfileLinksUI;
Expand All @@ -145,6 +154,7 @@ public interface Binder
Presenter presenter;
String originalButtonText;
CookieProvider cookies;
SynapseJavascriptClient jsClient;

@Inject
public UserProfileEditorWidgetViewImpl(
Expand All @@ -154,12 +164,14 @@ public UserProfileEditorWidgetViewImpl(
AuthenticationController authController,
SynapseJSNIUtils jsniUtils,
SynapseReactClientFullContextPropsProvider propsProvider,
CookieProvider cookies
CookieProvider cookies,
SynapseJavascriptClient jsClient
) {
widget = binder.createAndBindUi(this);
this.jsniUtils = jsniUtils;
this.propsProvider = propsProvider;
this.cookies = cookies;
this.jsClient = jsClient;
locationSuggestBox = new SuggestBox(locationOracle);
locationSuggestBox.setWidth("100%");
locationTextBox = locationSuggestBox.getTextBox();
Expand Down Expand Up @@ -388,13 +400,14 @@ public void setSynAlert(IsWidget w) {

@Override
public void setOwnerId(String userId) {
ReactNode accountLevelBadgeComponent =
ReactNode accountLevelBadgesComponent =
React.createElementWithSynapseContext(
SRC.SynapseComponents.AccountLevelBadge,
AccountLevelBadgeProps.create(userId),
SRC.SynapseComponents.AccountLevelBadges,
AccountLevelBadgesProps.create(userId),
propsProvider.getJsInteropContextProps()
);
accountLevelBadgeContainer.render(accountLevelBadgeComponent);
accountLevelBadgesContainer.render(accountLevelBadgesComponent);
setAccountTypeVisibility(Long.parseLong(userId));

UserProfileLinksProps props = UserProfileLinksProps.create(userId);
ReactNode profileLinksComponent = React.createElementWithSynapseContext(
Expand All @@ -405,6 +418,26 @@ public void setOwnerId(String userId) {
userProfileLinksReactComponentContainer.render(profileLinksComponent);
}

public void setAccountTypeVisibility(Long userId) {
int mask = IS_CERTIFIED | IS_VERIFIED;
jsClient.getUserBundle(
userId,
mask,
new AsyncCallback<UserBundle>() {
@Override
public void onSuccess(UserBundle bundle) {
boolean showAccountType =
bundle.getIsCertified() | bundle.getIsVerified();
accountTypeContainer.setVisible(showAccountType);
}

// error will be handled/shown by React component
@Override
public void onFailure(Throwable caught) {}
}
);
}

@Override
public void resetSaveButtonState() {
DisplayUtils.showLoading(saveProfileButton, false, originalButtonText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@
</bh:Div>
</b:FormGroup>
</b:Column>
<b:Column size="MD_12,LG_6">
</b:Row>
<b:Row>
<b:Column size="XS_12" ui:field="accountTypeContainer">
<b:FormGroup>
<b:FormLabel for="accountType">Account Type</b:FormLabel>
<bh:Div>
<w:ReactComponentDiv
ui:field="accountLevelBadgeContainer"
addStyleNames="accountLevelBadgeContainer"
/>
</bh:Div>
<w:ReactComponentDiv
ui:field="accountLevelBadgesContainer"
addStyleNames="accountLevelBadgesContainer margin-top-5"
/>
</b:FormGroup>
</b:Column>
</b:Row>
Expand Down

0 comments on commit ae24da7

Please sign in to comment.