The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(front): keep the filename when a file has no extension (#21576)
Yash Singhd7d4b36d5e2e
diff --git a/packages/twenty-front/src/utils/file/__tests__/getFileNameAndExtension.test.ts b/packages/twenty-front/src/utils/file/__tests__/getFileNameAndExtension.test.tsindex 9a0032cb9bd..f6736901b0c 100644--- a/packages/twenty-front/src/utils/file/__tests__/getFileNameAndExtension.test.ts+++ b/packages/twenty-front/src/utils/file/__tests__/getFileNameAndExtension.test.ts@@ -20,8 +20,24 @@ describe('getFileNameAndExtension', () => {it('should handle files with no extension', () => {const result = getFileNameAndExtension('README');expect(result).toEqual({- name: '',- extension: 'README',+ name: 'README',+ extension: '',+ });+ });++ it('should keep the full name when there is no dot at all', () => {+ const result = getFileNameAndExtension('my document file');+ expect(result).toEqual({+ name: 'my document file',+ extension: '',+ });+ });++ it('should handle a trailing dot', () => {+ const result = getFileNameAndExtension('file.');+ expect(result).toEqual({+ name: 'file',+ extension: '.',});});diff --git a/packages/twenty-front/src/utils/file/getFileNameAndExtension.ts b/packages/twenty-front/src/utils/file/getFileNameAndExtension.tsindex 231648cd5c9..966c1ccb762 100644--- a/packages/twenty-front/src/utils/file/getFileNameAndExtension.ts+++ b/packages/twenty-front/src/utils/file/getFileNameAndExtension.ts@@ -1,6 +1,15 @@export const getFileNameAndExtension = (filenameWithExtension: string) => {const lastDotIndex = filenameWithExtension.lastIndexOf('.');+ // Without a dot, substring(0, -1) and substring(-1) would put the whole+ // filename into the extension, so keep it as the name with an empty extension.+ if (lastDotIndex === -1) {+ return {+ name: filenameWithExtension,+ extension: '',+ };+ }+return {name: filenameWithExtension.substring(0, lastDotIndex),extension: filenameWithExtension.substring(lastDotIndex),