Skip to content

Commit d754ea0

Browse files
committed
refactor: DynamicDataTable, SelectTextArea - code improvement, types update
1 parent 725adc4 commit d754ea0

File tree

4 files changed

+33
-42
lines changed

4 files changed

+33
-42
lines changed

src/Shared/Components/DynamicDataTable/DynamicDataTableRow.tsx

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +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'
5+
import { ReactComponent as ICCross } from '@Icons/ic-cross.svg'
66
import { DEFAULT_SECRET_PLACEHOLDER } from '@Shared/constants'
77
import { Tooltip } from '@Common/Tooltip'
88

@@ -38,7 +38,6 @@ export const DynamicDataTableRow = <K extends string, CustomStateType = Record<s
3838
headers,
3939
maskValue,
4040
readOnly,
41-
isAdditionNotAllowed,
4241
isDeletionNotAllowed,
4342
validationSchema = () => ({ isValid: true, errorMessages: [] }),
4443
showError,
@@ -52,7 +51,7 @@ export const DynamicDataTableRow = <K extends string, CustomStateType = Record<s
5251
// CONSTANTS
5352
const isFirstRowEmpty = headers.every(({ key }) => !rows[0]?.data[key].value)
5453
/** Boolean determining if table has rows. */
55-
const hasRows = (!readOnly && !isAdditionNotAllowed) || !!rows.length
54+
const hasRows = !!rows.length
5655
const disableDeleteRow = rows.length === 1 && isFirstRowEmpty
5756
/** style: grid-template-columns */
5857
const rowGridTemplateColumn = getRowGridTemplateColumn(
@@ -227,7 +226,7 @@ export const DynamicDataTableRow = <K extends string, CustomStateType = Record<s
227226

228227
const renderErrorMessage = (errorMessage: string) => (
229228
<div key={errorMessage} className="flexbox align-items-center dc__gap-4">
230-
<ICClose className="icon-dim-16 fcr-5 dc__align-self-start dc__no-shrink" />
229+
<ICCross className="icon-dim-16 fcr-5 dc__align-self-start dc__no-shrink" />
231230
<p className="fs-12 lh-16 cn-7 m-0">{errorMessage}</p>
232231
</div>
233232
)
@@ -300,35 +299,30 @@ export const DynamicDataTableRow = <K extends string, CustomStateType = Record<s
300299

301300
return hasRows ? (
302301
<div className="bcn-2 px-1 pb-1 dc__bottom-radius-4">
303-
{!!rows.length && (
304-
<div
305-
className={`dynamic-data-table w-100 bcn-1 dc__bottom-radius-4 ${!readOnly ? 'three-columns' : 'two-columns'}`}
306-
style={{
307-
gridTemplateColumns: rowGridTemplateColumn,
308-
}}
309-
>
310-
{rows.map((row) => (
311-
<div key={row.id} className="dynamic-data-table__row">
312-
{headers.map(({ key }, index) => (
313-
<Fragment key={key}>{renderCell(row, key, index)}</Fragment>
314-
))}
315-
{!isDeletionNotAllowed && !readOnly && (
316-
<button
317-
type="button"
318-
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 || row.disableDelete ? 'dc__disabled' : 'dc__hover-n50 dc__tab-focus'}`}
319-
onClick={onDelete(row)}
320-
disabled={disableDeleteRow || row.disableDelete}
321-
>
322-
<ICClose
323-
aria-label="delete-row"
324-
className="icon-dim-16 fcn-4 dc__align-self-start"
325-
/>
326-
</button>
327-
)}
328-
</div>
329-
))}
330-
</div>
331-
)}
302+
<div
303+
className={`dynamic-data-table w-100 bcn-1 dc__bottom-radius-4 ${!readOnly ? 'three-columns' : 'two-columns'}`}
304+
style={{
305+
gridTemplateColumns: rowGridTemplateColumn,
306+
}}
307+
>
308+
{rows.map((row) => (
309+
<div key={row.id} className="dynamic-data-table__row">
310+
{headers.map(({ key }, index) => (
311+
<Fragment key={key}>{renderCell(row, key, index)}</Fragment>
312+
))}
313+
{!isDeletionNotAllowed && !readOnly && (
314+
<button
315+
type="button"
316+
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 || row.disableDelete ? 'dc__disabled' : 'dc__hover-n50 dc__tab-focus'}`}
317+
onClick={onDelete(row)}
318+
disabled={disableDeleteRow || row.disableDelete}
319+
>
320+
<ICCross aria-label="delete-row" className="icon-dim-16 fcn-4 dc__align-self-start" />
321+
</button>
322+
)}
323+
</div>
324+
))}
325+
</div>
332326
</div>
333327
) : null
334328
}

src/Shared/Components/DynamicDataTable/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
padding: 8px;
7777
}
7878

79-
&:not(:has(.select-picker-borderless-control)) .dynamic-data-table__select-text-area {
79+
&:has(.select-picker-hidden) .dynamic-data-table__select-text-area {
8080
padding-left: 8px;
8181
}
8282

src/Shared/Components/SelectTextArea/SelectTextArea.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ export const SelectTextArea = ({
3333
const selectedValue = getSelectPickerOptionByValue<string>(options, value, null)
3434

3535
useEffectAfterMount(() => {
36-
if (value && refVar?.current) {
37-
refVar.current.focus()
38-
const refElement = refVar.current
39-
refElement.selectionStart = refElement.value.length
40-
} else if (!value && selectRef.current) {
36+
if (!value && selectRef.current) {
4137
selectRef.current.focus()
4238
selectRef.current.openMenu('first')
4339
}
@@ -74,7 +70,7 @@ export const SelectTextArea = ({
7470
onChange={onTextAreaChange}
7571
placeholder={placeholder}
7672
/>
77-
{!value ? (
73+
<div className={`w-100 ${value ? 'select-picker-hidden dc__hide-section' : ''}`}>
7874
<SelectPicker<string, false>
7975
isCreatable
8076
{...selectPickerProps}
@@ -89,7 +85,8 @@ export const SelectTextArea = ({
8985
isDisabled={disabled}
9086
fullWidth
9187
/>
92-
) : (
88+
</div>
89+
{value && (
9390
<button
9491
type="button"
9592
className="flex dc__transparent dc__position-abs dc__top-8 dc__right-8"

src/Shared/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ export interface RuntimePluginVariables
345345
valueConstraint: ValueConstraint & { id: number }
346346
stepVariableId: number
347347
valueType: RefVariableType
348-
refPluginId?: number
349348
stepName: string
350349
stepType: PluginType
351350
isRequired: boolean
351+
pluginIcon?: string
352352
}
353353

354354
export interface RuntimeParamsAPIResponseType {

0 commit comments

Comments
 (0)