Skip to content

Commit 9a1bf3a

Browse files
committed
refactor: Multiple improvements and review fixes
1 parent 0d14f3a commit 9a1bf3a

File tree

15 files changed

+112
-128
lines changed

15 files changed

+112
-128
lines changed

src/Common/CustomTagSelector/ResizableTagTextArea.tsx

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,54 +24,68 @@ export const ResizableTagTextArea = ({
2424
value,
2525
minHeight,
2626
maxHeight,
27-
dataTestId,
2827
onBlur,
2928
onFocus,
3029
refVar,
3130
dependentRef,
31+
dependentRefs,
3232
className = '',
3333
disableOnBlurResizeToMinHeight,
34-
...resProps
34+
id,
35+
...restProps
3536
}: ResizableTagTextAreaProps) => {
36-
const updateRefHeight = (height: number) => {
37-
const refElement = refVar?.current
37+
const updateDependentRefsHeight = (height: number) => {
38+
const refElement = dependentRef?.current
3839
if (refElement) {
3940
refElement.style.height = `${height}px`
4041
}
42+
43+
Object.values(dependentRefs || {}).forEach((ref) => {
44+
const dependentRefElement = ref?.current
45+
if (dependentRefElement) {
46+
dependentRefElement.style.height = `${height}px`
47+
}
48+
})
4149
}
4250

43-
const updateDependentRefsHeight = (height: number) => {
44-
if (dependentRef) {
45-
Object.values(Array.isArray(dependentRef) ? dependentRef : [dependentRef]).forEach((ref) => {
46-
const refElement = ref.current
47-
if (refElement) {
48-
refElement.style.height = `${height}px`
49-
}
50-
})
51+
const updateRefsHeight = (height: number) => {
52+
const refElement = refVar?.current
53+
if (refElement) {
54+
refElement.style.height = `${height}px`
5155
}
56+
updateDependentRefsHeight(height)
5257
}
5358

5459
const reInitHeight = () => {
55-
updateRefHeight(minHeight || 0)
56-
updateDependentRefsHeight(minHeight || 0)
60+
updateRefsHeight(minHeight || 0)
5761

5862
let nextHeight = refVar?.current?.scrollHeight || 0
63+
5964
if (dependentRef) {
60-
Object.values(Array.isArray(dependentRef) ? dependentRef : [dependentRef]).forEach((ref) => {
65+
const refElement = dependentRef.current
66+
if (refElement && refElement.scrollHeight > nextHeight) {
67+
nextHeight = refElement.scrollHeight
68+
}
69+
}
70+
71+
if (dependentRefs) {
72+
Object.values(dependentRefs).forEach((ref) => {
6173
const refElement = ref.current
6274
if (refElement && refElement.scrollHeight > nextHeight) {
6375
nextHeight = refElement.scrollHeight
6476
}
6577
})
6678
}
79+
6780
if (minHeight && nextHeight < minHeight) {
6881
nextHeight = minHeight
6982
}
83+
7084
if (maxHeight && nextHeight > maxHeight) {
7185
nextHeight = maxHeight
7286
}
73-
updateRefHeight(nextHeight)
74-
updateDependentRefsHeight(nextHeight)
87+
88+
updateRefsHeight(nextHeight)
7589
}
7690

7791
useEffect(() => {
@@ -82,8 +96,7 @@ export const ResizableTagTextArea = ({
8296

8397
const handleOnBlur = (event) => {
8498
if (!disableOnBlurResizeToMinHeight) {
85-
updateRefHeight(minHeight)
86-
updateDependentRefsHeight(minHeight)
99+
updateRefsHeight(minHeight)
87100
}
88101
onBlur?.(event)
89102
}
@@ -95,15 +108,16 @@ export const ResizableTagTextArea = ({
95108

96109
return (
97110
<textarea
98-
{...resProps}
111+
{...restProps}
112+
id={id}
113+
data-testid={id}
99114
rows={1}
100115
ref={refVar}
101116
value={value}
102117
className={`${className || ''} lh-20`}
103118
style={{ resize: 'none' }}
104119
onBlur={handleOnBlur}
105120
onFocus={handleOnFocus}
106-
data-testid={dataTestId}
107121
/>
108122
)
109123
}

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: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ export interface ResizableTagTextAreaProps
8080
maxHeight?: number
8181
value: string
8282
refVar?: MutableRefObject<HTMLTextAreaElement>
83-
dependentRef?:
84-
| MutableRefObject<HTMLTextAreaElement>
85-
| Record<string | number, MutableRefObject<HTMLTextAreaElement>>
86-
dataTestId?: string
83+
dependentRef?: MutableRefObject<HTMLTextAreaElement>
84+
dependentRefs?: Record<string | number, MutableRefObject<HTMLTextAreaElement>>
8785
disableOnBlurResizeToMinHeight?: boolean
8886
}

src/Shared/Components/DynamicDataTable/DynamicDataTableHeader.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export const DynamicDataTableHeader = <K extends string>({
3434
const isActionButtonAtTheStart =
3535
getActionButtonPosition({ headers, actionButtonConfig }) === 0 && actionButtonConfig.position !== 'end'
3636

37+
const handleSorting = (key: K) => () => sortingConfig?.handleSorting(key)
38+
3739
// RENDERERS
3840
const renderHeaderCell = ({ key, label, isSortable }: DynamicDataTableHeaderType<K>) => (
3941
<div
@@ -44,7 +46,7 @@ export const DynamicDataTableHeader = <K extends string>({
4446
<button
4547
type="button"
4648
className="cn-7 fs-12 lh-20-imp fw-6 flexbox dc__align-items-center dc__gap-2 dc__transparent"
47-
onClick={sortingConfig?.handleSorting}
49+
onClick={handleSorting(key)}
4850
>
4951
{label}
5052
<ICArrowDown
@@ -78,7 +80,7 @@ export const DynamicDataTableHeader = <K extends string>({
7880
return (
7981
<div className={`bcn-2 p-1 ${hasRows ? 'dc__top-radius-4' : 'br-4'}`}>
8082
<div
81-
className="dynamic-data-table two-columns w-100 bcn-1 br-4"
83+
className="dynamic-data-table header-column w-100 bcn-1 br-4"
8284
style={{ gridTemplateColumns: headerGridTemplateColumn }}
8385
>
8486
<div className="dynamic-data-table__row">

src/Shared/Components/DynamicDataTable/DynamicDataTableRow.tsx

Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { createElement, createRef, Fragment, ReactElement, RefObject, useEffect,
22
// eslint-disable-next-line import/no-extraneous-dependencies
33
import { followCursor } from 'tippy.js'
44

5-
import { ReactComponent as ICClose } from '@Icons/ic-close.svg'
6-
import { DEFAULT_SECRET_PLACEHOLDER } from '@Shared/constants'
5+
import { ReactComponent as ICCross } from '@Icons/ic-cross.svg'
76
import { Tooltip } from '@Common/Tooltip'
87

98
import { ConditionalWrap } from '@Common/Helper'
@@ -32,7 +31,6 @@ const conditionalWrap =
3231
export const DynamicDataTableRow = <K extends string>({
3332
rows = [],
3433
headers,
35-
maskValue,
3634
readOnly,
3735
isAdditionNotAllowed,
3836
isDeletionNotAllowed,
@@ -122,6 +120,7 @@ export const DynamicDataTableRow = <K extends string>({
122120
<SelectPicker<string, false>
123121
{...row.data[key].props}
124122
inputId={`data-table-${row.id}-${key}-cell`}
123+
classNamePrefix="dynamic-data-table__cell__select-picker"
125124
variant={SelectPickerVariantType.BORDER_LESS}
126125
value={getSelectPickerOptionByValue(row.data[key].props?.options, row.data[key].value)}
127126
onChange={onChange(row, key)}
@@ -140,7 +139,10 @@ export const DynamicDataTableRow = <K extends string>({
140139
inputId={`data-table-${row.id}-${key}-cell`}
141140
disabled={readOnly || row.data[key].disabled}
142141
refVar={cellRef?.current?.[row.id]?.[key]}
143-
dependentRef={cellRef?.current?.[row.id]}
142+
dependentRefs={cellRef?.current?.[row.id]}
143+
selectPickerProps={{
144+
classNamePrefix: 'dynamic-data-table__cell__select-picker',
145+
}}
144146
textAreaProps={{
145147
...row.data[key].props?.textAreaProps,
146148
className: 'dynamic-data-table__cell-input placeholder-cn5 py-8 pr-8 cn-9 fs-13 lh-20',
@@ -172,14 +174,15 @@ export const DynamicDataTableRow = <K extends string>({
172174
return (
173175
<ResizableTagTextArea
174176
{...row.data[key].props}
177+
id={`data-table-${row.id}-${key}-cell`}
175178
className={`dynamic-data-table__cell-input placeholder-cn5 p-8 cn-9 fs-13 lh-20 dc__align-self-start dc__no-border-radius ${readOnly || row.data[key].disabled ? 'cursor-not-allowed' : ''}`}
176179
minHeight={20}
177180
maxHeight={160}
178181
value={row.data[key].value}
179182
onChange={onChange(row, key)}
180183
disabled={readOnly || row.data[key].disabled}
181184
refVar={cellRef?.current?.[row.id]?.[key]}
182-
dependentRef={cellRef?.current?.[row.id]}
185+
dependentRefs={cellRef?.current?.[row.id]}
183186
disableOnBlurResizeToMinHeight
184187
/>
185188
)
@@ -206,7 +209,7 @@ export const DynamicDataTableRow = <K extends string>({
206209

207210
const renderErrorMessage = (errorMessage: string) => (
208211
<div key={errorMessage} className="flexbox align-items-center dc__gap-4">
209-
<ICClose className="icon-dim-16 fcr-5 dc__align-self-start dc__no-shrink" />
212+
<ICCross className="icon-dim-16 fcr-5 dc__align-self-start dc__no-shrink" />
210213
<p className="fs-12 lh-16 cn-7 m-0">{errorMessage}</p>
211214
</div>
212215
)
@@ -236,17 +239,11 @@ export const DynamicDataTableRow = <K extends string>({
236239
<div
237240
className={`dynamic-data-table__cell bcn-0 flexbox dc__align-items-center dc__gap-4 dc__position-rel ${readOnly || row.data[key].disabled ? 'cursor-not-allowed no-hover' : ''} ${showError && !validationSchema(row.data[key].value, key, row).isValid ? 'dynamic-data-table__cell--error no-hover' : ''} ${!rowTypeHasInputField(row.data[key].type) ? 'no-hover no-focus' : ''}`}
238241
>
239-
{maskValue?.[key] && row.data[key].value ? (
240-
<div className="py-8 px-12 h-36 flex">{DEFAULT_SECRET_PLACEHOLDER}</div>
241-
) : (
242-
<>
243-
{renderCellIcon(row, key, true)}
244-
{renderCellContent(row, key)}
245-
{renderAsterisk(row, key)}
246-
{renderCellIcon(row, key)}
247-
{renderErrorMessages(row, key)}
248-
</>
249-
)}
242+
{renderCellIcon(row, key, true)}
243+
{renderCellContent(row, key)}
244+
{renderAsterisk(row, key)}
245+
{renderCellIcon(row, key)}
246+
{renderErrorMessages(row, key)}
250247
</div>
251248
</Tooltip>
252249
)
@@ -274,35 +271,30 @@ export const DynamicDataTableRow = <K extends string>({
274271

275272
return hasRows ? (
276273
<div className="bcn-2 px-1 pb-1 dc__bottom-radius-4">
277-
{!!rows.length && (
278-
<div
279-
className={`dynamic-data-table w-100 bcn-1 dc__bottom-radius-4 ${!readOnly ? 'three-columns' : 'two-columns'}`}
280-
style={{
281-
gridTemplateColumns: rowGridTemplateColumn,
282-
}}
283-
>
284-
{rows.map((row) => (
285-
<div key={row.id} className="dynamic-data-table__row">
286-
{headers.map(({ key }, index) => (
287-
<Fragment key={key}>{renderCell(row, key, index)}</Fragment>
288-
))}
289-
{!isDeletionNotAllowed && !readOnly && (
290-
<button
291-
type="button"
292-
className={`dynamic-data-table__row-delete-btn dc__unset-button-styles dc__align-self-stretch dc__no-shrink flex py-10 px-8 bcn-0 dc__hover-n50 dc__tab-focus ${disableDeleteRow ? 'dc__disabled' : ''}`}
293-
onClick={onDelete(row)}
294-
disabled={disableDeleteRow}
295-
>
296-
<ICClose
297-
aria-label="delete-row"
298-
className="icon-dim-16 fcn-4 dc__align-self-start"
299-
/>
300-
</button>
301-
)}
302-
</div>
303-
))}
304-
</div>
305-
)}
274+
<div
275+
className={`dynamic-data-table w-100 bcn-1 dc__bottom-radius-4 ${!readOnly ? 'row-column' : 'header-column'}`}
276+
style={{
277+
gridTemplateColumns: rowGridTemplateColumn,
278+
}}
279+
>
280+
{rows.map((row) => (
281+
<div key={row.id} className="dynamic-data-table__row">
282+
{headers.map(({ key }, index) => (
283+
<Fragment key={key}>{renderCell(row, key, index)}</Fragment>
284+
))}
285+
{!isDeletionNotAllowed && !readOnly && (
286+
<button
287+
type="button"
288+
className={`dynamic-data-table__row-delete-btn dc__unset-button-styles dc__align-self-stretch dc__no-shrink flex py-10 px-8 bcn-0 ${disableDeleteRow ? 'dc__disabled' : 'dc__hover-n50 dc__tab-focus'}`}
289+
onClick={onDelete(row)}
290+
disabled={disableDeleteRow}
291+
>
292+
<ICCross aria-label="delete-row" className="icon-dim-16 fcn-4 dc__align-self-start" />
293+
</button>
294+
)}
295+
</div>
296+
))}
297+
</div>
306298
</div>
307299
) : null
308300
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const ACTION_BUTTON_DEFAULT_WIDTH = '33px'
2+
export const DELETE_BUTTON_WIDTH = '33px'

src/Shared/Components/DynamicDataTable/styles.scss

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
display: grid;
1919
gap: 1px;
2020

21-
&.two-columns {
22-
.dynamic-data-table__row:last-of-type {
23-
.dynamic-data-table__cell:first-child,
24-
.dynamic-data-table__cell-input:first-child {
25-
border-bottom-left-radius: 4px !important;
26-
}
21+
&__row:last-of-type {
22+
.dynamic-data-table__cell:first-child,
23+
.dynamic-data-table__cell-input:first-child {
24+
border-bottom-left-radius: 4px !important;
2725
}
26+
}
2827

28+
&.header-column {
2929
.dynamic-data-table__row:last-of-type {
3030
.dynamic-data-table__cell:last-child,
3131
.dynamic-data-table__cell-input:last-child {
@@ -34,14 +34,7 @@
3434
}
3535
}
3636

37-
&.three-columns {
38-
.dynamic-data-table__row:last-of-type {
39-
.dynamic-data-table__cell:first-child,
40-
.dynamic-data-table__cell-input:first-child {
41-
border-bottom-left-radius: 4px !important;
42-
}
43-
}
44-
37+
&.row-column {
4538
.dynamic-data-table__row:last-of-type {
4639
.dynamic-data-table__cell:last-child,
4740
.dynamic-data-table__row-delete-btn {
@@ -70,8 +63,11 @@
7063
}
7164

7265
&__cell {
73-
.select-picker-borderless-control {
74-
padding: 8px;
66+
min-width: 0;
67+
68+
&__select-picker__control {
69+
gap: 6px !important;
70+
padding: 8px !important;
7571
}
7672

7773
&:not(:has(.select-picker-borderless-control)) .dynamic-data-table__select-text-area {

0 commit comments

Comments
 (0)