Skip to content

Commit

Permalink
fix: 3.0 sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
kdoran committed Apr 25, 2020
1 parent ba48c87 commit 1928da5
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 31 deletions.
4 changes: 4 additions & 0 deletions api/remote-couch-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ class RemoteCouchApi {
return this.fetcher(databaseName)
}

async getServer () {
return this.fetcher('/')
}

async destroyDatabase (databaseName) {
return this.fetcher(databaseName, {method: 'DELETE'})
}
Expand Down
5 changes: 5 additions & 0 deletions app/app-classes.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,8 @@
.search-modal {
height: 80%;
}

.server-info {
font-size: .7em;
margin-bottom: 20px;
}
102 changes: 71 additions & 31 deletions app/containers/DatabasesContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DatabasesContainer extends React.Component {
}

componentDidMount () {
this.fetchInfos()
this.fetchInfos().catch(error => this.setState({error}))
}

componentDidUpdate (prevProps) {
Expand All @@ -33,8 +33,10 @@ class DatabasesContainer extends React.Component {
// infos and dbs are split for couch < 2.2 that does not have
// single infos call. lazy load dbs & display first
// so you're not always waiting on the 100 individual info calls
const serverInfo = await this.props.api.getServer()
const isThreeO = (serverInfo.version && serverInfo.version.startsWith('3'))
const dbs = await this.props.api.listDatabases()
this.setState({dbs})
this.setState({dbs, serverInfo, isThreeO})
const infosResponse = await this.props.api.listInfos(dbs)
const infos = keyBy(infosResponse, 'key')
this.setState({loaded: true, infos})
Expand All @@ -53,41 +55,79 @@ class DatabasesContainer extends React.Component {

render () {
const { couchUrl, couch } = this.props
const { loaded, error, infos, dbs, showNewDBModal } = this.state
const { loaded, error, serverInfo, isThreeO, infos, dbs, showNewDBModal } = this.state

const table = isThreeO
? (
<table>
<thead>
<tr>
<th>name</th>
<th />
<th>doc count</th>
<th>sizes.active</th>
<th>sizes.external</th>
<th>sizes.file</th>
<th>deleted</th>
<th>seq no. (as int)</th>
</tr>
</thead>
<tbody>
{dbs.map(db => {
return (
<tr key={db}>
<td><Link to={`/${couch}/${db}/query`}>{db}</Link></td>
<td><Link to={`/${couch}/${db}/`}>all docs</Link></td>
<td>{infos[db] ? withCommas(infos[db].info.doc_count) : 'loading...'}</td>
<td>{infos[db] ? showMBSize(infos[db].info.sizes.active) : 'loading...'}</td>
<td>{infos[db] ? showMBSize(infos[db].info.sizes.external) : 'loading...'}</td>
<td>{infos[db] ? showMBSize(infos[db].info.sizes.file) : 'loading...'}</td>
<td>{infos[db] ? withCommas(infos[db].info.doc_del_count) : 'loading...'}</td>
<td>{infos[db] ? infos[db].info.update_seq.split('-')[0] : 'loading...'}</td>
</tr>
)
})}
</tbody>
</table>
)
: (
<table>
<thead>
<tr>
<th>name</th>
<th />
<th>doc count</th>
<th>data size</th>
<th>disk space</th>
<th>deleted</th>
<th>seq no. (as int)</th>
</tr>
</thead>
<tbody>
{dbs.map(db => {
return (
<tr key={db}>
<td><Link to={`/${couch}/${db}/query`}>{db}</Link></td>
<td><Link to={`/${couch}/${db}/`}>all docs</Link></td>
<td>{infos[db] ? withCommas(infos[db].info.doc_count) : 'loading...'}</td>
<td>{infos[db] ? showMBSize(infos[db].info.data_size) : 'loading...'}</td>
<td>{infos[db] ? showMBSize(infos[db].info.disk_size) : 'loading...'}</td>
<td>{infos[db] ? withCommas(infos[db].info.doc_del_count) : 'loading...'}</td>
<td>{infos[db] ? infos[db].info.update_seq.split('-')[0] : 'loading...'}</td>
</tr>
)
})}
</tbody>
</table>
)

return (
<div>
<Breadcrumbs couch={couch} />
{loaded ? error ? <ErrorDisplay error={error} /> : (
<div>
<table>
<thead>
<tr>
<th>name</th>
<th />
<th>doc count</th>
<th>data size</th>
<th>disk space</th>
<th>deleted</th>
<th>seq no. (as int)</th>
</tr>
</thead>
<tbody>
{dbs.map(db => {
return (
<tr key={db}>
<td><Link to={`/${couch}/${db}/query`}>{db}</Link></td>
<td><Link to={`/${couch}/${db}/`}>all docs</Link></td>
<td>{infos[db] ? withCommas(infos[db].info.doc_count) : 'loading...'}</td>
<td>{infos[db] ? showMBSize(infos[db].info.data_size) : 'loading...'}</td>
<td>{infos[db] ? showMBSize(infos[db].info.disk_size) : 'loading...'}</td>
<td>{infos[db] ? withCommas(infos[db].info.doc_del_count) : 'loading...'}</td>
<td>{infos[db] ? infos[db].info.update_seq.split('-')[0] : 'loading...'}</td>
</tr>
)
})}
</tbody>
</table>
<div className='server-info'>{JSON.stringify(serverInfo)}</div>
{table}
<br /><br />
<table>
<thead>
Expand Down

0 comments on commit 1928da5

Please sign in to comment.