import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { Edit, ViewServer, ViewImage } from './ContentView/ContentViews'
import * as MetaViews from './ContentView/MetaViews'
import ShowFullContentButton from './ContentView/ShowFullContentButton'


import { displayLarge, updateEdit } from '../ducks/ui/flow'

ContentView.propTypes = {
    // It may seem a bit weird at the first glance:
    // Every view takes the flow and the message as props, e.g.
    // <Auto flow={flow} message={flow.request}/>
    flow: PropTypes.object.isRequired,
    message: PropTypes.object.isRequired,
}

ContentView.isContentTooLarge = msg => msg.contentLength > 1024 * 1024 * (ViewImage.matches(msg) ? 10 : 0.2)

function ContentView(props) {
    const { flow, message, contentView, isDisplayLarge, displayLarge, onContentChange, readonly } = props

    if (message.contentLength === 0 && readonly) {
        return <MetaViews.ContentEmpty {...props}/>
    }

    if (message.contentLength === null && readonly) {
        return <MetaViews.ContentMissing {...props}/>
    }

    if (!isDisplayLarge && ContentView.isContentTooLarge(message)) {
        return <MetaViews.ContentTooLarge {...props} onClick={displayLarge}/>
    }

    let view;
    if(contentView === "Edit") {
        view = <Edit flow={flow} message={message} onChange={onContentChange}/>
    } else {
        view = <ViewServer flow={flow} message={message} contentView={contentView}/>
    }
    return (
        <div className="contentview">
            {view}
            <ShowFullContentButton/>
        </div>
    )
}

export default connect(
    state => ({
        contentView: state.ui.flow.contentView,
        isDisplayLarge: state.ui.flow.displayLarge,
    }),
    {
        displayLarge,
        updateEdit
    }
)(ContentView)
24a7ed51b8670fd69f'>tree</a><a href='/cgit/xen/xen/commit/tools/firmware/vgabios/dataseghack?id=4c090758911b717c89f05d24a7ed51b8670fd69f'>commit</a><a href='/cgit/xen/xen/diff/tools/firmware/vgabios/dataseghack?id=4c090758911b717c89f05d24a7ed51b8670fd69f'>diff</a><a href='/cgit/xen/xen/stats/tools/firmware/vgabios/dataseghack'>stats</a></td><td class='form'><form class='right' method='get' action='/cgit/xen/xen/log/tools/firmware/vgabios/dataseghack'>
<input type='hidden' name='id' value='4c090758911b717c89f05d24a7ed51b8670fd69f'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/cgit/xen/xen/tree/?id=4c090758911b717c89f05d24a7ed51b8670fd69f'>root</a>/<a href='/cgit/xen/xen/tree/tools?id=4c090758911b717c89f05d24a7ed51b8670fd69f'>tools</a>/<a href='/cgit/xen/xen/tree/tools/firmware?id=4c090758911b717c89f05d24a7ed51b8670fd69f'>firmware</a>/<a href='/cgit/xen/xen/tree/tools/firmware/vgabios?id=4c090758911b717c89f05d24a7ed51b8670fd69f'>vgabios</a>/<a href='/cgit/xen/xen/tree/tools/firmware/vgabios/dataseghack?id=4c090758911b717c89f05d24a7ed51b8670fd69f'>dataseghack</a></div><div class='content'>blob: 02a2d4c525dcd6f5cec4817a08c98ed29d2394a7 (<a href='/cgit/xen/xen/plain/tools/firmware/vgabios/dataseghack?id=4c090758911b717c89f05d24a7ed51b8670fd69f'>plain</a>)
<table summary='blob content' class='blob'>
<tr><td class='linenumbers'><pre><a id='n1' href='#n1'>1</a>
<a id='n2' href='#n2'>2</a>
<a id='n3' href='#n3'>3</a>
<a id='n4' href='#n4'>4</a>
<a id='n5' href='#n5'>5</a>
<a id='n6' href='#n6'>6</a>
<a id='n7' href='#n7'>7</a>
<a id='n8' href='#n8'>8</a>
<a id='n9' href='#n9'>9</a>
<a id='n10' href='#n10'>10</a>
<a id='n11' href='#n11'>11</a>
<a id='n12' href='#n12'>12</a>
<a id='n13' href='#n13'>13</a>
<a id='n14' href='#n14'>14</a>
<a id='n15' href='#n15'>15</a>
<a id='n16' href='#n16'>16</a>
<a id='n17' href='#n17'>17</a>
<a id='n18' href='#n18'>18</a>
<a id='n19' href='#n19'>19</a>
<a id='n20' href='#n20'>20</a>
<a id='n21' href='#n21'>21</a>
<a id='n22' href='#n22'>22</a>
<a id='n23' href='#n23'>23</a>
</pre></td>
<td class='lines'><pre><code>