Skip to content

Commit 33df65f

Browse files
committed
highlighted selected request body option in drop down list
1 parent 8b38561 commit 33df65f

2 files changed

Lines changed: 47 additions & 35 deletions

File tree

src/components/molecules/flow/nodes/RequestBody.js

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import React, { Fragment, useState, useRef } from 'react';
22
import { PropTypes } from 'prop-types';
3+
import { Listbox, Transition } from '@headlessui/react';
4+
import { CheckIcon, ChevronUpDownIcon } from '@heroicons/react/20/solid';
35
import { EllipsisVerticalIcon, PlusIcon } from '@heroicons/react/24/solid';
46
import {
57
DocumentArrowUpIcon,
68
ClipboardDocumentCheckIcon,
79
ClipboardDocumentIcon,
810
TrashIcon,
911
} from '@heroicons/react/24/outline';
10-
import { Menu, Transition } from '@headlessui/react';
12+
//import { Menu, Transition } from '@headlessui/react';
1113
import useCanvasStore from 'stores/CanvasStore';
1214
import { toast } from 'react-toastify';
1315
import { Editor } from 'components/atoms/Editor';
@@ -216,36 +218,50 @@ const RequestBody = ({ nodeId, nodeData }) => {
216218
<>
217219
<div className='flex items-center justify-between bg-background p-4'>
218220
<h3>Body</h3>
219-
<Menu as='div' className='relative inline-block text-left'>
220-
<Menu.Button data-click-from='body-type-menu'>
221-
<EllipsisVerticalIcon className='h-4 w-4' aria-hidden='true' data-click-from='body-type-menu' />
222-
</Menu.Button>
223-
<Transition
224-
as={Fragment}
225-
enter='transition ease-out duration-100'
226-
enterFrom='transform opacity-0 scale-95'
227-
enterTo='transform opacity-100 scale-100'
228-
leave='transition ease-in duration-75'
229-
leaveFrom='transform opacity-100 scale-100'
230-
leaveTo='transform opacity-0 scale-95'
231-
>
232-
<Menu.Items
233-
className='absolute right-0 z-10 mt-2 w-56 origin-top-right divide-y divide-gray-100 rounded-md bg-white px-1 py-1 shadow-lg ring-1 ring-black/5 focus:outline-none'
234-
data-click-from='body-type-menu'
221+
<Listbox
222+
value={nodeData.requestBody?.type ? nodeData.requestBody.type : 'None'}
223+
onChange={(selectedValue) => {
224+
handleClose(selectedValue);
225+
}}
226+
className='text-xl'
227+
>
228+
<div>
229+
<Listbox.Button className='relative flex cursor-default border-cyan-950 text-left'>
230+
<EllipsisVerticalIcon className='h-4 w-4' aria-hidden='true' data-click-from='body-type-menu' />
231+
</Listbox.Button>
232+
<Transition
233+
as={Fragment}
234+
leave='transition ease-in duration-100'
235+
leaveFrom='opacity-100'
236+
leaveTo='opacity-0'
235237
>
236-
{requestBodyTypeOptions.map((bodyTypeOption, index) => (
237-
<Menu.Item key={index} data-click-from='body-type-menu' onClick={() => handleClose(bodyTypeOption)}>
238-
<button
239-
className='group flex w-full items-center rounded-md px-2 py-2 text-sm text-gray-900 hover:bg-background-light'
240-
data-click-from='body-type-menu'
238+
<Listbox.Options className='absolute z-50 mt-1 max-h-60 w-36 overflow-auto bg-white py-1 text-base focus:outline-none'>
239+
{requestBodyTypeOptions.map((bodyTypeOption) => (
240+
<Listbox.Option
241+
key={bodyTypeOption}
242+
className={({ active }) =>
243+
`relative cursor-default select-none py-2 pl-7 pr-4 hover:font-semibold ${
244+
active ? 'bg-background-light text-slate-900' : ''
245+
}`
246+
}
247+
value={bodyTypeOption}
241248
>
242-
{bodyTypeOption}
243-
</button>
244-
</Menu.Item>
245-
))}
246-
</Menu.Items>
247-
</Transition>
248-
</Menu>
249+
{({ selected }) => (
250+
<>
251+
<span className={`block`}>{bodyTypeOption}</span>
252+
{selected ? (
253+
<span className='absolute inset-y-0 left-0 flex items-center pl-1 font-semibold'>
254+
<CheckIcon className='h-5 w-5' aria-hidden='true' />
255+
</span>
256+
) : null}
257+
</>
258+
)}
259+
</Listbox.Option>
260+
))}
261+
</Listbox.Options>
262+
</Transition>
263+
</div>
264+
</Listbox>
249265
</div>
250266
{nodeData.requestBody && nodeData.requestBody.type === 'raw-json' && (
251267
<>

src/stores/CanvasStore.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,10 @@ const useCanvasStore = create((set, get) => ({
296296
if (node.id === nodeId) {
297297
// it's important to create a new object here, to inform React Flow about the cahnges
298298
if (type === 'None') {
299+
const { ['requestBody']: _, ...data } = node.data;
299300
return {
300301
...node,
301-
data: {
302-
...node.data,
303-
requestBody: {
304-
type,
305-
},
306-
},
302+
data,
307303
};
308304
} else if (type === 'raw-json') {
309305
return {

0 commit comments

Comments
 (0)