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

fix(graphCardHelpers): sw-235 generateChartId threshold #1001

Merged
merged 1 commit into from
Nov 17, 2022
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
6 changes: 6 additions & 0 deletions public/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
"label_Storage-gibibyte-months": "Data storage",
"label_threshold": "Subscription threshold",
"label_threshold_infinite": "<0>unlimited</0>",
"label_thresholdCores": "Subscription threshold",
"label_thresholdSockets": "Subscription threshold",
"label_Transfer-gibibytes": "Data transfer",
"legendTooltip": "{{product}} metric usage",
"legendTooltip_cores": "{{product}} CPU usage, per CPU core.",
Expand All @@ -113,6 +115,10 @@
"legendTooltip_sockets": "{{product}} CPU usage, per CPU socket pair.",
"legendTooltip_Storage-gibibytes": "Data storage usage",
"legendTooltip_Storage-gibibyte-months": "Data storage usage",
"legendTooltip_thresholdSockets": "Maximum capacity, based on total {{product}} subscriptions in this account.",
"legendTooltip_thresholdSockets_RHEL": "Maximum capacity, as CPU sockets, based on total {{product}} subscriptions in this account.",
"legendTooltip_thresholdCores_OpenShift Container Platform": "Maximum capacity, as CPU cores, based on total {{product}} Annual subscriptions in this account.",
"legendTooltip_thresholdSockets_OpenShift Container Platform": "Maximum capacity, as CPU sockets, based on total {{product}} Annual subscriptions in this account.",
"legendTooltip_threshold_thresholdSockets": "Maximum capacity, based on total {{product}} subscriptions in this account.",
"legendTooltip_threshold_thresholdSockets_RHEL": "Maximum capacity, as CPU sockets, based on total {{product}} subscriptions in this account.",
"legendTooltip_threshold_thresholdCores_OpenShift Container Platform": "Maximum capacity, as CPU cores, based on total {{product}} Annual subscriptions in this account.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ exports[`GraphCardChartLegend Component should handle variations in data when re
}
distance={5}
enableFlip={true}
key="curiosity-tooltip-dolorSit_mock-product-id"
key="curiosity-tooltip-threshold_dolorSit_mock-product-id"
position="top"
>
<Button
Expand All @@ -91,13 +91,13 @@ exports[`GraphCardChartLegend Component should handle variations in data when re
/>
}
isDisabled={false}
key="curiosity-button-dolorSit_mock-product-id"
key="curiosity-button-threshold_dolorSit_mock-product-id"
onClick={[Function]}
onKeyPress={[Function]}
tabIndex={0}
variant="link"
>
t([curiosity-graph.label,curiosity-graph.label_no], {"product":"mock-product-label","context":"threshold"})
t([curiosity-graph.label_threshold_dolorSit,curiosity-graph.label_no], {"product":"mock-product-label","context":"mock-product-id"})
</Button>
</Tooltip>
</Fragment>
Expand Down Expand Up @@ -224,7 +224,7 @@ exports[`GraphCardChartLegend Component should render basic data: data 1`] = `
}
distance={5}
enableFlip={true}
key="curiosity-tooltip-dolorSit_mock-product-id"
key="curiosity-tooltip-threshold_dolorSit_mock-product-id"
position="top"
>
<Button
Expand All @@ -244,13 +244,13 @@ exports[`GraphCardChartLegend Component should render basic data: data 1`] = `
/>
}
isDisabled={false}
key="curiosity-button-dolorSit_mock-product-id"
key="curiosity-button-threshold_dolorSit_mock-product-id"
onClick={[Function]}
onKeyPress={[Function]}
tabIndex={0}
variant="link"
>
t([curiosity-graph.label,curiosity-graph.label_no], {"product":"mock-product-label","context":"threshold"})
t([curiosity-graph.label_threshold_dolorSit,curiosity-graph.label_no], {"product":"mock-product-label","context":"mock-product-id"})
</Button>
</Tooltip>
<Tooltip
Expand All @@ -261,7 +261,7 @@ exports[`GraphCardChartLegend Component should render basic data: data 1`] = `
}
distance={5}
enableFlip={true}
key="curiosity-tooltip-nonCursus_mock-product-id"
key="curiosity-tooltip-threshold_nonCursus_mock-product-id"
position="top"
>
<Button
Expand All @@ -281,13 +281,13 @@ exports[`GraphCardChartLegend Component should render basic data: data 1`] = `
/>
}
isDisabled={false}
key="curiosity-button-nonCursus_mock-product-id"
key="curiosity-button-threshold_nonCursus_mock-product-id"
onClick={[Function]}
onKeyPress={[Function]}
tabIndex={0}
variant="link"
>
t([curiosity-graph.label,curiosity-graph.label_no], {"product":"mock-product-label","context":"threshold"})
t([curiosity-graph.label_threshold_nonCursus,curiosity-graph.label_no], {"product":"mock-product-label","context":"mock-product-id"})
</Button>
</Tooltip>
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports[`GraphCardHelpers generateChartIds should return consistent IDs: base id

