Commit 40df5488 authored by mehdilouraoui's avatar mehdilouraoui
Browse files

feat(ruler): add total folder count

parent caf21db3
......@@ -9,6 +9,7 @@ import {
getMaxDepth,
getVirtualPathToIdFromStore,
ROOT_FF_ID,
isFolder,
} from "reducers/files-and-folders/files-and-folders-selectors";
import { moveElement } from "reducers/files-and-folders/files-and-folders-thunks";
import { getTagsFromStore } from "reducers/tags/tags-selectors";
......@@ -21,7 +22,10 @@ import {
useWorkspaceMetadata,
} from "reducers/workspace-metadata/workspace-metadata-selectors";
import { useFillColor } from "util/color/color-util";
import { createFilePathSequence } from "util/files-and-folders/file-and-folders-utils";
import {
createFilePathSequence,
getAllChildren,
} from "util/files-and-folders/file-and-folders-utils";
import IcicleMain from "./icicle-main";
import { IcicleSortMethod } from "reducers/icicle-sort-method/icicle-sort-method-types";
import { useIcicleSortMethod } from "reducers/icicle-sort-method/icicle-sort-method-selectors";
......@@ -58,6 +62,15 @@ export default function IcicleApiToProps() {
[filesAndFoldersMetadata, filesAndFolders]
);
const getAllChildrenFolderCount = useCallback(
(id: string) => {
const children = getAllChildren(filesAndFolders, id);
const folderCount = children.map(getFfByFfId).filter(isFolder).length - 1;
return folderCount;
},
[filesAndFolders]
);
const maxDepth = useMemo(() => getMaxDepth(filesAndFolders), [
filesAndFolders,
]);
......@@ -137,6 +150,7 @@ export default function IcicleApiToProps() {
originalPath={originalPath}
fillColor={fillColor}
getChildrenIdFromId={getChildrenIdFromId}
getAllChildrenFolderCount={getAllChildrenFolderCount}
elementsToDelete={elementsToDelete}
getFfByFfId={getFfByFfId}
maxDepth={maxDepth}
......
......@@ -113,6 +113,7 @@ type IcicleMainProps = {
hoverSequence: string[];
lockedSequence: string[];
elementsToDelete: string[];
getAllChildrenFolderCount: (id: string) => number;
getChildrenIdFromId: (id: string) => string[];
getFfByFfId: (id: string) => FilesAndFolders & FilesAndFoldersMetadata;
elementWeightMethod: ElementWeightMethod;
......@@ -137,6 +138,7 @@ const IcicleMain: FC<IcicleMainProps> = ({
hoverSequence,
lockedSequence,
elementsToDelete,
getAllChildrenFolderCount,
getChildrenIdFromId,
getFfByFfId,
elementWeightMethod,
......@@ -375,6 +377,7 @@ const IcicleMain: FC<IcicleMainProps> = ({
</IcicleWrapper>
<RulerWrapper>
<Ruler
getAllChildrenFolderCount={getAllChildrenFolderCount}
getFfByFfId={getFfByFfId}
widthUnit={viewBoxWidth}
hoveredDims={hoveredDims}
......
......@@ -50,10 +50,9 @@ const getFilesCount = (node: FilesAndFoldersMetadata): string =>
*/
const getFoldersCount = (
node: FilesAndFolders,
getFfById: (id: string) => FilesAndFolders & FilesAndFoldersMetadata
getAllChildrenFolderCount: (id: string) => number
): string => {
const { children } = node;
const foldersCount = children.map(getFfById).filter(isFolder).length;
const foldersCount = getAllChildrenFolderCount(node.id);
return `${foldersCount} ${translations.t("common.folders")}`;
};
......@@ -77,7 +76,7 @@ const makePercentageText = (nodeSize: number, totalSize: number) => {
const makeRulerText = (
node: FilesAndFolders & FilesAndFoldersMetadata,
rootNode: FilesAndFolders & FilesAndFoldersMetadata,
getFfById: (id: string) => FilesAndFolders & FilesAndFoldersMetadata
getAllChildrenFolderCount: (id: string) => number
) => {
const { childrenTotalSize } = node;
const { childrenTotalSize: rootChildrenTotalSize } = rootNode;
......@@ -89,7 +88,7 @@ const makeRulerText = (
const rulerInfo = [percentageText, filesAndFolderSize];
if (isFolder(node)) {
rulerInfo.push(getFoldersCount(node, getFfById));
rulerInfo.push(getFoldersCount(node, getAllChildrenFolderCount));
rulerInfo.push(getFilesCount(node));
}
......@@ -97,6 +96,7 @@ const makeRulerText = (
};
type RulerProps = {
getAllChildrenFolderCount: any;
widthUnit: number;
totalSize: number;
hoveredDims: Dims | null;
......@@ -108,6 +108,7 @@ type RulerProps = {
};
const Ruler: FC<RulerProps> = ({
getAllChildrenFolderCount,
widthUnit,
totalSize,
hoveredDims = EmptyDims,
......@@ -125,7 +126,7 @@ const Ruler: FC<RulerProps> = ({
? makeRulerText(
getFfByFfId(elementId),
getFfByFfId(ROOT_FF_ID),
getFfByFfId
getAllChildrenFolderCount
)
: "";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment