@@ -2,21 +2,18 @@ import React, { Fragment, useState } from 'react';
22import { PropTypes } from 'prop-types' ;
33import { Dialog , Transition , Listbox } from '@headlessui/react' ;
44import { createFolder , createFlowTest , createEnvironmentFile } from 'service/collection' ;
5- import { DirectoryOptionsActions } from 'constants/WorkspaceDirectory' ;
65import { toast } from 'react-toastify' ;
76import Button from 'components/atoms/common/Button' ;
87import { BUTTON_INTENT_TYPES , BUTTON_TYPES , OBJ_TYPES } from 'constants/Common' ;
98import TextInput from 'components/atoms/common/TextInput' ;
10- import Collection from '../../sidebar/content/Collection' ;
119import useCollectionStore from 'stores/CollectionStore' ;
1210import { CheckIcon , ChevronUpDownIcon } from '@heroicons/react/20/solid' ;
1311import { isEmpty } from 'lodash' ;
14- import TimeoutSelector from 'components/atoms/common/TimeoutSelector' ;
15- import { timeoutForGraphRun } from 'components/molecules/flow/utils' ;
12+ import { flattenItems } from 'stores/utils' ;
1613
1714const NewFlowTestModal = ( { closeFn = ( ) => null , open = false } ) => {
15+ const { ipcRenderer } = window ;
1816 const collections = useCollectionStore . getState ( ) . collections ;
19- console . log ( `\n \n Inside NewFlowTestModal :: collections :: ${ JSON . stringify ( collections ) } \n \n ` ) ;
2017
2118 const [ flowtestName , setFlowtestName ] = useState ( '' ) ;
2219 const [ selectedCollection , setSelectionCollection ] = useState ( { } ) ;
@@ -25,7 +22,7 @@ const NewFlowTestModal = ({ closeFn = () => null, open = false }) => {
2522 // Error flags
2623 const [ showFlowtestNameError , setShowFlowtestNameError ] = useState ( false ) ;
2724 const [ showCollectionSelectionError , setShowCollectionSelectionError ] = useState ( false ) ;
28- const [ showFolderSelectionError , setShowFolderSelectionError ] = useState ( false ) ;
25+ // const [showFolderSelectionError, setShowFolderSelectionError] = useState(false);
2926 const containsFolder = ( collection ) => {
3027 const items = collection . items ;
3128 let haveFolderItem = false ;
@@ -44,7 +41,7 @@ const NewFlowTestModal = ({ closeFn = () => null, open = false }) => {
4441 setSelectedFolder ( { } ) ;
4542 setShowFlowtestNameError ( false ) ;
4643 setShowCollectionSelectionError ( false ) ;
47- setShowFolderSelectionError ( false ) ;
44+ // setShowFolderSelectionError(false);
4845 } ;
4946 return (
5047 < div >
@@ -94,14 +91,14 @@ const NewFlowTestModal = ({ closeFn = () => null, open = false }) => {
9491 } }
9592 name = { 'flowtest-name' }
9693 />
97- { showFlowtestNameError ? (
94+ { flowtestName . trim ( ) === '' && showFlowtestNameError ? (
9895 < div className = 'py-2 text-red-600' > Please provide a name for your new flowtest</ div >
9996 ) : (
10097 ''
10198 ) }
10299 </ div >
103100 < div >
104- < div className = 'flex justify-between gap-2 transition border rounded whitespace-nowrap border-cyan-900 bg-background-light text-cyan-900 hover:bg-background ' >
101+ < div className = 'flex justify-between gap-2 transition border rounded bg-background-light hover:bg-background whitespace-nowrap border-cyan-900 text-cyan-900' >
105102 < Listbox
106103 value = { selectedCollection }
107104 onChange = { ( value ) => {
@@ -154,7 +151,7 @@ const NewFlowTestModal = ({ closeFn = () => null, open = false }) => {
154151 </ div >
155152 </ Listbox >
156153 </ div >
157- { showCollectionSelectionError ? (
154+ { isEmpty ( selectedCollection ) && showCollectionSelectionError ? (
158155 < div className = 'py-2 text-red-600' >
159156 Please provide a collection in which you wants to create your new flowtest
160157 </ div >
@@ -165,7 +162,7 @@ const NewFlowTestModal = ({ closeFn = () => null, open = false }) => {
165162
166163 { ! isEmpty ( selectedCollection ) && containsFolder ( selectedCollection ) ? (
167164 < div >
168- < div className = 'flex justify-between gap-2 transition border rounded whitespace-nowrap border-cyan-900 bg-background-light text-cyan-900 hover:bg-background ' >
165+ < div className = 'flex justify-between gap-2 transition border rounded bg-background-light hover:bg-background whitespace-nowrap border-cyan-900 text-cyan-900' >
169166 < Listbox
170167 value = { selectedFolder }
171168 onChange = { ( value ) => {
@@ -184,7 +181,7 @@ const NewFlowTestModal = ({ closeFn = () => null, open = false }) => {
184181 leaveTo = 'opacity-0'
185182 >
186183 < Listbox . Options className = 'absolute right-0 z-10 w-full py-1 mt-1 overflow-auto text-base bg-white rounded shadow-lg top-10 max-h-60 ring-1 ring-black/5' >
187- { selectedCollection . items . map ( ( collectionItem , index ) => {
184+ { flattenItems ( selectedCollection . items ) . map ( ( collectionItem , index ) => {
188185 if ( collectionItem . type === OBJ_TYPES . folder ) {
189186 return (
190187 < Listbox . Option
@@ -201,7 +198,10 @@ const NewFlowTestModal = ({ closeFn = () => null, open = false }) => {
201198 < span
202199 className = { `block truncate ${ selected ? 'font-medium' : 'font-normal' } ` }
203200 >
204- { collectionItem . name }
201+ { ipcRenderer . relative (
202+ selectedCollection . pathname ,
203+ collectionItem . pathname ,
204+ ) }
205205 </ span >
206206 { selected ? (
207207 < span className = 'absolute inset-y-0 left-0 flex items-center pl-3 font-semibold' >
@@ -219,13 +219,13 @@ const NewFlowTestModal = ({ closeFn = () => null, open = false }) => {
219219 </ div >
220220 </ Listbox >
221221 </ div >
222- { showFolderSelectionError ? (
222+ { /* {selectedFolder.trim() === '' && showFolderSelectionError ? (
223223 <div className='py-2 text-red-600'>
224- Please provide a folder in which you wants to create your new flowtest
224+ Please provide a folder in which you want to create your new flowtest
225225 </div>
226226 ) : (
227227 ''
228- ) }
228+ )} */ }
229229 </ div >
230230 ) : (
231231 ''
@@ -249,30 +249,22 @@ const NewFlowTestModal = ({ closeFn = () => null, open = false }) => {
249249 isDisabled = { false }
250250 onClickHandle = { ( ) => {
251251 let pathName = '' ;
252- if ( ! flowtestName || flowtestName === '' ) {
252+ if ( ! flowtestName || flowtestName . trim ( ) === '' ) {
253253 setShowFlowtestNameError ( true ) ;
254254 return ;
255255 }
256256 if ( ! selectedCollection || ! selectedCollection . id || selectedCollection . id === '' ) {
257257 setShowCollectionSelectionError ( true ) ;
258258 return ;
259259 }
260- if ( containsFolder ( selectedCollection ) ) {
261- if ( ! selectedFolder || ! selectedFolder . pathname || selectedFolder . pathname === '' ) {
262- setShowFolderSelectionError ( true ) ;
263- return ;
264- } else {
265- pathName = selectedFolder . pathname ;
266- }
267- } else {
260+ if ( ! selectedFolder || ! selectedFolder . pathname || selectedFolder . pathname === '' ) {
268261 pathName = selectedCollection . pathname ;
262+ } else {
263+ pathName = selectedFolder . pathname ;
269264 }
270265 setShowFlowtestNameError ( false ) ;
271266 setShowCollectionSelectionError ( false ) ;
272- setShowFolderSelectionError ( false ) ;
273- console . log (
274- `\n \n flowtestName :: ${ flowtestName } :: pathName :: ${ selectedFolder . pathname } :: collectionId :: ${ selectedCollection . id } \n \n` ,
275- ) ;
267+ //setShowFolderSelectionError(false);
276268
277269 createFlowTest ( flowtestName , pathName , selectedCollection . id )
278270 . then ( ( result ) => {
0 commit comments