pixel-react-excel-sheet 1.0.31 → 1.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/Accordion/Accordion.d.ts +1 -1
- package/lib/components/Accordion/types.d.ts +4 -0
- package/lib/components/AllProjectsDropdown/types.d.ts +2 -0
- package/lib/components/Button/Button.d.ts +2 -2
- package/lib/components/Button/types.d.ts +17 -0
- package/lib/components/Charts/DashboardDonutChart/types.d.ts +2 -0
- package/lib/components/Charts/MultiRadialChart/types.d.ts +3 -0
- package/lib/components/ChooseFile/ChooseFile.d.ts +3 -0
- package/lib/components/ChooseFile/types.d.ts +68 -0
- package/lib/components/ConditionalDropdown/ConditionalDropdown.d.ts +1 -2
- package/lib/components/ConditionalDropdown/types.d.ts +4 -4
- package/lib/components/ConnectingBranch/ConnectingBranch.d.ts +2 -1
- package/lib/components/ConnectingBranch/data.d.ts +19 -33
- package/lib/components/ConnectingBranch/types.d.ts +10 -0
- package/lib/components/Excel/ExcelFile/ExcelFileComponents/actions.d.ts +7 -1
- package/lib/components/FileDropzone/types.d.ts +12 -4
- package/lib/components/LabelEditTextField/types.d.ts +3 -1
- package/lib/components/MachineInputField/MachineInputField.d.ts +4 -1
- package/lib/components/ScriptSwitchButton/ScriptSwitchButton.d.ts +9 -0
- package/lib/components/ScriptSwitchButton/index.d.ts +1 -0
- package/lib/components/Select/types.d.ts +1 -1
- package/lib/components/StatusCard/types.d.ts +2 -0
- package/lib/components/TableTree/Components/TableCell.d.ts +1 -1
- package/lib/components/TableTree/Components/TableRow.d.ts +1 -1
- package/lib/components/TableTree/data.d.ts +115 -1
- package/lib/components/TableTree/types.d.ts +4 -0
- package/lib/components/TextArea/Textarea.d.ts +1 -1
- package/lib/components/TextArea/Types.d.ts +1 -0
- package/lib/components/ThemeProvider/types.d.ts +1 -1
- package/lib/index.d.ts +250 -75
- package/lib/index.esm.js +863 -489
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +909 -488
- package/lib/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/validateFile/validateFile.d.ts +2 -0
- package/lib/validations/regex.d.ts +46 -0
- package/package.json +2 -2
- package/src/StyleGuide/ColorPalette/colorPaletteList.ts +5 -0
- package/src/assets/Themes/BaseTheme.scss +2 -1
- package/src/assets/Themes/BlueTheme.scss +279 -0
- package/src/assets/Themes/DarkTheme.scss +2 -1
- package/src/assets/Themes/Theme.scss +5 -0
- package/src/assets/icons/failed_status_icon.svg +1 -1
- package/src/assets/icons/flaky_status_icon.svg +1 -1
- package/src/assets/icons/settings.svg +3 -0
- package/src/assets/icons/skipped_status_icon.svg +1 -1
- package/src/assets/icons/warning_status_icon.svg +1 -1
- package/src/components/Accordion/Accordion.stories.tsx +13 -0
- package/src/components/Accordion/Accordion.tsx +2 -1
- package/src/components/Accordion/types.ts +4 -0
- package/src/components/AllProjectsDropdown/types.ts +2 -0
- package/src/components/AppHeader/AppHeader.scss +6 -2
- package/src/components/AppHeader/AppHeader.tsx +4 -2
- package/src/components/Button/Button.scss +12 -0
- package/src/components/Button/Button.tsx +29 -11
- package/src/components/Button/types.ts +21 -0
- package/src/components/Charts/DashboardDonutChart/DashboardDonutChart.scss +83 -30
- package/src/components/Charts/DashboardDonutChart/DashboardDonutChart.stories.tsx +3 -0
- package/src/components/Charts/DashboardDonutChart/DashboardDonutChart.tsx +39 -16
- package/src/components/Charts/DashboardDonutChart/types.ts +2 -0
- package/src/components/Charts/MultiRadialChart/MultiRadialChart.scss +0 -1
- package/src/components/Charts/MultiRadialChart/MultiRadialChart.stories.tsx +2 -1
- package/src/components/Charts/MultiRadialChart/MultiRadialChart.tsx +18 -4
- package/src/components/Charts/MultiRadialChart/types.ts +4 -1
- package/src/components/ChooseFile/ChooseFile.stories.tsx +190 -0
- package/src/components/ChooseFile/ChooseFile.tsx +46 -0
- package/src/components/ChooseFile/types.ts +78 -0
- package/src/components/ConditionalDropdown/ConditionalDropdown.stories.tsx +8 -5
- package/src/components/ConditionalDropdown/ConditionalDropdown.tsx +133 -135
- package/src/components/ConditionalDropdown/types.ts +8 -8
- package/src/components/ConnectingBranch/BranchComponents/MachineInstances.tsx +94 -79
- package/src/components/ConnectingBranch/ConnectingBranch.scss +183 -195
- package/src/components/ConnectingBranch/ConnectingBranch.stories.tsx +33 -1
- package/src/components/ConnectingBranch/ConnectingBranch.tsx +121 -107
- package/src/components/ConnectingBranch/{data.ts → data.tsx} +106 -17
- package/src/components/ConnectingBranch/types.ts +21 -0
- package/src/components/DatePicker/DatePicker.scss +310 -0
- package/src/components/Excel/ExcelFile/ExcelFile.tsx +4 -4
- package/src/components/Excel/ExcelFile/ExcelFileComponents/ActiveCell.tsx +22 -10
- package/src/components/Excel/ExcelFile/ExcelFileComponents/ColumnIndicator.tsx +2 -2
- package/src/components/Excel/ExcelFile/ExcelFileComponents/DataEditor.tsx +4 -1
- package/src/components/Excel/ExcelFile/ExcelFileComponents/FloatingRect.tsx +6 -1
- package/src/components/Excel/ExcelFile/ExcelFileComponents/RowIndicator.tsx +2 -2
- package/src/components/Excel/ExcelFile/ExcelFileComponents/Spreadsheet.scss +30 -11
- package/src/components/Excel/ExcelFile/ExcelFileComponents/Spreadsheet.tsx +65 -19
- package/src/components/Excel/ExcelFile/ExcelFileComponents/actions.ts +14 -0
- package/src/components/Excel/ExcelFile/ExcelFileComponents/reducer.ts +16 -0
- package/src/components/Excel/ExcelFile/ExcelFileComponents/reducerFunctions.ts +77 -10
- package/src/components/Excel/ExcelToolBar/ExcelToolBar.tsx +6 -5
- package/src/components/FileDropzone/Dropzone.tsx +3 -0
- package/src/components/FileDropzone/FileDropzone.scss +18 -0
- package/src/components/FileDropzone/FileDropzone.stories.tsx +75 -7
- package/src/components/FileDropzone/FileDropzone.tsx +2 -0
- package/src/components/FileDropzone/RadioFilePreview.tsx +7 -3
- package/src/components/FileDropzone/types.ts +13 -4
- package/src/components/Icon/iconList.ts +4 -2
- package/src/components/InputWithDropdown/InputWithDropdown.tsx +1 -1
- package/src/components/LabelEditTextField/LabelEditTextField.scss +4 -0
- package/src/components/LabelEditTextField/LabelEditTextField.stories.tsx +8 -3
- package/src/components/LabelEditTextField/LabelEditTextField.tsx +42 -18
- package/src/components/LabelEditTextField/types.ts +3 -1
- package/src/components/MachineInputField/MachineInputField.tsx +67 -70
- package/src/components/NLPInput/components/NlpDropDown/NlpDropdown.scss +1 -1
- package/src/components/ScriptSwitchButton/ScriptSwitchButton.scss +33 -0
- package/src/components/ScriptSwitchButton/ScriptSwitchButton.stories.tsx +48 -0
- package/src/components/ScriptSwitchButton/ScriptSwitchButton.tsx +65 -0
- package/src/components/ScriptSwitchButton/index.ts +1 -0
- package/src/components/Search/Search.tsx +3 -1
- package/src/components/Select/Select.tsx +4 -4
- package/src/components/Select/types.ts +1 -1
- package/src/components/SequentialConnectingBranch/components/Branches/Branches.scss +1 -0
- package/src/components/SequentialConnectingBranch/components/Branches/Branches.tsx +2 -8
- package/src/components/StatusCard/StatusCard.scss +2 -1
- package/src/components/StatusCard/StatusCard.stories.tsx +59 -1
- package/src/components/StatusCard/StatusCard.tsx +10 -2
- package/src/components/StatusCard/types.ts +2 -0
- package/src/components/TableTree/Components/TableBody.tsx +20 -16
- package/src/components/TableTree/Components/TableCell.tsx +47 -31
- package/src/components/TableTree/Components/TableRow.tsx +4 -0
- package/src/components/TableTree/TableTree.scss +121 -109
- package/src/components/TableTree/data.ts +48 -2
- package/src/components/TableTree/types.ts +4 -0
- package/src/components/TextArea/Textarea.tsx +2 -0
- package/src/components/TextArea/Types.ts +3 -0
- package/src/components/ThemeProvider/types.ts +1 -1
- package/src/index.ts +97 -0
- package/src/utils/validateFile/validateFile.stories.tsx +49 -0
- package/src/utils/validateFile/validateFile.ts +39 -0
- package/src/validations/regex.stories.tsx +362 -0
- package/src/validations/regex.ts +194 -0
- package/src/components/SequentialConnectingBranch/components/AddBrowserModal/AddBrowserModal.scss +0 -51
- package/src/components/SequentialConnectingBranch/components/AddBrowserModal/AddBrowserModal.tsx +0 -107
- package/src/components/SequentialConnectingBranch/components/AddBrowserModal/types.ts +0 -5
- package/src/components/SequentialConnectingBranch/components/DatasetListModal/DatasetListModal.scss +0 -31
- package/src/components/SequentialConnectingBranch/components/DatasetListModal/DatasetListModal.tsx +0 -85
- package/src/components/SequentialConnectingBranch/components/DatasetListModal/types.ts +0 -4
- /package/src/assets/icons/{impactList.svg → impact_list.svg} +0 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
3
|
+
import ChooseFile from './ChooseFile';
|
|
4
|
+
import Drawer from '../Drawer/Drawer';
|
|
5
|
+
import FileDropzone from '../FileDropzone/FileDropzone';
|
|
6
|
+
import { RadioOption } from '../FileDropzone/types';
|
|
7
|
+
import { DynamicObj } from '../CreateVariable/types';
|
|
8
|
+
import Button from '../Button';
|
|
9
|
+
import ConditionalDropdown from '../ConditionalDropdown/ConditionalDropdown';
|
|
10
|
+
|
|
11
|
+
const meta: Meta<typeof ChooseFile> = {
|
|
12
|
+
title: 'Components/ChooseFile',
|
|
13
|
+
component: ChooseFile,
|
|
14
|
+
parameters: {
|
|
15
|
+
layout: 'centered',
|
|
16
|
+
},
|
|
17
|
+
tags: ['autodocs'],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type Story = StoryObj<typeof ChooseFile>;
|
|
21
|
+
|
|
22
|
+
const defaultArgs = {
|
|
23
|
+
disabled: false,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const ChooseFileDisplay: Story = {
|
|
27
|
+
render: () => {
|
|
28
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
29
|
+
const [showModal, setShowModal] = useState(false);
|
|
30
|
+
const [selectedRadioOption, setSelectedRadioOption] =
|
|
31
|
+
useState<RadioOption>();
|
|
32
|
+
const [selectedFile, setSelectedFile] = useState<File | DynamicObj | null>(
|
|
33
|
+
null
|
|
34
|
+
);
|
|
35
|
+
const [testDataSelectedFile, setTestDataSelectedFile] = useState<
|
|
36
|
+
DynamicObj | File | null
|
|
37
|
+
>(null);
|
|
38
|
+
|
|
39
|
+
const testData = [
|
|
40
|
+
{
|
|
41
|
+
_id: '1',
|
|
42
|
+
name: 'File1.txt',
|
|
43
|
+
actualPath: '/documents/File1.txt',
|
|
44
|
+
searchKey: 'file1',
|
|
45
|
+
parentId: 'root',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
_id: '2',
|
|
49
|
+
name: 'File2.doc',
|
|
50
|
+
actualPath: '/documents/File2.doc',
|
|
51
|
+
searchKey: 'file2',
|
|
52
|
+
parentId: 'root',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
_id: '3',
|
|
56
|
+
name: 'Image1.png',
|
|
57
|
+
actualPath: '/images/Image1.png',
|
|
58
|
+
searchKey: 'image1',
|
|
59
|
+
parentId: 'folder1',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
_id: '4',
|
|
63
|
+
name: 'Presentation.ppt',
|
|
64
|
+
actualPath: '/presentations/Presentation.ppt',
|
|
65
|
+
searchKey: 'presentation',
|
|
66
|
+
parentId: 'folder2',
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
const radioOptions: RadioOption[] = [
|
|
71
|
+
{ value: 'Test Data', label: 'Test Data' },
|
|
72
|
+
{ value: 'Local File', label: 'Local File' },
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
const handleOptionChange = (option: RadioOption) => {
|
|
76
|
+
setSelectedRadioOption(option);
|
|
77
|
+
setShowModal(option.value === 'Test Data');
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
81
|
+
const file = event.target.files?.[0];
|
|
82
|
+
setSelectedFile(file || null);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const handleRemoveFile = () => setSelectedFile(null);
|
|
86
|
+
|
|
87
|
+
const handleSaveButton = () => {
|
|
88
|
+
setSelectedFile(testDataSelectedFile);
|
|
89
|
+
setShowModal(false);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const handleCloseIcon = () => {
|
|
93
|
+
setSelectedFile(null);
|
|
94
|
+
setIsOpen(false);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const handleSaveChooseFile = () => {
|
|
98
|
+
setIsOpen(false);
|
|
99
|
+
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const renderFooterButtons = (onSave: () => void, onCancel: () => void) => (
|
|
103
|
+
<div className="footer_basic_button">
|
|
104
|
+
<Button
|
|
105
|
+
type="button"
|
|
106
|
+
variant="secondary"
|
|
107
|
+
size="small"
|
|
108
|
+
onClick={onCancel}
|
|
109
|
+
label="Cancel"
|
|
110
|
+
/>
|
|
111
|
+
<Button
|
|
112
|
+
type="button"
|
|
113
|
+
variant="primary"
|
|
114
|
+
size="small"
|
|
115
|
+
onClick={onSave}
|
|
116
|
+
label="Save"
|
|
117
|
+
/>
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
setSelectedFile(testDataSelectedFile);
|
|
123
|
+
}, [testDataSelectedFile]);
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<>
|
|
127
|
+
<ChooseFile
|
|
128
|
+
label={selectedFile?.name || 'Choose File'}
|
|
129
|
+
variant="secondary"
|
|
130
|
+
buttonWidth="308px"
|
|
131
|
+
isChooseFile
|
|
132
|
+
iconName={selectedFile?.name ? 'close' : 'attachment_icon'}
|
|
133
|
+
onClick={() => setIsOpen(true)}
|
|
134
|
+
selectedFile={selectedFile}
|
|
135
|
+
handleCloseIcon={handleCloseIcon}
|
|
136
|
+
/>
|
|
137
|
+
|
|
138
|
+
<Drawer
|
|
139
|
+
isOpen={isOpen}
|
|
140
|
+
onClose={() => setIsOpen(false)}
|
|
141
|
+
isFooterRequired={false}
|
|
142
|
+
_isExpanded={false}
|
|
143
|
+
size="medium"
|
|
144
|
+
>
|
|
145
|
+
<FileDropzone
|
|
146
|
+
{...defaultArgs}
|
|
147
|
+
accept={[
|
|
148
|
+
'image/png',
|
|
149
|
+
'image/jpeg',
|
|
150
|
+
'application/x-zip-compressed',
|
|
151
|
+
'application/zip',
|
|
152
|
+
]}
|
|
153
|
+
validateMIMEType
|
|
154
|
+
isWebServiceFileDropZone
|
|
155
|
+
selectedRadioOption={selectedRadioOption}
|
|
156
|
+
radioOptions={radioOptions}
|
|
157
|
+
handleOptionChange={handleOptionChange}
|
|
158
|
+
setSelectedFile={setSelectedFile}
|
|
159
|
+
selectedFile={selectedFile}
|
|
160
|
+
handleFileChange={handleFileChange}
|
|
161
|
+
handleRemoveFile={handleRemoveFile}
|
|
162
|
+
setShowDrawer={setShowModal}
|
|
163
|
+
/>
|
|
164
|
+
{selectedRadioOption?.value === 'Test Data' && (
|
|
165
|
+
<Drawer
|
|
166
|
+
isOpen={showModal}
|
|
167
|
+
onClose={() => setShowModal(false)}
|
|
168
|
+
isFooterRequired={false}
|
|
169
|
+
_isExpanded={false}
|
|
170
|
+
size="small"
|
|
171
|
+
>
|
|
172
|
+
<ConditionalDropdown
|
|
173
|
+
label="Select Path Using #"
|
|
174
|
+
placeholder="Enter # to search files"
|
|
175
|
+
isHash
|
|
176
|
+
dataFiles={testData}
|
|
177
|
+
dropdownWidth="auto"
|
|
178
|
+
setHashInputValue={setTestDataSelectedFile}
|
|
179
|
+
/>
|
|
180
|
+
{renderFooterButtons(handleSaveButton, () => setShowModal(false))}
|
|
181
|
+
</Drawer>
|
|
182
|
+
)}
|
|
183
|
+
{renderFooterButtons(handleSaveChooseFile, () => setIsOpen(false))}
|
|
184
|
+
</Drawer>
|
|
185
|
+
</>
|
|
186
|
+
);
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export default meta;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { memo, type FC } from 'react'
|
|
2
|
+
import { ChooseFileProps } from './types'
|
|
3
|
+
import Button from '../Button'
|
|
4
|
+
|
|
5
|
+
const areEqual = (prevProps: ChooseFileProps, nextProps: ChooseFileProps) =>
|
|
6
|
+
prevProps.selectedFile?.name === nextProps.selectedFile?.name;
|
|
7
|
+
|
|
8
|
+
const ChooseFile:FC<ChooseFileProps> = ({
|
|
9
|
+
variant = 'primary',
|
|
10
|
+
size = 'small',
|
|
11
|
+
onClick,
|
|
12
|
+
label='Choose File',
|
|
13
|
+
disabled = false,
|
|
14
|
+
type = 'button',
|
|
15
|
+
className = '',
|
|
16
|
+
style = {},
|
|
17
|
+
iconName,
|
|
18
|
+
isChooseFile=false,
|
|
19
|
+
buttonWidth='auto',
|
|
20
|
+
selectedFile = {},
|
|
21
|
+
handleCloseIcon,
|
|
22
|
+
}) => {
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<div>
|
|
26
|
+
<Button
|
|
27
|
+
variant={variant}
|
|
28
|
+
label={label}
|
|
29
|
+
type={type}
|
|
30
|
+
onClick={onClick}
|
|
31
|
+
buttonWidth={buttonWidth}
|
|
32
|
+
isChooseFile={isChooseFile}
|
|
33
|
+
size={size}
|
|
34
|
+
disabled={disabled}
|
|
35
|
+
className={className}
|
|
36
|
+
iconName={iconName}
|
|
37
|
+
style={style}
|
|
38
|
+
iconPosition='right'
|
|
39
|
+
selectedFile={selectedFile}
|
|
40
|
+
handleCloseIcon={handleCloseIcon}
|
|
41
|
+
/>
|
|
42
|
+
</div>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default memo(ChooseFile, areEqual);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { DynamicObj } from '../CreateVariable/types';
|
|
2
|
+
|
|
3
|
+
export interface ChooseFileProps {
|
|
4
|
+
/**
|
|
5
|
+
* Variant of the button
|
|
6
|
+
*/
|
|
7
|
+
variant: 'primary' | 'secondary' | 'tertiary' | 'delete' | 'warning';
|
|
8
|
+
/**
|
|
9
|
+
* What background color to use
|
|
10
|
+
*/
|
|
11
|
+
backgroundColor?: string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Width in string format can be sent for needed width
|
|
15
|
+
*/
|
|
16
|
+
buttonWidth?: string;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* How large should the button be?
|
|
20
|
+
*/
|
|
21
|
+
size?: 'small' | 'medium' | 'large';
|
|
22
|
+
/**
|
|
23
|
+
* Button contents
|
|
24
|
+
*/
|
|
25
|
+
label?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Type of the button
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
type?: 'button' | 'submit';
|
|
31
|
+
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Optional click handler
|
|
35
|
+
*/
|
|
36
|
+
onClick?: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Button id
|
|
40
|
+
*/
|
|
41
|
+
id?: string;
|
|
42
|
+
/**
|
|
43
|
+
* onSubmit function handler
|
|
44
|
+
*/
|
|
45
|
+
onSubmit?: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
|
46
|
+
/**
|
|
47
|
+
* react ref for the button
|
|
48
|
+
*/
|
|
49
|
+
ref?: any;
|
|
50
|
+
/**
|
|
51
|
+
* Classname for the button
|
|
52
|
+
*/
|
|
53
|
+
className?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Additional styles for the button
|
|
56
|
+
*/
|
|
57
|
+
style?: React.CSSProperties;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Give icon name availble in storybook that to be on left side of button
|
|
61
|
+
*/
|
|
62
|
+
iconName?: string;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* isChooseFile is a Boolean prop
|
|
66
|
+
*/
|
|
67
|
+
isChooseFile?: boolean;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* selectedfile object will be send.
|
|
71
|
+
*/
|
|
72
|
+
selectedFile?: File | DynamicObj | null;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* handleCloseIcon function will set to the initial state .
|
|
76
|
+
*/
|
|
77
|
+
handleCloseIcon?: () => void;
|
|
78
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
1
|
+
import React, { useRef, useState } from 'react';
|
|
2
2
|
import { Meta, StoryFn, StoryObj } from '@storybook/react';
|
|
3
3
|
import ConditionalDropdown from './ConditionalDropdown';
|
|
4
4
|
import { ConditionalDropdownProps, dynamicObject } from './types';
|
|
@@ -23,6 +23,7 @@ export default {
|
|
|
23
23
|
type Story = StoryObj<typeof ConditionalDropdown>;
|
|
24
24
|
|
|
25
25
|
const Template: StoryFn<ConditionalDropdownProps> = (args) => {
|
|
26
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
26
27
|
const [inputValue, setInputValue] = useState<string>('');
|
|
27
28
|
const [openCreateVariable, setOpenCreateVariable] = useState<boolean>(false);
|
|
28
29
|
const [variableName, setVariableName] = useState<string>('');
|
|
@@ -37,9 +38,12 @@ const Template: StoryFn<ConditionalDropdownProps> = (args) => {
|
|
|
37
38
|
<>
|
|
38
39
|
<ConditionalDropdown
|
|
39
40
|
{...args}
|
|
40
|
-
onChange={(
|
|
41
|
+
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
|
|
42
|
+
setInputValue(event.target.value)
|
|
43
|
+
}
|
|
41
44
|
value={inputValue}
|
|
42
45
|
onCreateVariableClick={() => setOpenCreateVariable(true)}
|
|
46
|
+
ref={inputRef}
|
|
43
47
|
/>
|
|
44
48
|
{openCreateVariable && (
|
|
45
49
|
<CreateVariableSlider
|
|
@@ -83,9 +87,8 @@ WithInitialValue.args = {
|
|
|
83
87
|
|
|
84
88
|
export const DropdownOnHash: Story = {
|
|
85
89
|
render: () => {
|
|
86
|
-
const [hashInputValue, setHashInputValue] =
|
|
87
|
-
dynamicObject |
|
|
88
|
-
>();
|
|
90
|
+
const [hashInputValue, setHashInputValue] =
|
|
91
|
+
useState<dynamicObject | null>();
|
|
89
92
|
const testData = [
|
|
90
93
|
{
|
|
91
94
|
_id: '1',
|
|
@@ -1,158 +1,156 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useState,
|
|
3
|
+
useEffect,
|
|
4
|
+
forwardRef,
|
|
5
|
+
useImperativeHandle,
|
|
6
|
+
useRef,
|
|
7
|
+
} from 'react';
|
|
1
8
|
import { checkEmpty } from '../../utils/checkEmpty/checkEmpty';
|
|
2
9
|
import VariableDropdown from '../Editor/VariableDropdown';
|
|
3
10
|
import Icon from '../Icon';
|
|
4
11
|
import Input from '../Input';
|
|
5
12
|
import { ConditionalDropdownProps, dynamicObject } from './types';
|
|
6
13
|
import './ConditionalDropdown.scss';
|
|
7
|
-
import React, { useState, useRef, useEffect } from 'react';
|
|
8
14
|
import OptionsDropdown from './OptionsDropdown';
|
|
9
15
|
|
|
10
|
-
const ConditionalDropdown
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
16
|
+
const ConditionalDropdown = forwardRef<
|
|
17
|
+
HTMLInputElement,
|
|
18
|
+
ConditionalDropdownProps
|
|
19
|
+
>(
|
|
20
|
+
(
|
|
21
|
+
{
|
|
22
|
+
label = '',
|
|
23
|
+
hashInputValue = '',
|
|
24
|
+
setHashInputValue,
|
|
25
|
+
variableList = [],
|
|
26
|
+
placeholder = 'Enter text',
|
|
27
|
+
onChange,
|
|
28
|
+
onCreateVariableClick,
|
|
29
|
+
value = '',
|
|
30
|
+
dropdownWidth = 'inherit',
|
|
31
|
+
isHash = false,
|
|
32
|
+
dataFiles = [],
|
|
33
|
+
...props
|
|
34
|
+
},
|
|
35
|
+
ref
|
|
36
|
+
) => {
|
|
37
|
+
const [showDropdown, setShowDropdown] = useState<boolean>(false);
|
|
38
|
+
const [cursorPosition, setCursorPosition] = useState<number | null>(null);
|
|
39
|
+
const [showCreateVariableIcon, setShowCreateVariableIcon] =
|
|
40
|
+
useState<boolean>(false);
|
|
41
|
+
const [filteredOptions, setFilteredOptions] = useState<dynamicObject[]>([]);
|
|
42
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
31
43
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
inputRef.current.setSelectionRange(cursorPosition, cursorPosition);
|
|
35
|
-
inputRef.current.focus();
|
|
36
|
-
}
|
|
37
|
-
}, [cursorPosition]);
|
|
44
|
+
// Expose the `inputRef` to the parent via `ref`
|
|
45
|
+
useImperativeHandle(ref, () => inputRef.current as HTMLInputElement);
|
|
38
46
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
setFilteredOptions(filtered);
|
|
47
|
-
setShowDropdown(filtered.length > 0);
|
|
48
|
-
} else if (!isHash) {
|
|
49
|
-
const newPayload = replaceVariablesWithIds(inputValue);
|
|
50
|
-
onChange?.(newPayload);
|
|
51
|
-
}
|
|
52
|
-
}, [inputValue]);
|
|
53
|
-
|
|
54
|
-
const replaceVariablesWithIds = (input: string): string => {
|
|
55
|
-
return input.replace(/\${.*?_(.*?)}/g, (_, variableName) => {
|
|
56
|
-
const foundVariable = variableList.find(
|
|
57
|
-
(varaible) => varaible.name === variableName.trim()
|
|
58
|
-
);
|
|
59
|
-
return foundVariable ? `\${${foundVariable.id}}` : `\${${variableName}}`;
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
64
|
-
const fieldValue = event.target.value;
|
|
65
|
-
setInputValue(fieldValue);
|
|
66
|
-
const cursorPos = inputRef.current?.selectionStart || 0;
|
|
67
|
-
const isDollarTyped = fieldValue[cursorPos - 1] === '$';
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (cursorPosition !== null && inputRef.current) {
|
|
49
|
+
inputRef.current.setSelectionRange(cursorPosition, cursorPosition);
|
|
50
|
+
inputRef.current.focus();
|
|
51
|
+
}
|
|
52
|
+
}, [cursorPosition]);
|
|
68
53
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
setShowDropdown(
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
const cursorPos = inputRef.current?.selectionStart || 0;
|
|
56
|
+
const isDollarTyped = value[cursorPos - 1] === '$';
|
|
57
|
+
if (isHash) {
|
|
58
|
+
setShowDropdown(value.startsWith('#'));
|
|
74
59
|
} else {
|
|
75
|
-
setShowDropdown(
|
|
60
|
+
setShowDropdown(isDollarTyped);
|
|
61
|
+
setShowCreateVariableIcon(!value?.includes('$'));
|
|
76
62
|
}
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
63
|
+
if (value.startsWith('#') && isHash) {
|
|
64
|
+
const searchQuery = value.slice(1).toLowerCase();
|
|
65
|
+
const filtered = dataFiles.filter((file) =>
|
|
66
|
+
file.name.toLowerCase().includes(searchQuery)
|
|
67
|
+
);
|
|
68
|
+
setFilteredOptions(filtered);
|
|
69
|
+
setShowDropdown(filtered.length > 0);
|
|
81
70
|
}
|
|
82
|
-
}
|
|
83
|
-
};
|
|
71
|
+
}, [value]);
|
|
84
72
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
73
|
+
const handleDropdownClick = (item: dynamicObject) => {
|
|
74
|
+
if (inputRef.current) {
|
|
75
|
+
const { selectionStart, selectionEnd } = inputRef.current;
|
|
76
|
+
const dollarSyntax = `{${
|
|
77
|
+
item.type === 'LOCAL'
|
|
78
|
+
? 'LV'
|
|
79
|
+
: item.type === 'GLOBAL'
|
|
80
|
+
? 'GV'
|
|
81
|
+
: item.type === 'GROUP'
|
|
82
|
+
? 'SG'
|
|
83
|
+
: 'PEV'
|
|
84
|
+
}_${item.name}}`;
|
|
97
85
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
86
|
+
let newValue;
|
|
87
|
+
if (isHash && value[0] === '#') {
|
|
88
|
+
newValue = item.name + value.slice(selectionEnd || 1);
|
|
89
|
+
} else {
|
|
90
|
+
newValue =
|
|
91
|
+
value.slice(0, selectionStart || 0) +
|
|
92
|
+
dollarSyntax +
|
|
93
|
+
value.slice(selectionEnd || 0);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (onChange) {
|
|
97
|
+
const event = {
|
|
98
|
+
target: {
|
|
99
|
+
value: newValue,
|
|
100
|
+
},
|
|
101
|
+
} as React.ChangeEvent<HTMLInputElement>;
|
|
102
|
+
onChange(event);
|
|
103
|
+
}
|
|
104
|
+
inputRef.current.value = newValue;
|
|
105
|
+
setHashInputValue?.(item);
|
|
106
|
+
setCursorPosition((selectionStart || 0) + dollarSyntax.length);
|
|
107
|
+
setShowDropdown(false);
|
|
106
108
|
}
|
|
107
|
-
|
|
108
|
-
setInputValue(newValue);
|
|
109
|
-
setCursorPosition((selectionStart || 0) + dollarSyntax.length);
|
|
110
|
-
setShowDropdown(false);
|
|
111
|
-
}
|
|
112
|
-
};
|
|
109
|
+
};
|
|
113
110
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
name="add_variable"
|
|
120
|
-
ref={inputRef}
|
|
121
|
-
type="text"
|
|
122
|
-
value={inputValue}
|
|
123
|
-
onChange={handleChange}
|
|
124
|
-
variant="primary"
|
|
125
|
-
label={label}
|
|
126
|
-
placeholder={placeholder}
|
|
127
|
-
/>
|
|
128
|
-
{!checkEmpty(value) && !isHash && showCreateVariableIcon && (
|
|
129
|
-
<Icon
|
|
130
|
-
onClick={onCreateVariableClick}
|
|
111
|
+
return (
|
|
112
|
+
<div className="ff-add-variable-container">
|
|
113
|
+
<div className="ff-add-variable-input">
|
|
114
|
+
<Input
|
|
115
|
+
{...props}
|
|
131
116
|
name="add_variable"
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
117
|
+
ref={inputRef}
|
|
118
|
+
type="text"
|
|
119
|
+
value={value}
|
|
120
|
+
onChange={onChange}
|
|
121
|
+
variant="primary"
|
|
122
|
+
label={label}
|
|
123
|
+
placeholder={placeholder}
|
|
135
124
|
/>
|
|
136
|
-
|
|
125
|
+
{!checkEmpty(value) && !isHash && showCreateVariableIcon && (
|
|
126
|
+
<Icon
|
|
127
|
+
onClick={onCreateVariableClick}
|
|
128
|
+
name="add_variable"
|
|
129
|
+
width={24}
|
|
130
|
+
height={24}
|
|
131
|
+
hoverEffect
|
|
132
|
+
/>
|
|
133
|
+
)}
|
|
134
|
+
</div>
|
|
135
|
+
{showDropdown &&
|
|
136
|
+
(isHash ? (
|
|
137
|
+
<OptionsDropdown
|
|
138
|
+
position="relative"
|
|
139
|
+
width={dropdownWidth}
|
|
140
|
+
filteredOptions={filteredOptions}
|
|
141
|
+
onSelectVariable={handleDropdownClick}
|
|
142
|
+
/>
|
|
143
|
+
) : (
|
|
144
|
+
<VariableDropdown
|
|
145
|
+
position="absolute"
|
|
146
|
+
width={dropdownWidth}
|
|
147
|
+
optionsList={variableList}
|
|
148
|
+
onSelectVariable={handleDropdownClick}
|
|
149
|
+
/>
|
|
150
|
+
))}
|
|
137
151
|
</div>
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
position="relative"
|
|
142
|
-
width={dropdownWidth}
|
|
143
|
-
filteredOptions={filteredOptions}
|
|
144
|
-
onSelectVariable={handleDropdownClick}
|
|
145
|
-
/>
|
|
146
|
-
) : (
|
|
147
|
-
<VariableDropdown
|
|
148
|
-
position="absolute"
|
|
149
|
-
width={dropdownWidth}
|
|
150
|
-
optionsList={variableList}
|
|
151
|
-
onSelectVariable={handleDropdownClick}
|
|
152
|
-
/>
|
|
153
|
-
))}
|
|
154
|
-
</div>
|
|
155
|
-
);
|
|
156
|
-
};
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
);
|
|
157
155
|
|
|
158
156
|
export default ConditionalDropdown;
|
|
@@ -26,7 +26,7 @@ export interface ConditionalDropdownProps {
|
|
|
26
26
|
/**
|
|
27
27
|
* Function storing and updating the inputValue state
|
|
28
28
|
*/
|
|
29
|
-
setHashInputValue?:(value: dynamicObject |
|
|
29
|
+
setHashInputValue?: (value: File | dynamicObject | null) => void;
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* List of variables
|
|
@@ -41,7 +41,7 @@ export interface ConditionalDropdownProps {
|
|
|
41
41
|
* @param value
|
|
42
42
|
* @returns
|
|
43
43
|
*/
|
|
44
|
-
onChange?: (
|
|
44
|
+
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
45
45
|
/**
|
|
46
46
|
* Function to handle create variable icon click
|
|
47
47
|
*/
|
|
@@ -122,14 +122,14 @@ export interface ConditionalDropdownProps {
|
|
|
122
122
|
*/
|
|
123
123
|
isLabelRequired?: boolean;
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
/**
|
|
126
126
|
* If true, dropdown opens when '#' is entered at the first position.
|
|
127
127
|
*/
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
isHash?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Options for the dropdown when `isHash` is true.
|
|
131
|
+
*/
|
|
132
|
+
dataFiles?: dynamicObject[];
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
export interface OptionsDropdownProps {
|