Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bookmark feature should give user fullURL (and shortened version if b… #2940

Merged
merged 1 commit into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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