Skip to content

Commit 15b0dc6

Browse files
committed
Merge branch 'feat/approval-policy' of github.com:devtron-labs/devtron-fe-common-lib into fix/approval-policy
2 parents 7b8e0f3 + 18b9705 commit 15b0dc6

File tree

21 files changed

+1220
-168
lines changed

21 files changed

+1220
-168
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ src/Common/CodeEditor/CodeEditor.tsx
1515
src/Common/Common.service.ts
1616
src/Common/CustomInput/CustomInput.tsx
1717
src/Common/CustomTagSelector/PropagateTagInfo.tsx
18-
src/Common/CustomTagSelector/ResizableTagTextArea.tsx
1918
src/Common/CustomTagSelector/TagDetails.tsx
2019
src/Common/CustomTagSelector/TagLabelSelect.tsx
2120
src/Common/CustomTagSelector/TagLabelValueSelector.tsx

src/Assets/Icon/ic-clear-square.svg

Lines changed: 8 additions & 0 deletions
Loading

src/Common/CustomTagSelector/ResizableTagTextArea.tsx

Lines changed: 55 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,95 +14,110 @@
1414
* limitations under the License.
1515
*/
1616

17-
import React, { useEffect, useState } from 'react'
18-
import { useThrottledEffect } from '../Helper'
17+
import { useEffect } from 'react'
18+
19+
import { useThrottledEffect } from '@Common/Helper'
20+
1921
import { ResizableTagTextAreaProps } from './Types'
2022

