Skip to content

Commit 24ff798

Browse files
authoredJul 18, 2024
Merge pull request #3929 from dlabrecq/project-link
Add project link to optimizations breakdown page
2 parents 82fe69a + 1e87fd3 commit 24ff798

File tree

13 files changed

+35
-40
lines changed

13 files changed

+35
-40
lines changed
 

‎src/routes/details/awsBreakdown/awsBreakdown.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ const mapStateToProps = createMapStateToProps<AwsBreakdownOwnProps, BreakdownSta
109109
const title = queryFromRoute[breakdownTitleKey] ? queryFromRoute[breakdownTitleKey] : groupByValue;
110110

111111
return {
112+
breadcrumbPath: formatPath(routes.awsDetails.path),
112113
costOverviewComponent: (
113114
<CostOverview costType={costType} currency={currency} groupBy={groupBy} query={queryFromRoute} report={report} />
114115
),
115116
costType,
116117
currency,
117-
defaultBreadcrumbPath: formatPath(routes.awsDetails.path),
118118
description: queryFromRoute[breakdownDescKey],
119119
detailsURL,
120120
emptyStateTitle: intl.formatMessage(messages.awsDetailsTitle),

‎src/routes/details/azureBreakdown/azureBreakdown.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ const mapStateToProps = createMapStateToProps<AzureOwnProps, BreakdownStateProps
8989
const title = queryFromRoute[breakdownTitleKey] ? queryFromRoute[breakdownTitleKey] : groupByValue;
9090

9191
return {
92+
breadcrumbPath: formatPath(routes.azureDetails.path),
9293
costOverviewComponent: <CostOverview currency={currency} groupBy={groupBy} report={report} />,
9394
currency,
94-
defaultBreadcrumbPath: formatPath(routes.azureDetails.path),
9595
description: queryFromRoute[breakdownDescKey],
9696
detailsURL,
9797
emptyStateTitle: intl.formatMessage(messages.azureDetailsTitle),

‎src/routes/details/components/breakdown/breakdownBase.tsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ interface BreakdownOwnProps extends RouterComponentProps {
5555
}
5656

5757
export interface BreakdownStateProps {
58+
breadcrumbLabel?: string;
59+
breadcrumbPath?: string; // Default breadcrumb path
5860
clusterInfoComponent?: React.ReactNode;
5961
costDistribution?: string;
6062
costOverviewComponent?: React.ReactNode;
6163
costType?: string;
6264
currency?: string;
6365
dataDetailsComponent?: React.ReactNode;
64-
defaultBreadcrumbPath?: string;
6566
description?: string;
6667
detailsURL?: string;
6768
emptyStateTitle?: string;
@@ -280,12 +281,13 @@ class BreakdownBase extends React.Component<BreakdownProps, BreakdownState> {
280281

281282
public render() {
282283
const {
284+
breadcrumbLabel,
285+
breadcrumbPath,
283286
clusterInfoComponent,
284287
costDistribution,
285288
costType,
286289
currency,
287290
dataDetailsComponent,
288-
defaultBreadcrumbPath,
289291
description,
290292
detailsURL,
291293
emptyStateTitle,
@@ -327,10 +329,11 @@ class BreakdownBase extends React.Component<BreakdownProps, BreakdownState> {
327329
return (
328330
<>
329331
<BreakdownHeader
330-
breadcrumb={
331-
router.location.state && router.location.state.details
332+
breadcrumbLabel={breadcrumbLabel}
333+
breadcrumbPath={
334+
router?.location?.state?.details?.breadcrumbPath
332335
? router.location.state.details.breadcrumbPath
333-
: defaultBreadcrumbPath
336+
: breadcrumbPath
334337
}
335338
clusterInfoComponent={clusterInfoComponent}
336339
dataDetailsComponent={dataDetailsComponent}

‎src/routes/details/components/breakdown/breakdownHeader.tsx

+11-8
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ import { withRouter } from 'utils/router';
3939
import { styles } from './breakdownHeader.styles';
4040

4141
interface BreakdownHeaderOwnProps extends RouterComponentProps {
42-
breadcrumb?: string;
42+
breadcrumbLabel?: string;
43+
breadcrumbPath?: string;
4344
clusterInfoComponent?: React.ReactNode;
4445
costDistribution?: string;
4546
costType?: string;
@@ -80,17 +81,19 @@ class BreakdownHeader extends React.Component<BreakdownHeaderProps, any> {
8081
public state: BreakdownHeaderState = { ...this.defaultState };
8182

8283
private getBackToLink = groupByKey => {
83-
const { breadcrumb, intl, router, tagPathsType } = this.props;
84+
const { breadcrumbLabel, breadcrumbPath, intl, router, tagPathsType } = this.props;
8485

85-
if (!breadcrumb) {
86+
if (!breadcrumbPath) {
8687
return null;
8788
}
8889
return (
89-
<Link to={breadcrumb} state={{ ...router.location.state }}>
90-
{intl.formatMessage(messages.breakdownBackToDetails, {
91-
value: intl.formatMessage(messages.breakdownBackToTitles, { value: tagPathsType }),
92-
groupBy: groupByKey,
93-
})}
90+
<Link to={breadcrumbPath} state={{ ...router.location.state }}>
91+
{breadcrumbLabel
92+
? breadcrumbLabel
93+
: intl.formatMessage(messages.breakdownBackToDetails, {
94+
value: intl.formatMessage(messages.breakdownBackToTitles, { value: tagPathsType }),
95+
groupBy: groupByKey,
96+
})}
9497
</Link>
9598
);
9699
};

‎src/routes/details/gcpBreakdown/gcpBreakdown.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ const mapStateToProps = createMapStateToProps<GcpBreakdownOwnProps, BreakdownSta
8787
);
8888

8989
return {
90+
breadcrumbPath: formatPath(routes.gcpDetails.path),
9091
costOverviewComponent: <CostOverview currency={currency} groupBy={groupBy} report={report} />,
9192
currency,
92-
defaultBreadcrumbPath: formatPath(routes.gcpDetails.path),
9393
description: queryFromRoute[breakdownDescKey],
9494
detailsURL,
9595
emptyStateTitle: intl.formatMessage(messages.gcpDetailsTitle),

‎src/routes/details/ibmBreakdown/ibmBreakdown.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ const mapStateToProps = createMapStateToProps<IbmBreakdownOwnProps, BreakdownSta
8787
);
8888

8989
return {
90+
breadcrumbPath: formatPath(routes.ibmDetails.path),
9091
costOverviewComponent: <CostOverview currency={currency} groupBy={groupBy} report={report} />,
9192
currency,
92-
defaultBreadcrumbPath: formatPath(routes.ibmDetails.path),
9393
description: queryFromRoute[breakdownDescKey],
9494
detailsURL,
9595
emptyStateTitle: intl.formatMessage(messages.ibmDetailsTitle),

‎src/routes/details/ociBreakdown/ociBreakdown.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ const mapStateToProps = createMapStateToProps<OciOwnProps, BreakdownStateProps>(
8787
);
8888

8989
return {
90+
breadcrumbPath: formatPath(routes.ociDetails.path),
9091
costOverviewComponent: <CostOverview currency={currency} groupBy={groupBy} report={report} />,
9192
currency,
92-
defaultBreadcrumbPath: formatPath(routes.ociDetails.path),
9393
description: queryFromRoute[breakdownDescKey],
9494
detailsURL,
9595
emptyStateTitle: intl.formatMessage(messages.ociDetailsTitle),

‎src/routes/details/ocpBreakdown/ocpBreakdown.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { providersQuery, providersSelectors } from 'store/providers';
2323
import { reportActions, reportSelectors } from 'store/reports';
2424
import { uiActions } from 'store/ui';
2525
import { formatPath } from 'utils/paths';
26-
import { breakdownDescKey, breakdownTitleKey, platformCategoryKey } from 'utils/props';
26+
import { breadcrumbLabelKey, breakdownDescKey, breakdownTitleKey, platformCategoryKey } from 'utils/props';
2727
import type { RouterComponentProps } from 'utils/router';
2828
import { withRouter } from 'utils/router';
2929
import { getCostDistribution, getCurrency } from 'utils/sessionStorage';
@@ -94,9 +94,11 @@ const mapStateToProps = createMapStateToProps<OcpBreakdownOwnProps, BreakdownSta
9494
providersQueryString
9595
);
9696

97+
const breadcrumbLabel = queryFromRoute[breadcrumbLabelKey] ? queryFromRoute[breadcrumbLabelKey] : undefined;
9798
const title = queryFromRoute[breakdownTitleKey] ? queryFromRoute[breakdownTitleKey] : groupByValue;
9899

99100
return {
101+
breadcrumbLabel,
100102
clusterInfoComponent: groupBy === 'cluster' ? <ClusterInfo clusterId={groupByValue} /> : undefined,
101103
dataDetailsComponent: groupBy === 'cluster' ? <DataDetails clusterId={groupByValue} /> : undefined,
102104
costDistribution,
@@ -111,7 +113,6 @@ const mapStateToProps = createMapStateToProps<OcpBreakdownOwnProps, BreakdownSta
111113
/>
112114
),
113115
currency,
114-
defaultBreadcrumbPath: formatPath(routes.ocpDetails.path),
115116
description: queryFromRoute[breakdownDescKey],
116117
detailsURL,
117118
emptyStateTitle: intl.formatMessage(messages.ocpDetailsTitle),

‎src/routes/details/ocpBreakdown/optimizations.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const Optimizations: React.FC<OptimizationsProps> = () => {
2424
const groupByValue = getGroupByValue(queryFromRoute);
2525
const otimizationsTab = location.search.indexOf('optimizationsTab') === -1 ? '&optimizationsTab=true' : '';
2626

27-
const clusterFilter = queryState?.filter_by?.cluster ? queryState.filter_by.cluster : undefined;
27+
const clusterFilter = queryState?.filter_by?.cluster;
28+
const isOptimizationsPath = queryFromRoute?.optimizationsPath === 'true';
2829

2930
return (
3031
<AsyncComponent
@@ -36,6 +37,7 @@ const Optimizations: React.FC<OptimizationsProps> = () => {
3637
cluster={clusterFilter}
3738
hideCluster={clusterFilter !== undefined}
3839
hideProject={groupBy === 'project'}
40+
isOptimizationsPath={isOptimizationsPath}
3941
linkPath={formatPath(routes.optimizationsBreakdown.path)}
4042
linkState={{
4143
...(location.state && location.state),

‎src/routes/details/rhelBreakdown/rhelBreakdown.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ const mapStateToProps = createMapStateToProps<RhelBreakdownOwnProps, BreakdownSt
8989
const title = queryFromRoute[breakdownTitleKey] ? queryFromRoute[breakdownTitleKey] : groupByValue;
9090

9191
return {
92+
breadcrumbPath: formatPath(routes.rhelDetails.path),
9293
costOverviewComponent: <CostOverview currency={currency} groupBy={groupBy} report={report} title={title} />,
9394
currency,
94-
defaultBreadcrumbPath: formatPath(routes.rhelDetails.path),
9595
description: queryFromRoute[breakdownDescKey],
9696
detailsURL,
9797
emptyStateTitle: intl.formatMessage(messages.rhelDetailsTitle),

‎src/routes/optimizations/optimizationsBreakdown/optimizationsBreakdown.tsx

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import AsyncComponent from '@redhat-cloud-services/frontend-components/AsyncComponent';
2-
import messages from 'locales/messages';
32
import React from 'react';
4-
import { useIntl } from 'react-intl';
5-
import { routes } from 'routes';
6-
import { useQueryFromRoute } from 'utils/hooks';
7-
import { formatPath } from 'utils/paths';
83

94
import { styles } from './optimizationsBreakdown.styles';
105

@@ -15,19 +10,9 @@ interface OptimizationsBreakdownOwnProps {
1510
type OptimizationsBreakdownProps = OptimizationsBreakdownOwnProps;
1611

1712
const OptimizationsBreakdown: React.FC<OptimizationsBreakdownProps> = () => {
18-
const intl = useIntl();
19-
const queryFromRoute = useQueryFromRoute();
20-
2113
return (
2214
<div style={styles.container}>
23-
<AsyncComponent
24-
scope="costManagementMfe"
25-
appName="cost-management-mfe"
26-
module="./MfeOptimizationsBreakdown"
27-
breadcrumbLabel={intl.formatMessage(messages.breakdownBackToOptimizations)}
28-
breadcrumbPath={formatPath(routes.optimizationsDetails.path)}
29-
id={queryFromRoute ? queryFromRoute.id : ''}
30-
/>
15+
<AsyncComponent scope="costManagementMfe" appName="cost-management-mfe" module="./MfeOptimizationsBreakdown" />
3116
</div>
3217
);
3318
};

‎src/routes/optimizations/optimizationsDetails/optimizationsDetails.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const OptimizationsDetails: React.FC<OptimizationsDetailsProps> = () => {
3030
linkState={{
3131
...(location.state && location.state),
3232
}}
33+
projectPath={formatPath(routes.ocpBreakdown.path)}
3334
/>
3435
</div>
3536
);

‎src/routes/utils/queryState.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import type * as H from 'history';
22
import { cloneDeep } from 'lodash';
33

44
export function clearQueryState(location: H.Location, key: string) {
5-
if (location?.state && location.state[key]) {
5+
if (location?.state?.[key]) {
66
location.state[key] = undefined;
77
}
88
}
99

1010
export function getQueryState(location: H.Location, key: string) {
11-
return location?.state && location.state[key] ? cloneDeep(location.state[key]) : undefined;
11+
return location?.state?.[key] ? cloneDeep(location.state[key]) : undefined;
1212
}

0 commit comments

Comments
 (0)
Failed to load comments.