-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sysinfo cleanup #1472
Sysinfo cleanup #1472
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we perhaps use git commands to rename this file? As it stands now, it looks like we'll lose the commit history on this file after it was renamed... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking a single commit that only renamed would be enough, I'll try git mv! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems to me from this stack overflow thread it doesn't matter if I use git mv instead? https://stackoverflow.com/questions/2314652/is-it-possible-to-move-rename-files-in-git-and-maintain-their-history |
||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import React, { Component, ReactNode } from 'react' | ||
import { connect } from 'react-redux' | ||
import { withBus } from 'react-suber' | ||
import { CYPHER_REQUEST } from 'shared/modules/cypher/cypherDuck' | ||
import { Database, isEnterprise } from 'shared/modules/dbMeta/dbMetaDuck' | ||
import { | ||
isConnected, | ||
getUseDb | ||
} from 'shared/modules/connections/connectionsDuck' | ||
import FrameTemplate from 'browser/modules/Frame/FrameTemplate' | ||
import FrameError from 'browser/modules/Frame/FrameError' | ||
import { | ||
StyledStatusBar, | ||
AutoRefreshToggle, | ||
AutoRefreshSpan, | ||
StatusbarWrapper | ||
} from '../AutoRefresh/styled' | ||
import { NEO4J_BROWSER_USER_ACTION_QUERY } from 'services/bolt/txMetadata' | ||
import { hasMultiDbSupport } from 'shared/modules/features/versionedFeatures' | ||
import { ErrorsView } from '../CypherFrame/ErrorsView' | ||
import { getDatabases } from 'shared/modules/dbMeta/dbMetaDuck' | ||
import * as legacyHelpers from './legacyHelpers' | ||
import * as helpers from './helpers' | ||
import { SysInfoTable } from './SysInfoTable' | ||
import { Bus } from 'suber' | ||
import { GlobalState } from 'shared/globalState' | ||
import { Frame } from 'shared/modules/stream/streamDuck' | ||
|
||
export type DatabaseMetric = { label: string; value?: string } | ||
export type SysInfoFrameState = { | ||
lastFetch?: null | number | ||
storeSizes: DatabaseMetric[] | ||
idAllocation: DatabaseMetric[] | ||
pageCache: DatabaseMetric[] | ||
transactions: DatabaseMetric[] | ||
error: string | ||
results: boolean | ||
success: boolean | ||
autoRefresh: boolean | ||
autoRefreshInterval: number | ||
} | ||
|
||
type SysInfoFrameProps = { | ||
bus: Bus | ||
databases: Database[] | ||
frame: Frame | ||
hasMultiDbSupport: boolean | ||
isConnected: boolean | ||
isEnterprise: boolean | ||
useDb: string | null | ||
} | ||
|
||
export class SysInfoFrame extends Component< | ||
SysInfoFrameProps, | ||
SysInfoFrameState | ||
> { | ||
timer: number | null = null | ||
state: SysInfoFrameState = { | ||
lastFetch: null, | ||
storeSizes: [], | ||
idAllocation: [], | ||
pageCache: [], | ||
transactions: [], | ||
error: '', | ||
results: false, | ||
success: false, | ||
autoRefresh: false, | ||
autoRefreshInterval: 20 // seconds | ||
} | ||
helpers = this.props.hasMultiDbSupport ? helpers : legacyHelpers | ||
|
||
componentDidMount(): void { | ||
this.getSysInfo() | ||
} | ||
|
||
componentDidUpdate( | ||
_prevProps: SysInfoFrameProps, | ||
prevState: SysInfoFrameState | ||
): void { | ||
if (prevState.autoRefresh !== this.state.autoRefresh) { | ||
if (this.state.autoRefresh) { | ||
this.timer = setInterval( | ||
this.getSysInfo.bind(this), | ||
this.state.autoRefreshInterval * 1000 | ||
) | ||
} else { | ||
this.timer && clearInterval(this.timer) | ||
} | ||
} | ||
} | ||
|
||
getSysInfo(): void { | ||
const { bus, isConnected, useDb } = this.props | ||
const { sysinfoQuery, responseHandler } = this.helpers | ||
|
||
if (bus && isConnected) { | ||
this.setState({ lastFetch: Date.now() }) | ||
bus.self( | ||
CYPHER_REQUEST, | ||
{ | ||
query: sysinfoQuery(useDb), | ||
queryType: NEO4J_BROWSER_USER_ACTION_QUERY | ||
}, | ||
responseHandler(newState => { | ||
this.setState(newState) | ||
}, useDb) | ||
) | ||
} else { | ||
this.setState({ error: 'No connection available' }) | ||
} | ||
} | ||
|
||
setAutoRefresh(autoRefresh: boolean): void { | ||
this.setState({ autoRefresh }) | ||
|
||
if (autoRefresh) { | ||
this.getSysInfo() | ||
} | ||
} | ||
|
||
render(): ReactNode { | ||
const { | ||
autoRefresh, | ||
error, | ||
idAllocation, | ||
lastFetch, | ||
pageCache, | ||
storeSizes, | ||
success, | ||
transactions | ||
} = this.state | ||
const { databases, frame, isConnected, isEnterprise } = this.props | ||
|
||
const content = !isConnected ? ( | ||
<ErrorsView | ||
result={{ code: 'No connection', message: 'No connection available' }} | ||
/> | ||
) : ( | ||
<SysInfoTable | ||
pageCache={pageCache} | ||
storeSizes={storeSizes} | ||
idAllocation={idAllocation} | ||
transactions={transactions} | ||
databases={databases} | ||
isEnterpriseEdition={isEnterprise} | ||
/> | ||
) | ||
|
||
return ( | ||
<FrameTemplate | ||
header={frame} | ||
contents={content} | ||
statusbar={ | ||
<StatusbarWrapper> | ||
{error && <FrameError message={error} />} | ||
{success && ( | ||
<StyledStatusBar> | ||
{lastFetch && `Updated: ${new Date(lastFetch).toISOString()}`} | ||
|
||
{success} | ||
|
||
<AutoRefreshSpan> | ||
<AutoRefreshToggle | ||
checked={autoRefresh} | ||
onChange={e => this.setAutoRefresh(e.target.checked)} | ||
/> | ||
</AutoRefreshSpan> | ||
</StyledStatusBar> | ||
)} | ||
</StatusbarWrapper> | ||
} | ||
/> | ||
) | ||
} | ||
} | ||
|
||
const mapStateToProps = (state: GlobalState) => ({ | ||
hasMultiDbSupport: hasMultiDbSupport(state), | ||
isEnterprise: isEnterprise(state), | ||
isConnected: isConnected(state), | ||
databases: getDatabases(state), | ||
useDb: getUseDb(state) | ||
}) | ||
|
||
export default withBus(connect(mapStateToProps)(SysInfoFrame)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the reason for removing this test?