Skip to content

Commit 4650df1

Browse files
committed
Add cost model links to cluster info
https://issues.redhat.com/browse/COST-4925
1 parent fb6b518 commit 4650df1

File tree

6 files changed

+41
-14
lines changed

6 files changed

+41
-14
lines changed

locales/data.json

+6
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,12 @@
11561156
"value": "Cost Management"
11571157
}
11581158
],
1159+
"costModel": [
1160+
{
1161+
"type": 0,
1162+
"value": "Cost Model:"
1163+
}
1164+
],
11591165
"costModels": [
11601166
{
11611167
"type": 0,

locales/translations.json

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"costDistributionTitle": "Overhead cost breakdown",
8282
"costDistributionType": "{value, select, distributed {Distribute through cost models} total {Don't distribute overhead costs} other {}}",
8383
"costManagement": "Cost Management",
84+
"costModel": "Cost Model:",
8485
"costModels": "Cost Models",
8586
"costModelsActions": "Cost model actions",
8687
"costModelsAddTagValues": "Add more tag values",

src/locales/messages.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@ export default defineMessages({
461461
description: 'Cost Management',
462462
id: 'costManagement',
463463
},
464+
costModel: {
465+
defaultMessage: 'Cost Model:',
466+
description: 'Cost Model:',
467+
id: 'costModel',
468+
},
464469
costModels: {
465470
defaultMessage: 'Cost Models',
466471
description: 'Cost Models',
@@ -1030,13 +1035,11 @@ export default defineMessages({
10301035
description: 'Currency and calculations',
10311036
id: 'currencyCalcuationsTitle',
10321037
},
1033-
10341038
currencyDesc: {
10351039
defaultMessage: 'Select the preferred currency view for your organization',
10361040
description: 'Select the preferred currency view for your organization',
10371041
id: 'currencyDesc',
10381042
},
1039-
10401043
// See https://www.localeplanet.com/icu/currency.html
10411044
currencyOptions: {
10421045
defaultMessage:

src/routes/details/ocpBreakdown/providerDetails/clusterInfo/clusterInfoContent.tsx

+12-5
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ const ClusterInfoContent: React.FC<ClusterInfoContentProps> = ({ clusterId }: Cl
6767
<span style={styles.spacingRight}>{clusterId}</span>
6868
<a href={`${release}/openshift/details/${clusterId}`}>{intl.formatMessage(messages.ocpClusterDetails)}</a>
6969
</TextListItem>
70-
{clusterProvider?.cost_models?.length === 0 && (
71-
<TextListItem>
72-
<a href={formatPath(routes.settings.path)}>{intl.formatMessage(messages.assignCostModel)}</a>
73-
</TextListItem>
74-
)}
7570
</TextList>
7671
<Text component={TextVariants.h3}>{intl.formatMessage(messages.metricsOperatorVersion)}</Text>
7772
<TextList isPlain>
@@ -95,6 +90,18 @@ const ClusterInfoContent: React.FC<ClusterInfoContentProps> = ({ clusterId }: Cl
9590
<span style={styles.spacingRight}>{intl.formatMessage(messages.source, { value: 'ocp' })}</span>
9691
<a href={`${release}/settings/integrations/detail/${clusterProvider.id}`}>{clusterProvider.name}</a>
9792
</TextListItem>
93+
<TextListItem>
94+
{clusterProvider?.cost_models?.length ? (
95+
clusterProvider.cost_models.map(cm => (
96+
<>
97+
<span style={styles.spacingRight}>{intl.formatMessage(messages.costModel)}</span>
98+
<a href={`${formatPath(routes.costModel.basePath, true)}/${cm.uuid}`}>{cm.name}</a>
99+
</>
100+
))
101+
) : (
102+
<a href={formatPath(routes.settings.path, true)}>{intl.formatMessage(messages.assignCostModel)}</a>
103+
)}
104+
</TextListItem>
98105
</TextList>
99106
{cloudProvider && <CloudIntegration provider={cloudProvider} />}
100107
</>

src/routes/details/ocpBreakdown/providerDetails/clusterInfo/components/cloudIntegration.tsx

+14-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { routes } from 'routes';
77
import { SourceLink } from 'routes/details/ocpBreakdown/providerDetails/components/sourceLink';
88
import { formatPath } from 'utils/paths';
99

10+
import { styles } from '../clusterInfo.styles';
11+
1012
interface CloudIntegrationOwnProps {
1113
provider: Provider;
1214
}
@@ -27,11 +29,18 @@ const CloudIntegration: React.FC<CloudIntegrationProps> = ({ provider }: CloudIn
2729
<TextListItem>
2830
<SourceLink provider={provider} />
2931
</TextListItem>
30-
{provider?.cost_models?.length === 0 && (
31-
<TextListItem>
32-
<a href={formatPath(routes.settings.path)}>{intl.formatMessage(messages.assignCostModel)}</a>
33-
</TextListItem>
34-
)}
32+
<TextListItem>
33+
{provider?.cost_models?.length ? (
34+
provider.cost_models.map(cm => (
35+
<>
36+
<span style={styles.spacingRight}>{intl.formatMessage(messages.costModel)}</span>
37+
<a href={`${formatPath(routes.costModel.basePath, true)}/${cm.uuid}`}>{cm.name}</a>
38+
</>
39+
))
40+
) : (
41+
<a href={formatPath(routes.settings.path, true)}>{intl.formatMessage(messages.assignCostModel)}</a>
42+
)}
43+
</TextListItem>
3544
</TextList>
3645
</>
3746
);

src/utils/paths.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { routes } from 'routes';
55
//
66
// Note the basename does not include a release prefix (/beta, /preview, etc.), unlike the getBaseName function from
77
// @redhat-cloud-services/frontend-components-utilities/helpers
8-
export const formatPath = path => {
8+
export const formatPath = (path, isReleasePath = false) => {
99
const basename = '/openshift/cost-management';
10-
return path === routes.overview.path ? basename : `${basename}${path}`;
10+
const newPath = path === routes.overview.path ? basename : `${basename}${path}`;
11+
return isReleasePath ? `${getReleasePath()}${newPath}` : newPath;
1112
};
1213

1314
export const getReleasePath = () => {

0 commit comments

Comments
 (0)