This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added top consumer card for storage dashboard
- Loading branch information
Showing
7 changed files
with
230 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/components/StorageOverview/TopConsumers/TopConsumers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { LineChart, Row, Col } from 'patternfly-react'; | ||
|
||
import { InlineLoading } from '../../Loading'; | ||
|
||
import { | ||
DashboardCard, | ||
DashboardCardBody, | ||
DashboardCardHeader, | ||
DashboardCardTitle, | ||
} from '../../Dashboard/DashboardCard'; | ||
import { StorageOverviewContext } from '../StorageOverviewContext/StorageOverviewContext'; | ||
import { getTopConsumerVectorStats } from '../../../selectors'; | ||
|
||
const TopConsumersBody = ({ stats }) => { | ||
let results = 'Not data available'; | ||
|
||
if (stats.length) { | ||
const columnsConf = getTopConsumerVectorStats(stats); | ||
const { columns, unit } = columnsConf; | ||
const formatTime = x => { | ||
const dt = new Date(x); | ||
|
||
let hrs = dt.getHours(); | ||
hrs = hrs > 9 ? `${hrs}` : `0${hrs}`; | ||
|
||
let mins = dt.getMinutes(); | ||
mins = mins > 9 ? `${mins}` : `0${mins}`; | ||
|
||
return `${hrs}:${mins}`; | ||
}; | ||
|
||
results = ( | ||
<Row> | ||
<Col lg={12} md={12} sm={12} xs={12}> | ||
<LineChart | ||
className="kubevirt-top-consumers__body" | ||
id="line-chart" | ||
data={{ | ||
x: 'x', | ||
columns, | ||
type: 'line', | ||
}} | ||
axis={{ | ||
y: { | ||
label: { | ||
text: `Used Capacity(${unit})`, | ||
position: 'outer-top', | ||
}, | ||
min: 0, | ||
padding: { | ||
bottom: 3, | ||
}, | ||
}, | ||
x: { | ||
tick: { | ||
format: formatTime, | ||
fit: true, | ||
values: [...columns[0].slice(1)], | ||
}, | ||
}, | ||
}} | ||
/> | ||
</Col> | ||
</Row> | ||
); | ||
} | ||
|
||
return <div>{results}</div>; | ||
}; | ||
|
||
export const TopConsumers = ({ stats, LoadingComponent, loaded }) => ( | ||
<DashboardCard> | ||
<DashboardCardHeader> | ||
<DashboardCardTitle>Top Projects by Used Capacity</DashboardCardTitle> | ||
</DashboardCardHeader> | ||
<DashboardCardBody isLoading={!loaded} LoadingComponent={LoadingComponent}> | ||
<TopConsumersBody stats={stats} /> | ||
</DashboardCardBody> | ||
</DashboardCard> | ||
); | ||
|
||
TopConsumersBody.propTypes = { | ||
stats: PropTypes.array.isRequired, | ||
}; | ||
|
||
TopConsumers.defaultProps = { | ||
stats: [], | ||
loaded: false, | ||
LoadingComponent: InlineLoading, | ||
}; | ||
|
||
TopConsumers.propTypes = { | ||
stats: PropTypes.array, | ||
loaded: PropTypes.bool, | ||
LoadingComponent: PropTypes.oneOfType([PropTypes.node, PropTypes.func]), | ||
}; | ||
|
||
const TopConsumersConnected = () => ( | ||
<StorageOverviewContext.Consumer>{props => <TopConsumers {...props} />}</StorageOverviewContext.Consumer> | ||
); | ||
|
||
export default TopConsumersConnected; |
31 changes: 31 additions & 0 deletions
31
src/components/StorageOverview/TopConsumers/fixtures/TopConsumers.fixture.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { TopConsumers } from '../TopConsumers'; | ||
|
||
export const TopConsumerStats = { | ||
stats: [ | ||
{ | ||
metric: { | ||
namespace: 'openshift-namespace', | ||
}, | ||
values: [ | ||
[1554797100, '46161920'], | ||
[1554797400, '46161920'], | ||
[1554797700, '46161920'], | ||
[1554798000, '46161920'], | ||
[1554798300, '46161920'], | ||
[1554798600, '46161920'], | ||
], | ||
}, | ||
], | ||
loaded: true, | ||
}; | ||
|
||
export default [ | ||
{ | ||
component: TopConsumers, | ||
props: { ...TopConsumerStats }, | ||
}, | ||
{ | ||
component: TopConsumers, | ||
name: 'Loading top consumers', | ||
}, | ||
]; |
14 changes: 14 additions & 0 deletions
14
src/components/StorageOverview/TopConsumers/tests/TopConsumers.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
import { render } from 'enzyme'; | ||
|
||
import { TopConsumers } from '../TopConsumers'; | ||
import { TopConsumerStats } from '../fixtures/TopConsumers.fixture'; | ||
|
||
const testTopConsumersOverview = () => <TopConsumers {...TopConsumerStats} />; | ||
|
||
describe('<TopConsumers />', () => { | ||
it('renders correctly', () => { | ||
const component = render(testTopConsumersOverview()); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
src/components/StorageOverview/TopConsumers/tests/__snapshots__/TopConsumers.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<TopConsumers /> renders correctly 1`] = ` | ||
<div | ||
class="card-pf kubevirt-dashboard__card" | ||
> | ||
<div | ||
class="card-pf-heading kubevirt-dashboard__card-heading" | ||
> | ||
<h2 | ||
class="card-pf-title" | ||
> | ||
Top Projects by Used Capacity | ||
</h2> | ||
</div> | ||
<div | ||
class="card-pf-body" | ||
> | ||
<div> | ||
<div | ||
class="row" | ||
> | ||
<div | ||
class="col-lg-12 col-md-12 col-sm-12 col-xs-12" | ||
> | ||
<div | ||
class=" kubevirt-top-consumers__body" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters