aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/code/components/ComponentPin.tsx
diff options
context:
space:
mode:
authorStas Vilchik <stas.vilchik@sonarsource.com>2018-03-14 12:47:17 +0100
committerGitHub <noreply@github.com>2018-03-14 12:47:17 +0100
commit6f189a7c95ee207e02c7c9321ed37d0c6ca4afe6 (patch)
tree494c72690c0ac9607716574a5bfa49f9c4ca315a /server/sonar-web/src/main/js/apps/code/components/ComponentPin.tsx
parent47d50b8a9c17d595a07b6a7e157849ccf1ffc302 (diff)
downloadsonarqube-6f189a7c95ee207e02c7c9321ed37d0c6ca4afe6.tar.gz
sonarqube-6f189a7c95ee207e02c7c9321ed37d0c6ca4afe6.zip
rewrite workspace in react (#3140)
Diffstat (limited to 'server/sonar-web/src/main/js/apps/code/components/ComponentPin.tsx')
-rw-r--r--server/sonar-web/src/main/js/apps/code/components/ComponentPin.tsx42
1 files changed, 29 insertions, 13 deletions
diff --git a/server/sonar-web/src/main/js/apps/code/components/ComponentPin.tsx b/server/sonar-web/src/main/js/apps/code/components/ComponentPin.tsx
index 867f4bd476f..c9b3fb86af6 100644
--- a/server/sonar-web/src/main/js/apps/code/components/ComponentPin.tsx
+++ b/server/sonar-web/src/main/js/apps/code/components/ComponentPin.tsx
@@ -18,10 +18,11 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import * as React from 'react';
+import * as PropTypes from 'prop-types';
import { Component } from '../types';
import { BranchLike } from '../../../app/types';
import PinIcon from '../../../components/shared/pin-icon';
-import Workspace from '../../../components/workspace/main';
+import { WorkspaceContext } from '../../../components/workspace/context';
import { translate } from '../../../helpers/l10n';
interface Props {
@@ -29,19 +30,34 @@ interface Props {
component: Component;
}
-export default function ComponentPin({ branchLike, component }: Props) {
- const handleClick = (event: React.SyntheticEvent<HTMLAnchorElement>) => {
+export default class ComponentPin extends React.PureComponent<Props> {
+ // prettier-ignore
+ context!: { workspace: WorkspaceContext };
+
+ static contextTypes = {
+ workspace: PropTypes.object.isRequired
+ };
+
+ handleClick = (event: React.SyntheticEvent<HTMLAnchorElement>) => {
event.preventDefault();
- Workspace.openComponent({ branchLike, key: component.key });
+ event.currentTarget.blur();
+ this.context.workspace.openComponent({
+ branchLike: this.props.branchLike,
+ key: this.props.component.key,
+ name: this.props.component.path,
+ qualifier: this.props.component.qualifier
+ });
};
- return (
- <a
- className="link-no-underline"
- onClick={handleClick}
- title={translate('component_viewer.open_in_workspace')}
- href="#">
- <PinIcon />
- </a>
- );
+ render() {
+ return (
+ <a
+ className="link-no-underline"
+ href="#"
+ onClick={this.handleClick}
+ title={translate('component_viewer.open_in_workspace')}>
+ <PinIcon />
+ </a>
+ );
+ }
}