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

97 lines
3.1 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-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 && (
2025-02-25 06:52:50 +00:00
<div className="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
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,
2025-02-25 06:52:50 +00:00
width: width ? width : '300px',
2024-05-14 08:11:11 +00:00
borderTopRightRadius: '0',
borderBottomRightRadius: '0',
borderRight: 'none',
}}
/>
<Input
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
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
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>
);
};