Skip to content

Commit

Permalink
fix(dashboard): folders with same name but different parents (#8605)
Browse files Browse the repository at this point in the history
* fix(dashboard): folders with same name but different parents

* remove log
  • Loading branch information
CompuIves authored Sep 11, 2024
1 parent bb19860 commit 031d9a6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
DashboardSkeletonRow,
} from 'app/pages/Dashboard/types';

import { getParentPath, normalizePath } from '../../../utils/path';

const skeletonRow = {
type: 'skeleton-row' as 'skeleton-row',
};
Expand Down Expand Up @@ -36,10 +38,10 @@ export const useFilteredItems = (

useEffect(() => {
const sandboxesForPath = getFilteredSandboxes(folderSandboxes || []);
const parent = path.split('/').pop();
const normalizedPath = normalizePath(path);
const folderFolders =
allCollections?.filter(
collection => collection.level === level && collection.parent === parent
collection => getParentPath(collection.path) === normalizedPath
) || [];

const sortedFolders = orderBy(folderFolders, 'name').sort(a => 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from './utils';
import { NEW_FOLDER_ID } from './constants';
import { RowItem } from './RowItem';
import { getParentPath } from '../utils/path';

interface NestableRowItemProps {
name: string;
Expand Down Expand Up @@ -110,7 +111,7 @@ export const NestableRowItem: React.FC<NestableRowItemProps> = ({
});
} else {
subFolders = folders.filter(folder => {
const parentPath = folder.path.split('/').slice(0, -1).join('/');
const parentPath = getParentPath(folder.path);

return parentPath === folderPath;
});
Expand Down
17 changes: 17 additions & 0 deletions packages/app/src/app/pages/Dashboard/utils/path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export function getParentPath(path: string) {
if (path === '/' || path === '') {
return '/';
}

const split = path.split('/');
split.pop();

return split.join('/');
}

export function normalizePath(path: string) {
if (!path.startsWith('/')) {
return '/' + path;
}
return path;
}

0 comments on commit 031d9a6

Please sign in to comment.