<commit_before>// Walkhub
// Copyright (C) 2015 Pronovix
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

import React from "react";
import Step from "components/step";
import EmbedCode from "components/embedcode";
import {noop} from "form";
import {t} from "t";
import {severities} from "util";
import {Link} from "react-router";

class Walkthrough extends React.Component {

	static defaultProps = {
		walkthrough: {},
		onPlayClick: noop,
		onEditClick: noop,
		onDeleteClick: noop,
		editable: false,
		embedded: false,
		compact: false,
		linkTo: true,
		httpReloadURL: "",
		helpcenter: false,
	};

	static contextTypes = {
		location: React.PropTypes.shape,
		history: React.PropTypes.shape,
	};

	render() {
		const walkthrough = this.props.walkthrough;

		const playButton = this.props.helpcenter ? <a onClick={this.props.onPlayClick} href="#" className="helpcenter-play"><span className="glyphicon glyphicon-play-circle" aria-hidden="true" data-toggle="tooltip" title={t("Play walkthrough")}></span></a> :
			<a onClick={this.props.onPlayClick} className="btn btn-success btn-sm">{t("Play")}</a>;

		if (this.props.embedded) {
			return playButton;
		}

		let counter = 0;
		const steps = walkthrough.steps ? walkthrough.steps.map((step) => {
			return <Step key={counter++} step={step} />;
		}) : null;

		const editbuttons = [];
		if (this.props.editable) {
			if (this.props.compact) {
				const href = this.context.history.createHref(`/walkthrough/${walkthrough.uuid}`);
				editbuttons.push(<a href={href} key="edit" target="_blank" className="btn btn-default btn-sm">{t("Edit")}</a>);
			} else {
				editbuttons.push(<a onClick={this.props.onEditClick} key="edit" className="btn btn-default btn-sm">{t("Edit")}</a>);
				editbuttons.push(<a onClick={this.props.onDeleteClick} key="delete" className="btn btn-danger btn-sm">{t("Delete")}</a>);
			}
		}

		const titleName = this.props.compact && this.props.linkTo ?
			<Link to={`/walkthrough/${walkthrough.uuid}`}>{walkthrough.name}</Link> :
			walkthrough.name;

		const title = this.props.helpcenter ? (
			<div className="row row-wt-helpcenter">
				<div className="col-xs-1 col-md-3 play-col">
					{playButton}
				</div>
				<div className="col-xs-11 col-md-9">
					<h5 className="wt-title">
						{titleName}
					</h5>
				</div>
			</div>
		) : (
			<div className="row row-wt-no-helpcenter">
				<div className="col-xs-9 col-md-8">
					<h5 className="wt-title">
						{titleName}
					</h5>
				</div>
				<div className="col-xs-3 col-md-4">
					{playButton}
					{editbuttons}
				</div>
			</div>
		);

		const severity = (
			<div className="row">
				<div className="col-xs-12">
					<p> {t("This walkthrough @severity", {
						"@severity": severities[walkthrough.severity],
					})} </p>
				</div>
			</div>
		);

		const description = (
			<div className="row"><commit_msg>Turns walkthrough titles into play buttons in helpcenter.<commit_after>// Walkhub
// Copyright (C) 2015 Pronovix
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

import React from "react";
import Step from "components/step";
import EmbedCode from "components/embedcode";
import {noop} from "form";
import {t} from "t";
import {severities} from "util";
import {Link} from "react-router";

class Walkthrough extends React.Component {

	static defaultProps = {
		walkthrough: {},
		onPlayClick: noop,
		onEditClick: noop,
		onDeleteClick: noop,
		editable: false,
		embedded: false,
		compact: false,
		linkTo: true,
		httpReloadURL: "",
		helpcenter: false,
	};

	static contextTypes = {
		location: React.PropTypes.shape,
		history: React.PropTypes.shape,
	};

	render() {
		const walkthrough = this.props.walkthrough;

		const playButton = this.props.helpcenter ? <a onClick={this.props.onPlayClick} href="#" className="helpcenter-play"><span className="glyphicon glyphicon-play-circle" aria-hidden="true" data-toggle="tooltip" title={t("Play walkthrough")}></span></a> :
			<a onClick={this.props.onPlayClick} className="btn btn-success btn-sm">{t("Play")}</a>;

		if (this.props.embedded) {
			return playButton;
		}

		let counter = 0;
		const steps = walkthrough.steps ? walkthrough.steps.map((step) => {
			return <Step key={counter++} step={step} />;
		}) : null;

		const editbuttons = [];
		if (this.props.editable) {
			if (this.props.compact) {
				const href = this.context.history.createHref(`/walkthrough/${walkthrough.uuid}`);
				editbuttons.push(<a href={href} key="edit" target="_blank" className="btn btn-default btn-sm">{t("Edit")}</a>);
			} else {
				editbuttons.push(<a onClick={this.props.onEditClick} key="edit" className="btn btn-default btn-sm">{t("Edit")}</a>);
				editbuttons.push(<a onClick={this.props.onDeleteClick} key="delete" className="btn btn-danger btn-sm">{t("Delete")}</a>);
			}
		}

		const titleName = this.props.compact && this.props.linkTo ?
			<Link to={`/walkthrough/${walkthrough.uuid}`}>{walkthrough.name}</Link> :
			walkthrough.name;

		const title = this.props.helpcenter ? (
			<div className="row row-wt-helpcenter">
				<div className="col-xs-1 col-md-3 play-col">
					{playButton}
				</div>
				<div className="col-xs-11 col-md-9">
					<h5 className="wt-title">
						<a href="#" onClick={this.props.onPlayClick}>{titleName}</a>
					</h5>
				</div>
			</div>
		) : (
			<div className="row row-wt-no-helpcenter">
				<div className="col-xs-9 col-md-8">
					<h5 className="wt-title">
						{titleName}
					</h5>
				</div>
				<div className="col-xs-3 col-md-4">
					{playButton}
					{editbuttons}
				</div>
			</div>
		);

		const severity = (
			<div className="row">
				<div className="col-xs-12">
					<p> {t("This walkthrough @severity", {
						"@severity": severities[walkthrough.severity],
					})} </p>
				</div>
			</div>
		);

		const description = (
			<div className="row">
{'fraction_non_alphanumeric': 0.15880436322425273, 'fraction_numerical': 0.005949851253718657, 'mean_word_length': 3.6386333771353483, 'pattern_counts': {'":': 2, '<': 83, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6484065', 'n_tokens_mistral': 2631, 'n_tokens_neox': 2260, 'n_words': 604}