@integry/sdk 4.7.39 → 4.7.41

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.
Files changed (267) hide show
  1. package/dist/esm/index.csm.js +1 -1
  2. package/dist/umd/index.umd.js +1 -1
  3. package/package.json +6 -1
  4. package/.eslintignore +0 -1
  5. package/.vscode/launch.json +0 -17
  6. package/CHANGELOG_INTERNAL.md +0 -134
  7. package/README_INTERNAL.md +0 -176
  8. package/THIRD_PARTY_LICENSES +0 -525
  9. package/generateTests.js +0 -80
  10. package/jest.config.cjs +0 -10
  11. package/src/components/AddTagButton/index.ts +0 -23
  12. package/src/components/BasicSelect/index.ts +0 -123
  13. package/src/components/BasicSelect/styles.module.scss +0 -44
  14. package/src/components/Button/index.ts +0 -97
  15. package/src/components/Button/styles.module.scss +0 -152
  16. package/src/components/CheckboxGroup/Checkbox.ts +0 -104
  17. package/src/components/CheckboxGroup/index.ts +0 -190
  18. package/src/components/CheckboxGroup/styles.module.scss +0 -63
  19. package/src/components/CollapsedMenu/index.ts +0 -104
  20. package/src/components/CollapsedMenu/styles.module.scss +0 -46
  21. package/src/components/ConfigureFieldWrapper/index.ts +0 -85
  22. package/src/components/ConfigureFieldWrapper/styles.module.scss +0 -57
  23. package/src/components/EditableText/index.ts +0 -121
  24. package/src/components/EditableText/styles.module.scss +0 -38
  25. package/src/components/EditableTextArea/index.ts +0 -143
  26. package/src/components/EditableTextArea/styles.module.scss +0 -91
  27. package/src/components/ErrorMessage/index.ts +0 -16
  28. package/src/components/ErrorMessage/styles.module.scss +0 -19
  29. package/src/components/ErrorPage/index.ts +0 -42
  30. package/src/components/ErrorPage/styles.module.scss +0 -26
  31. package/src/components/Footer/index.ts +0 -41
  32. package/src/components/Footer/styles.module.scss +0 -40
  33. package/src/components/HTMLContent/index.tsx +0 -205
  34. package/src/components/HTMLContent/styles.module.scss +0 -3
  35. package/src/components/InfoBox/index.ts +0 -48
  36. package/src/components/InfoBox/styles.module.scss +0 -21
  37. package/src/components/Input/BaseInput/index.ts +0 -170
  38. package/src/components/Input/BaseInput/styles.module.scss +0 -95
  39. package/src/components/Input/DateInput/index.ts +0 -103
  40. package/src/components/Input/DateInput/styles.module.scss +0 -50
  41. package/src/components/Input/Input/index.ts +0 -225
  42. package/src/components/Input/Input/styles.module.scss +0 -16
  43. package/src/components/Input/PasswordInput/index.ts +0 -164
  44. package/src/components/Input/PasswordInput/styles.module.scss +0 -37
  45. package/src/components/Input/index.ts +0 -7
  46. package/src/components/Label/index.ts +0 -61
  47. package/src/components/Label/styles.module.scss +0 -41
  48. package/src/components/LargeLoader/index.ts +0 -25
  49. package/src/components/LargeLoader/styles.module.scss +0 -16
  50. package/src/components/Listbox/ListBoxItem.ts +0 -57
  51. package/src/components/Listbox/index.ts +0 -488
  52. package/src/components/Listbox/styles.module.scss +0 -197
  53. package/src/components/Loader/index.ts +0 -25
  54. package/src/components/Loader/styles.module.scss +0 -16
  55. package/src/components/MediaGallery/MediaGalleryModal.ts +0 -82
  56. package/src/components/MediaGallery/MediaSlider.ts +0 -76
  57. package/src/components/MediaGallery/index.ts +0 -92
  58. package/src/components/MediaGallery/styles.module.scss +0 -156
  59. package/src/components/MediaUpload/index.ts +0 -233
  60. package/src/components/MediaUpload/styles.module.scss +0 -118
  61. package/src/components/Modal/index.ts +0 -87
  62. package/src/components/Modal/styles.module.scss +0 -441
  63. package/src/components/MultipurposeField/Dropdown/ListBoxItem.tsx +0 -59
  64. package/src/components/MultipurposeField/Dropdown/index.tsx +0 -1202
  65. package/src/components/MultipurposeField/Dropdown/styles.module.scss +0 -215
  66. package/src/components/MultipurposeField/TagMenu/index.ts +0 -536
  67. package/src/components/MultipurposeField/TagMenu/styles.module.scss +0 -175
  68. package/src/components/MultipurposeField/TagOptions/index.tsx +0 -83
  69. package/src/components/MultipurposeField/TagOptions/styles.module.scss +0 -95
  70. package/src/components/MultipurposeField/index.tsx +0 -944
  71. package/src/components/MultipurposeField/styles.module.scss +0 -77
  72. package/src/components/NewModal/index.ts +0 -69
  73. package/src/components/NewModal/styles.module.scss +0 -70
  74. package/src/components/OverflowTooltip/index.tsx +0 -59
  75. package/src/components/PopUp/ConfirmationPopUp/index.ts +0 -58
  76. package/src/components/PopUp/ConfirmationPopUp/styles.module.scss +0 -49
  77. package/src/components/PopUp/SuccessPopUp/index.ts +0 -62
  78. package/src/components/PopUp/SuccessPopUp/styles.module.scss +0 -38
  79. package/src/components/RadioGroup/Radio.ts +0 -128
  80. package/src/components/RadioGroup/index.ts +0 -169
  81. package/src/components/RadioGroup/styles.module.scss +0 -81
  82. package/src/components/Search/index.ts +0 -69
  83. package/src/components/Search/styles.module.scss +0 -149
  84. package/src/components/TabBar/Tab.ts +0 -33
  85. package/src/components/TabBar/index.ts +0 -64
  86. package/src/components/TabBar/styles.module.scss +0 -43
  87. package/src/components/Tag/index.ts +0 -29
  88. package/src/components/Tag/styles.module.scss +0 -57
  89. package/src/components/TagsMenu/index.ts +0 -1697
  90. package/src/components/TagsMenu/styles.module.scss +0 -350
  91. package/src/components/TestComponent/index.ts +0 -71
  92. package/src/components/TestComponent/styles.module.scss +0 -152
  93. package/src/components/TextArea/index.ts +0 -172
  94. package/src/components/TextArea/styles.module.scss +0 -72
  95. package/src/components/TextContent/index.tsx +0 -128
  96. package/src/components/TextContent/styles.module.scss +0 -6
  97. package/src/components/ThreeDotLoader/index.ts +0 -39
  98. package/src/components/ThreeDotLoader/styles.module.scss +0 -41
  99. package/src/components/TimeInput/index.ts +0 -129
  100. package/src/components/TimeInput/styles.module.scss +0 -16
  101. package/src/components/Toggle/index.ts +0 -34
  102. package/src/components/Toggle/styles.module.scss +0 -56
  103. package/src/components/Toggle-v2/index.ts +0 -40
  104. package/src/components/Toggle-v2/styles.module.scss +0 -86
  105. package/src/components/Tooltip/index.ts +0 -271
  106. package/src/components/Tooltip/styles.module.scss +0 -105
  107. package/src/components/form/FunctionField/index.ts +0 -816
  108. package/src/components/form/FunctionField/styles.module.scss +0 -478
  109. package/src/components/form/ObjectField/__snapshots__/index.ts.test.tsx.snap +0 -3
  110. package/src/components/form/ObjectField/index.ts +0 -593
  111. package/src/components/form/ObjectField/index.ts.test.tsx +0 -213
  112. package/src/components/form/ObjectField/styles.module.scss +0 -103
  113. package/src/components/form/index.ts +0 -4
  114. package/src/contexts/AppContext.ts +0 -12
  115. package/src/declaration.d.ts +0 -7
  116. package/src/extensions/HMAC.ts +0 -25
  117. package/src/extensions/IntegryAPIError.ts +0 -19
  118. package/src/features/common/AccountDropdown/index.ts +0 -291
  119. package/src/features/common/AccountDropdown/styles.module.scss +0 -19
  120. package/src/features/common/ActionForm/index.ts +0 -2602
  121. package/src/features/common/ActionForm/styles.module.scss +0 -35
  122. package/src/features/common/AppCard/index.ts +0 -207
  123. package/src/features/common/AppCard/styles.module.scss +0 -117
  124. package/src/features/common/AppCardCompact/index.ts +0 -189
  125. package/src/features/common/AppCardCompact/styles.module.scss +0 -141
  126. package/src/features/common/AuthSelector/index.ts +0 -537
  127. package/src/features/common/AuthSelector/styles.module.scss +0 -161
  128. package/src/features/common/AuthSelectorCompact/index.ts +0 -706
  129. package/src/features/common/AuthSelectorCompact/styles.module.scss +0 -219
  130. package/src/features/common/AuthSelectorDropdown/index.ts +0 -704
  131. package/src/features/common/AuthSelectorDropdown/styles.module.scss +0 -361
  132. package/src/features/common/AuthSelectorV2/index.ts +0 -336
  133. package/src/features/common/AuthSelectorV2/styles.module.scss +0 -235
  134. package/src/features/common/DynamicField/index.ts +0 -402
  135. package/src/features/common/DynamicField/styles.module.scss +0 -266
  136. package/src/features/common/DynamicTypedField/index.ts +0 -504
  137. package/src/features/common/DynamicTypedField/styles.module.scss +0 -135
  138. package/src/features/common/FunctionForm/index.ts +0 -1095
  139. package/src/features/common/FunctionForm/styles.module.scss +0 -225
  140. package/src/features/common/MappingUI/index.ts +0 -649
  141. package/src/features/common/MappingUI/styles.module.scss +0 -121
  142. package/src/features/common/MarketplaceAppCard/index.ts +0 -279
  143. package/src/features/common/MarketplaceAppCard/styles.module.scss +0 -231
  144. package/src/features/common/MarketplaceAppCardCompact/index.ts +0 -283
  145. package/src/features/common/MarketplaceAppCardCompact/styles.module.scss +0 -255
  146. package/src/features/common/NewMappingUI/index.ts +0 -515
  147. package/src/features/common/NewMappingUI/styles.module.scss +0 -113
  148. package/src/features/common/RequestAppWidget/RequestAppModal/index.ts +0 -67
  149. package/src/features/common/RequestAppWidget/RequestAppModal/styles.module.scss +0 -23
  150. package/src/features/common/RequestAppWidget/index.ts +0 -48
  151. package/src/features/common/RequestAppWidget/request-app-form.ts +0 -89
  152. package/src/features/common/RequestAppWidget/styles.module.scss +0 -43
  153. package/src/features/common/SectionField/index.ts +0 -272
  154. package/src/features/common/SectionField/styles.module.scss +0 -67
  155. package/src/features/common/Step/index.ts +0 -827
  156. package/src/features/common/Step/styles.module.scss +0 -12
  157. package/src/features/common/StepNavigation/CollapsedSteps.ts +0 -131
  158. package/src/features/common/StepNavigation/NavItem.ts +0 -111
  159. package/src/features/common/StepNavigation/index.ts +0 -261
  160. package/src/features/common/StepNavigation/styles.module.scss +0 -117
  161. package/src/features/common/Steps/index.ts +0 -1140
  162. package/src/features/common/Steps/styles.module.scss +0 -314
  163. package/src/features/containers/AppFlowContainer/AppFlowListing/compactStyles.module.scss +0 -404
  164. package/src/features/containers/AppFlowContainer/AppFlowListing/flow-instance.tsx +0 -367
  165. package/src/features/containers/AppFlowContainer/AppFlowListing/flowCard.test.tsx +0 -58
  166. package/src/features/containers/AppFlowContainer/AppFlowListing/flowCard.tsx +0 -208
  167. package/src/features/containers/AppFlowContainer/AppFlowListing/flowCardCompact.test.tsx +0 -49
  168. package/src/features/containers/AppFlowContainer/AppFlowListing/flowCardCompact.tsx +0 -421
  169. package/src/features/containers/AppFlowContainer/AppFlowListing/flowInstanceCompact.tsx +0 -577
  170. package/src/features/containers/AppFlowContainer/AppFlowListing/index.tsx +0 -83
  171. package/src/features/containers/AppFlowContainer/AppFlowListing/styles.module.scss +0 -233
  172. package/src/features/containers/AppFlowContainer/AppFlowWrap/app-page-loader.tsx +0 -45
  173. package/src/features/containers/AppFlowContainer/AppFlowWrap/index.tsx +0 -1085
  174. package/src/features/containers/AppFlowContainer/AppFlowWrap/styles.module.scss +0 -465
  175. package/src/features/containers/AppFlowContainer/Authentication/index.ts +0 -610
  176. package/src/features/containers/AppFlowContainer/Authentication/styles.module.scss +0 -468
  177. package/src/features/containers/AppFlowContainer/index.ts +0 -114
  178. package/src/features/containers/AppPageContainer/AppPage/index.tsx +0 -262
  179. package/src/features/containers/AppPageContainer/AppPage/styles.module.scss +0 -120
  180. package/src/features/containers/AppPageContainer/IntegrationCard/index.ts +0 -165
  181. package/src/features/containers/AppPageContainer/IntegrationCard/styles.module.scss +0 -81
  182. package/src/features/containers/AppPageContainer/index.tsx +0 -93
  183. package/src/features/containers/AppPageContainer/styles.module.scss +0 -0
  184. package/src/features/containers/AppsForFlows/index.ts +0 -161
  185. package/src/features/containers/AppsForFlows/styles.module.scss +0 -280
  186. package/src/features/containers/AppsForFlowsCompact/index.ts +0 -161
  187. package/src/features/containers/AppsForFlowsCompact/styles.module.scss +0 -279
  188. package/src/features/containers/AuthSetupContainer/AppSelection.ts +0 -73
  189. package/src/features/containers/AuthSetupContainer/AuthTypeSelection.ts +0 -67
  190. package/src/features/containers/AuthSetupContainer/Footer.ts +0 -32
  191. package/src/features/containers/AuthSetupContainer/Header.ts +0 -39
  192. package/src/features/containers/AuthSetupContainer/PostAdditionPopup.ts +0 -27
  193. package/src/features/containers/AuthSetupContainer/index.ts +0 -349
  194. package/src/features/containers/AuthSetupContainer/styles.module.scss +0 -229
  195. package/src/features/containers/FlowSetupContainer/index.ts +0 -391
  196. package/src/features/containers/FlowSetupContainer/styles.module.scss +0 -18
  197. package/src/features/containers/MarkeplaceApps/index.ts +0 -583
  198. package/src/features/containers/MarkeplaceApps/styles.module.scss +0 -558
  199. package/src/features/containers/MarketplaceAppsCompact/index.ts +0 -585
  200. package/src/features/containers/MarketplaceAppsCompact/styles.module.scss +0 -563
  201. package/src/features/containers/MarketplaceAppsContainer/index.ts +0 -91
  202. package/src/features/containers/MarketplaceContainer/AppCard/index.ts +0 -91
  203. package/src/features/containers/MarketplaceContainer/AppCard/styles.module.scss +0 -66
  204. package/src/features/containers/MarketplaceContainer/AppListing/index.ts +0 -34
  205. package/src/features/containers/MarketplaceContainer/AppListing/styles.module.scss +0 -10
  206. package/src/features/containers/MarketplaceContainer/MarketplaceContentWrap/index.ts +0 -132
  207. package/src/features/containers/MarketplaceContainer/MarketplaceContentWrap/styles.module.scss +0 -117
  208. package/src/features/containers/MarketplaceContainer/index.ts +0 -242
  209. package/src/features/containers/MarketplaceContainer/styles.module.scss +0 -84
  210. package/src/features/containers/SDKContainer/index.ts +0 -817
  211. package/src/features/containers/SDKContainer/styles.module.scss +0 -266
  212. package/src/features/containers/SDKDebugContainer/index.ts +0 -137
  213. package/src/features/containers/SDKDebugContainer/styles.module.scss +0 -37
  214. package/src/features/containers/SDKFailedContainer/index.ts +0 -117
  215. package/src/features/containers/SDKFailedContainer/styles.module.scss +0 -57
  216. package/src/features/integrations/IntegrationRow/Icons.ts +0 -77
  217. package/src/features/integrations/IntegrationRow/index.ts +0 -129
  218. package/src/features/integrations/IntegrationRow/styles.module.scss +0 -62
  219. package/src/features/integrations/IntegrationsHeader/index.ts +0 -34
  220. package/src/features/integrations/IntegrationsHeader/styles.module.scss +0 -47
  221. package/src/features/integrations/IntegrationsList/index.ts +0 -252
  222. package/src/features/integrations/IntegrationsList/styles.module.scss +0 -67
  223. package/src/features/templates/Template/index.ts +0 -295
  224. package/src/features/templates/Template/styles.module.scss +0 -226
  225. package/src/features/templates/TemplatesView/index.ts +0 -368
  226. package/src/features/templates/TemplatesView/styles.module.scss +0 -71
  227. package/src/features/templates/TemplatesViewCompact/index.ts +0 -364
  228. package/src/features/templates/TemplatesViewCompact/styles.module.scss +0 -141
  229. package/src/hooks/useAutosizeTextArea.ts +0 -22
  230. package/src/hooks/useCustomRef.ts +0 -13
  231. package/src/hooks/useDebounce.ts +0 -17
  232. package/src/hooks/useElementResize.ts +0 -40
  233. package/src/hooks/useEventListener.ts +0 -42
  234. package/src/hooks/useHover.ts +0 -40
  235. package/src/hooks/useOnClickOutside.ts +0 -32
  236. package/src/index.ts +0 -2244
  237. package/src/index.umd.ts +0 -13
  238. package/src/interfaces/index.ts +0 -938
  239. package/src/modules/api/index.ts +0 -1325
  240. package/src/modules/api/responseHandler.ts +0 -38
  241. package/src/modules/event-emitter/index.ts +0 -72
  242. package/src/modules/event-emitter/runners/abstract.ts +0 -21
  243. package/src/modules/event-emitter/runners/default.ts +0 -11
  244. package/src/modules/event-emitter/runners/ntimes.ts +0 -28
  245. package/src/modules/event-emitter/types.ts +0 -34
  246. package/src/store/actionFunctions.ts +0 -1578
  247. package/src/store/index.ts +0 -17
  248. package/src/store/initialState.ts +0 -58
  249. package/src/types/index.ts +0 -320
  250. package/src/types/preact-compat.d.ts +0 -4
  251. package/src/types/store.ts +0 -366
  252. package/src/types/utils.ts +0 -19
  253. package/src/utils/ActivityOutputUtils.ts +0 -176
  254. package/src/utils/common.ts +0 -20
  255. package/src/utils/copyToClipboard.ts +0 -24
  256. package/src/utils/datetime.ts +0 -101
  257. package/src/utils/getUrlParam.ts +0 -11
  258. package/src/utils/isAuthMessage.ts +0 -16
  259. package/src/utils/isBrowser.ts +0 -1
  260. package/src/utils/jsonEncodeDecode.ts +0 -15
  261. package/src/utils/objectUtils.ts +0 -117
  262. package/src/utils/popup.ts +0 -30
  263. package/src/utils/searchJson.ts +0 -51
  264. package/src/utils/stepUtils.ts +0 -45
  265. package/src/utils/truncate.ts +0 -6
  266. package/test/setup.ts +0 -1
  267. package/vitest.config.ts +0 -16
