Skip to content

Commit e32bb77

Browse files
feat(file-tree): enable manual height resizing while preserving content adaptation when switching between sizes
1 parent 0f02295 commit e32bb77

File tree

3 files changed

+48
-38
lines changed

3 files changed

+48
-38
lines changed

src/common/components/mock-components/front-rich-components/file-tree/file-tree-resize.hook.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ElementSize, Size } from '@/core/model';
22
import { useCanvasContext } from '@/core/providers';
33
import { useEffect, useRef } from 'react';
4+
import { FileTreeItem, FileTreeSizeValues } from './file-tree.model';
45

56
// Hook to resize edition text area based on content
67
const useFileTreeResizeOnContentChange = (
@@ -54,6 +55,8 @@ const useFileTreeResizeOnSizeChange = (
5455
id: string,
5556
coords: { x: number; y: number },
5657
currentSize: Size,
58+
treeItems: FileTreeItem[],
59+
sizeValues: FileTreeSizeValues,
5760
size?: ElementSize
5861
) => {
5962
const previousSize = useRef(size);
@@ -66,22 +69,34 @@ const useFileTreeResizeOnSizeChange = (
6669

6770
const newWidth = size === 'XS' ? 150 : 230;
6871

69-
if (currentSize.width !== newWidth) {
72+
const minContentHeight =
73+
treeItems && sizeValues
74+
? treeItems.length * sizeValues.elementHeight +
75+
sizeValues.paddingY * 2
76+
: currentSize.height;
77+
78+
if (
79+
currentSize.width !== newWidth ||
80+
currentSize.height !== minContentHeight
81+
) {
7082
updateShapeSizeAndPosition(
7183
id,
7284
coords,
73-
{ width: newWidth, height: currentSize.height },
85+
{ width: newWidth, height: minContentHeight },
7486
false
7587
);
7688
}
7789
}
7890
}, [
7991
size,
8092
currentSize.width,
93+
currentSize.height,
8194
id,
8295
coords.x,
8396
coords.y,
8497
updateShapeSizeAndPosition,
98+
treeItems,
99+
sizeValues,
85100
]);
86101
};
87102

@@ -92,6 +107,8 @@ export const useFileTreeResize = (
92107
currentSize: Size,
93108
calculatedSize: Size,
94109
minHeight: number,
110+
treeItems: FileTreeItem[],
111+
sizeValues: FileTreeSizeValues,
95112
size?: ElementSize
96113
) => {
97114
useFileTreeResizeOnContentChange(
@@ -103,5 +120,13 @@ export const useFileTreeResize = (
103120
minHeight
104121
);
105122

106-
useFileTreeResizeOnSizeChange(id, coords, currentSize, size);
123+
useFileTreeResizeOnSizeChange(
124+
id,
125+
coords,
126+
currentSize,
127+
128+
treeItems,
129+
sizeValues,
130+
size
131+
);
107132
};

src/common/components/mock-components/front-rich-components/file-tree/file-tree.business.ts

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes';
22
import { ElementSize, ShapeSizeRestrictions, Size } from '@/core/model';
33
import { FONT_SIZE_VALUES } from '../../front-components/shape.const';
4-
5-
interface FileTreeSizeValues {
6-
fontSize: number;
7-
iconDimension: number;
8-
elementHeight: number;
9-
paddingX: number;
10-
paddingY: number;
11-
extraTextTopPadding: number;
12-
iconTextSpacing: number;
13-
indentationStep: number;
14-
}
4+
import {
5+
FileTreeDynamicSizeParams,
6+
FileTreeItem,
7+
FileTreeSizeValues,
8+
} from './file-tree.model';
159

1610
export const getFileTreeSizeValues = (
1711
size?: ElementSize
@@ -53,28 +47,6 @@ export const getFileTreeSizeValues = (
5347
}
5448
};
5549

56-
export const joinTextContent = (text: string): string[] => {
57-
return text.split(', ');
58-
};
59-
60-
// Symbol -> + Folder - Subfolder * File
61-
// Level -> Level 0: no indentation in Folder / Level 1: 1 indentation (3 spaces) in Subfolder / Level 2: 2 indentations (6 spaces) in File
62-
export interface FileTreeItem {
63-
type: 'folder' | 'subfolder' | 'file';
64-
text: string;
65-
level: number;
66-
}
67-
68-
interface FileTreeDynamicSizeParams {
69-
width: number;
70-
elementHeight: number;
71-
paddingY: number;
72-
paddingX: number;
73-
iconDimension: number;
74-
indentationStep: number;
75-
baseRestrictions: ShapeSizeRestrictions;
76-
}
77-
7850
export const parseFileTreeText = (text: string): FileTreeItem[] => {
7951
return text
8052
.split('\n')
@@ -128,6 +100,7 @@ export const calculateFileTreeDynamicSize = (
128100
): Size => {
129101
const {
130102
width,
103+
height,
131104
elementHeight,
132105
paddingY,
133106
paddingX,
@@ -151,7 +124,7 @@ export const calculateFileTreeDynamicSize = (
151124
defaultHeight: minContentHeight,
152125
};
153126

154-
const finalHeight = minContentHeight;
127+
const finalHeight = Math.max(height, minContentHeight);
155128

156129
return fitSizeToShapeSizeRestrictions(
157130
dynamicRestrictions,

src/common/components/mock-components/front-rich-components/file-tree/file-tree.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import { useShapeProps } from '@/common/components/shapes/use-shape-props.hook';
88
import { BASIC_SHAPE } from '../../front-components/shape.const';
99
import {
1010
calculateFileTreeDynamicSize,
11-
FileTreeItem,
1211
getFileTreeSizeValues,
1312
parseFileTreeText,
1413
} from './file-tree.business';
1514
import { useFileTreeResize } from './file-tree-resize.hook';
15+
import { FileTreeItem } from './file-tree.model';
1616

1717
const fileTreeShapeRestrictions: ShapeSizeRestrictions = {
1818
minWidth: 150,
@@ -74,6 +74,7 @@ export const FileTreeShape = forwardRef<any, FileTreeShapeProps>(
7474

7575
const restrictedSize = calculateFileTreeDynamicSize(treeItems, {
7676
width,
77+
height,
7778
elementHeight,
7879
paddingY,
7980
paddingX,
@@ -89,6 +90,17 @@ export const FileTreeShape = forwardRef<any, FileTreeShapeProps>(
8990
{ width, height },
9091
restrictedSize,
9192
fileTreeShapeRestrictions.minHeight,
93+
treeItems,
94+
{
95+
fontSize,
96+
iconDimension,
97+
elementHeight,
98+
extraTextTopPadding,
99+
paddingX,
100+
paddingY,
101+
iconTextSpacing,
102+
indentationStep,
103+
},
92104
otherProps?.size
93105
);
94106

0 commit comments

Comments
 (0)