@@ -27,6 +27,7 @@ import {
27
27
getObjFromJsonOrYamlString ,
28
28
isValidUiWorkflow ,
29
29
isValidWorkflow ,
30
+ isCompatibleWorkflow ,
30
31
} from '../../../utils' ;
31
32
import { getCore } from '../../../services' ;
32
33
import {
@@ -43,7 +44,7 @@ import {
43
44
WORKFLOW_NAME_RESTRICTIONS ,
44
45
} from '../../../../common' ;
45
46
import { WORKFLOWS_TAB } from '../workflows' ;
46
- import { getDataSourceId } from '../../../utils/utils' ;
47
+ import { getDataSourceId , getEffectiveVersion , formatDisplayVersion } from '../../../utils/utils' ;
47
48
48
49
interface ImportWorkflowModalProps {
49
50
isImportModalOpen : boolean ;
@@ -61,6 +62,17 @@ interface ImportWorkflowModalProps {
61
62
export function ImportWorkflowModal ( props : ImportWorkflowModalProps ) {
62
63
const dispatch = useAppDispatch ( ) ;
63
64
const dataSourceId = getDataSourceId ( ) ;
65
+ const [ dataSourceVersion , setDataSourceVersion ] = useState <
66
+ string | undefined
67
+ > ( undefined ) ;
68
+ useEffect ( ( ) => {
69
+ async function getVersion ( ) {
70
+ if ( dataSourceId !== undefined ) {
71
+ setDataSourceVersion ( await getEffectiveVersion ( dataSourceId ) ) ;
72
+ }
73
+ }
74
+ getVersion ( ) ;
75
+ } , [ dataSourceId ] ) ;
64
76
const { workflows } = useSelector ( ( state : AppState ) => state . workflows ) ;
65
77
66
78
// workflow name state
@@ -86,6 +98,9 @@ export function ImportWorkflowModal(props: ImportWorkflowModalProps) {
86
98
return description . length > MAX_DESCRIPTION_LENGTH ;
87
99
}
88
100
101
+ // State for tracking workflow template compatibility with current data source version
102
+ const [ isCompatible , setIsCompatible ] = useState < boolean > ( true ) ;
103
+
89
104
// transient importing state for button state
90
105
const [ isImporting , setIsImporting ] = useState < boolean > ( false ) ;
91
106
@@ -115,6 +130,16 @@ export function ImportWorkflowModal(props: ImportWorkflowModalProps) {
115
130
}
116
131
} , [ fileObj ] ) ;
117
132
133
+ useEffect ( ( ) => {
134
+ async function checkCompatibility ( ) {
135
+ if ( isValidWorkflow ( fileObj ) ) {
136
+ const isCompatible = await isCompatibleWorkflow ( fileObj , dataSourceId ) ;
137
+ setIsCompatible ( isCompatible ) ;
138
+ }
139
+ }
140
+ checkCompatibility ( ) ;
141
+ } , [ fileObj , dataSourceId ] ) ;
142
+
118
143
function onModalClose ( ) : void {
119
144
props . setIsImportModalOpen ( false ) ;
120
145
setFileContents ( undefined ) ;
@@ -142,6 +167,18 @@ export function ImportWorkflowModal(props: ImportWorkflowModalProps) {
142
167
< EuiSpacer size = "m" />
143
168
</ >
144
169
) }
170
+ { isValidWorkflow ( fileObj ) && ! isCompatible && dataSourceVersion && (
171
+ < >
172
+ < EuiFlexItem >
173
+ < EuiCallOut
174
+ title = { `The uploaded file is not compatible with the current data source version ${ formatDisplayVersion ( dataSourceVersion ) } . Upload a compatible file or switch to another data source.` }
175
+ iconType = { 'alert' }
176
+ color = "danger"
177
+ />
178
+ </ EuiFlexItem >
179
+ < EuiSpacer size = "m" />
180
+ </ >
181
+ ) }
145
182
{ isValidWorkflow ( fileObj ) && ! isValidUiWorkflow ( fileObj ) && (
146
183
< >
147
184
< EuiFlexItem >
@@ -230,6 +267,7 @@ export function ImportWorkflowModal(props: ImportWorkflowModalProps) {
230
267
< EuiSmallButton
231
268
disabled = {
232
269
! isValidWorkflow ( fileObj ) ||
270
+ ! isCompatible ||
233
271
isImporting ||
234
272
isInvalidName ( workflowName ) ||
235
273
isInvalidDescription ( workflowDescription )
0 commit comments