Skip to content

Commit

Permalink
[ui-core] remove urlPrefix option from useLoadData hook (#3868)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramprasadagarwal authored Oct 16, 2024
1 parent 59fad96 commit 43f8e00
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ const StorageBrowserTabContent = ({
data: filesData,
loading,
reloadData
} = useLoadData<PathAndFileData>(filePath, {
urlPrefix: VIEWFILES_API_URl,
} = useLoadData<PathAndFileData>(`${VIEWFILES_API_URl}${filePath}`, {
params: {
pagesize: pageSize.toString(),
pagenum: pageNumber.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ const FileChooserModal: React.FC<FileProps> = ({ show, onCancel, title, okText }
}
}, [fileSystemsData]);

const { data: filesData, loading: loadingFiles } = useLoadData<PathAndFileData>(filePath, {
urlPrefix: VIEWFILES_API_URl,
skip: !!filePath
});
const { data: filesData, loading: loadingFiles } = useLoadData<PathAndFileData>(
`${VIEWFILES_API_URl}${filePath}`,
{
skip: !!filePath
}
);

return (
<Modal
Expand Down
15 changes: 0 additions & 15 deletions desktop/core/src/desktop/js/utils/hooks/useLoadData.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,6 @@ describe('useLoadData', () => {
});
});

it('should handle URL prefix correctly', async () => {
const { result } = renderHook(() => useLoadData(mockEndpoint, { urlPrefix: mockUrlPrefix }));

expect(result.current.data).toBeUndefined();
expect(result.current.error).toBeUndefined();
expect(result.current.loading).toBe(true);

await waitFor(() => {
expect(mockGet).toHaveBeenCalledWith(mockUrl, undefined, expect.any(Object));
expect(result.current.data).toEqual(mockData);
expect(result.current.error).toBeUndefined();
expect(result.current.loading).toBe(false);
});
});

it('should update options correctly', async () => {
const { result, rerender } = renderHook(
(props: { url: string; options }) => useLoadData(props.url, props.options),
Expand Down
4 changes: 1 addition & 3 deletions desktop/core/src/desktop/js/utils/hooks/useLoadData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
import { ApiFetchOptions, get } from '../../api/utils';

export interface Options<T, U> {
urlPrefix?: string;
params?: U;
fetchOptions?: ApiFetchOptions<T>;
skip?: boolean;
Expand Down Expand Up @@ -63,8 +62,7 @@ const useLoadData = <T, U = unknown>(
setError(undefined);

try {
const fetchUrl = localOptions?.urlPrefix ? `${localOptions.urlPrefix}${url}` : url;
const response = await get<T, U>(fetchUrl, localOptions?.params, fetchOptions);
const response = await get<T, U>(url, localOptions?.params, fetchOptions);
setData(response);
if (localOptions?.onSuccess) {
localOptions.onSuccess(response);
Expand Down

0 comments on commit 43f8e00

Please sign in to comment.