Skip to content

Commit c4092a9

Browse files
sachinrameshnaderghamov
authored andcommitted
fix(ips): export ips to csv fixes
ref: #MANAGER-18928 Signed-off-by: Sachin Ramesh <[email protected]>
1 parent 73e22f2 commit c4092a9

File tree

7 files changed

+43
-24
lines changed

7 files changed

+43
-24
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"manager_error_page_default": "Une erreur est survenue lors du chargement de la page.",
3-
"managerApiError": "Une erreur est survenue <br> {{error}} <br> request_id: {{ovhQueryId}}"
3+
"managerApiError": "Une erreur est survenue <br> {{error}} <br> request_id: {{ovhQueryId}}",
4+
"managerApiErrorWithoutRequestId": "Une erreur est survenue <br> {{error}}"
45
}

packages/manager/apps/ips/src/components/ApiError/ApiErrorMessage.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ import { TRANSLATION_NAMESPACES } from '@/utils';
88
export const useApiErrorMessage = (error?: ApiError) => {
99
const { t } = useTranslation(TRANSLATION_NAMESPACES.error);
1010

11-
return error
12-
? t('managerApiError', {
13-
error: error?.response?.data?.message,
14-
ovhQueryId: error?.response.headers?.['x-ovh-queryid'],
15-
})
16-
: undefined;
11+
const errorMessage = error?.response?.data?.message || error?.message;
12+
const ovhQueryId = error?.response.headers?.['x-ovh-queryid'];
13+
14+
if (!errorMessage) {
15+
return undefined;
16+
}
17+
18+
return ovhQueryId
19+
? t('managerApiError', { error: errorMessage, ovhQueryId })
20+
: t('managerApiErrorWithoutRequestId', { error: errorMessage });
1721
};
1822

1923
export type ApiErrorMessageProps = {

packages/manager/apps/ips/src/data/api/get/ipExport.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { aapi } from '@ovh-ux/manager-core-api';
2-
import { GetIpListParams } from './ipList';
32
import { ExportIpToCsvData } from '@/data/hooks';
3+
import { IpTypeEnum } from './ipDetails';
44

5-
export type GetIpExportParams = GetIpListParams & {
6-
serviceName: string;
5+
export type GetIpExportParams = {
6+
ip?: string;
7+
isAdditionalIp?: boolean;
8+
type?: IpTypeEnum;
9+
serviceName?: string;
10+
version?: number;
711
};
812

913
export type IpExportType = {

packages/manager/apps/ips/src/data/hooks/useExportIpToCsv.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useTranslation } from 'react-i18next';
22
import { mkConfig, generateCsv, download } from 'export-to-csv';
33
import { useMutation } from '@tanstack/react-query';
4+
import { ApiError } from '@ovh-ux/manager-core-api';
45
import { TRANSLATION_NAMESPACES } from '@/utils';
56
import { getIpExport, GetIpListParams } from '../api';
67

@@ -32,7 +33,10 @@ export const useExportIpToCsv = ({
3233
const handleExportToCsv = async (): Promise<ExportIpMutationData> => {
3334
const result = await getIpExport({
3435
...apiFilter,
35-
serviceName: apiFilter['routedTo.serviceName'],
36+
serviceName:
37+
apiFilter['routedTo.serviceName'] === null
38+
? '_PARK'
39+
: apiFilter['routedTo.serviceName'],
3640
});
3741

3842
const resultLength = result?.data?.length ?? 0;
@@ -60,7 +64,7 @@ export const useExportIpToCsv = ({
6064
throw new Error('No valid CSV could be downloaded');
6165
};
6266

63-
return useMutation({
67+
return useMutation<ExportIpMutationData, ApiError>({
6468
mutationFn: handleExportToCsv,
6569
onSuccess,
6670
onError,

packages/manager/apps/ips/src/pages/actions/exportIpToCsv/exportIpToCsv.page.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useContext, useRef } from 'react';
22
import { useTranslation } from 'react-i18next';
3-
import { useNavigate } from 'react-router-dom';
3+
import { useNavigate, useSearchParams } from 'react-router-dom';
44
import { ODS_TEXT_PRESET } from '@ovhcloud/ods-components';
55
import { NAMESPACES } from '@ovh-ux/manager-common-translations';
66
import { OdsText } from '@ovhcloud/ods-components/react';
@@ -9,34 +9,37 @@ import Loading from '@/components/Loading/Loading';
99
import { TRANSLATION_NAMESPACES } from '@/utils';
1010
import { useExportIpToCsv } from '@/data/hooks';
1111
import { ListingContext } from '@/pages/listing/listingContext';
12+
import { ApiErrorMessage } from '@/components/ApiError/ApiErrorMessage';
1213

1314
export default function ExportIpToCsv() {
1415
const { t } = useTranslation([
1516
TRANSLATION_NAMESPACES.exportIpToCsv,
1617
NAMESPACES.ACTIONS,
1718
]);
1819
const { apiFilter } = useContext(ListingContext);
19-
const { addSuccess, addError } = useNotifications();
20+
const { addSuccess } = useNotifications();
2021
const navigate = useNavigate();
22+
const [search] = useSearchParams();
2123

2224
/*
2325
We need this ref to prevent a double navigation
2426
when closing the modale before the end of the download.
25-
A useState or useLocation would have required a rerender
27+
A useState or useLocation would have required a rerender
2628
that we cannot have upon closing the modale
2729
*/
2830
const isOpen = useRef<boolean>(true);
2931

3032
const closeModal = () => {
3133
if (isOpen.current) {
3234
isOpen.current = false;
33-
navigate('..');
35+
navigate(`..?${search.toString()}`);
3436
}
3537
};
3638

3739
const {
38-
mutateAsync: handleExportToCsv,
40+
mutate: handleExportToCsv,
3941
isPending: isCSVLoading,
42+
error,
4043
} = useExportIpToCsv({
4144
apiFilter,
4245
onSuccess: (data) => {
@@ -46,7 +49,6 @@ export default function ExportIpToCsv() {
4649
closeModal();
4750
}
4851
},
49-
onError: () => addError(t('exportIpToCsvError')),
5052
});
5153

5254
return (
@@ -77,6 +79,7 @@ export default function ExportIpToCsv() {
7779
</OdsText>
7880
</>
7981
)}
82+
<ApiErrorMessage error={error} />
8083
</Modal>
8184
);
8285
}

packages/manager/apps/ips/src/pages/actions/exportIpToCsv/exportIpToCsv.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ vi.mock('react-i18next', () => ({
2222

2323
vi.mock('react-router-dom', () => ({
2424
useNavigate: () => vi.fn(),
25+
useSearchParams: () => ['', vi.fn()],
2526
}));
2627

2728
const renderComponent = () => {

packages/manager/apps/ips/src/pages/listing/ipListing/ip.listing.page.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,14 @@ export default function IpListingPage() {
7878
]}
7979
/>
8080
<OdsButton
81-
variant={ODS_BUTTON_VARIANT.outline}
82-
icon={ODS_ICON_NAME.download}
83-
size={ODS_BUTTON_SIZE.sm}
84-
onClick={() => navigate(urls.listingExportIpToCsv)}
85-
label=""
86-
/>
81+
variant={ODS_BUTTON_VARIANT.outline}
82+
icon={ODS_ICON_NAME.download}
83+
size={ODS_BUTTON_SIZE.sm}
84+
onClick={() =>
85+
navigate(`${urls.listingExportIpToCsv}?${search.toString()}`)
86+
}
87+
label=""
88+
/>
8789
</div>
8890
<QuickFilter />
8991
</div>

0 commit comments

Comments
 (0)