-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
materialize droppableIDs, add utils and corresponding tests
- Loading branch information
Showing
10 changed files
with
185 additions
and
40 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/twenty-front/src/modules/favorites/constants/FavoriteDroppableIds.ts
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,5 @@ | ||
export const FAVORITE_DROPPABLE_IDS = { | ||
ORPHAN_FAVORITES: 'orphan-favorites', | ||
FOLDER_PREFIX: 'folder-', | ||
FOLDER_HEADER_PREFIX: 'folder-header-', | ||
}; |
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
6 changes: 6 additions & 0 deletions
6
packages/twenty-front/src/modules/favorites/types/FavoriteDroppableId.ts
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,6 @@ | ||
import { FAVORITE_DROPPABLE_IDS } from '@/favorites/constants/FavoriteDroppableIds'; | ||
|
||
export type FavoriteDroppableId = | ||
| typeof FAVORITE_DROPPABLE_IDS.ORPHAN_FAVORITES | ||
| `${typeof FAVORITE_DROPPABLE_IDS.FOLDER_PREFIX}${string}` | ||
| `${typeof FAVORITE_DROPPABLE_IDS.FOLDER_HEADER_PREFIX}${string}`; |
17 changes: 17 additions & 0 deletions
17
packages/twenty-front/src/modules/favorites/utils/__tests__/createFolderDroppableId.test.ts
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,17 @@ | ||
import { FAVORITE_DROPPABLE_IDS } from '@/favorites/constants/FavoriteDroppableIds'; | ||
import { createFolderDroppableId } from '../createFolderDroppableId'; | ||
|
||
describe('createFolderDroppableId', () => { | ||
it('should create a valid folder droppable id', () => { | ||
const folderId = '123-456'; | ||
const result = createFolderDroppableId(folderId); | ||
|
||
expect(result).toBe(`${FAVORITE_DROPPABLE_IDS.FOLDER_PREFIX}${folderId}`); | ||
}); | ||
|
||
it('should work with empty string', () => { | ||
const result = createFolderDroppableId(''); | ||
|
||
expect(result).toBe(FAVORITE_DROPPABLE_IDS.FOLDER_PREFIX); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
.../twenty-front/src/modules/favorites/utils/__tests__/createFolderHeaderDroppableId.test.ts
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,19 @@ | ||
import { FAVORITE_DROPPABLE_IDS } from '@/favorites/constants/FavoriteDroppableIds'; | ||
import { createFolderHeaderDroppableId } from '../createFolderHeaderDroppableId'; | ||
|
||
describe('createFolderHeaderDroppableId', () => { | ||
it('should create a valid folder header droppable id', () => { | ||
const folderId = '123-456'; | ||
const result = createFolderHeaderDroppableId(folderId); | ||
|
||
expect(result).toBe( | ||
`${FAVORITE_DROPPABLE_IDS.FOLDER_HEADER_PREFIX}${folderId}`, | ||
); | ||
}); | ||
|
||
it('should work with empty string', () => { | ||
const result = createFolderHeaderDroppableId(''); | ||
|
||
expect(result).toBe(FAVORITE_DROPPABLE_IDS.FOLDER_HEADER_PREFIX); | ||
}); | ||
}); |
47 changes: 47 additions & 0 deletions
47
...ges/twenty-front/src/modules/favorites/utils/__tests__/validateAndExtractFolderId.test.ts
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,47 @@ | ||
import { FAVORITE_DROPPABLE_IDS } from '@/favorites/constants/FavoriteDroppableIds'; | ||
import { validateAndExtractFolderId } from '../validateAndExtractFolderId'; | ||
|
||
describe('validateAndExtractFolderId', () => { | ||
it('should return null for orphan favorites', () => { | ||
const result = validateAndExtractFolderId( | ||
FAVORITE_DROPPABLE_IDS.ORPHAN_FAVORITES, | ||
); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
it('should extract folder id from folder droppable id', () => { | ||
const folderId = '123-456'; | ||
const droppableId = `${FAVORITE_DROPPABLE_IDS.FOLDER_PREFIX}${folderId}`; | ||
|
||
const result = validateAndExtractFolderId(droppableId); | ||
expect(result).toBe(folderId); | ||
}); | ||
|
||
it('should extract folder id from folder header droppable id', () => { | ||
const folderId = '123-456'; | ||
const droppableId = `${FAVORITE_DROPPABLE_IDS.FOLDER_HEADER_PREFIX}${folderId}`; | ||
|
||
const result = validateAndExtractFolderId(droppableId); | ||
expect(result).toBe(folderId); | ||
}); | ||
|
||
it('should throw error for invalid droppable id format', () => { | ||
expect(() => { | ||
validateAndExtractFolderId('invalid-id'); | ||
}).toThrow('Invalid droppable ID format: invalid-id'); | ||
}); | ||
|
||
it('should throw error for empty folder id in folder format', () => { | ||
expect(() => { | ||
validateAndExtractFolderId(FAVORITE_DROPPABLE_IDS.FOLDER_PREFIX); | ||
}).toThrow(`Invalid folder ID: ${FAVORITE_DROPPABLE_IDS.FOLDER_PREFIX}`); | ||
}); | ||
|
||
it('should throw error for empty folder id in folder header format', () => { | ||
expect(() => { | ||
validateAndExtractFolderId(FAVORITE_DROPPABLE_IDS.FOLDER_HEADER_PREFIX); | ||
}).toThrow( | ||
`Invalid folder header ID: ${FAVORITE_DROPPABLE_IDS.FOLDER_HEADER_PREFIX}`, | ||
); | ||
}); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/twenty-front/src/modules/favorites/utils/createFolderDroppableId.ts
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,6 @@ | ||
import { FAVORITE_DROPPABLE_IDS } from '@/favorites/constants/FavoriteDroppableIds'; | ||
import { FavoriteDroppableId } from '@/favorites/types/FavoriteDroppableId'; | ||
|
||
export const createFolderDroppableId = ( | ||
folderId: string, | ||
): FavoriteDroppableId => `${FAVORITE_DROPPABLE_IDS.FOLDER_PREFIX}${folderId}`; |
7 changes: 7 additions & 0 deletions
7
packages/twenty-front/src/modules/favorites/utils/createFolderHeaderDroppableId.ts
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,7 @@ | ||
import { FAVORITE_DROPPABLE_IDS } from '@/favorites/constants/FavoriteDroppableIds'; | ||
import { FavoriteDroppableId } from '@/favorites/types/FavoriteDroppableId'; | ||
|
||
export const createFolderHeaderDroppableId = ( | ||
folderId: string, | ||
): FavoriteDroppableId => | ||
`${FAVORITE_DROPPABLE_IDS.FOLDER_HEADER_PREFIX}${folderId}`; |
29 changes: 29 additions & 0 deletions
29
packages/twenty-front/src/modules/favorites/utils/validateAndExtractFolderId.ts
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,29 @@ | ||
import { FAVORITE_DROPPABLE_IDS } from '@/favorites/constants/FavoriteDroppableIds'; | ||
|
||
export const validateAndExtractFolderId = ( | ||
droppableId: string, | ||
): string | null => { | ||
if (droppableId === FAVORITE_DROPPABLE_IDS.ORPHAN_FAVORITES) { | ||
return null; | ||
} | ||
|
||
if (droppableId.startsWith(FAVORITE_DROPPABLE_IDS.FOLDER_HEADER_PREFIX)) { | ||
const folderId = droppableId.replace( | ||
FAVORITE_DROPPABLE_IDS.FOLDER_HEADER_PREFIX, | ||
'', | ||
); | ||
if (!folderId) throw new Error(`Invalid folder header ID: ${droppableId}`); | ||
return folderId; | ||
} | ||
|
||
if (droppableId.startsWith(FAVORITE_DROPPABLE_IDS.FOLDER_PREFIX)) { | ||
const folderId = droppableId.replace( | ||
FAVORITE_DROPPABLE_IDS.FOLDER_PREFIX, | ||
'', | ||
); | ||
if (!folderId) throw new Error(`Invalid folder ID: ${droppableId}`); | ||
return folderId; | ||
} | ||
|
||
throw new Error(`Invalid droppable ID format: ${droppableId}`); | ||
}; |