-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into task/WP-505--APCD--File-Upload-Failures
- Loading branch information
Showing
5 changed files
with
162 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { useDispatch, useSelector, shallowEqual } from 'react-redux'; | ||
import { useSelectedFiles } from 'hooks/datafiles'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { apiClient } from 'utils/apiClient'; | ||
import truncateMiddle from 'utils/truncateMiddle'; | ||
|
||
export async function moveFileUtil({ | ||
api, | ||
scheme, | ||
system, | ||
path, | ||
destSystem, | ||
destPath, | ||
}: { | ||
api: string; | ||
scheme: string; | ||
system: string; | ||
path: string; | ||
destSystem: string; | ||
destPath: string; | ||
}): Promise<{ name: string; path: string }> { | ||
const body = { | ||
dest_system: destSystem, | ||
dest_path: destPath, | ||
}; | ||
const url = `/api/datafiles/${api}/move/${scheme}/${system}/${path}/`; | ||
const request = await apiClient.put(url, body); | ||
return request.data; | ||
} | ||
|
||
function useMove() { | ||
const dispatch = useDispatch(); | ||
const { selectedFiles: selected } = useSelectedFiles(); | ||
const status = useSelector( | ||
(state: any) => state.files.operationStatus.move, | ||
shallowEqual | ||
); | ||
|
||
const { api, scheme } = useSelector( | ||
(state: any) => state.files.params.FilesListing | ||
); | ||
const setStatus = () => { | ||
dispatch({ | ||
type: 'DATA_FILES_SET_OPERATION_STATUS', | ||
payload: { operation: 'move', status: 'RUNNING' }, | ||
}); | ||
}; | ||
|
||
const { mutateAsync } = useMutation({ | ||
mutationFn: moveFileUtil, | ||
}); | ||
|
||
const move = ({ | ||
destSystem, | ||
destPath, | ||
callback, | ||
}: { | ||
destSystem: string; | ||
destPath: string; | ||
callback: () => void; | ||
}) => { | ||
const filteredSelected = selected.filter( | ||
(f: any) => status[f.id] !== 'SUCCESS' | ||
); | ||
const moveCalls: Promise<any>[] = filteredSelected.forEach((file: any) => { | ||
dispatch({ | ||
type: 'DATA_FILES_SET_OPERATION_STATUS_BY_KEY', | ||
payload: { | ||
status: 'RUNNING', | ||
key: file.id, | ||
operation: 'move', | ||
}, | ||
}); | ||
return mutateAsync( | ||
{ | ||
api: api, | ||
scheme: scheme, | ||
system: file.system, | ||
path: file.path, | ||
destSystem: destSystem, | ||
destPath: destPath, | ||
}, | ||
{ | ||
onSuccess: () => { | ||
dispatch({ | ||
type: 'DATA_FILES_SET_OPERATION_STATUS_BY_KEY', | ||
payload: { | ||
status: 'SUCCESS', | ||
key: (index: string) => index, | ||
operation: 'move', | ||
}, | ||
}); | ||
dispatch({ | ||
type: 'DATA_FILES_TOGGLE_MODAL', | ||
payload: { operation: 'move', props: {} }, | ||
}); | ||
dispatch({ | ||
type: 'ADD_TOAST', | ||
payload: { | ||
message: `${ | ||
filteredSelected.length > 1 | ||
? `${filteredSelected.length} files` | ||
: 'File' | ||
} moved to ${truncateMiddle(destPath, 20) || '/'}`, | ||
}, | ||
}); | ||
callback(); | ||
}, | ||
onError: () => { | ||
dispatch({ | ||
type: 'DATA_FILES_SET_OPERATION_STATUS_BY_KEY', | ||
payload: { | ||
status: 'ERROR', | ||
key: (index: string) => index, | ||
operation: 'move', | ||
}, | ||
}); | ||
}, | ||
} | ||
); | ||
}); | ||
}; | ||
|
||
return { move, status, setStatus }; | ||
} | ||
|
||
export default useMove; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,36 @@ | ||
from unittest.mock import patch | ||
|
||
from tapipy.errors import BaseTapyException | ||
|
||
from portal.apps.site_search.api.views import SiteSearchApiView | ||
|
||
|
||
def test_search_unauthenticated(client, regular_user): | ||
response = client.get('/search/') | ||
response = client.get("/search/") | ||
assert response.status_code == 200 | ||
assert response.context['setup_complete'] is False | ||
assert response.context["setup_complete"] is False | ||
|
||
|
||
def test_search_authenticated_without_setup_complete(client, authenticated_user): | ||
response = client.get('/search/') | ||
response = client.get("/search/") | ||
assert response.status_code == 200 | ||
assert response.context['setup_complete'] is False | ||
assert response.context["setup_complete"] is False | ||
|
||
|
||
def test_search_authenticated_with_setup_complete(client, authenticated_user): | ||
authenticated_user.profile.setup_complete = True | ||
authenticated_user.profile.save() | ||
response = client.get('/search/') | ||
response = client.get("/search/") | ||
assert response.status_code == 200 | ||
assert response.context['setup_complete'] | ||
assert response.context["setup_complete"] | ||
|
||
|
||
@patch("portal.apps.site_search.api.views.logger") | ||
def test_handle_tapis_ssh_exception_files_client_ssh_op_err1(mock_logger): | ||
view = SiteSearchApiView() | ||
message = "FILES_CLIENT_SSH_OP_ERR1" | ||
exception = BaseTapyException(message) | ||
view._handle_tapis_ssh_exception(exception) | ||
mock_logger.exception.assert_called_once_with( | ||
f"Error retrieving search results due to TAPIS SSH related error: message: {message}" | ||
) |