ToolJet/frontend/src/_ui/HttpHeaders/SourceEditor.jsx

102 lines
3.4 KiB
React
Raw Normal View History

import React from 'react';
import Input from '../Input';
2024-05-14 08:11:11 +00:00
import Trash from '@/_ui/Icon/solidIcons/Trash';
import { ButtonSolid } from '@/_ui/AppButton/AppButton';
import AddRectangle from '@/_ui/Icon/bulkIcons/AddRectangle';
import '@/_ui/HttpHeaders/sourceEditorStyles.scss';
import InfoIcon from '@assets/images/icons/info.svg';
2025-02-04 13:29:19 +00:00
export default ({
options,
addNewKeyValuePair,
removeKeyValuePair,
keyValuePairValueChanged,
workspaceConstants,
2025-02-25 06:52:50 +00:00
isDisabled,
width,
2025-03-19 08:26:33 +00:00
dataCy,
2025-02-04 13:29:19 +00:00
}) => {
2024-05-14 08:11:11 +00:00
const darkMode = localStorage.getItem('darkMode') === 'true';
2025-02-25 06:52:50 +00:00
return (
2024-05-14 08:11:11 +00:00
<div className="table-content-wrapper">
{options.length === 0 && (
<div className="empty-key-value" data-cy="label-empty-key-value">
2024-05-14 08:11:11 +00:00
<InfoIcon style={{ width: '16px', marginRight: '5px' }} />
<span>There are no key value pairs added</span>
</div>
)}
{options.map((option, index) => (
<div className="d-flex align-items-top row-container query-manager-border-color" key={index}>
2024-05-14 08:11:11 +00:00
<Input
2025-03-19 08:26:33 +00:00
data-cy={`${dataCy}-key-input-field-${index}`}
2024-05-14 08:11:11 +00:00
type="text"
className="input-control"
onChange={(e) => keyValuePairValueChanged(e.target.value, 0, index)}
value={option[0]}
workspaceConstants={workspaceConstants}
placeholder="Key"
2024-05-14 08:11:11 +00:00
autoComplete="off"
2025-02-25 06:52:50 +00:00
disabled={isDisabled}
2024-05-14 08:11:11 +00:00
style={{
flex: 1,
Feature: Dynamic form validations (#12292) * fixed datasource page crash as function definition was referenced wrongly (#11562) * Add new dynamicform * Refactor postgres manifest file * Add new input-v3 component * Conditionally render DynamicformV2 * Make change to design system component * Remove key-value label over header input and increase width * Add validation function for individual inputs * Add validations on datasource creation * Update custom input wrapper * Update manifest file * Add validation setup for dynamic form with JSON schema * Fix input labels * Add more validation checks * Update manifest * Remove console logs * Add props for header component * Skip validation for encrypted fields * Add validations while saving datasource * Remove validations for connection-options * Add fetch manifest function * Centralise validation errors * Add property name in datapath * Initialize and map validation errors to property * Reuse validationErrors while saving datasource * Bypass design system validation by implementing custom validation prop * Skip initial render validation Skip validation message for unchanged elements * Remove fetchManifest * Add text input for connection string * Add workflow schema * Fix double border on error or success * Remove redundant default populating logic * Fix the error helper text color to red * Validate all fields post initial render * Show label name in helper-text for failed validation * Correctly switch between the password eye svg * Incorporate edit button on encrypted inputs * Resolve lint issue --------- Co-authored-by: Ganesh Kumar <40178541+ganesh8056@users.noreply.github.com> Co-authored-by: Parth Adhikari <parthadhikari@192.168.1.3> Co-authored-by: Parth Adhikari <parthadhikari@192.168.1.2> Co-authored-by: Parth Adhikari <parthadhikari@192.168.1.6> Co-authored-by: parthy007 <parthadhikari1812@gmail.com>
2025-04-03 08:17:49 +00:00
width: '316px',
2024-05-14 08:11:11 +00:00
borderTopRightRadius: '0',
borderBottomRightRadius: '0',
borderRight: 'none',
}}
/>
<Input
2025-03-19 08:26:33 +00:00
data-cy={`${dataCy}-value-input-field-${index}`}
2024-05-14 08:11:11 +00:00
type="text"
value={option[1]}
placeholder="Value"
2024-05-14 08:11:11 +00:00
autoComplete="off"
className="input-control"
onChange={(e) => keyValuePairValueChanged(e.target.value, 1, index)}
workspaceConstants={workspaceConstants}
2025-02-25 06:52:50 +00:00
disabled={isDisabled}
2024-05-14 08:11:11 +00:00
style={{
flex: 2,
2025-02-25 06:52:50 +00:00
width: width ? width : '316px',
2024-05-14 08:11:11 +00:00
borderTopLeftRadius: '0',
borderBottomLeftRadius: '0',
borderTopRightRadius: '0',
borderBottomRightRadius: '0',
}}
/>
<button
2025-03-19 08:26:33 +00:00
data-cy={`${dataCy}-delete-button-${index}`}
2024-05-14 08:11:11 +00:00
className={`d-flex justify-content-center align-items-center delete-field-option bg-transparent border-0 rounded-0 border-top border-bottom border-end rounded-end ${
darkMode ? 'delete-field-option-dark' : ''
}`}
style={{ height: '35px' }}
role="button"
2025-02-25 06:52:50 +00:00
disabled={isDisabled}
2024-05-14 08:11:11 +00:00
onClick={() => removeKeyValuePair(index)}
>
<Trash fill="var(--slate9)" style={{ height: '16px' }} />
</button>
</div>
))}
<div className="d-flex mb-2" style={{ height: '16px' }}>
<ButtonSolid
data-cy={`${dataCy}-add-button`}
variant="ghostBlue"
size="sm"
onClick={() => addNewKeyValuePair(options)}
style={{ gap: '0px', fontSize: '12px', fontWeight: '500', padding: '0px 9px' }}
2025-02-25 06:52:50 +00:00
disabled={isDisabled}
>
2024-05-14 08:11:11 +00:00
<AddRectangle width="15" fill="#3E63DD" opacity="1" secondaryFill="#ffffff" />
2025-02-25 06:52:50 +00:00
&nbsp;&nbsp;Add
2024-05-14 08:11:11 +00:00
</ButtonSolid>
</div>
</div>
);
};