Skip to content

Commit 10bf572

Browse files
committed
Optimizations requires Axios to be a shared federated module
https://issues.redhat.com/browse/COST-4890
1 parent 392605b commit 10bf572

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+207
-201
lines changed

fec.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ module.exports = {
5959
* Package can be re-enabled for sharing once chrome starts providing global routing package to all applications
6060
*/
6161
// exclude: ['react-router-dom'],
62-
exclude: ['axios'], // Setting the base URL affects Cost Management APIs in OCM, when navigating between apps
6362
exposes: {
6463
'./RootApp': path.resolve(__dirname, './src/appEntry.tsx'),
6564
},

src/api/accountSettings.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios from 'axios';
1+
import { axiosInstance } from 'api';
22

33
import type { PagedLinks, PagedMetaData } from './api';
44

@@ -38,10 +38,10 @@ export const AccountSettingsTypePaths: Partial<Record<AccountSettingsType, strin
3838

3939
export function fetchAccountSettings(settingsType: AccountSettingsType) {
4040
const path = AccountSettingsTypePaths[settingsType];
41-
return axios.get<AccountSettings>(`${path}`);
41+
return axiosInstance.get<AccountSettings>(`${path}`);
4242
}
4343

4444
export function updateAccountSettings(settingsType: AccountSettingsType, payload: AccountSettingsPayload) {
4545
const path = AccountSettingsTypePaths[settingsType];
46-
return axios.put(`${path}`, payload);
46+
return axiosInstance.put(`${path}`, payload);
4747
}

src/api/api.ts

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AxiosRequestConfig } from 'axios';
1+
import type { AxiosInstance, AxiosRequestConfig } from 'axios';
22
import axios from 'axios';
33

