Skip to content

Commit

Permalink
fix: Send target for group uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
josebui committed Oct 17, 2023
1 parent badf3b1 commit d1c8be3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
7 changes: 5 additions & 2 deletions src/group/components/GroupSharedDataUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ const GroupSharedDataUpload = () => {
<PageHeader
header={t('group.shared_data_upload_title', { name: group.name })}
/>
<GroupContextProvider group={group} owner={group}>
<GroupContextProvider owner={group}>
<SharedDataUpload
groupSlug={slug}
targetInput={{
targetType: 'group',
targetSlug: slug,
}}
onCancel={onCancel}
onCompleteSuccess={onCompleteSuccess}
/>
Expand Down
4 changes: 4 additions & 0 deletions src/group/components/GroupSharedDataUploadFiles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ test('GroupSharedDataUpload: Complete Success', async () => {
await waitFor(() => expect(uploadButton).not.toHaveAttribute('disabled'));
await act(async () => fireEvent.click(uploadButton));
expect(navigate.mock.calls[0]).toEqual(['/groups/slug-1']);

const saveCall = terrasoApi.request.mock.calls[0];
expect(saveCall[0].body.get('target_type')).toBe('group');
expect(saveCall[0].body.get('target_slug')).toBe('slug-1');
});

test('GroupSharedDataUpload: PDF Success', async () => {
Expand Down
3 changes: 1 addition & 2 deletions src/landscape/components/LandscapeSharedDataUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ const LandscapeSharedDataUpload = () => {
name: landscape.name,
})}
/>
<GroupContextProvider group={landscape.defaultGroup} owner={landscape}>
<GroupContextProvider owner={landscape}>
<SharedDataUpload
groupSlug={_.get('defaultGroup.slug', landscape)}
onCancel={onCancel}
onCompleteSuccess={onCompleteSuccess}
targetInput={{
Expand Down
12 changes: 4 additions & 8 deletions src/sharedData/sharedDataService.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,16 @@ import { SHARED_DATA_ACCEPTED_EXTENSIONS } from 'config';
const ALL_RESOURCE_TYPES = [...SHARED_DATA_ACCEPTED_EXTENSIONS, 'link'];

export const uploadSharedDataFile = async ({
groupSlug,
landscapeSlug,
targetType,
targetSlug,
file,
}) => {
const path = '/shared-data/upload/';

const body = new FormData();
const filename = `${file.name}${file.resourceType}`;
if (groupSlug) {
body.append('groups', groupSlug);
}
if (landscapeSlug) {
body.append('landscapes', landscapeSlug);
}
body.append('target_type', targetType);
body.append('target_slug', targetSlug);
body.append('name', file.name);
if (file.description) {
body.append('description', file.description);
Expand Down

0 comments on commit d1c8be3

Please sign in to comment.