forked from microsoft/OCR-Form-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alex krasn/relocate share button (microsoft#464)
* feat: relocate share priject button to title bar * strings
- Loading branch information
1 parent
0e1b637
commit 78996ea
Showing
8 changed files
with
109 additions
and
49 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
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
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,19 @@ | ||
@import '../../../assets/sass/theme.scss'; | ||
|
||
.share-button { | ||
background-color: transparent; | ||
height: 100%; | ||
width: 100%; | ||
border-radius: 0; | ||
&:hover{ | ||
background-color: $lighter-3; | ||
} | ||
&.is-disabled { | ||
.ms-Icon { | ||
color: $darker-5; | ||
font-size: 1rem; | ||
|
||
} | ||
} | ||
} | ||
|
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,75 @@ | ||
import React from 'react'; | ||
import { getSasFolderString } from "../../../common/utils"; | ||
import { IProject, IAppSettings, ISecurityToken, IApplicationState } from "../../../models/applicationState"; | ||
import { connect } from "react-redux"; | ||
import { toast } from "react-toastify"; | ||
import { IconButton, Customizer, ICustomizations } from "@fluentui/react"; | ||
import { strings } from "../../../common/strings"; | ||
import { getDarkGreyTheme } from "../../../common/themes"; | ||
import "./shareProjectButton.scss" | ||
|
||
|
||
interface IShareProps { | ||
appSettings?: IAppSettings, | ||
currentProject?: IProject; | ||
} | ||
interface IShareState { | ||
appSettings: IAppSettings, | ||
currentProject: IProject; | ||
} | ||
|
||
function mapStateToProps(state: IApplicationState) { | ||
return { | ||
appSettings: state.appSettings, | ||
currentProject: state.currentProject, | ||
}; | ||
} | ||
|
||
const dark: ICustomizations = { | ||
settings: { | ||
theme: getDarkGreyTheme(), | ||
}, | ||
scopedSettings: {}, | ||
}; | ||
|
||
@connect(mapStateToProps) | ||
export default class ShareProjectButton extends React.Component<IShareProps> { | ||
|
||
// creates string for sharing project | ||
private shareProject = (): void => { | ||
const currentProject: IProject = this.props.currentProject; | ||
const sasFolder: string = getSasFolderString(currentProject.sourceConnection.providerOptions["sas"]); | ||
const projectToken: ISecurityToken = this.props.appSettings.securityTokens | ||
.find((securityToken: { name: string; }) => securityToken.name === currentProject.securityToken); | ||
const shareProjectString: string = JSON.stringify({ | ||
sasFolder, | ||
projectName: currentProject.name, | ||
token: { name: currentProject.securityToken, key: projectToken.key } | ||
}); | ||
|
||
this.copyToClipboard(shareProjectString) | ||
} | ||
|
||
private async copyToClipboard(value: string) { | ||
const clipboard = (navigator as any).clipboard; | ||
if (clipboard && clipboard.writeText) { | ||
await clipboard.writeText(btoa(value)); | ||
toast.success(strings.shareProject.copy.success); | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<Customizer {...dark}> | ||
<IconButton | ||
className="share-button" | ||
ariaLabel={strings.shareProject.name} | ||
iconProps={{ iconName: "Share" }} | ||
disabled={this.props.currentProject && this.props.currentProject.sourceConnection.providerType === "azureBlobStorage" ? false : true} | ||
title={strings.shareProject.name} | ||
onClick={this.shareProject} | ||
/> | ||
</Customizer> | ||
) | ||
} | ||
} |