exports[`GraphCardHelpers generateChartIds should return consistent IDs: category id 1`] = `"lorem_dolor-sir_ipsum"`;

exports[`GraphCardHelpers generateChartIds should return consistent IDs: threshold, capacity id 1`] = `"threshold_lorem_ipsum"`;

exports[`GraphCardHelpers generateChartSettings should return base graph settings: basic filters 1`] = `
{
"groupedFiltersSettings": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ describe('GraphCardChartLegend Component', () => {
},
{
stroke: '#ff0000',
id: 'dolorSit_mock-product-id',
id: 'threshold_dolorSit_mock-product-id',
metric: 'dolorSit',
isThreshold: true,
data: [{ y: 0, isInfinite: false }]
},
{
stroke: '#ff0000',
id: 'nonCursus_mock-product-id',
id: 'threshold_nonCursus_mock-product-id',
metric: 'nonCursus',
isThreshold: true,
data: [{ y: 0, isInfinite: true }]
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('GraphCardChartLegend Component', () => {
},
{
stroke: '#ff0000',
id: 'dolorSit_mock-product-id',
id: 'threshold_dolorSit_mock-product-id',
metric: 'dolorSit',
isThreshold: true,
data: [{ y: 0, isInfinite: false }]
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('GraphCardChartLegend Component', () => {
},
{
stroke: '#ff0000',
id: 'dolorSit_mock-product-id',
id: 'threshold_dolorSit_mock-product-id',
metric: 'dolorSit',
isThreshold: true,
data: [{ y: 0, isInfinite: false }]
Expand Down
4 changes: 4 additions & 0 deletions src/components/graphCard/__tests__/graphCardHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ describe('GraphCardHelpers', () => {
it('generateChartIds should return consistent IDs', () => {
expect(generateChartIds({ metric: 'lorem', productId: 'ipsum' })).toMatchSnapshot('base id');

expect(generateChartIds({ isCapacity: true, metric: 'lorem', productId: 'ipsum' })).toMatchSnapshot(
'threshold, capacity id'
);

expect(
generateChartIds({
metric: 'lorem',
Expand Down
9 changes: 5 additions & 4 deletions src/components/graphCard/graphCardChartLegend.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ const GraphCardChartLegend = ({

const labelContent = t([`curiosity-graph.label`, 'curiosity-graph.label_no'], {
product: productLabel,
context: (isThreshold && 'threshold') || id
context: id
});

const tooltipContent = t(
`curiosity-graph.legendTooltip`,
{
product: productLabel,
context: [isThreshold && 'threshold', id]
context: id
},
[<span style={{ whiteSpace: 'nowrap' }} />]
);
Expand Down Expand Up @@ -145,9 +145,10 @@ GraphCardChartLegend.propTypes = {
datum: PropTypes.shape({
dataSets: PropTypes.arrayOf(
PropTypes.shape({
stroke: PropTypes.string.isRequired,
data: PropTypes.array,
id: PropTypes.string.isRequired,
isThreshold: PropTypes.bool
isThreshold: PropTypes.bool,
stroke: PropTypes.string.isRequired
})
)
}),
Expand Down
9 changes: 6 additions & 3 deletions src/components/graphCard/graphCardHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import { dateHelpers, helpers } from '../../common';
* Generate a consistent chart identifier from API.
*
* @param {object} params
* @param {boolean} params.isCapacity
* @param {string} params.metric
* @param {string} params.productId
* @param {object} params.query
* @returns {string}
*/
const generateChartIds = ({ metric, productId, query = {} } = {}) => {
const generateChartIds = ({ isCapacity, metric, productId, query = {} } = {}) => {
const metricCategory = query?.[RHSM_API_QUERY_SET_TYPES.CATEGORY] || undefined;
return `${metric}${(metricCategory && `_${metricCategory}`) || ''}${(productId && `_${productId}`) || ''}`;
return `${(isCapacity && 'threshold_') || ''}${metric}${(metricCategory && `_${metricCategory}`) || ''}${
(productId && `_${productId}`) || ''
}`;
};

/**
Expand All @@ -41,7 +44,7 @@ const generateChartSettings = ({ filters = [], settings: graphCardSettings = {},

const isThreshold = filterSettings?.chartType === ChartTypeVariant.threshold;
const baseFilterSettings = {
id: generateChartIds({ metric, productId, query: filterSettings?.query }),
id: generateChartIds({ isCapacity: isThreshold, metric, productId, query: filterSettings?.query }),
isStacked: !isThreshold,
isStandalone,
isThreshold,
Expand Down
4 changes: 2 additions & 2 deletions src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ exports[`I18n Component should generate a predictable locale key output snapshot
"keys": [
{
"key": "curiosity-graph.label",
"match": "t([\`curiosity-graph.label\`, 'curiosity-graph.label_no'], { product: productLabel, context: (isThreshold && 'threshold')",
"match": "t([\`curiosity-graph.label\`, 'curiosity-graph.label_no'], { product: productLabel, context: id })",
},
{
"key": "curiosity-graph.legendTooltip",
"match": "t( \`curiosity-graph.legendTooltip\`, { product: productLabel, context: [isThreshold && 'threshold', id] }, [<span style={{ whiteSpace: 'nowrap' }} />] )",
"match": "t( \`curiosity-graph.legendTooltip\`, { product: productLabel, context: id }, [<span style={{ whiteSpace: 'nowrap' }} />] )",
},
],
},
Expand Down
4 changes: 2 additions & 2 deletions src/redux/actions/__tests__/rhsmActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ describe('RhsmActions', () => {
expect(response.tally.sit_dolor.fulfilled).toBe(true);
expect(Object.entries(response.tally).length).toBe(2);

expect(response.capacity.ipsum_lorem.fulfilled).toBe(true);
expect(response.capacity.sit_dolor.fulfilled).toBe(true);
expect(response.capacity.threshold_ipsum_lorem.fulfilled).toBe(true);
expect(response.capacity.threshold_sit_dolor.fulfilled).toBe(true);
expect(Object.entries(response.capacity).length).toBe(2);
done();
});
Expand Down
2 changes: 1 addition & 1 deletion src/redux/actions/rhsmActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const getGraphMetrics =
const methodService = isCapacity ? rhsmServices.getGraphCapacity : rhsmServices.getGraphTally;
const methodType = isCapacity ? rhsmTypes.GET_GRAPH_CAPACITY_RHSM : rhsmTypes.GET_GRAPH_TALLY_RHSM;
const methodCancelId = isCapacity ? 'graphCapacity' : cancelId;
const generatedId = generateChartIds({ metric, productId: id, query: metricQuery });
const generatedId = generateChartIds({ isCapacity, metric, productId: id, query: metricQuery });

multiDispatch.push({
type: methodType,
Expand Down