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]);
|
}, [activity]);
|
||||||
|
|
||||||
const handleEditorBuiltInUploadFile = async (file: File) => {
|
const handleEditorBuiltInUploadFile = async (file: File) => {
|
||||||
const { attachementAbsoluteURL } = await handleUploadAttachment(file);
|
const { attachmentAbsoluteURL } = await handleUploadAttachment(file);
|
||||||
|
|
||||||
return attachementAbsoluteURL;
|
return attachmentAbsoluteURL;
|
||||||
};
|
};
|
||||||
|
|
||||||
const editor = useCreateBlockNote({
|
const editor = useCreateBlockNote({
|
||||||
|
|||||||
@ -17,7 +17,6 @@ import { useMemo, useState } from 'react';
|
|||||||
import { IconCalendar, OverflowingTextWithTooltip } from 'twenty-ui';
|
import { IconCalendar, OverflowingTextWithTooltip } from 'twenty-ui';
|
||||||
|
|
||||||
import { formatToHumanReadableDate } from '~/utils/date-utils';
|
import { formatToHumanReadableDate } from '~/utils/date-utils';
|
||||||
import { getFileAbsoluteURI } from '~/utils/file/getFileAbsoluteURI';
|
|
||||||
import { getFileNameAndExtension } from '~/utils/file/getFileNameAndExtension';
|
import { getFileNameAndExtension } from '~/utils/file/getFileNameAndExtension';
|
||||||
|
|
||||||
const StyledLeftContent = styled.div`
|
const StyledLeftContent = styled.div`
|
||||||
@ -139,8 +138,9 @@ export const AttachmentRow = ({ attachment }: { attachment: Attachment }) => {
|
|||||||
) : (
|
) : (
|
||||||
<StyledLinkContainer>
|
<StyledLinkContainer>
|
||||||
<StyledLink
|
<StyledLink
|
||||||
href={getFileAbsoluteURI(attachment.fullPath)}
|
href={attachment.fullPath}
|
||||||
target="__blank"
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
>
|
>
|
||||||
<OverflowingTextWithTooltip text={attachment.name} />
|
<OverflowingTextWithTooltip text={attachment.name} />
|
||||||
</StyledLink>
|
</StyledLink>
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSi
|
|||||||
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
|
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
|
||||||
import { isNonEmptyString } from '@sniptt/guards';
|
import { isNonEmptyString } from '@sniptt/guards';
|
||||||
import { FileFolder, useUploadFileMutation } from '~/generated/graphql';
|
import { FileFolder, useUploadFileMutation } from '~/generated/graphql';
|
||||||
import { getFileAbsoluteURI } from '~/utils/file/getFileAbsoluteURI';
|
|
||||||
|
|
||||||
// Note: This is probably not the right way to do this.
|
// Note: This is probably not the right way to do this.
|
||||||
export const computePathWithoutToken = (attachmentPath: string): string => {
|
export const computePathWithoutToken = (attachmentPath: string): string => {
|
||||||
@ -56,11 +55,9 @@ export const useUploadAttachmentFile = () => {
|
|||||||
updatedAt: new Date().toISOString(),
|
updatedAt: new Date().toISOString(),
|
||||||
} as Partial<Attachment>;
|
} as Partial<Attachment>;
|
||||||
|
|
||||||
await createOneAttachment(attachmentToCreate);
|
const createdAttachment = await createOneAttachment(attachmentToCreate);
|
||||||
|
|
||||||
const attachementAbsoluteURL = getFileAbsoluteURI(attachmentPath);
|
return { attachmentAbsoluteURL: createdAttachment.fullPath };
|
||||||
|
|
||||||
return { attachementAbsoluteURL };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return { uploadAttachmentFile };
|
return { uploadAttachmentFile };
|
||||||
|
|||||||
@ -17,12 +17,10 @@ window.URL.revokeObjectURL = jest.fn();
|
|||||||
describe.skip('downloadFile', () => {
|
describe.skip('downloadFile', () => {
|
||||||
it('should download a file', () => {
|
it('should download a file', () => {
|
||||||
// Call downloadFile
|
// Call downloadFile
|
||||||
downloadFile('path/to/file.pdf', 'file.pdf');
|
downloadFile('url/to/file.pdf', 'file.pdf');
|
||||||
|
|
||||||
// Assert on fetch
|
// Assert on fetch
|
||||||
expect(fetch).toHaveBeenCalledWith(
|
expect(fetch).toHaveBeenCalledWith('url/to/file.pdf');
|
||||||
process.env.REACT_APP_SERVER_BASE_URL + '/files/path/to/file.pdf',
|
|
||||||
);
|
|
||||||
|
|
||||||
// Assert on element creation
|
// Assert on element creation
|
||||||
const link = document.querySelector(
|
const link = document.querySelector(
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
import { saveAs } from 'file-saver';
|
import { saveAs } from 'file-saver';
|
||||||
import { getFileAbsoluteURI } from '~/utils/file/getFileAbsoluteURI';
|
|
||||||
|
|
||||||
export const downloadFile = (fullPath: string, fileName: string) => {
|
export const downloadFile = (fullPath: string, fileName: string) => {
|
||||||
fetch(getFileAbsoluteURI(fullPath))
|
fetch(fullPath)
|
||||||
.then((resp) =>
|
.then((resp) =>
|
||||||
resp.status === 200
|
resp.status === 200
|
||||||
? resp.blob()
|
? 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 {
|
return {
|
||||||
...attachment,
|
...attachment,
|
||||||
fullPath: `${attachment.fullPath}?token=${signedPayload}`,
|
fullPath: `${process.env.SERVER_URL}/files/${attachment.fullPath}?token=${signedPayload}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user