Skip to content

Commit

Permalink
Merge pull request #2940 from alisman/shorten
Browse files Browse the repository at this point in the history
Bookmark feature should give user fullURL (and shortened version if b…
  • Loading branch information
alisman authored Dec 19, 2019
2 parents 371411d + 5b9bda5 commit 1a5786d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 49 deletions.
4 changes: 2 additions & 2 deletions src/pages/resultsView/bookmark/BookmarkModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class BookmarkModal extends React.Component<{ onHide: () => void, urlProm
initializeClipboards(){
this.clipboards.push(new Clipboard(this.sessionButton, {
text: function() {
return this.urlData.sessionUrl || this.urlData.fullUrl;
return this.urlData.fullUrl;
}.bind(this),
container: this.container
}));
Expand Down Expand Up @@ -83,7 +83,7 @@ export class BookmarkModal extends React.Component<{ onHide: () => void, urlProm
<div className="form-group">
<label htmlFor="exampleInputAmount">Share link</label>
<div className="input-group">
<input type="text" className="form-control" value={(this.urlData ? this.urlData.sessionUrl : "")}/>
<input type="text" className="form-control" value={(this.urlData ? this.urlData.fullUrl : "")}/>
<div className="input-group-addon">
<a ref={(el:HTMLAnchorElement)=>this.sessionButton=el}
onClick={this.showThumb}
Expand Down
53 changes: 6 additions & 47 deletions src/pages/resultsView/querySummary/ShareUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,29 @@ import ResultsViewURLWrapper from "pages/resultsView/ResultsViewURLWrapper";

interface IShareUI {
sessionEnabled: boolean;
//routingStore: ExtendedRouterStore;
urlWrapper:ResultsViewURLWrapper;
bitlyAccessToken?: string | null;
}

const win = getBrowserWindow();

export interface ShareUrls {
sessionUrl:string|undefined;
bitlyUrl:any|undefined;
bitlyUrl:string|undefined;
fullUrl:string;
sessionUrl:string|undefined;
}

@observer
export class ShareUI extends React.Component<IShareUI, {}> {

@observable showBookmarkDialog:boolean = false;

async getUrl():Promise<ShareUrls> {
async getUrls():Promise<ShareUrls> {

let sessionUrl = win.location.href;

let bitlyResponse;

if (this.props.sessionEnabled) {
if (this.props.urlWrapper.hasSessionId) {
sessionUrl = getBrowserWindow().location.href;
} else {
const resp = await this.props.urlWrapper.saveRemoteSession(this.props.urlWrapper.query);
// for testing purposes we don't have links to localhost
sessionUrl = URL.format({
hostname: (win.location.hostname.includes("localhost") ? "www.cbioportal.org" : win.location.hostname),
pathname: win.location.pathname,
protocol: win.location.protocol,
query: {
session_id: resp.id
}
});
}
}

// now lets shorten with bityly, if we have key
// WE ARE DISABLING BITLY PENDING DISCUSSION
if (this.props.bitlyAccessToken) {
Expand All @@ -66,42 +48,19 @@ export class ShareUI extends React.Component<IShareUI, {}> {
}

return {
sessionUrl,
bitlyUrl: ((bitlyResponse && bitlyResponse.data && bitlyResponse.data.url) ? bitlyResponse.data.url : undefined),
fullUrl: win.location.href
fullUrl: win.location.href,
sessionUrl:sessionUrl
}

}

@autobind
shareTwitter() {
this.getUrl().then((urlData:ShareUrls) => {
win.open(`https://twitter.com/intent/tweet?url=${encodeURIComponent(this.shortenedUrl(urlData))}&text=${encodeURIComponent(document.title)}&via=cbioportal`);
});
}

@autobind
openEmail() {
this.getUrl().then((urlData)=>{
window.location.href =
`mailto:?subject=${encodeURIComponent(document.title)}&body=${encodeURIComponent(this.shortenedUrl(urlData))}%20${encodeURIComponent(document.title)}`;
});
}

@autobind
@action
toggleBookmarkDialog(){
this.showBookmarkDialog = !this.showBookmarkDialog;
}

shortenedUrl(urlData:ShareUrls){
const url = urlData.bitlyUrl || urlData.sessionUrl || urlData.fullUrl
if (!url) {
throw("URL bookmarking error");
}
return url;
}

render() {
return <div className={styles.shareModule}>

Expand All @@ -114,7 +73,7 @@ export class ShareUI extends React.Component<IShareUI, {}> {
</a>
</DefaultTooltip>
{
(this.showBookmarkDialog) && (<BookmarkModal onHide={this.toggleBookmarkDialog} urlPromise={this.getUrl()}/>)
(this.showBookmarkDialog) && (<BookmarkModal onHide={this.toggleBookmarkDialog} urlPromise={this.getUrls()}/>)
}
</div>
}
Expand Down

0 comments on commit 1a5786d

Please sign in to comment.