Skip to content

Commit c7a1fa8

Browse files
committed
fix(file-selection): Display items in alphabetical order
Closes #463
1 parent 5c2df14 commit c7a1fa8

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

components/FileSelector/AllFilesList.tsx

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,34 @@ export const AllFilesList = ({
3939
onSelect(getNewValue(fullPath, checked, multiple, value));
4040

4141
const items = [
42-
...dirs.map((path) => {
43-
const fullPath = getFullPath(breadcrumbs, path);
44-
const type: FileOrDirectory = 'directory';
45-
return {
46-
fullPath,
47-
key: fullPath,
48-
mimeType: undefined,
49-
title: path,
50-
type,
51-
onClick: () => setBreadcrumbs([...breadcrumbs, path]),
52-
onSelect: targetType.startsWith('dir') ? handleSelect(fullPath) : undefined,
53-
};
54-
}),
55-
...files.map((file) => {
56-
const fullPath = getFullPath(breadcrumbs, file.file_name);
57-
const type: FileOrDirectory = 'file';
58-
return {
59-
fullPath,
60-
mimeType: file.mime_type,
61-
title: file.file_name,
62-
type,
63-
onSelect: handleSelect(fullPath),
64-
};
65-
}),
42+
...dirs
43+
.map((path) => {
44+
const fullPath = getFullPath(breadcrumbs, path);
45+
const type: FileOrDirectory = 'directory';
46+
return {
47+
fullPath,
48+
key: fullPath,
49+
mimeType: undefined,
50+
title: path,
51+
type,
52+
onClick: () => setBreadcrumbs([...breadcrumbs, path]),
53+
onSelect: targetType.startsWith('dir') ? handleSelect(fullPath) : undefined,
54+
};
55+
})
56+
.sort((dirA, dirB) => dirA.title.localeCompare(dirB.title)),
57+
...files
58+
.map((file) => {
59+
const fullPath = getFullPath(breadcrumbs, file.file_name);
60+
const type: FileOrDirectory = 'file';
61+
return {
62+
fullPath,
63+
mimeType: file.mime_type,
64+
title: file.file_name,
65+
type,
66+
onSelect: handleSelect(fullPath),
67+
};
68+
})
69+
.sort((fileA, fileB) => fileA.title.localeCompare(fileB.title)),
6670
];
6771

6872
if (isLoading) {

components/FileSelector/FavouritesList.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export const FavouritesList = ({
2222

2323
const selectedFilesToDisplay = selectedFiles
2424
?.filter((file) => file.type.includes(targetType))
25-
.filter((file) => !file.mimeType || mimeTypes?.includes(file.mimeType));
25+
.filter((file) => !file.mimeType || mimeTypes?.includes(file.mimeType))
26+
.sort((fileA, fileB) => fileA.path.localeCompare(fileB.path));
2627

2728
return selectedFilesToDisplay?.length ? (
2829
<ScrollList dense>

0 commit comments

Comments
 (0)