1
1
import React from "react" ;
2
2
import { MitoAPI } from "../../../api/api" ;
3
- import { CodeOptions , ParamName , ParamSubType , ParamType , ParamValue , ParameterizableParams } from "../../../types" ;
3
+ import { CodeOptions , ParamName , ParamSubType , ParamValue , ParameterizableParams } from "../../../types" ;
4
4
5
5
import { useStateFromAPIAsync } from "../../../hooks/useStateFromAPIAsync" ;
6
6
import DropdownButton from "../../elements/DropdownButton" ;
7
7
import DropdownItem from "../../elements/DropdownItem" ;
8
8
import Input from "../../elements/Input" ;
9
9
import LabelAndTooltip from "../../elements/LabelAndTooltip" ;
10
+ import XIcon from "../../icons/XIcon" ;
10
11
import Col from "../../layout/Col" ;
11
12
import Row from "../../layout/Row" ;
12
- import XIcon from "../../icons/XIcon" ;
13
13
14
14
15
15
interface CodeOptionsParametersProps {
@@ -18,8 +18,14 @@ interface CodeOptionsParametersProps {
18
18
setCodeOptions : React . Dispatch < React . SetStateAction < CodeOptions > > ;
19
19
}
20
20
21
- const getParamDisplayString = ( paramValue : string , paramType : ParamType ) : string => {
22
- if ( paramType === 'file_name' ) {
21
+ /**
22
+ * @param paramValue The value of the parameter
23
+ * @param isFile - Whether the param is a file or not. This is calculated in different ways
24
+ * depending on where we call it.
25
+ * @returns A string to display the parameter value
26
+ */
27
+ const getParamDisplayString = ( paramValue : string , isFile : boolean ) : string => {
28
+ if ( isFile ) {
23
29
return getFileNameFromParamValue ( paramValue ) ;
24
30
} else {
25
31
return paramValue ;
@@ -42,8 +48,6 @@ const getParamDescriptionString = (paramSubtype: ParamSubType): string => {
42
48
} else {
43
49
return paramSubtype ;
44
50
}
45
-
46
-
47
51
}
48
52
49
53
const getFileNameFromParamValue = ( paramValue : string ) : string => {
@@ -58,14 +62,14 @@ const getFileNameFromParamValue = (paramValue: string): string => {
58
62
return fileName ;
59
63
}
60
64
61
- const getDefaultParamName = ( paramValue : string , paramType : ParamType ) : string => {
62
- if ( paramType === 'file_name' ) {
65
+ const getDefaultParamName = ( paramValue : string , paramSubType : ParamSubType ) : string => {
66
+ if ( paramSubType === 'import_dataframe' ) {
67
+ return paramValue ;
68
+ } else {
63
69
const fileName = getFileNameFromParamValue ( paramValue ) ;
64
70
const noExt = fileName . substring ( 0 , fileName . indexOf ( '.' ) ) ; // Remove the file extension
65
71
const withUnderscores = noExt . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, '_' ) ; // Replace all non-alphanumeric characters with underscores
66
72
return withUnderscores + '_path' ;
67
- } else {
68
- return paramValue ;
69
73
}
70
74
}
71
75
@@ -115,13 +119,15 @@ const CodeOptionsParameters = (props: CodeOptionsParametersProps): JSX.Element =
115
119
disabled = { disabled }
116
120
title = { ! props . codeOptions . as_function ? 'Toggle Generate Function before adding parameters.' : ( parameterizableParams . length === 0 ? 'There are no available options to parameterize. Import data first.' : undefined ) }
117
121
>
118
- { unparametizedParams . map ( ( [ paramValue , paramType , paramSubtype ] , index ) => {
122
+ { unparametizedParams . map ( ( paramInfo , index ) => {
123
+ const paramValue = paramInfo [ 0 ] ;
124
+ const paramSubtype = paramInfo [ 2 ] ;
119
125
const paramDescription = getParamDescriptionString ( paramSubtype ) ;
120
126
121
127
return (
122
128
< DropdownItem
123
129
key = { index }
124
- title = { getParamDisplayString ( paramValue , paramType ) }
130
+ title = { getParamDisplayString ( paramValue , paramSubtype !== 'import_dataframe' ) }
125
131
subtext = { paramDescription }
126
132
onClick = { ( ) => {
127
133
props . setCodeOptions ( ( prevCodeOptions ) => {
@@ -130,7 +136,7 @@ const CodeOptionsParameters = (props: CodeOptionsParametersProps): JSX.Element =
130
136
return prevCodeOptions ;
131
137
}
132
138
133
- const paramName = getDefaultParamName ( paramValue , paramType ) ;
139
+ const paramName = getDefaultParamName ( paramValue , paramSubtype ) ;
134
140
135
141
newCodeOptions . function_params [ paramName ] = paramValue ;
136
142
return newCodeOptions ;
@@ -169,7 +175,7 @@ const CodeOptionsParameters = (props: CodeOptionsParametersProps): JSX.Element =
169
175
< Row key = { index } justify = 'space-between' align = 'center' >
170
176
< Col span = { 8 } offsetRight = { 2 } >
171
177
< p title = { paramValue } >
172
- { getParamDisplayString ( paramValue , paramValue . startsWith ( 'r"' ) || paramValue . startsWith ( "r'" ) || paramValue . startsWith ( "'" ) ? 'file_name' : 'df_name' ) }
178
+ { getParamDisplayString ( paramValue , paramValue . startsWith ( 'r"' ) || paramValue . startsWith ( "r'" ) || paramValue . startsWith ( "'" ) ) }
173
179
</ p >
174
180
</ Col >
175
181
< Col span = { 10 } offsetRight = { 2 } >
0 commit comments