44
export interface PagedMetaData {
@@ -18,10 +18,10 @@ export interface PagedResponse<D = any, M = any> {
1818
data: D[];
1919
}
2020

21-
export function initApi({ version }: { version: string }) {
22-
axios.defaults.baseURL = `/api/cost-management/${version}/`;
23-
axios.interceptors.request.use(authInterceptor);
24-
}
21+
// export function initApi({ version }: { version: string }) {
22+
// axios.defaults.baseURL = `/api/cost-management/${version}/`;
23+
// axios.interceptors.request.use(authInterceptor);
24+
// }
2525

2626
export function authInterceptor(reqConfig: AxiosRequestConfig) {
2727
return {
@@ -31,3 +31,16 @@ export function authInterceptor(reqConfig: AxiosRequestConfig) {
3131
} as any,
3232
};
3333
}
34+
35+
// Create an instance instead of setting global defaults
36+
// Setting global values affects Cost Management APIs in OCM and HCS, when navigating between apps
37+
//
38+
// See https://issues.redhat.com/browse/RHCLOUD-25573
39+
const axiosInstance: AxiosInstance = axios.create({
40+
baseURL: '/api/cost-management/v1/',
41+
headers: { 'X-Custom-Header': 'foobar' },
42+
});
43+
44+
axiosInstance.interceptors.request.use(authInterceptor);
45+
46+
export default axiosInstance;

src/api/costModels.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import axios from 'axios';
1+
import { axiosInstance } from 'api';
22

33
import type { CostModelRequest } from './costModels';
44
import { addCostModel, deleteCostModel, fetchCostModels, updateCostModel } from './costModels';
55

66
test('api get cost models calls axios to costmodels', () => {
77
fetchCostModels();
8-
expect(axios.get).toBeCalledWith('cost-models/');
8+
expect(axiosInstance.get).toBeCalledWith('cost-models/');
99
});
1010

1111
test('api get cost models calls axios to costmodels with query', () => {
1212
const query = 'limit=20&offset=10';
1313
fetchCostModels(query);
14-
expect(axios.get).toBeCalledWith(`cost-models/?${query}`);
14+
expect(axiosInstance.get).toBeCalledWith(`cost-models/?${query}`);
1515
});
1616

1717
test('add cost model calls axios post', () => {
@@ -33,7 +33,7 @@ test('add cost model calls axios post', () => {
3333
],
3434
};
3535
addCostModel(request);
36-
expect(axios.post).toBeCalledWith('cost-models/', request);
36+
expect(axiosInstance.post).toBeCalledWith('cost-models/', request);
3737
});
3838

3939
test('update cost model calls axios put', () => {
@@ -55,10 +55,10 @@ test('update cost model calls axios put', () => {
5555
],
5656
};
5757
updateCostModel('123abc456def', request);
58-
expect(axios.put).toBeCalledWith('cost-models/123abc456def/', request);
58+
expect(axiosInstance.put).toBeCalledWith('cost-models/123abc456def/', request);
5959
});
6060

6161
test('delete cost model calls axios delete', () => {
6262
deleteCostModel('123abc456def');
63-
expect(axios.delete).toBeCalledWith('cost-models/123abc456def/');
63+
expect(axiosInstance.delete).toBeCalledWith('cost-models/123abc456def/');
6464
});

src/api/costModels.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios from 'axios';
1+
import { axiosInstance } from 'api';
22

33
import type { PagedResponse } from './api';
44
import type { Rate, RateRequest } from './rates';
@@ -45,21 +45,21 @@ export interface CostModelRequest {
4545
export type CostModels = PagedResponse<CostModel>;
4646

4747
export function fetchCostModels(query = '') {
48-
return axios.get<CostModels>(`cost-models/${query && '?'}${query}`);
48+
return axiosInstance.get<CostModels>(`cost-models/${query && '?'}${query}`);
4949
}
5050

5151
export function fetchCostModel(uuid: string) {
52-
return axios.get<CostModels>(`cost-models/${uuid}/`);
52+
return axiosInstance.get<CostModels>(`cost-models/${uuid}/`);
5353
}
5454

5555
export function addCostModel(request: CostModelRequest) {
56-
return axios.post(`cost-models/`, request);
56+
return axiosInstance.post(`cost-models/`, request);
5757
}
5858

5959
export function updateCostModel(uuid: string, request: CostModelRequest) {
60-
return axios.put(`cost-models/${uuid}/`, request);
60+
return axiosInstance.put(`cost-models/${uuid}/`, request);
6161
}
6262

6363
export function deleteCostModel(uuid: string) {
64-
return axios.delete(`cost-models/${uuid}/`);
64+
return axiosInstance.delete(`cost-models/${uuid}/`);
6565
}

src/api/export/awsExport.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { axiosInstance } from 'api';
12
import { ReportTypePaths } from 'api/reports/awsReports';
23
import type { ReportType } from 'api/reports/report';
3-
import axios from 'axios';
44

55
export function runExport(reportType: ReportType, query: string) {
66
const path = ReportTypePaths[reportType];
7-
return axios.get<string>(`${path}?${query}`, {
7+
return axiosInstance.get<string>(`${path}?${query}`, {
88
headers: {
99
Accept: 'text/csv',
1010
},

src/api/export/awsOcpExport.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { axiosInstance } from 'api';
12
import { ReportTypePaths } from 'api/reports/awsOcpReports';
23
import type { ReportType } from 'api/reports/report';
3-
import axios from 'axios';
44

55
export function runExport(reportType: ReportType, query: string) {
66
const path = ReportTypePaths[reportType];
7-
return axios.get<string>(`${path}?${query}`, {
7+
return axiosInstance.get<string>(`${path}?${query}`, {
88
headers: {
99
Accept: 'text/csv',
1010
},

src/api/export/azureExport.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { axiosInstance } from 'api';
12
import { ReportTypePaths } from 'api/reports/azureReports';
23
import type { ReportType } from 'api/reports/report';
3-
import axios from 'axios';
44

55
export function runExport(reportType: ReportType, query: string) {
66
const path = ReportTypePaths[reportType];
7-
return axios.get<string>(`${path}?${query}`, {
7+
return axiosInstance.get<string>(`${path}?${query}`, {
88
headers: {
99
Accept: 'text/csv',
1010
},

src/api/export/azureOcpExport.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { axiosInstance } from 'api';
12
import { ReportTypePaths } from 'api/reports/azureOcpReports';
23
import type { ReportType } from 'api/reports/report';
3-
import axios from 'axios';
44

55
export function runExport(reportType: ReportType, query: string) {
66
const path = ReportTypePaths[reportType];
7-
return axios.get<string>(`${path}?${query}`, {
7+
return axiosInstance.get<string>(`${path}?${query}`, {
88
headers: {
99
Accept: 'text/csv',
1010
},

src/api/export/gcpExport.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { axiosInstance } from 'api';
12
import { ReportTypePaths } from 'api/reports/gcpReports';
23
import type { ReportType } from 'api/reports/report';
3-
import axios from 'axios';
44

55
export function runExport(reportType: ReportType, query: string) {
66
const path = ReportTypePaths[reportType];
7-
return axios.get<string>(`${path}?${query}`, {
7+
return axiosInstance.get<string>(`${path}?${query}`, {
88
headers: {
99
Accept: 'text/csv',
1010
},

src/api/export/gcpOcpExport.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { axiosInstance } from 'api';
12
import { ReportTypePaths } from 'api/reports/gcpOcpReports';
23
import type { ReportType } from 'api/reports/report';
3-
import axios from 'axios';
44

55
export function runExport(reportType: ReportType, query: string) {
66
const path = ReportTypePaths[reportType];
7-
return axios.get<string>(`${path}?${query}`, {
7+
return axiosInstance.get<string>(`${path}?${query}`, {
88
headers: {
99
Accept: 'text/csv',
1010
},

src/api/export/ibmExport.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { axiosInstance } from 'api';
12
import { ReportTypePaths } from 'api/reports/ibmReports';
23
import type { ReportType } from 'api/reports/report';
3-
import axios from 'axios';
44

55
export function runExport(reportType: ReportType, query: string) {
66
const path = ReportTypePaths[reportType];
7-
return axios.get<string>(`${path}?${query}`, {
7+
return axiosInstance.get<string>(`${path}?${query}`, {
88
headers: {
99
Accept: 'text/csv',
1010
},

src/api/export/ociExport.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { axiosInstance } from 'api';
12
import { ReportTypePaths } from 'api/reports/ociReports';
23
import type { ReportType } from 'api/reports/report';
3-
import axios from 'axios';
44

55
export function runExport(reportType: ReportType, query: string) {
66
const path = ReportTypePaths[reportType];
7-
return axios.get<string>(`${path}?${query}`, {
7+
return axiosInstance.get<string>(`${path}?${query}`, {
88
headers: {
99
Accept: 'text/csv',
1010
},

src/api/export/ocpCloudExport.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { axiosInstance } from 'api';
12
import { ReportTypePaths } from 'api/reports/ocpCloudReports';
23
import type { ReportType } from 'api/reports/report';
3-
import axios from 'axios';
44

55
export function runExport(reportType: ReportType, query: string) {
66
const path = ReportTypePaths[reportType];
7-
return axios.get<string>(`${path}?${query}`, {
7+
return axiosInstance.get<string>(`${path}?${query}`, {
88
headers: {
99
Accept: 'text/csv',
1010
},

src/api/export/ocpExport.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { axiosInstance } from 'api';
12
import { ReportTypePaths } from 'api/reports/ocpReports';
23
import type { ReportType } from 'api/reports/report';
3-
import axios from 'axios';
44

55
export function runExport(reportType: ReportType, query: string) {
66
const path = ReportTypePaths[reportType];
7-
return axios.get<string>(`${path}?${query}`, {
7+
return axiosInstance.get<string>(`${path}?${query}`, {
88
headers: {
99
Accept: 'text/csv',
1010
},

src/api/export/rhelExport.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { axiosInstance } from 'api';
12
import { ReportTypePaths } from 'api/reports/ocpReports';
23
import type { ReportType } from 'api/reports/report';
3-
import axios from 'axios';
44

55
export function runExport(reportType: ReportType, query: string) {
66
const path = ReportTypePaths[reportType];
7-
return axios.get<string>(`${path}?${query}`, {
7+
return axiosInstance.get<string>(`${path}?${query}`, {
88
headers: {
99
Accept: 'text/csv',
1010
},

src/api/forecasts/awsForecast.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios from 'axios';
1+
import { axiosInstance } from 'api';
22

33
import type { Forecast } from './forecast';
44
import { ForecastType } from './forecast';
@@ -9,5 +9,5 @@ export const ForecastTypePaths: Partial<Record<ForecastType, string>> = {
99

1010
export function runForecast(forecastType: ForecastType, query: string) {
1111
const path = ForecastTypePaths[forecastType];
12-
return axios.get<Forecast>(`${path}?${query}`);
12+
return axiosInstance.get<Forecast>(`${path}?${query}`);
1313
}

src/api/forecasts/awsOcpForecast.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios from 'axios';
1+
import { axiosInstance } from 'api';
22

33
import type { Forecast } from './forecast';
44
import { ForecastType } from './forecast';
@@ -9,5 +9,5 @@ export const ForecastTypePaths: Partial<Record<ForecastType, string>> = {
99

1010
export function runForecast(forecastType: ForecastType, query: string) {
1111
const path = ForecastTypePaths[forecastType];
12-
return axios.get<Forecast>(`${path}?${query}`);
12+
return axiosInstance.get<Forecast>(`${path}?${query}`);
1313
}

src/api/forecasts/azureForecast.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios from 'axios';
1+
import { axiosInstance } from 'api';
22

33
import type { Forecast } from './forecast';
44
import { ForecastType } from './forecast';
@@ -9,5 +9,5 @@ export const ForecastTypePaths: Partial<Record<ForecastType, string>> = {
99

1010
export function runForecast(forecastType: ForecastType, query: string) {
1111
const path = ForecastTypePaths[forecastType];
12-
return axios.get<Forecast>(`${path}?${query}`);
12+
return axiosInstance.get<Forecast>(`${path}?${query}`);
1313
}

src/api/forecasts/azureOcpForecast.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios from 'axios';
1+
import { axiosInstance } from 'api';
22

33
import type { Forecast } from './forecast';
44
import { ForecastType } from './forecast';
@@ -9,5 +9,5 @@ export const ForecastTypePaths: Partial<Record<ForecastType, string>> = {
99

1010
export function runForecast(forecastType: ForecastType, query: string) {
1111
const path = ForecastTypePaths[forecastType];
12-
return axios.get<Forecast>(`${path}?${query}`);
12+
return axiosInstance.get<Forecast>(`${path}?${query}`);
1313
}

src/api/forecasts/gcpForecast.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios from 'axios';
1+
import { axiosInstance } from 'api';
22

33
import type { Forecast } from './forecast';
44
import { ForecastType } from './forecast';
@@ -9,5 +9,5 @@ export const ForecastTypePaths: Partial<Record<ForecastType, string>> = {
99

1010
export function runForecast(forecastType: ForecastType, query: string) {
1111
const path = ForecastTypePaths[forecastType];
12-
return axios.get<Forecast>(`${path}?${query}`);
12+
return axiosInstance.get<Forecast>(`${path}?${query}`);
1313
}

src/api/forecasts/gcpOcpForecast.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios from 'axios';
1+
import { axiosInstance } from 'api';
22

33
import type { Forecast } from './forecast';
44
import { ForecastType } from './forecast';
@@ -9,5 +9,5 @@ export const ForecastTypePaths: Partial<Record<ForecastType, string>> = {
99

1010
export function runForecast(forecastType: ForecastType, query: string) {
1111
const path = ForecastTypePaths[forecastType];
12-
return axios.get<Forecast>(`${path}?${query}`);
12+
return axiosInstance.get<Forecast>(`${path}?${query}`);
1313
}

src/api/forecasts/ibmForecast.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios from 'axios';
1+
import { axiosInstance } from 'api';
22

33
import type { Forecast } from './forecast';
44
import { ForecastType } from './forecast';
@@ -9,5 +9,5 @@ export const ForecastTypePaths: Partial<Record<ForecastType, string>> = {
99

1010
export function runForecast(forecastType: ForecastType, query: string) {
1111
const path = ForecastTypePaths[forecastType];
12-
return axios.get<Forecast>(`${path}?${query}`);
12+
return axiosInstance.get<Forecast>(`${path}?${query}`);
1313
}

src/api/forecasts/ociForecast.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios from 'axios';
1+
import { axiosInstance } from 'api';
22

33
import type { Forecast } from './forecast';
44
import { ForecastType } from './forecast';
@@ -9,5 +9,5 @@ export const ForecastTypePaths: Partial<Record<ForecastType, string>> = {
99

1010
export function runForecast(forecastType: ForecastType, query: string) {
1111
const path = ForecastTypePaths[forecastType];
12-
return axios.get<Forecast>(`${path}?${query}`);
12+
return axiosInstance.get<Forecast>(`${path}?${query}`);
1313
}

0 commit comments

Comments
 (0)