2123
export const ResizableTagTextArea = ({
22-
className,
24+
value,
2325
minHeight,
2426
maxHeight,
25-
value,
26-
onChange,
2727
onBlur,
2828
onFocus,
29-
placeholder,
30-
tabIndex,
3129
refVar,
3230
dependentRef,
33-
dataTestId,
34-
handleKeyDown,
35-
disabled,
31+
dependentRefs,
32+
className = '',
3633
disableOnBlurResizeToMinHeight,
34+
id,
35+
...restProps
3736
}: ResizableTagTextAreaProps) => {
38-
const [text, setText] = useState(value ?? '')
37+
const updateDependentRefsHeight = (height: number) => {
38+
const refElement = dependentRef?.current
39+
if (refElement) {
40+
refElement.style.height = `${height}px`
41+
}
3942

40-
useEffect(() => {
41-
setText(value)
42-
}, [value])
43+
Object.values(dependentRefs || {}).forEach((ref) => {
44+
const dependentRefElement = ref?.current
45+
if (dependentRefElement) {
46+
dependentRefElement.style.height = `${height}px`
47+
}
48+
})
49+
}
4350

44-
const handleChange = (event) => {
45-
setText(event.target.value)
46-
onChange?.(event)
51+
const updateRefsHeight = (height: number) => {
52+
const refElement = refVar?.current
53+
if (refElement) {
54+
refElement.style.height = `${height}px`
55+
}
56+
updateDependentRefsHeight(height)
4757
}
4858

4959
const reInitHeight = () => {
50-
refVar.current.style.height = `${minHeight}px`
60+
updateRefsHeight(minHeight || 0)
61+
62+
let nextHeight = refVar?.current?.scrollHeight || 0
63+
5164
if (dependentRef) {
52-
dependentRef.current.style.height = `${minHeight}px`
65+
const refElement = dependentRef.current
66+
if (refElement && refElement.scrollHeight > nextHeight) {
67+
nextHeight = refElement.scrollHeight
68+
}
5369
}
54-
let nextHeight = refVar.current.scrollHeight
55-
if (dependentRef && nextHeight < dependentRef.current.scrollHeight) {
56-
nextHeight = dependentRef.current.scrollHeight
70+
71+
if (dependentRefs) {
72+
Object.values(dependentRefs).forEach((ref) => {
73+
const refElement = ref.current
74+
if (refElement && refElement.scrollHeight > nextHeight) {
75+
nextHeight = refElement.scrollHeight
76+
}
77+
})
5778
}
79+
5880
if (minHeight && nextHeight < minHeight) {
5981
nextHeight = minHeight
6082
}
83+
6184
if (maxHeight && nextHeight > maxHeight) {
6285
nextHeight = maxHeight
6386
}
64-
refVar.current.style.height = `${nextHeight}px`
65-
if (dependentRef) {
66-
dependentRef.current.style.height = `${nextHeight}px`
67-
}
87+
88+
updateRefsHeight(nextHeight)
6889
}
6990

7091
useEffect(() => {
7192
reInitHeight()
7293
}, [])
7394

74-
useThrottledEffect(reInitHeight, 500, [text])
95+
useThrottledEffect(reInitHeight, 500, [value])
7596

7697
const handleOnBlur = (event) => {
7798
if (!disableOnBlurResizeToMinHeight) {
78-
refVar.current.style.height = `${minHeight}px`
79-
if (dependentRef) {
80-
dependentRef.current.style.height = `${minHeight}px`
81-
}
99+
updateRefsHeight(minHeight)
82100
}
83-
onBlur && onBlur(event)
101+
onBlur?.(event)
84102
}
85103

86104
const handleOnFocus = (event) => {
87105
reInitHeight()
88-
onFocus && onFocus(event)
106+
onFocus?.(event)
89107
}
90108

91109
return (
92110
<textarea
111+
{...restProps}
112+
id={id}
113+
data-testid={id}
93114
rows={1}
94115
ref={refVar}
95-
value={text}
96-
placeholder={placeholder}
116+
value={value}
97117
className={`${className || ''} lh-20`}
98118
style={{ resize: 'none' }}
99-
onChange={handleChange}
100119
onBlur={handleOnBlur}
101120
onFocus={handleOnFocus}
102-
tabIndex={tabIndex}
103-
data-testid={dataTestId}
104-
onKeyDown={handleKeyDown}
105-
disabled={disabled}
106121
/>
107122
)
108123
}

src/Common/CustomTagSelector/TagLabelValueSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export const TagLabelValueSelector = ({
192192
tabIndex={tabIndex}
193193
refVar={refVar}
194194
dependentRef={dependentRef}
195-
dataTestId={`tag-${tagInputType === KEY_VALUE.KEY ? 'key' : 'value'}-${selectedTagIndex}`}
195+
id={`tag-${tagInputType === KEY_VALUE.KEY ? 'key' : 'value'}-${selectedTagIndex}`}
196196
/>
197197
</PopupMenu.Button>
198198
{popupMenuBody && (

src/Common/CustomTagSelector/Types.ts

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

17+
import { DetailedHTMLProps, MutableRefObject, TextareaHTMLAttributes } from 'react'
1718
import { KEY_VALUE } from '../Constants'
1819
import { OptionType } from '../Types'
1920

@@ -68,25 +69,18 @@ export interface TagLabelValueSelectorType {
6869
tagInputType?: KEY_VALUE
6970
placeholder?: string
7071
tabIndex?: number
71-
refVar?: React.MutableRefObject<HTMLTextAreaElement>
72-
dependentRef?: React.MutableRefObject<HTMLTextAreaElement>
72+
refVar?: MutableRefObject<HTMLTextAreaElement>
73+
dependentRef?: MutableRefObject<HTMLTextAreaElement>
7374
noBackDrop?: boolean
7475
}
7576

76-
export interface ResizableTagTextAreaProps {
77-
className?: string
77+
export interface ResizableTagTextAreaProps
78+
extends Omit<DetailedHTMLProps<TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, 'value'> {
7879
minHeight?: number
7980
maxHeight?: number
80-
value?: string
81-
onChange?: (e) => void
82-
onBlur?: (e) => void
83-
onFocus?: (e) => void
84-
placeholder?: string
85-
tabIndex?: number
86-
refVar?: React.MutableRefObject<HTMLTextAreaElement>
87-
dependentRef?: React.MutableRefObject<HTMLTextAreaElement>
88-
dataTestId?: string
89-
handleKeyDown?: any
90-
disabled?: boolean
81+
value: string
82+
refVar?: MutableRefObject<HTMLTextAreaElement>
83+
dependentRef?: MutableRefObject<HTMLTextAreaElement>
84+
dependentRefs?: Record<string | number, MutableRefObject<HTMLTextAreaElement>>
9185
disableOnBlurResizeToMinHeight?: boolean
9286
}

src/Common/Types.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1616

1717
import React, { ReactNode, CSSProperties, ReactElement, MutableRefObject } from 'react'
1818
import { TippyProps } from '@tippyjs/react'

0 commit comments

Comments
 (0)