Skip to content

Commit 6db0d55

Browse files
author
Amrit Kashyap Borah
committed
feat: uat changes
1 parent 536973e commit 6db0d55

8 files changed

Lines changed: 75 additions & 20 deletions

File tree

Lines changed: 4 additions & 0 deletions
Loading

src/Shared/Components/Button/Button.component.tsx

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

17-
import { MutableRefObject, PropsWithChildren, useEffect, useRef, useState } from 'react'
17+
import { MutableRefObject, PropsWithChildren, useCallback, useEffect, useRef, useState } from 'react'
1818
import { Link } from 'react-router-dom'
1919

2020
import { Progressing } from '@Common/Progressing'
@@ -61,7 +61,9 @@ const ButtonElement = ({
6161
// Added the specific class to ensure that the link override is applied
6262
const linkOrAnchorClassName = `${props.className} button__link ${props.disabled ? 'dc__disable-click' : ''}`
6363

64-
const refCallback = (el: HTMLButtonElement | HTMLAnchorElement) => {
64+
// NOTE: If the ref callback is re-created every render (i.e., not wrapped in useCallback),
65+
// it will be invoked on every render: first with null, then with the new node.
66+
const refCallback = useCallback((el: HTMLButtonElement | HTMLAnchorElement) => {
6567
if (!el) {
6668
return
6769
}
@@ -73,7 +75,7 @@ const ButtonElement = ({
7375
// eslint-disable-next-line no-param-reassign
7476
buttonRef.current = el
7577
}
76-
}
78+
}, [])
7779

7880
if (component === ButtonComponentType.link) {
7981
return (

src/Shared/Components/Header/PageHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ const PageHeader = ({
143143
)
144144

145145
const onAskButtonClick = () => {
146-
setSidePanelConfig(() => ({ state: SidePanelTab.ASK_DEVTRON }))
146+
setSidePanelConfig((prev) => ({ ...prev, state: SidePanelTab.ASK_DEVTRON }))
147147
}
148148

149149
const renderLogoutHelpSection = () => (

src/Shared/Components/Icon/Icon.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ import { ReactComponent as ICSpinny } from '@IconsV2/ic-spinny.svg'
142142
import { ReactComponent as ICSprayCan } from '@IconsV2/ic-spray-can.svg'
143143
import { ReactComponent as ICStack } from '@IconsV2/ic-stack.svg'
144144
import { ReactComponent as ICStamp } from '@IconsV2/ic-stamp.svg'
145+
import { ReactComponent as ICStopCircle } from '@IconsV2/ic-stop-circle.svg'
145146
import { ReactComponent as ICSuccess } from '@IconsV2/ic-success.svg'
146147
import { ReactComponent as ICSuspended } from '@IconsV2/ic-suspended.svg'
147148
import { ReactComponent as ICTata1mg } from '@IconsV2/ic-tata1mg.svg'
@@ -308,6 +309,7 @@ export const iconMap = {
308309
'ic-spray-can': ICSprayCan,
309310
'ic-stack': ICStack,
310311
'ic-stamp': ICStamp,
312+
'ic-stop-circle': ICStopCircle,
311313
'ic-success': ICSuccess,
312314
'ic-suspended': ICSuspended,
313315
'ic-tata1mg': ICTata1mg,

src/Shared/Components/Textarea/Textarea.component.tsx

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

17-
import { TextareaHTMLAttributes, useEffect, useRef, useState } from 'react'
17+
import { TextareaHTMLAttributes, useCallback, useEffect, useRef, useState } from 'react'
1818

1919
import { useThrottledEffect } from '@Common/Helper'
2020
import {
@@ -25,16 +25,15 @@ import {
2525
import { deriveBorderRadiusAndBorderClassFromConfig } from '@Shared/Helpers'
2626

2727
import { FormFieldWrapper, getFormFieldAriaAttributes } from '../FormFieldWrapper'
28-
import { TEXTAREA_CONSTRAINTS } from './constants'
2928
import { TextareaProps } from './types'
29+
import { getTextAreaConstraintsForSize } from './utils'
3030

3131
import './textarea.scss'
3232

33-
const { MIN_HEIGHT, AUTO_EXPANSION_MAX_HEIGHT } = TEXTAREA_CONSTRAINTS
34-
3533
const Textarea = ({
3634
name,
3735
label,
36+
textareaRef: textareaRefProp,
3837
fullWidth,
3938
error,
4039
helperText,
@@ -51,20 +50,37 @@ const Textarea = ({
5150
hideFormFieldInfo,
5251
value,
5352
borderConfig,
53+
disableResize,
54+
newlineOnShiftEnter = false,
5455
...props
5556
}: TextareaProps) => {
5657
const textareaRef = useRef<HTMLTextAreaElement>(null)
5758
// If the passed value remains the same, the component will behave as un-controlled
5859
// else, it behaves as controlled
5960
const [text, setText] = useState('')
6061

62+
const { MIN_HEIGHT, AUTO_EXPANSION_MAX_HEIGHT } = getTextAreaConstraintsForSize(size)
63+
6164
const updateRefsHeight = (height: number) => {
6265
const refElement = textareaRef.current
6366
if (refElement) {
6467
refElement.style.height = `${height}px`
6568
}
6669
}
6770

71+
const refCallback = useCallback((node: HTMLTextAreaElement) => {
72+
if (textareaRefProp) {
73+
if (typeof textareaRefProp === 'function') {
74+
textareaRefProp(node)
75+
} else {
76+
// eslint-disable-next-line no-param-reassign
77+
textareaRefProp.current = node
78+
}
79+
}
80+
81+
textareaRef.current = node
82+
}, [])
83+
6884
const reInitHeight = () => {
6985
const currentHeight = parseInt(textareaRef.current.style.height, 10)
7086
let nextHeight = textareaRef.current.scrollHeight || 0
@@ -116,9 +132,13 @@ const Textarea = ({
116132
const handleKeyDown: TextareaHTMLAttributes<HTMLTextAreaElement>['onKeyDown'] = (
117133
event: React.KeyboardEvent<HTMLTextAreaElement>,
118134
) => {
119-
if ((event.key === 'Enter' && !event.metaKey && !event.ctrlKey) || event.key === 'Escape') {
135+
if (event.key === 'Enter' || event.key === 'Escape') {
120136
event.stopPropagation()
121137

138+
if (newlineOnShiftEnter && event.key === 'Enter' && !event.shiftKey) {
139+
event.preventDefault()
140+
}
141+
122142
if (event.key === 'Escape') {
123143
textareaRef.current.blur()
124144
}
@@ -163,11 +183,12 @@ const Textarea = ({
163183
onBlur={handleBlur}
164184
onKeyDown={handleKeyDown}
165185
className={`${COMPONENT_SIZE_TYPE_TO_FONT_AND_BLOCK_PADDING_MAP[size]} ${COMPONENT_SIZE_TYPE_TO_INLINE_PADDING_MAP[size]} ${deriveBorderRadiusAndBorderClassFromConfig({ borderConfig, borderRadiusConfig })} w-100 dc__overflow-auto textarea`}
166-
ref={textareaRef}
186+
ref={refCallback}
167187
style={{
168188
// No max height when user is expanding
169189
maxHeight: 'none',
170190
minHeight: MIN_HEIGHT,
191+
resize: disableResize ? 'none' : 'vertical',
171192
}}
172193
/>
173194
</FormFieldWrapper>

src/Shared/Components/Textarea/types.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,25 @@ export interface TextareaProps
3535
*
3636
* @default ComponentSizeType.large
3737
*/
38-
size?: Extract<ComponentSizeType, ComponentSizeType.medium | ComponentSizeType.large>
38+
size?: Extract<ComponentSizeType, ComponentSizeType.small | ComponentSizeType.medium | ComponentSizeType.large>
3939
/**
4040
* Value of the textarea
4141
*/
4242
value: string
43+
/**
44+
* If true, the textarea resize is disabled
45+
*
46+
* @default false
47+
*/
48+
disableResize?: true
49+
/**
50+
* Allows inserting a newline with Shift + Enter instead of Enter alone.
51+
*
52+
* When enabled, pressing Enter submits the form, while Shift + Enter inserts a newline.
53+
* Useful for forms where Enter should trigger submission, but multiline input is still needed.
54+
*
55+
* @default false
56+
*/
57+
newlineOnShiftEnter?: boolean
58+
textareaRef?: React.MutableRefObject<HTMLTextAreaElement> | React.RefCallback<HTMLTextAreaElement>
4359
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ComponentSizeType } from '@Shared/constants'
2+
3+
import { TEXTAREA_CONSTRAINTS } from './constants'
4+
import { TextareaProps } from './types'
5+
6+
export const getTextAreaConstraintsForSize = (size: TextareaProps['size']) => {
7+
if (size === ComponentSizeType.small) {
8+
return {
9+
MIN_HEIGHT: 56,
10+
AUTO_EXPANSION_MAX_HEIGHT: 150,
11+
}
12+
}
13+
14+
return TEXTAREA_CONSTRAINTS
15+
}

src/Shared/Providers/types.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,10 @@ export enum SidePanelTab {
3535
ASK_DEVTRON = 'ask-devtron',
3636
}
3737

38-
export type SidePanelConfig =
39-
| {
40-
state: SidePanelTab.DOCUMENTATION
41-
docLink?: string | null
42-
}
43-
| {
44-
state: SidePanelTab.ASK_DEVTRON | 'closed'
45-
docLink?: never
46-
}
38+
export interface SidePanelConfig {
39+
state: SidePanelTab | 'closed'
40+
docLink?: string | null
41+
}
4742

4843
export interface MainContext {
4944
serverMode: SERVER_MODE

0 commit comments

Comments
 (0)