refactor(datasets): extract hooks and components with comprehensive tests (#31707)

Co-authored-by: CodingOnStar <hanxujiang@dify.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Coding On Star
2026-02-04 18:12:17 +08:00
committed by GitHub
parent cc5705cb71
commit 297dd832aa
38 changed files with 9328 additions and 1653 deletions

View File

@@ -148,3 +148,23 @@ export const formatNumberAbbreviated = (num: number) => {
export const formatToLocalTime = (time: Dayjs, local: Locale, format: string) => {
return time.locale(localeMap[local] ?? 'en').format(format)
}
/**
* Get file extension from file name.
* @param fileName file name
* @example getFileExtension('document.pdf') will return 'pdf'
* @example getFileExtension('archive.tar.gz') will return 'gz'
* @example getFileExtension('.gitignore') will return '' (hidden file with no extension)
* @example getFileExtension('.hidden.txt') will return 'txt'
*/
export const getFileExtension = (fileName: string): string => {
if (!fileName)
return ''
// Handle hidden files (starting with dot) by finding dot after the first character
const dotIndex = fileName.indexOf('.', fileName.startsWith('.') ? 1 : 0)
if (dotIndex === -1 || dotIndex === fileName.length - 1)
return ''
return fileName.slice(dotIndex + 1).split('.').pop()?.toLowerCase() ?? ''
}