chore: update returned attachement fullPath (#9516)
### Solution fullPath prop on attachement (when returned by backend) is updated to 'domain + path' (formerly 'path'). Consequently, getFileAbsoluteURI util in front is removed. closes #8763 --------- Co-authored-by: etiennejouan <jouan.etienne@gmail.com>
This commit is contained in:
@ -173,9 +173,9 @@ export const ActivityRichTextEditor = ({
|
||||
}, [activity]);
|
||||
|
||||
const handleEditorBuiltInUploadFile = async (file: File) => {
|
||||
const { attachementAbsoluteURL } = await handleUploadAttachment(file);
|
||||
const { attachmentAbsoluteURL } = await handleUploadAttachment(file);
|
||||
|
||||
return attachementAbsoluteURL;
|
||||
return attachmentAbsoluteURL;
|
||||
};
|
||||
|
||||
const editor = useCreateBlockNote({
|
||||
|
||||
@ -17,7 +17,6 @@ import { useMemo, useState } from 'react';
|
||||
import { IconCalendar, OverflowingTextWithTooltip } from 'twenty-ui';
|
||||
|
||||
import { formatToHumanReadableDate } from '~/utils/date-utils';
|
||||
import { getFileAbsoluteURI } from '~/utils/file/getFileAbsoluteURI';
|
||||
import { getFileNameAndExtension } from '~/utils/file/getFileNameAndExtension';
|
||||
|
||||
const StyledLeftContent = styled.div`
|
||||
@ -139,8 +138,9 @@ export const AttachmentRow = ({ attachment }: { attachment: Attachment }) => {
|
||||
) : (
|
||||
<StyledLinkContainer>
|
||||
<StyledLink
|
||||
href={getFileAbsoluteURI(attachment.fullPath)}
|
||||
target="__blank"
|
||||
href={attachment.fullPath}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<OverflowingTextWithTooltip text={attachment.name} />
|
||||
</StyledLink>
|
||||
|
||||
@ -9,7 +9,6 @@ import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSi
|
||||
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { FileFolder, useUploadFileMutation } from '~/generated/graphql';
|
||||
import { getFileAbsoluteURI } from '~/utils/file/getFileAbsoluteURI';
|
||||
|
||||
// Note: This is probably not the right way to do this.
|
||||
export const computePathWithoutToken = (attachmentPath: string): string => {
|
||||
@ -56,11 +55,9 @@ export const useUploadAttachmentFile = () => {
|
||||
updatedAt: new Date().toISOString(),
|
||||
} as Partial<Attachment>;
|
||||
|
||||
await createOneAttachment(attachmentToCreate);
|
||||
const createdAttachment = await createOneAttachment(attachmentToCreate);
|
||||
|
||||
const attachementAbsoluteURL = getFileAbsoluteURI(attachmentPath);
|
||||
|
||||
return { attachementAbsoluteURL };
|
||||
return { attachmentAbsoluteURL: createdAttachment.fullPath };
|
||||
};
|
||||
|
||||
return { uploadAttachmentFile };
|
||||
|
||||
@ -17,12 +17,10 @@ window.URL.revokeObjectURL = jest.fn();
|
||||
describe.skip('downloadFile', () => {
|
||||
it('should download a file', () => {
|
||||
// Call downloadFile
|
||||
downloadFile('path/to/file.pdf', 'file.pdf');
|
||||
downloadFile('url/to/file.pdf', 'file.pdf');
|
||||
|
||||
// Assert on fetch
|
||||
expect(fetch).toHaveBeenCalledWith(
|
||||
process.env.REACT_APP_SERVER_BASE_URL + '/files/path/to/file.pdf',
|
||||
);
|
||||
expect(fetch).toHaveBeenCalledWith('url/to/file.pdf');
|
||||
|
||||
// Assert on element creation
|
||||
const link = document.querySelector(
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import { saveAs } from 'file-saver';
|
||||
import { getFileAbsoluteURI } from '~/utils/file/getFileAbsoluteURI';
|
||||
|
||||
export const downloadFile = (fullPath: string, fileName: string) => {
|
||||
fetch(getFileAbsoluteURI(fullPath))
|
||||
fetch(fullPath)
|
||||
.then((resp) =>
|
||||
resp.status === 200
|
||||
? resp.blob()
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
import { getFileAbsoluteURI } from '../getFileAbsoluteURI';
|
||||
import { REACT_APP_SERVER_BASE_URL } from '~/config';
|
||||
|
||||
describe('getFileAbsoluteURI', () => {
|
||||
test('should return absolute uri', () => {
|
||||
expect(getFileAbsoluteURI('foo')).toEqual(
|
||||
`${REACT_APP_SERVER_BASE_URL}/files/foo`,
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -1,5 +0,0 @@
|
||||
import { REACT_APP_SERVER_BASE_URL } from '~/config';
|
||||
|
||||
export const getFileAbsoluteURI = (fileUrl?: string) => {
|
||||
return `${REACT_APP_SERVER_BASE_URL}/files/${fileUrl}`;
|
||||
};
|
||||
@ -23,7 +23,7 @@ export class AttachmentQueryResultGetterHandler
|
||||
|
||||
return {
|
||||
...attachment,
|
||||
fullPath: `${attachment.fullPath}?token=${signedPayload}`,
|
||||
fullPath: `${process.env.SERVER_URL}/files/${attachment.fullPath}?token=${signedPayload}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user