Skip to content
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

feat(openshiftView): issues/185 add cores sockets selector #205

Merged
merged 1 commit into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"authorizedCopy": "You do not have permission to access reporting. Contact your administrator."
},
"curiosity-graph": {
"cardHeading": "CPU usage",
"coresHeading": "CPU core usage",
"socketsHeading": "CPU socket usage",
"dropdownDaily": "Daily",
Expand Down
5 changes: 4 additions & 1 deletion src/components/graphCard/graphCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,15 @@ class GraphCard extends React.Component {
}

render() {
const { cardTitle, error, graphGranularity, selectOptionsType, pending, t } = this.props;
const { cardTitle, children, error, graphGranularity, selectOptionsType, pending, t } = this.props;
const { options } = graphCardTypes.getGranularityOptions(selectOptionsType);

return (
<Card className="curiosity-usage-graph fadein">
<CardHead>
<h2>{cardTitle}</h2>
<CardActions>
{children}
<Select
aria-label={t('curiosity-graph.dropdownPlaceholder')}
onSelect={this.onSelect}
Expand Down Expand Up @@ -165,6 +166,7 @@ class GraphCard extends React.Component {

GraphCard.propTypes = {
cardTitle: PropTypes.string,
children: PropTypes.node,
error: PropTypes.bool,
filterGraphData: PropTypes.arrayOf(
PropTypes.shape({
Expand All @@ -186,6 +188,7 @@ GraphCard.propTypes = {

GraphCard.defaultProps = {
cardTitle: null,
children: null,
error: false,
filterGraphData: [],
getGraphReportsCapacity: helpers.noop,
Expand Down
13 changes: 5 additions & 8 deletions src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ exports[`I18n Component should generate a predictable pot output snapshot: pot o
msgstr \\"\\"
\\"Content-Type: text/plain; charset=UTF-8\\\\n\\"

#: src/components/openshiftView/openshiftView.js:32
msgid \\"curiosity-graph.coresHeading\\"
#: src/components/openshiftView/openshiftView.js:61
#: src/components/rhelView/rhelView.js:31
msgid \\"curiosity-graph.cardHeading\\"
msgstr \\"\\"

#: src/components/graphCard/graphCardHelpers.js:73
Expand All @@ -30,8 +31,8 @@ msgstr \\"\\"
msgid \\"curiosity-graph.dropdownMonthly\\"
msgstr \\"\\"

#: src/components/graphCard/graphCard.js:140
#: src/components/graphCard/graphCard.js:144
#: src/components/graphCard/graphCard.js:141
#: src/components/graphCard/graphCard.js:145
msgid \\"curiosity-graph.dropdownPlaceholder\\"
msgstr \\"\\"

Expand All @@ -47,10 +48,6 @@ msgstr \\"\\"
msgid \\"curiosity-graph.noDataLabel\\"
msgstr \\"\\"

#: src/components/rhelView/rhelView.js:35
msgid \\"curiosity-graph.socketsHeading\\"
msgstr \\"\\"

#: src/components/graphCard/graphCard.js:112
#: src/components/graphCard/graphCardHelpers.js:81
msgid \\"curiosity-graph.thresholdLabel\\"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`OpenshiftView Component should have a fallback title: title 1`] = `
</PageHeader>
<PageSection>
<Connect(GraphCard)
cardTitle="t(curiosity-graph.coresHeading)"
cardTitle="t(curiosity-graph.cardHeading)"
filterGraphData={
Array [
Object {
Expand All @@ -24,7 +24,31 @@ exports[`OpenshiftView Component should have a fallback title: title 1`] = `
productId="lorem ipsum"
productShortLabel="OpenShift"
viewId="test_id"
/>
>
<Select
ariaLabel="Select option"
className=""
id="generatedid-"
isDisabled={false}
name={null}
onSelect={[Function]}
options={
Array [
Object {
"title": "Cores",
"value": "cores",
},
Object {
"title": "Sockets",
"value": "sockets",
},
]
}
placeholder="Select option"
selectedOptions="cores"
variant="single"
/>
</Connect(GraphCard)>
</PageSection>
</PageLayout>
`;
Expand All @@ -36,7 +60,7 @@ exports[`OpenshiftView Component should render a non-connected component: non-co
</PageHeader>
<PageSection>
<Connect(GraphCard)
cardTitle="t(curiosity-graph.coresHeading)"
cardTitle="t(curiosity-graph.cardHeading)"
filterGraphData={
Array [
Object {
Expand All @@ -53,7 +77,31 @@ exports[`OpenshiftView Component should render a non-connected component: non-co
productId="lorem ipsum"
productShortLabel="OpenShift"
viewId="test_id"
/>
>
<Select
ariaLabel="Select option"
className=""
id="generatedid-"
isDisabled={false}
name={null}
onSelect={[Function]}
options={
Array [
Object {
"title": "Cores",
"value": "cores",
},
Object {
"title": "Sockets",
"value": "sockets",
},
]
}
placeholder="Select option"
selectedOptions="cores"
variant="single"
/>
</Connect(GraphCard)>
</PageSection>
</PageLayout>
`;
54 changes: 47 additions & 7 deletions src/components/openshiftView/openshiftView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,44 @@ import {
} from '@patternfly/react-tokens';
import { PageLayout, PageHeader, PageSection } from '../pageLayout/pageLayout';
import GraphCard from '../graphCard/graphCard';
import { Select } from '../select/select';
import { helpers } from '../../common';

class OpenshiftView extends React.Component {
componentDidMount() {}
state = {
option: null,
filters: []
};

componentDidMount() {
const { initialOption } = this.props;
this.onSelect({ value: initialOption });
}

onSelect = (event = {}) => {
const { option } = this.state;
const { initialFilters } = this.props;
const { value } = event;

if (value !== option) {
const filters = initialFilters.filter(val => new RegExp(value, 'i').test(val.id));
this.setState({
option,
filters
});
}
};

renderSelect() {
const { option } = this.state;
const { initialOption } = this.props;
const options = [{ title: 'Cores', value: 'cores' }, { title: 'Sockets', value: 'sockets' }];

return <Select onSelect={this.onSelect} options={options} selectedOptions={option || initialOption} />;
}

render() {
const { filters } = this.state;
const { routeDetail, t } = this.props;

return (
Expand All @@ -23,22 +55,23 @@ class OpenshiftView extends React.Component {
<PageSection>
<GraphCard
key={routeDetail.pathParameter}
filterGraphData={[
{ id: 'cores', fill: chartColorBlueLight.value, stroke: chartColorBlueDark.value },
{ id: 'thresholdCores' }
]}
filterGraphData={filters}
productId={routeDetail.pathParameter}
viewId={routeDetail.pathId}
cardTitle={t('curiosity-graph.coresHeading')}
cardTitle={t('curiosity-graph.cardHeading')}
productShortLabel="OpenShift"
/>
>
{this.renderSelect()}
</GraphCard>
</PageSection>
</PageLayout>
);
}
}

OpenshiftView.propTypes = {
initialOption: PropTypes.oneOf(['cores', 'sockets']),
initialFilters: PropTypes.array,
routeDetail: PropTypes.shape({
pathParameter: PropTypes.string.isRequired,
pathId: PropTypes.string.isRequired,
Expand All @@ -50,6 +83,13 @@ OpenshiftView.propTypes = {
};

OpenshiftView.defaultProps = {
initialOption: 'cores',
initialFilters: [
{ id: 'cores', fill: chartColorBlueLight.value, stroke: chartColorBlueDark.value },
{ id: 'sockets', fill: chartColorBlueLight.value, stroke: chartColorBlueDark.value },
{ id: 'thresholdSockets' },
{ id: 'thresholdCores' }
],
t: helpers.noopTranslate
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`RhelView Component should have a fallback title: title 1`] = `
</PageHeader>
<PageSection>
<Connect(GraphCard)
cardTitle="t(curiosity-graph.socketsHeading)"
cardTitle="t(curiosity-graph.cardHeading)"
filterGraphData={
Array [
Object {
Expand Down Expand Up @@ -41,7 +41,7 @@ exports[`RhelView Component should render a non-connected component: non-connect
</PageHeader>
<PageSection>
<Connect(GraphCard)
cardTitle="t(curiosity-graph.socketsHeading)"
cardTitle="t(curiosity-graph.cardHeading)"
filterGraphData={
Array [
Object {
Expand Down
16 changes: 9 additions & 7 deletions src/components/rhelView/rhelView.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RhelView extends React.Component {
componentDidMount() {}

render() {
const { routeDetail, t } = this.props;
const { initialFilters, routeDetail, t } = this.props;

return (
<PageLayout>
Expand All @@ -25,14 +25,10 @@ class RhelView extends React.Component {
<PageSection>
<GraphCard
key={routeDetail.pathParameter}
filterGraphData={[
{ id: 'physicalSockets', fill: chartColorBlueLight.value, stroke: chartColorBlueDark.value },
{ id: 'hypervisorSockets', fill: chartColorCyanLight.value, stroke: chartColorCyanDark.value },
{ id: 'thresholdSockets' }
]}
filterGraphData={initialFilters}
productId={routeDetail.pathParameter}
viewId={routeDetail.pathId}
cardTitle={t('curiosity-graph.socketsHeading')}
cardTitle={t('curiosity-graph.cardHeading')}
productShortLabel="RHEL"
/>
</PageSection>
Expand All @@ -42,6 +38,7 @@ class RhelView extends React.Component {
}

RhelView.propTypes = {
initialFilters: PropTypes.array,
routeDetail: PropTypes.shape({
pathParameter: PropTypes.string.isRequired,
pathId: PropTypes.string.isRequired,
Expand All @@ -53,6 +50,11 @@ RhelView.propTypes = {
};

RhelView.defaultProps = {
initialFilters: [
{ id: 'physicalSockets', fill: chartColorBlueLight.value, stroke: chartColorBlueDark.value },
{ id: 'hypervisorSockets', fill: chartColorCyanLight.value, stroke: chartColorCyanDark.value },
{ id: 'thresholdSockets' }
],
t: helpers.noopTranslate
};

Expand Down