<commit_before>import { Modal, Button, Tabs, Tab } from 'react-bootstrap';
import { Link } from 'react-router-dom';

const Row = ({label,value,children}) => {
  return (
    <tr>
      <th style={{width: '30%'}}>{label}</th>
      <td>{value || children}</td>
    </tr>
  )
};

export default class ShowShareModal extends React.Component{
  constructor(props){
  	super(props);
  	this.state = {show: props.share!=null};
    this.close = this.close.bind(this)
  }

  close(e) {
    if(e) e.stopPropagation()
    //this.props.history.goBack()
    this.setState({show: false})
    setTimeout(() => this.props.history.replace('/shares'),300)
  }

  componentDidMount() {
    if(this.props.share) this.props.loadExportLocationsOnce(this.props.share.id)
    this.props.loadShareTypesOnce()
  }

  componentWillReceiveProps(nextProps) {
    this.setState({show: nextProps.share!=null})
    if(nextProps.share && !nextProps.share.export_locations) {
      this.props.loadExportLocationsOnce(nextProps.share.id)
    }
  }

  overview(share) {
    return (
      <table className='table no-borders'>
        <tbody>
          <Row label='Name' value={share.name}/>
          <Row label='Description' value={share.description}/>
          <Row label='ID' value={share.id}/>
          <Row label='Status' value={share.status}/>
          <Row label='Export Locations'>
            {share.export_locations ? (
              share.export_locations.map((location) =>
                <div key={location.id}>{location.path}</div>)
              ) : (<span className='spinner'></span>)
            }
          </Row>
          <Row label='Availability zone' value={share.availability_zone}/>
          <Row label='Size' value={share.size+' GiB'}/>
          <Row label='Protocol' value={share.share_proto}/>
          <Row label='Share Type' value={share.share_type_name + ' ('+share.share_type+')'}/>
          <Row label='Share network'>
            <Link to={`/share-networks/${share.share_network_id}/show`}>{share.share_network_id}</Link>
          </Row>
          <Row label='Created At' value={share.created_at}/>
          <Row label='Host' value={share.host}/>
        </tbody>
      </table>
    );
  }

  metadata(share) {
    if (share.metadata && Object.keys(share.metadata).length>0) {
      return (
        <table className="table no-borders">
          <tbody>
            Object.keys(share.metadata).map((key) =>
              <Row label={key} value={share.metadata[key]}/>
            )
          </tbody>
        </table>
      )
    } else return null
  }

  render(){
    let { share, onHide } = this.props

    return (
      <Modal show={this.state.show} onHide={this.close} bsSize="large" aria-labelledby="contained-modal-title-lg">
        <Modal.Header closeButton>
          <Modal.Title id="contained-modal-title-lg">Share {share ? share.name : ''}</Modal.Title>
        </Modal.Header>
        <Modal.Body>
          { share &&
            ( share.metadata && Object.keys(share.metadata).length>0 ? (
              <Tabs defaultActiveKey={1} id="share">
                <Tab eventKey={1} title="Overview">{this.overview(share)}</Tab>
                <Tab eventKey={2} title="Metadata">{this.metadata(share)}</Tab>
              </Tabs>
            ) : (
              this.overview(share)
            ))
          }<commit_msg>shares: fix bug in share show view<commit_after>import { Modal, Button, Tabs, Tab } from 'react-bootstrap';
import { Link } from 'react-router-dom';

const Row = ({label,value,children}) => {
  return (
    <tr>
      <th style={{width: '30%'}}>{label}</th>
      <td>{value || children}</td>
    </tr>
  )
};

export default class ShowShareModal extends React.Component{
  constructor(props){
  	super(props);
  	this.state = {show: props.share!=null};
    this.close = this.close.bind(this)
  }

  close(e) {
    if(e) e.stopPropagation()
    //this.props.history.goBack()
    this.setState({show: false})
    setTimeout(() => this.props.history.replace('/shares'),300)
  }

  componentDidMount() {
    if(this.props.share) this.props.loadExportLocationsOnce(this.props.share.id)
    this.props.loadShareTypesOnce()
  }

  componentWillReceiveProps(nextProps) {
    this.setState({show: nextProps.share!=null})
    if(nextProps.share && !nextProps.share.export_locations) {
      this.props.loadExportLocationsOnce(nextProps.share.id)
    }
  }

  overview(share) {
    return (
      <table className='table no-borders'>
        <tbody>
          <Row label='Name' value={share.name}/>
          <Row label='Description' value={share.description}/>
          <Row label='ID' value={share.id}/>
          <Row label='Status' value={share.status}/>
          <Row label='Export Locations'>
            {share.export_locations ? (
              share.export_locations.map((location) =>
                <div key={location.id}>{location.path}</div>)
              ) : (<span className='spinner'></span>)
            }
          </Row>
          <Row label='Availability zone' value={share.availability_zone}/>
          <Row label='Size' value={share.size+' GiB'}/>
          <Row label='Protocol' value={share.share_proto}/>
          <Row label='Share Type' value={share.share_type_name + ' ('+share.share_type+')'}/>
          <Row label='Share network'>
            <Link to={`/share-networks/${share.share_network_id}/show`}>{share.share_network_id}</Link>
          </Row>
          <Row label='Created At' value={share.created_at}/>
          <Row label='Host' value={share.host}/>
        </tbody>
      </table>
    );
  }

  metadata(share) {
    if (share.metadata && Object.keys(share.metadata).length>0) {
      return (
        <table className="table no-borders">
          <tbody>
            {Object.keys(share.metadata).map((key,index) =>
              <Row label={key} key={index} value={share.metadata[key]}/>
            )}
          </tbody>
        </table>
      )
    } else return null
  }

  render(){
    let { share, onHide } = this.props

    return (
      <Modal show={this.state.show} onHide={this.close} bsSize="large" aria-labelledby="contained-modal-title-lg">
        <Modal.Header closeButton>
          <Modal.Title id="contained-modal-title-lg">Share {share ? share.name : ''}</Modal.Title>
        </Modal.Header>
        <Modal.Body>
          { share &&
            ( share.metadata && Object.keys(share.metadata).length>0 ? (
              <Tabs defaultActiveKey={1} id="share">
                <Tab eventKey={1} title="Overview">{this.overview(share)}</Tab>
                <Tab eventKey={2} title="Metadata">{this.metadata(share)}</Tab>
              </Tabs>
            ) : (
              this.overview(share)
            ))
          }
{'fraction_non_alphanumeric': 0.16852595567455006, 'fraction_numerical': 0.0029748624126134165, 'mean_word_length': 2.395959595959596, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2373722', 'n_tokens_mistral': 2095, 'n_tokens_neox': 2054, 'n_words': 335}