Skip to content

Commit bf81dd9

Browse files
committed
Merge branch 'develop' into feat/misc-cluster-map
2 parents f32f8c9 + e97ee17 commit bf81dd9

30 files changed

+1258
-186
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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,4 @@ typings/
105105

106106
.DS_Store
107107
.npmrc
108+
.build-cache

package-lock.json

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

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.2.5-beta-12",
3+
"version": "1.2.7",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",
@@ -48,7 +48,7 @@
4848
"@typescript-eslint/eslint-plugin": "8.3.0",
4949
"@typescript-eslint/parser": "8.3.0",
5050
"@vitejs/plugin-react": "4.3.1",
51-
"eslint": "^8.56.0",
51+
"eslint": "^8.57.1",
5252
"eslint-config-airbnb": "^19.0.4",
5353
"eslint-config-prettier": "^9.1.0",
5454
"eslint-import-resolver-typescript": "^3.6.1",
@@ -107,6 +107,7 @@
107107
"tslib": "2.7.0"
108108
},
109109
"overrides": {
110+
"cross-spawn": "^7.0.5",
110111
"react-dates": {
111112
"react": "^17.0.2",
112113
"react-dom": "^17.0.2"

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

Lines changed: 8 additions & 0 deletions
Loading

src/Common/Api.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,14 @@ async function fetchAPI<K = object>(
150150
})
151151
} else {
152152
handleLogout()
153-
return { code: 401, status: 'Unauthorized', result: [] }
153+
// Using this way to ensure that the user is redirected to the login page
154+
// and the component has enough time to get unmounted otherwise the component re-renders
155+
// and try to access some property of a variable and log exception to sentry
156+
return await new Promise((resolve) => {
157+
setTimeout(() => {
158+
resolve({ code: 401, status: 'Unauthorized', result: [] })
159+
}, 1000)
160+
})
154161
}
155162
} else if (response.status >= 300 && response.status <= 599) {
156163
return await handleServerError(contentType, response)

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/Helper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ export const getUrlWithSearchParams = <T extends string | number = string | numb
511511
/**
512512
* Custom exception logger function for logging errors to sentry
513513
*/
514-
export const logExceptionToSentry = Sentry.captureException.bind(window)
514+
export const logExceptionToSentry: typeof Sentry.captureException = Sentry.captureException.bind(window)
515515

516516
export const customStyles = {
517517
control: (base, state) => ({

0 commit comments

Comments
 (0)