Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
Capacity Card changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushAmbastha committed Apr 9, 2019
1 parent c0dd04e commit 8095fa6
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/components/StorageOverview/Capacity/Capacity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import PropTypes from 'prop-types';

import { InlineLoading } from '../../Loading';

import {
DashboardCard,
DashboardCardBody,
DashboardCardHeader,
DashboardCardTitle,
} from '../../Dashboard/DashboardCard';
import { StorageOverviewContext } from '../StorageOverviewContext';
import { CapacityItem } from '../../Dashboard/Capacity/CapacityItem';
import { formatBytes } from '../../../utils';
import { getCapacityStats } from '../../../selectors';
import { CapacityBody } from '../../Dashboard/Capacity/CapacityBody';

export const Capacity = ({ capacityTotal, capacityUsed, LoadingComponent }) => (
<DashboardCard>
<DashboardCardHeader>
<DashboardCardTitle>Capacity</DashboardCardTitle>
</DashboardCardHeader>
<DashboardCardBody>
<CapacityBody>
<CapacityItem
id="capacity"
title="Total capacity"
used={getCapacityStats(capacityUsed)}
total={getCapacityStats(capacityTotal)}
formatValue={formatBytes}
LoadingComponent={LoadingComponent}
isLoading={!(capacityUsed && capacityTotal)}
/>
</CapacityBody>
</DashboardCardBody>
</DashboardCard>
);

Capacity.defaultProps = {
capacityTotal: null,
capacityUsed: null,
LoadingComponent: InlineLoading,
};

Capacity.propTypes = {
capacityTotal: PropTypes.object,
capacityUsed: PropTypes.object,
LoadingComponent: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
};

export const CapacityConnected = () => (
<StorageOverviewContext.Consumer>{props => <Capacity {...props} />}</StorageOverviewContext.Consumer>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Capacity } from '../Capacity';

const getPromResponse = value => ({
data: {
result: [
{
value: [0, value],
},
],
},
});

export const capacityStats = {
capacityTotal: getPromResponse(11),
capacityUsed: getPromResponse(5),
};

export default {
component: Capacity,
props: { capacityStats },
};
19 changes: 19 additions & 0 deletions src/components/StorageOverview/Capacity/tests/Capacity.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { render } from 'enzyme';

import { Capacity } from '../Capacity';
import { default as CapacityFixtures } from '../fixtures/Capacity.fixture';

const testCapacityOverview = () => <Capacity {...CapacityFixtures.props} />;

describe('<Capacity />', () => {
it('renders correctly', () => {
const component = render(testCapacityOverview());
expect(component).toMatchSnapshot();
});

it('renders correctly in Loading state', () => {
const component = render(<Capacity />);
expect(component).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Capacity /> renders correctly 1`] = `
<div
class="card-pf kubevirt-dashboard__card"
>
<div
class="card-pf-heading kubevirt-dashboard__card-heading"
>
<h2
class="card-pf-title"
>
Capacity
</h2>
</div>
<div
class="card-pf-body"
>
<div
class="kubevirt-capacity__items"
>
<div
class="kubevirt-capacity__item"
>
<h2
class="kubevirt-capacity__item-title"
>
Total Capacity
</h2>
<h6>
<div>
<div
class="spinner spinner-md blank-slate-pf-icon"
/>
</div>
</h6>
<div>
<div
class=" donut-chart-pf"
/>
</div>
</div>
</div>
</div>
</div>
`;

exports[`<Capacity /> renders correctly in Loading state 1`] = `
<div
class="card-pf kubevirt-dashboard__card"
>
<div
class="card-pf-heading kubevirt-dashboard__card-heading"
>
<h2
class="card-pf-title"
>
Capacity
</h2>
</div>
<div
class="card-pf-body"
>
<div
class="kubevirt-capacity__items"
>
<div
class="kubevirt-capacity__item"
>
<h2
class="kubevirt-capacity__item-title"
>
Total Capacity
</h2>
<h6>
<div>
<div
class="spinner spinner-md blank-slate-pf-icon"
/>
</div>
</h6>
<div>
<div
class=" donut-chart-pf"
/>
</div>
</div>
</div>
</div>
</div>
`;
4 changes: 4 additions & 0 deletions src/components/StorageOverview/StorageOverview.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import { MEDIA_QUERY_EXCLUSIVE_DEVIATION, MEDIA_QUERY_LG } from '../../utils';
import { StorageDetailsConnected } from './Details/Details';
import { InventoryConnected } from './Inventory/Inventory';
import OCSHealthConnected from './OCSHealth/Health';
import { CapacityConnected } from './Capacity/Capacity';

const MainCards = () => (
<GridItem lg={6} md={12} sm={12}>
<Grid>
<GridItem span={12}>
<OCSHealthConnected />
</GridItem>
<GridItem span={6}>
<CapacityConnected />
</GridItem>
</Grid>
</GridItem>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';
import { StorageOverview as StorageOverviewComponent } from '../StorageOverview';
import { cephCluster } from '../Details/fixtures/Details.fixture';
import { ocsHealthData } from '../OCSHealth/fixtures/Health.fixture';
import { capacityStats } from '../Capacity/fixtures/Capacity.fixture';

import { StorageOverviewContext } from '../StorageOverviewContext';

Expand All @@ -26,9 +27,17 @@ export default [
props: {
cephCluster,
ocsHealthData,
...capacityStats,
nodes,
pvcs,
pvs,
},
},
{
component: StorageOverview,
name: 'Loading overview',
props: {
ocsHealthData: { loaded: false },
},
},
];

0 comments on commit 8095fa6

Please sign in to comment.