Skip to content

Commit

Permalink
Fix paths with leading slash
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Apr 17, 2024
1 parent 0272eb2 commit 1a6d5a0
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions web-common/src/features/entity-management/file-selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,19 @@ export function useFileNamesInDirectory(
instanceId: string,
directoryPath: string,
) {
if (directoryPath === "") directoryPath = "/";
directoryPath += "/";
return createRuntimeServiceListFiles(instanceId, undefined, {
query: {
select: (data) => {
const files = data.files?.filter(
(file) => !file.isDir && file.path?.startsWith(directoryPath),
);
const fileNames = files?.map((file) => {
return file.path?.replace(directoryPath, "") ?? "";
});
const fileNames = files
.map((file) => {
return file.path?.replace(directoryPath, "") ?? "";
})
// filter out files in subdirectories
.filter((filePath) => !filePath.includes("/"));
const sortedFileNames = fileNames?.sort((fileNameA, fileNameB) =>
fileNameA.localeCompare(fileNameB, undefined, {
sensitivity: "base",
Expand All @@ -176,19 +179,23 @@ export function useDirectoryNamesInDirectory(
instanceId: string,
directoryPath: string,
) {
if (directoryPath === "") directoryPath = "/";
directoryPath += "/";
return createRuntimeServiceListFiles(instanceId, undefined, {
query: {
select: (data) => {
const files = data.files?.filter(
(file) =>
file.isDir &&
file.path?.startsWith(directoryPath) &&
file.path !== directoryPath,
);
const directoryNames = files?.map((file) => {
return file.path?.replace(directoryPath, "") ?? "";
});
const files =
data.files?.filter(
(file) =>
file.isDir &&
file.path?.startsWith(directoryPath) &&
file.path !== directoryPath,
) ?? [];
const directoryNames = files
?.map((file) => {
return file.path?.replace(directoryPath, "") ?? "";
})
// filter out dirs in subdirectories
.filter((filePath) => !filePath.includes("/"));
const sortedDirectoryNames = directoryNames?.sort(
(dirNameA, dirNameB) =>
dirNameA.localeCompare(dirNameB, undefined, {
Expand Down

0 comments on commit 1a6d5a0

Please sign in to comment.