Skip to content

Commit 96e5977

Browse files
Merge pull request #803 from devtron-labs/feat/tree-view
feat: add tree view component
2 parents a692030 + b4445cd commit 96e5977

28 files changed

Lines changed: 1203 additions & 187 deletions

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.17.0-pre-1",
3+
"version": "1.17.0-pre-4",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { useState } from 'react'
2+
3+
import { SUB_PIXEL_ERROR } from './constants'
4+
5+
const useIsTextTruncated = () => {
6+
const [isTextTruncated, setIsTextTruncated] = useState(false)
7+
8+
const handleMouseEnterEvent: React.MouseEventHandler = (event) => {
9+
const { currentTarget: node } = event
10+
const isTextOverflowing =
11+
node.scrollWidth > node.clientWidth + SUB_PIXEL_ERROR ||
12+
node.scrollHeight > node.clientHeight + SUB_PIXEL_ERROR
13+
if (isTextOverflowing && !isTextTruncated) {
14+
setIsTextTruncated(true)
15+
} else if (!isTextOverflowing && isTextTruncated) {
16+
setIsTextTruncated(false)
17+
}
18+
}
19+
20+
return {
21+
isTextTruncated,
22+
handleMouseEnterEvent,
23+
}
24+
}
25+
26+
export default useIsTextTruncated
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const SUB_PIXEL_ERROR = 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as useIsTextTruncated } from './UseIsTextTruncated'

src/Common/Hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
export { useClickOutside } from './UseClickOutside/UseClickOutside'
1818
export { useGetUserRoles } from './UseGetUserRoles'
19+
export { useIsTextTruncated } from './UseIsTextTruncated'
1920
export * from './UseRegisterShortcut'
2021
export * from './useStateFilters'
2122
export * from './useUrlFilters'

src/Common/Tooltip/Tooltip.tsx

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { cloneElement, useState } from 'react'
17+
import { cloneElement } from 'react'
1818
import TippyJS from '@tippyjs/react'
1919

20-
import { SUB_PIXEL_ERROR } from './constants'
20+
import { useIsTextTruncated } from '@Common/Hooks'
21+
2122
import ShortcutKeyComboTooltipContent from './ShortcutKeyComboTooltipContent'
2223
import { TooltipProps } from './types'
2324

@@ -32,19 +33,7 @@ const Tooltip = ({
3233
children: child,
3334
...rest
3435
}: TooltipProps) => {
35-
const [isTextTruncated, setIsTextTruncated] = useState(false)
36-
37-
const handleMouseEnterEvent: React.MouseEventHandler = (event) => {
38-
const { currentTarget: node } = event
39-
const isTextOverflowing =
40-
node.scrollWidth > node.clientWidth + SUB_PIXEL_ERROR ||
41-
node.scrollHeight > node.clientHeight + SUB_PIXEL_ERROR
42-
if (isTextOverflowing && !isTextTruncated) {
43-
setIsTextTruncated(true)
44-
} else if (!isTextOverflowing && isTextTruncated) {
45-
setIsTextTruncated(false)
46-
}
47-
}
36+
const { isTextTruncated, handleMouseEnterEvent } = useIsTextTruncated()
4837

4938
const showTooltipWhenShortcutKeyComboProvided =
5039
!!shortcutKeyCombo && (alwaysShowTippyOnHover === undefined || alwaysShowTippyOnHover)

src/Common/Tooltip/constants.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,3 @@
1717
export const TOOLTIP_CONTENTS = {
1818
INVALID_INPUT: 'Valid input is required for all mandatory fields.',
1919
}
20-
21-
export const SUB_PIXEL_ERROR = 1

src/Pages/ResourceBrowser/ResourceBrowser.Types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export interface ApiResourceType {
3838

3939
export interface K8SObjectBaseType {
4040
name: string
41-
isExpanded: boolean
4241
}
4342

4443
interface K8sRequestResourceIdentifierType {

src/Shared/Components/ActionMenu/ActionMenuItem.tsx

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ import { LegacyRef, MouseEvent, Ref } from 'react'
22
import { Link } from 'react-router-dom'
33

44
import { Tooltip } from '@Common/Tooltip'
5-
import { ComponentSizeType } from '@Shared/constants'
65

7-
import { Button, ButtonProps, ButtonVariantType } from '../Button'
86
import { Icon } from '../Icon'
9-
import { NumbersCount } from '../NumbersCount'
107
import { getTooltipProps } from '../SelectPicker/common'
11-
import { DTSwitch, DTSwitchProps } from '../Switch'
12-
import { ActionMenuItemProps, ActionMenuItemType } from './types'
8+
import { TrailingItem } from '../TrailingItem'
9+
import { ActionMenuItemProps } from './types'
1310

1411
const COMMON_ACTION_MENU_ITEM_CLASS = 'w-100 flex left top dc__gap-8 py-6 px-8'
1512

@@ -48,24 +45,6 @@ export const ActionMenuItem = <T extends string | number>({
4845
onClick(item, e)
4946
}
5047

51-
const handleTrailingSwitchChange =
52-
({ type: trailingItemType, config }: ActionMenuItemType<T>['trailingItem']): DTSwitchProps['onChange'] =>
53-
(e) => {
54-
if (trailingItemType === 'switch') {
55-
e.stopPropagation()
56-
config.onChange(e)
57-
}
58-
}
59-
60-
const handleTrailingButtonClick =
61-
({ type: trailingItemType, config }: ActionMenuItemType<T>['trailingItem']): ButtonProps['onClick'] =>
62-
(e) => {
63-
e.stopPropagation()
64-
if (trailingItemType === 'button' && config.onClick) {
65-
config.onClick(e)
66-
}
67-
}
68-
6948
// RENDERERS
7049
const renderIcon = (iconProps: typeof startIcon) =>
7150
iconProps && (
@@ -79,42 +58,7 @@ export const ActionMenuItem = <T extends string | number>({
7958
return null
8059
}
8160

82-
const { type: trailingItemType, config } = trailingItem
83-
84-
switch (trailingItemType) {
85-
case 'icon':
86-
return renderIcon(config)
87-
case 'text': {
88-
const { value, icon } = config
89-
return (
90-
<span className="flex dc__gap-2 mt-2">
91-
<span className="fs-12 lh-1-5 fw-4 cn-7">{value}</span>
92-
{icon && <Icon name={icon.name} color={icon.color || (isNegativeType ? 'R500' : 'N700')} />}
93-
</span>
94-
)
95-
}
96-
case 'counter':
97-
return <NumbersCount count={config.value} />
98-
case 'switch':
99-
return (
100-
<DTSwitch
101-
{...config}
102-
onChange={handleTrailingSwitchChange(trailingItem)}
103-
size={ComponentSizeType.small}
104-
/>
105-
)
106-
case 'button':
107-
return (
108-
<Button
109-
{...(config as ButtonProps)}
110-
onClick={handleTrailingButtonClick(trailingItem)}
111-
variant={ButtonVariantType.borderLess}
112-
size={ComponentSizeType.xxs}
113-
/>
114-
)
115-
default:
116-
return null
117-
}
61+
return <TrailingItem {...trailingItem} variant={type} />
11862
}
11963

12064
const renderContent = () => (

0 commit comments

Comments
 (0)