@@ -1,1202 +0,0 @@
1
- /* eslint-disable no-nested-ternary */
2
- /* eslint-disable no-use-before-define */
3
- import { html } from 'htm/preact';
4
- import {
5
- useCallback,
6
- useEffect,
7
- useMemo,
8
- useState,
9
- useRef,
10
- } from 'preact/hooks';
11
- import fuzzysort from 'fuzzysort';
12
- import { createNewSortInstance } from 'fast-sort';
13
- import { NestedObject } from '@/interfaces';
14
- import { Label } from '@/components/Label';
15
- import { Hint } from '@/components/Tooltip';
16
- import { useOnClickOutside } from '@/hooks/useOnClickOutside';
17
- import { ThreeDotLoader } from '@/components/ThreeDotLoader';
18
- import { IntegryAPI } from '@/modules/api';
19
- import { ErrorMessage } from '@/components/ErrorMessage';
20
- import useCustomRef from '@/hooks/useCustomRef';
21
- import { TagButton } from '@/components/AddTagButton';
22
- import { ListBoxItemProps } from './ListBoxItem';
23
- import { FieldDropdown, Tabs } from '../TagMenu';
24
-
25
- import styles from './styles.module.scss';
26
-
27
- type keyValueMapper = (
28
- input: any,
29
- ) => { id: any; value: any; icon?: any; description?: any }[];
30
-
31
- interface ListBoxProps {
32
- title: string;
33
- description: string;
34
- items: Omit<ListBoxItemProps, 'onClick'>[];
35
- value?: string;
36
- onChange(val: string, stopPropagation?: boolean): void;
37
- isOpen?: boolean;
38
- isDynamic?: boolean;
39
- endpointUrl?: string;
40
- isSearchable?: boolean;
41
- placeholder: string | null;
42
- isRequired?: boolean;
43
- isHidden?: boolean;
44
- showStepValidation?: boolean;
45
- responseMapper?(input: unknown): Omit<ListBoxItemProps, 'onClick'>[];
46
- apiHandler: IntegryAPI;
47
- endpointData: string;
48
- isReadOnly?: boolean;
49
- isChanged?: boolean;
50
- tagValue?: string;
51
- taggedSelect?: boolean;
52
- skipOptionFetch?: boolean;
53
- onAddTag?: () => void;
54
- activityOutputData?: NestedObject;
55
- sourceFlowData?: NestedObject;
56
- sourceFlowIntegrataionInvocationUrl?: string;
57
- isMappable: boolean;
58
- type: string;
59
- appName: string;
60
- fieldId?: string;
61
- isConfigMode: boolean;
62
- isEditable: boolean;
63
- allowTagsInText: boolean;
64
- labelTags: string[];
65
- hideTabs?: boolean;
66
- selectedAuthId?: string;
67
- disabled?: boolean;
68
- isMultiSelect?: boolean;
69
- optionKeyPath?: string;
70
- valueKeyPath?: string;
71
- dataSourceBody?: any;
72
- parentFieldChanged?: boolean;
73
- allowWorkspaceConnectedAccounts: boolean;
74
- tagsTree?: any;
75
- enableServerSideSearch?: boolean;
76
- serverSideSearchParamName?: string;
77
- iconKeyPath?: string;
78
- optionDescriptionKeyPath?: string;
79
- skipInitialLoad?: boolean;
80
- showMenuOnLeft?: boolean;
81
- }
82
-
83
- const ListBox = (props: ListBoxProps) => {
84
- const {
85
- title,
86
- description,
87
- items: passedItems = [],
88
- value = null,
89
- isOpen = false,
90
- isDynamic = false,
91
- endpointData,
92
- isSearchable = false,
93
- isRequired = false,
94
- isHidden = false,
95
- placeholder,
96
- onChange = () => null,
97
- showStepValidation = false,
98
- responseMapper = (input: { id: string; value: string }[]) => input,
99
- isReadOnly = false,
100
- isChanged = false,
101
- tagValue = '',
102
- taggedSelect = false,
103
- skipOptionFetch = false,
104
- onAddTag,
105
- activityOutputData = {},
106
- type,
107
- appName,
108
- fieldId = 'dropdown-field',
109
- isConfigMode = false,
110
- isMappable = false,
111
- isEditable = false,
112
- allowTagsInText = false,
113
- labelTags = [],
114
- endpointUrl,
115
- hideTabs = true,
116
- sourceFlowData = {},
117
- sourceFlowIntegrataionInvocationUrl = '',
118
- selectedAuthId = '',
119
- disabled = false,
120
- isMultiSelect = false,
121
- dataSourceBody = {},
122
- parentFieldChanged = false,
123
- allowWorkspaceConnectedAccounts = false,
124
- tagsTree = null,
125
- skipInitialLoad = false,
126
- showMenuOnLeft = false,
127
- } = props;
128
-
129
- const [query, setQuery] = useState<string>('');
130
-
131
- const [items, setItems] = useState<Omit<ListBoxItemProps, 'onClick'>[]>(
132
- passedItems,
133
- );
134
-
135
- const [highlightedIndex, setHighlightedIndex] = useState<number>(-1);
136
-
137
- const [filteredItems, setFilteredItems] = useState<
138
- Omit<ListBoxItemProps, 'onClick'>[]
139
- >(passedItems);
140
-
141
- const [loading, setLoading] = useState(
142
- isDynamic && !passedItems.length && !value && selectedAuthId !== '',
143
- );
144
-
145
- const [isDropdownOpen, setIsDropdownOpen] = useState(isOpen);
146
-
147
- const [tempPlaceholder, setTempPlaceholder] = useState('');
148
- const [searchValue, setSearchValue] = useState('');
149
- const [editableTextValue, setEditableTextValue] = useState(value);
150
- const [isErrorOnLoadingOptions, setIsErrorOnLoadingOptions] = useState(false);
151
- const [nextPage, setNextPage] = useState('');
152
-
153
- const [selectedTab, setSelectedTab] = useState('');
154
-
155
- const [dropdownRef] = useCustomRef<HTMLDivElement>();
156
- const [dropdownMenuRef] = useCustomRef<HTMLDivElement>();
157
- const [inputRef] = useCustomRef<HTMLInputElement>();
158
- const queryRef = useRef(query);
159
-
160
- useOnClickOutside(dropdownMenuRef, (e) => {
161
- const clickedElement = e.target as HTMLElement;
162
- const clickedElementIsDropdownField = document
163
- .getElementById(fieldId)
164
- ?.contains(clickedElement);
165
- setTempPlaceholder('');
166
-
167
- if (clickedElementIsDropdownField) {
168
- return;
169
- }
170
- if (isDropdownOpen) {
171
- setIsDropdownOpen(false);
172
- setHighlightedIndex(-1);
173
- setSearchValue('');
174
- }
175
- });
176
-
177
- useEffect(() => {
178
- queryRef.current = query;
179
- }, [query]);
180
-
181
- useEffect(() => {
182
- if (value) {
183
- if (onChange) onChange(value);
184
- }
185
- }, [fieldId]);
186
-
187
- useEffect(() => {
188
- if (highlightedIndex > -1 && isDropdownOpen) {
189
- const item = filteredItems[highlightedIndex];
190
- if (item) {
191
- const domEl = document.querySelector(`[data-value="${item.id}"]`);
192
- domEl?.scrollIntoView({ block: 'nearest', inline: 'nearest' });
193
- }
194
- }
195
- }, [highlightedIndex, isDropdownOpen]);
196
-
197
- useEffect(() => {
198
- if (tagValue && tagValue !== query) {
199
- setQuery(tagValue);
200
- }
201
- }, [tagValue]);
202
-
203
- useEffect(() => {
204
- if (dropdownRef && dropdownRef.current && isDropdownOpen === true) {
205
- if (dropdownRef && dropdownRef.current) {
206
- dropdownRef.current?.addEventListener('keyup', upHandler);
207
- }
208
- }
209
- document.addEventListener('keydown', handleKeyDown);
210
- // Remove event listeners on cleanup
211
- return () => {
212
- if (dropdownRef && dropdownRef.current) {
213
- dropdownRef.current.removeEventListener('keyup', upHandler);
214
- }
215
- document.removeEventListener('keydown', handleKeyDown);
216
- };
217
- }, [isDropdownOpen, dropdownRef, highlightedIndex]);
218
-
219
- useEffect(() => {
220
- let timer: null | ReturnType<typeof setTimeout> = null;
221
- if (!Array.isArray(items)) {
222
- setItems([]);
223
- }
224
- const item = items.find((a) => a.id === value);
225
-
226
- if (!isDropdownOpen && query && !value) {
227
- setQuery('');
228
- timer = setTimeout(() => {
229
- setSortedFilteredItems(items);
230
- }, 250);
231
- } else if (!isDropdownOpen && value && item) {
232
- setQuery(item.value);
233
- } else if (!isDropdownOpen && tagValue && !skipOptionFetch) {
234
- setQuery(tagValue);
235
- }
236
- return () => {
237
- if (timer) clearTimeout(timer);
238
- };
239
- }, [isDropdownOpen]);
240
-
241
- const isInitialLoadRef = useRef(true);
242
-
243
- useEffect(() => {
244
- if (isInitialLoadRef.current) {
245
- isInitialLoadRef.current = false;
246
- return;
247
- }
248
- setEditableTextValue('');
249
- setQuery('');
250
- setSearchValue('');
251
- if (inputRef.current) {
252
- inputRef.current.value = '';
253
- }
254
- onChange('');
255
- }, [endpointData, endpointUrl, selectedAuthId, parentFieldChanged]);
256
-
257
- useEffect(() => {
258
- if (query && isSearchable) {
259
- const filtered = items.filter((item) =>
260
- item.value.toLowerCase().includes(query.toLowerCase()),
261
- );
262
- setHighlightedIndex(-1);
263
- setSortedFilteredItems(filtered);
264
- if (filtered.length === 1) setHighlightedIndex(0);
265
- } else if (isDropdownOpen) {
266
- setHighlightedIndex(-1);
267
- setSortedFilteredItems(items);
268
- }
269
- }, [query]);
270
-
271
- useEffect(() => {
272
- const checkboxItems = [
273
- { id: '1', value: 'Yes' },
274
- { id: '0', value: 'No' },
275
- ];
276
-
277
- // eslint-disable-next-line @typescript-eslint/no-shadow
278
- if (skipOptionFetch && isDynamic) {
279
- // skip option fetch for dynamic dropdowns only. Static dropdowns should always fetch options
280
- setLoading(false);
281
- setFilteredItems([]);
282
- setItems([]);
283
- setQuery('');
284
- if (inputRef.current) {
285
- inputRef.current.value = '';
286
- }
287
- return;
288
- }
289
- const { apiHandler } = props;
290
-
291
- if (
292
- isDynamic &&
293
- sourceFlowIntegrataionInvocationUrl &&
294
- !disabled &&
295
- !skipInitialLoad
296
- ) {
297
- fetchDynamicDataFromSourceFlow();
298
- } else if (isDynamic && endpointUrl && !disabled && !skipInitialLoad) {
299
- setLoading(true);
300
- let data;
301
- try {
302
- if (endpointData) {
303
- data = JSON.parse(endpointData) || {};
304
- } else {
305
- data = {};
306
- }
307
-
308
- if (selectedAuthId) {
309
- data.connected_account_id = selectedAuthId;
310
- data.authorization_id = selectedAuthId;
311
- }
312
- if (allowWorkspaceConnectedAccounts) {
313
- data.allow_workspace_connected_accounts = true;
314
- }
315
-
316
- // When server side search is available and results are paginated, then better to search the results as value might be in the next page
317
- if (
318
- props.enableServerSideSearch &&
319
- props.serverSideSearchParamName &&
320
- value
321
- ) {
322
- data[props.serverSideSearchParamName] = value;
323
- }
324
- } catch (error) {
325
- data = '';
326
- }
327
- const requestBodyData =
328
- typeof dataSourceBody === 'object' &&
329
- Object.keys(dataSourceBody).length > 0
330
- ? dataSourceBody
331
- : activityOutputData;
332
- apiHandler
333
- .callDynamicDataEndpointWithTags<
334
- {
335
- id: string;
336
- value: string;
337
- }[]
338
- >(new URL(endpointUrl), data, requestBodyData)
339
- .then((res: any) => {
340
- if (res) {
341
- const tempFilteredItems = dynamicResponseMapper(res);
342
- setItems(tempFilteredItems);
343
- if (res.hasOwnProperty('_cursor') && res._cursor !== null) {
344
- setFilteredItems(tempFilteredItems);
345
- setSortedFilteredItems(tempFilteredItems);
346
- } else {
347
- setSortedFilteredItems(tempFilteredItems);
348
- }
349
- if (tempFilteredItems.length === 1) {
350
- setEditableTextValue(tempFilteredItems[0].value);
351
- onChange(tempFilteredItems[0].id, true);
352
- } else if (value) {
353
- const item = tempFilteredItems.find((a) => a.id === value);
354
- if (item) {
355
- setEditableTextValue(item.value);
356
- onChange(item.id, true);
357
- }
358
- }
359
- // if value was selected before items were loaded, select it again
360
- if (value && isSearchable) {
361
- const item = dynamicResponseMapper(res).find(
362
- (a) => a.id === value,
363
- );
364
- if (item) {
365
- setQuery(item.value);
366
- } else {
367
- setQuery('');
368
- }
369
- setLoading(false);
370
- } else {
371
- setQuery('');
372
- setSearchValue('');
373
- setLoading(false);
374
- }
375
- } else {
376
- setIsErrorOnLoadingOptions(true);
377
- setLoading(false);
378
- }
379
- });
380
- } else if (isDynamic && endpointUrl && disabled) {
381
- setLoading(false);
382
- } else if (!isDynamic && endpointUrl) {
383
- // if isDynamic is false, endpointUrl will have JSON data instead of URL
384
- try {
385
- const data = JSON.parse(endpointUrl);
386
- if (type === 'CHECKBOX' && data.length === 1 && data[0].id === '1') {
387
- setSortedFilteredItems(responseMapper(checkboxItems));
388
- setItems(responseMapper(checkboxItems));
389
- setLoading(false);
390
- } else {
391
- setItems(responseMapper(data));
392
- setSortedFilteredItems(responseMapper(data));
393
- setLoading(false);
394
- }
395
- } catch (error) {
396
- console.error(error);
397
- }
398
- } else if (type === 'CHECKBOX') {
399
- // in case of single checkbox, we need to set the items(Yes/No) and filteredItems(Yes/No)
400
- setSortedFilteredItems(responseMapper(checkboxItems));
401
- setItems(responseMapper(checkboxItems));
402
- setLoading(false);
403
- }
404
- }, [
405
- endpointData,
406
- skipOptionFetch,
407
- endpointUrl,
408
- selectedAuthId,
409
- parentFieldChanged,
410
- ]);
411
-
412
- const handleKeyDown = (event: KeyboardEvent) => {
413
- if (event.key === 'Tab') {
414
- setIsDropdownOpen(false);
415
- }
416
- };
417
-
418
- const dynamicResponseMapper: keyValueMapper = (input) => {
419
- const keyPath = props.optionKeyPath || 'id';
420
- const valuePath = props.valueKeyPath || 'value';
421
- const inputModified = Object.prototype.hasOwnProperty.call(input, 'output')
422
- ? input.output
423
- : Object.prototype.hasOwnProperty.call(input, 'functions')
424
- ? input.functions
425
- : input;
426
-
427
- // Check if inputModified is an array, if not, return an empty array
428
- if (!Array.isArray(inputModified)) {
429
- console.warn(
430
- `Invalid data format for dropdown options for field ${fieldId}`,
431
- );
432
- return [];
433
- }
434
-
435
- if (input.hasOwnProperty('_cursor')) {
436
- setNextPage(input._cursor);
437
- }
438
-
439
- return inputModified.map((item: any) => {
440
- // Helper function to resolve value based on plain property or tag
441
- const resolveValue = (path: string): any => {
442
- // If the path contains template tags, process it
443
- if (/{([^}]+)}/.test(path)) {
444
- return path.replace(/{([^}]+)}/g, (_, placeholder) => {
445
- const keys = placeholder.split('.');
446
- return keys.reduce((acc: any, key: any) => acc && acc?.[key], item);
447
- });
448
- }
449
-
450
- // Otherwise, treat it as a plain property path
451
- const keys = path.split('.');
452
- return keys.reduce((acc: any, key) => acc && acc?.[key], item);
453
- };
454
-
455
- // Resolve id and value using the helper function
456
- const id = resolveValue(keyPath);
457
- let optionValue = resolveValue(valuePath);
458
- const icon = resolveValue(props.iconKeyPath || '');
459
- const optionDescription = resolveValue(
460
- props.optionDescriptionKeyPath || '',
461
- );
462
-
463
- // Fallback: If 'value' is undefined or an empty string, use 'id' as the value
464
- if (typeof optionValue === 'undefined' || optionValue === '') {
465
- optionValue = id;
466
- }
467
-
468
- if (id === '') {
469
- console.warn(
470
- `${keyPath} was not found in the response for field ${fieldId}`,
471
- );
472
- }
473
- if (optionValue === '') {
474
- console.warn(
475
- `${valuePath} was not found in the response for field ${fieldId}`,
476
- );
477
- }
478
-
479
- return { id, value: optionValue, icon, description: optionDescription };
480
- });
481
- };
482
-
483
- // If released key is our target key then set to false
484
- const upHandler = useCallback(
485
- ({ key }: { key: string }): void => {
486
- switch (key) {
487
- case 'Enter': // item selected
488
- onDropdownItemClicked(filteredItems[highlightedIndex]);
489
- break;
490
- case 'Escape': // cancel selection
491
- setIsDropdownOpen(false);
492
- inputRef.current?.blur();
493
- break;
494
- case 'ArrowDown': {
495
- if (highlightedIndex < 0) {
496
- setHighlightedIndex(0); // first item
497
- } else if (highlightedIndex < filteredItems.length - 1) {
498
- setHighlightedIndex((idx) => idx + 1); // next item
499
- } else {
500
- setHighlightedIndex(0); // wrap around
501
- }
502
- break;
503
- }
504
- case 'ArrowUp': {
505
- if (highlightedIndex < 0) {
506
- setHighlightedIndex(filteredItems.length - 1); // last item
507
- } else if (
508
- highlightedIndex < filteredItems.length &&
509
- highlightedIndex > 0
510
- ) {
511
- setHighlightedIndex((idx) => idx - 1); // previous item
512
- } else {
513
- setHighlightedIndex(filteredItems.length - 1); // wrap around
514
- }
515
- break;
516
- }
517
- default:
518
- break;
519
- }
520
- },
521
- [highlightedIndex, filteredItems],
522
- );
523
-
524
- const setSortedFilteredItems = (
525
- data: { id: string; value: string }[],
526
- ): void => {
527
- if (type === 'SELECT') {
528
- // sort A-Z for dropdowns
529
- const naturalSort = createNewSortInstance({
530
- comparer: new Intl.Collator(undefined, {
531
- numeric: true,
532
- sensitivity: 'base',
533
- }).compare,
534
- });
535
- const sorted = naturalSort(data).asc((item) => item.value);
536
- setFilteredItems(sorted);
537
- } else {
538
- setFilteredItems(data);
539
- }
540
- };
541
-
542
- const toggleDropdown = () => {
543
- if (!isReadOnly) {
544
- if (!isDropdownOpen) {
545
- setQuery('');
546
- inputRef.current?.focus();
547
- }
548
- setIsDropdownOpen((prev) => !prev);
549
- }
550
- };
551
-
552
- const handleMultipurposeOnChange = (option: string) => {
553
- const textField = inputRef.current;
554
- let newValue = `${option}`;
555
-
556
- // if the field is editable only, then EU can only eneter text, no tags and tags menu wont show up, so this function wont be called
557
- if (textField) {
558
- const { selectionStart = 0, selectionEnd = 0 } = textField;
559
- const oldValue = textField.value;
560
- const textBeforeCursor = oldValue.substring(0, selectionStart || 0);
561
- const textAfterCursor = oldValue.substring(selectionEnd || 0);
562
- const insertedText = `${option}`;
563
- newValue = textBeforeCursor + insertedText + textAfterCursor;
564
- textField.selectionStart = (selectionStart || 0) + insertedText.length;
565
- textField.selectionEnd = textField.selectionStart;
566
- textField.focus();
567
- }
568
- if (onChange) onChange(newValue);
569
- };
570
- const onDropdownItemClicked = (el: Omit<ListBoxItemProps, 'onClick'>) => {
571
- setTempPlaceholder('');
572
- setSearchValue('');
573
- let fieldVal = el.value;
574
- if (isMultiSelect) {
575
- let fieldIds = [];
576
- try {
577
- if (value) {
578
- fieldIds = JSON.parse(value);
579
- }
580
- } catch (e) {
581
- fieldIds = [];
582
- }
583
- fieldIds = Array.isArray(fieldIds) ? fieldIds : [String(fieldIds)];
584
- // check if el.id is already selected and then remove it
585
- if (fieldIds.includes(el.id)) {
586
- const index = fieldIds.indexOf(el.id);
587
- fieldIds.splice(index, 1);
588
- } else {
589
- fieldIds.push(el.id);
590
- }
591
- let index = -1;
592
- let indexes: number[] = [];
593
- const selectedValues = fieldIds.map((val: any) => {
594
- index = items.findIndex((el) => el.id === val);
595
- indexes.push(index);
596
- });
597
- if (indexes.length > 0) {
598
- fieldVal = indexes.map((i) => items[i].value).join(', ');
599
- }
600
- onChange(fieldIds.length > 0 ? JSON.stringify(fieldIds) : '');
601
- setEditableTextValue(fieldIds.length > 0 ? JSON.stringify(fieldIds) : '');
602
- } else {
603
- onChange(el.id);
604
- setEditableTextValue(fieldVal);
605
- }
606
- setIsDropdownOpen(false);
607
- if (isSearchable) {
608
- setQuery(fieldVal); // set the query to the selected value
609
- inputRef.current?.blur();
610
- }
611
- };
612
-
613
- /* const onTagSelect = (option: string) => {
614
- if (onChange) onChange(`{${option}}`);
615
- setIsDropdownOpen(false);
616
- }; */
617
-
618
- const onTagSelect = (option: string) => {
619
- const textField = inputRef.current;
620
- let newValue = `{${option}}`;
621
- setTempPlaceholder('');
622
- // if (!isEditable) {
623
- if (textField) {
624
- if (allowTagsInText) {
625
- // allowTagsInText will be true only if the field is editable
626
- // if the fields is editable and allowTagsInText, then EU can enter text or select muliple tags within the text
627
- const { selectionStart = 0, selectionEnd = 0 } = textField;
628
- const oldValue = textField.value;
629
- const textBeforeCursor = oldValue.substring(0, selectionStart || 0);
630
- const textAfterCursor = oldValue.substring(selectionEnd || 0);
631
- const insertedText = `{${option}}`;
632
- newValue = textBeforeCursor + insertedText + textAfterCursor;
633
- textField.selectionStart = (selectionStart || 0) + insertedText.length;
634
- textField.selectionEnd = textField.selectionStart;
635
- }
636
- }
637
- // if the field is editable and mappable, then EU can enter text or select a tag
638
- // if the fields in mappable only, then select only one tag
639
- setIsDropdownOpen(false);
640
- setSearchValue('');
641
- setEditableTextValue(newValue);
642
- if (onChange) onChange(newValue);
643
- // } else {
644
- // handleMultipurposeOnChange(newValue);
645
- // setIsDropdownOpen(false);
646
- // setSearchValue('');
647
- // // if the field is editable only, then EU can only eneter text, no tags and tags menu wont show up, so this function wont be called
648
- // }
649
- };
650
-
651
- const getSelectedItem = useMemo(() => {
652
- let index = -1;
653
- if (isMultiSelect) {
654
- let values = [];
655
- try {
656
- if (value) {
657
- values = JSON.parse(value);
658
- }
659
- } catch (e) {
660
- values = [];
661
- }
662
- values = Array.isArray(values) ? values : [String(values)];
663
- const indexes: any = [];
664
- const selectedValues =
665
- values.map((val: any) => {
666
- index = items.findIndex((el) => el.id === val);
667
- indexes.push(index);
668
- }) || [];
669
- if (indexes.length > 0 && items.length > 0) {
670
- return indexes.map((i: number) => items[i].value).join(', ');
671
- }
672
- } else {
673
- try {
674
- index = items.findIndex((el) => el.id === value);
675
- } catch (error) {
676
- index = -1;
677
- }
678
- if (isMappable && selectedTab === 'AppFields') {
679
- return index > -1 ? items[index].value : value;
680
- }
681
- }
682
-
683
- return index > -1 ? items[index].value : '';
684
- }, [items, value]);
685
-
686
- const getSelectedItemIcon = useMemo(() => {
687
- let index = -1;
688
- if (isMultiSelect) {
689
- let values = [];
690
- try {
691
- if (value) {
692
- values = JSON.parse(value);
693
- }
694
- } catch (e) {
695
- values = [];
696
- }
697
- values = Array.isArray(values) ? values : [String(values)];
698
- const indexes: any = [];
699
- const selectedValues =
700
- values.map((val: any) => {
701
- index = items.findIndex((el) => el.id === val);
702
- indexes.push(index);
703
- }) || [];
704
- if (indexes.length > 0 && items.length > 0) {
705
- const firstItem = items[0] as ListBoxItemProps;
706
- return firstItem.icon || undefined;
707
- }
708
- } else {
709
- try {
710
- index = items.findIndex((el) => el.id === value);
711
- } catch (error) {
712
- index = -1;
713
- }
714
- if (isMappable && selectedTab === 'AppFields') {
715
- return index > -1 ? items[index].icon : '';
716
- }
717
- }
718
-
719
- return index > -1 ? items[index].icon : '';
720
- }, [items, value]);
721
-
722
- const getItemFromText = (
723
- textValue: string,
724
- ): {
725
- id: string;
726
- value: string;
727
- } => {
728
- let tempItem = {
729
- id: textValue,
730
- value: textValue,
731
- };
732
- let itemFound = false;
733
- items.forEach((item) => {
734
- if (item.id === textValue && !itemFound) {
735
- tempItem = item;
736
- itemFound = true;
737
- }
738
- });
739
- if (!itemFound) {
740
- items.forEach((item) => {
741
- if (item.value === textValue && !itemFound) {
742
- tempItem = item;
743
- itemFound = true;
744
- }
745
- });
746
- }
747
- return tempItem;
748
- };
749
-
750
- const updateValue = (e: InputEvent | any) => {
751
- setTempPlaceholder('');
752
- if (e.currentTarget instanceof HTMLInputElement) {
753
- const { value: newValue } = e.currentTarget;
754
- if (isEditable) {
755
- const tempItem = getItemFromText(newValue);
756
- onChange(tempItem.id);
757
- setEditableTextValue(tempItem.value);
758
- onSearchChange(e);
759
- } else {
760
- onChange(newValue);
761
- setEditableTextValue(newValue);
762
- }
763
- if (newValue !== '' && !isEditable) {
764
- setSearchValue(newValue.trim());
765
- } else {
766
- setSearchValue('');
767
- }
768
- }
769
- };
770
-
771
- const onInputClicked = (e: InputEvent) => {
772
- e.stopPropagation();
773
- if (!isDropdownOpen && !isReadOnly) {
774
- setQuery('');
775
- setIsDropdownOpen(true);
776
- }
777
- const isTag =
778
- getSelectedItem?.startsWith('{') && getSelectedItem?.endsWith('}');
779
-
780
- let itemsToProcess = items;
781
- if (!Array.isArray(items)) {
782
- setItems([]);
783
- itemsToProcess = [];
784
- }
785
- const isOption = itemsToProcess.find((el) => el.id === value);
786
- if (isEditable && !allowTagsInText && isTag) {
787
- setTempPlaceholder(getSelectedItem || '');
788
- } else if (isEditable && isOption) {
789
- setTempPlaceholder(getSelectedItem || '');
790
- }
791
- };
792
- const debounceTimeout = useRef<ReturnType<typeof setTimeout> | null>(null);
793
- const onSearchChange = async (e: InputEvent) => {
794
- if (e.currentTarget instanceof HTMLInputElement) {
795
- const searchTerm = e.currentTarget.value.trim();
796
- if (!props.enableServerSideSearch) {
797
- setSearchValue(searchTerm);
798
- setQuery(searchTerm);
799
- }
800
-
801
- if (
802
- isSearchable &&
803
- props.enableServerSideSearch &&
804
- props.serverSideSearchParamName &&
805
- endpointUrl
806
- ) {
807
- if (debounceTimeout.current) {
808
- clearTimeout(debounceTimeout.current);
809
- }
810
- debounceTimeout.current = setTimeout(async () => {
811
- setLoading(true);
812
- setItems([]);
813
- setSortedFilteredItems([]);
814
- try {
815
- const params = new URLSearchParams();
816
- params.append(props.serverSideSearchParamName || '', searchTerm);
817
- params.append('include', 'meta');
818
- params.append('include_private', 'true');
819
- params.append('page_size', '20');
820
-
821
- const response = await props.apiHandler.callDynamicDataEndpoint<
822
- {
823
- id: string;
824
- value: string;
825
- }[]
826
- >(new URL(`${endpointUrl}?${params.toString()}`), {}, 'POST');
827
-
828
- if (response) {
829
- const serverFilteredItems = dynamicResponseMapper(response);
830
- setItems(serverFilteredItems);
831
- setSortedFilteredItems(serverFilteredItems);
832
- } else {
833
- setItems([]);
834
- setSortedFilteredItems([]);
835
- }
836
- } catch (error) {
837
- console.error('Error performing server-side search:', error);
838
- setItems([]);
839
- setSortedFilteredItems([]);
840
- } finally {
841
- setLoading(false);
842
- }
843
- }, 500);
844
- }
845
- }
846
- };
847
-
848
- const fetchDynamicDataFromSourceFlow = (
849
- isRefresh: boolean = false,
850
- callback?: any,
851
- ): void => {
852
- const { apiHandler } = props;
853
- if (!isRefresh) {
854
- setLoading(true);
855
- }
856
- if (selectedAuthId) {
857
- apiHandler
858
- .callSourceFlowIntegrationInvocationUrl<
859
- {
860
- id: string;
861
- value: string;
862
- }[]
863
- >(
864
- new URL(sourceFlowIntegrataionInvocationUrl),
865
- { authorization_id: selectedAuthId },
866
- sourceFlowData,
867
- )
868
- .then((res) => {
869
- if (res) {
870
- setItems(responseMapper(res));
871
- setSortedFilteredItems(responseMapper(res));
872
- // if value was selected before items were loaded, select it again
873
- if (value && isSearchable) {
874
- const item = responseMapper(res).find((a) => a.id === value);
875
- if (item && !isRefresh) {
876
- setQuery(item.value);
877
- } else {
878
- setQuery('');
879
- }
880
- setLoading(false);
881
- if (callback) {
882
- callback();
883
- }
884
- } else {
885
- setQuery('');
886
- setLoading(false);
887
- if (callback) {
888
- callback();
889
- }
890
- }
891
- } else {
892
- setIsErrorOnLoadingOptions(true);
893
- }
894
- });
895
- }
896
- };
897
-
898
- const fetchDynamicData = (
899
- isRefresh: boolean = false,
900
- callback?: any,
901
- loadMore?: boolean,
902
- params?: any,
903
- ): void => {
904
- const { apiHandler } = props;
905
- if (isDynamic && sourceFlowIntegrataionInvocationUrl) {
906
- fetchDynamicDataFromSourceFlow(isRefresh, callback);
907
- } else if (endpointUrl) {
908
- setLoading(true);
909
- let data;
910
- try {
911
- data = JSON.parse(endpointData);
912
- } catch (error) {
913
- data = {};
914
- }
915
- if (!data) {
916
- data = {};
917
- }
918
- if (selectedAuthId) {
919
- data.connected_account_id = selectedAuthId;
920
- data.authorization_id = selectedAuthId;
921
- }
922
- if (allowWorkspaceConnectedAccounts) {
923
- data.allow_workspace_connected_accounts = true;
924
- }
925
- apiHandler
926
- .callDynamicDataEndpoint<
927
- {
928
- id: string;
929
- value: string;
930
- }[]
931
- >(new URL(endpointUrl), data, 'POST', params)
932
- .then((res) => {
933
- if (res) {
934
- if (loadMore) {
935
- setItems([...items, ...dynamicResponseMapper(res)]);
936
- setFilteredItems([...items, ...dynamicResponseMapper(res)]);
937
- } else {
938
- setItems(dynamicResponseMapper(res));
939
- setSortedFilteredItems(dynamicResponseMapper(res));
940
- }
941
- // if value was selected before items were loaded, select it again
942
- if (value && isSearchable) {
943
- const item = dynamicResponseMapper(res).find(
944
- (a) => a.id === value,
945
- );
946
- if (item && !isRefresh) {
947
- setQuery(item.value);
948
- } else {
949
- setQuery('');
950
- }
951
- setLoading(false);
952
- if (callback) {
953
- callback();
954
- }
955
- } else {
956
- setQuery('');
957
- setLoading(false);
958
- if (callback) {
959
- callback();
960
- }
961
- }
962
- } else {
963
- setIsErrorOnLoadingOptions(true);
964
- }
965
- });
966
- }
967
- };
968
- const handleRefreshClick = (callback?: any, nextPage?: string): void => {
969
- const requestBodyData =
970
- typeof dataSourceBody === 'object' &&
971
- Object.keys(dataSourceBody).length > 0
972
- ? dataSourceBody
973
- : activityOutputData;
974
-
975
- // Merge nextPage into requestBodyData if it exists
976
- const updatedRequestBodyData = nextPage
977
- ? { ...requestBodyData, _cursor: nextPage }
978
- : requestBodyData;
979
- if (nextPage) {
980
- fetchDynamicData(true, callback, true, updatedRequestBodyData);
981
- } else {
982
- setFilteredItems([]);
983
- fetchDynamicData(true, callback, false, updatedRequestBodyData);
984
- }
985
-
986
- if (isSearchable) {
987
- inputRef.current?.blur();
988
- }
989
- };
990
-
991
- const handleLoadMoreOptions = (callback?: any): void => {
992
- if (!loading) {
993
- fetchDynamicData(false, callback, true, { _cursor: nextPage });
994
- if (isSearchable) {
995
- inputRef.current?.blur();
996
- }
997
- }
998
- };
999
-
1000
- return html`
1001
- <${Hint} dismissOnClick=${false} position="top" deltaY=${0}>
1002
- <div ref=${dropdownRef} class="${styles.listboxGroupWrapper}">
1003
- <fieldset>
1004
- ${title &&
1005
- html`
1006
- <${Label}
1007
- title=${title}
1008
- description=${description}
1009
- isRequired=${isRequired}
1010
- isHidden=${isHidden}
1011
- labelTag=${labelTags}
1012
- allowRefresh=${false}
1013
- handleRefreshClick=${handleRefreshClick}
1014
- />
1015
- `}
1016
- <div class=${`${styles.listbox} integry-listbox-field`}>
1017
- <div
1018
- class=${`${styles.customSelect} ${
1019
- isDropdownOpen ? styles.open : ''
1020
- }`}
1021
- id="${fieldId}"
1022
- >
1023
- ${isReadOnly &&
1024
- html`<span
1025
- class=${styles.readonlyHint}
1026
- data-hint=${isReadOnly ? `` : ''}
1027
- ></span>`}
1028
- <div
1029
- class=${`${styles.customSelectTrigger} ${
1030
- showStepValidation &&
1031
- !value &&
1032
- isRequired &&
1033
- (!isDropdownOpen || items.length === 0) &&
1034
- styles.error
1035
- } ${(isSearchable || isEditable) && styles.searchable} ${
1036
- isReadOnly ? styles.readonly : ''
1037
- } ${disabled ? styles.disabled : ''}`}
1038
- role="button"
1039
- onclick=${() => !isDropdownOpen && setIsDropdownOpen(true)}
1040
- >
1041
- <span class=${value && styles.selected}>
1042
- ${false
1043
- ? html`<div class=${`${styles.arrow}`}>
1044
- <${ThreeDotLoader} color="#ababab" }><//>
1045
- </div>`
1046
- : html` ${isEditable
1047
- ? html`
1048
- <input
1049
- ref=${inputRef}
1050
- class=${styles.searchInput}
1051
- placeholder=${tempPlaceholder || placeholder}
1052
- value=${getSelectedItem || editableTextValue}
1053
- oninput=${updateValue}
1054
- onfocus=${onInputClicked}
1055
- readonly=${isReadOnly}
1056
- tabindex=${0}
1057
- disabled=${disabled}
1058
- />
1059
- `
1060
- : isDropdownOpen && !isEditable
1061
- ? html`
1062
- ${getSelectedItem &&
1063
- props.iconKeyPath &&
1064
- html`<img
1065
- src="${getSelectedItemIcon || ''}"
1066
- alt="icon"
1067
- class="${styles.selectedIcon}"
1068
- />`}
1069
- <input
1070
- ref=${(r: any) => {
1071
- if (r && isDropdownOpen) {
1072
- r.focus();
1073
- }
1074
- inputRef.current = r;
1075
- }}
1076
- class=${styles.searchInput}
1077
- placeholder=${getSelectedItem || placeholder}
1078
- oninput=${onSearchChange}
1079
- onfocus=${onInputClicked}
1080
- tabindex=${0}
1081
- />
1082
- `
1083
- : html`
1084
- ${getSelectedItem &&
1085
- props.iconKeyPath &&
1086
- html`<img
1087
- src="${getSelectedItemIcon || ''}"
1088
- alt="icon"
1089
- class="${styles.selectedIcon}"
1090
- />`}
1091
- <input
1092
- ref=${(r: any) => {
1093
- if (r && isDropdownOpen) {
1094
- r.focus();
1095
- }
1096
- inputRef.current = r;
1097
- }}
1098
- class=${styles.searchInput}
1099
- placeholder=${getSelectedItem ||
1100
- placeholder ||
1101
- 'Please Select...'}
1102
- value=${value
1103
- ? getSelectedItem !== ''
1104
- ? getSelectedItem
1105
- : null
1106
- : null}
1107
- tabindex=${0}
1108
- onfocus=${onInputClicked}
1109
- disabled=${disabled}
1110
- />
1111
- `}`}
1112
- </span>
1113
- <div class=${styles.chevronIcon}>
1114
- <svg
1115
- class="styles-module_accountFieldDropdownIcon__3161J"
1116
- width="20"
1117
- height="20"
1118
- viewBox="0 0 20 20"
1119
- fill="none"
1120
- xmlns="http://www.w3.org/2000/svg"
1121
- style=""
1122
- >
1123
- <path
1124
- d="M15 8L10 13L5 8"
1125
- stroke="#999999"
1126
- stroke-width="2"
1127
- stroke-linecap="round"
1128
- ></path>
1129
- </svg>
1130
- </div>
1131
- <div ref=${dropdownRef} style="display: flex;">
1132
- ${taggedSelect &&
1133
- onAddTag &&
1134
- html`
1135
- <${TagButton}
1136
- onClick=${(e: { stopPropagation: () => void }) => {
1137
- e.stopPropagation();
1138
- setIsDropdownOpen(false);
1139
- onAddTag();
1140
- }}
1141
- />
1142
- `}
1143
- </div>
1144
- </div>
1145
- <div>
1146
- ${!false &&
1147
- html`
1148
- <div ref=${dropdownMenuRef}>
1149
- ${isDropdownOpen &&
1150
- html`<${FieldDropdown}
1151
- tags=${activityOutputData}
1152
- onTagClick=${onTagSelect}
1153
- onOptionClick=${onDropdownItemClicked}
1154
- options=${filteredItems}
1155
- defaultTab=${Tabs.Values}
1156
- hideTabs=${!isMappable}
1157
- hideTabs=${hideTabs}
1158
- appName=${appName}
1159
- fieldId=${fieldId}
1160
- searchValue=${searchValue}
1161
- value=${value}
1162
- onTabSelect=${(tab: string) => {
1163
- setSelectedTab(tab);
1164
- setSearchValue('');
1165
- if (!isEditable) {
1166
- updateValue({ currentTarget: { value: '' } });
1167
- if (inputRef.current) {
1168
- inputRef.current.value = '';
1169
- }
1170
- }
1171
- if (inputRef.current) {
1172
- inputRef.current.focus();
1173
- }
1174
- }}
1175
- isMappable=${isMappable}
1176
- isEditable=${isEditable}
1177
- handleRefreshClick=${handleRefreshClick}
1178
- isErrorOnLoadingOptions=${isErrorOnLoadingOptions}
1179
- isMultiSelect=${isMultiSelect}
1180
- loadingOptions=${loading}
1181
- nextPage=${nextPage}
1182
- isDynamic=${isDynamic}
1183
- tagsTree=${tagsTree}
1184
- showMenuOnLeft=${props.showMenuOnLeft || false}
1185
- />`}
1186
- </div>
1187
- `}
1188
- </div>
1189
- </div>
1190
- ${showStepValidation &&
1191
- !value &&
1192
- (!isDropdownOpen || items.length === 0) &&
1193
- isRequired &&
1194
- html` <${ErrorMessage}>Please select an option</${ErrorMessage}>`}
1195
- </div>
1196
- </fieldset>
1197
- </div>
1198
- <//>
1199
- `;
1200
- };
1201
-
1202
- export { ListBox, ListBoxProps };