@@ -160,27 +160,38 @@ export function isValidWorkflow(workflowObj: any): boolean {
160
160
161
161
// Determines if a file used for import workflow is compatible with the current data source version.
162
162
export async function isCompatibleWorkflow (
163
- workflowObj : any ,
163
+ workflowObj : any ,
164
164
dataSourceId ?: string | undefined
165
165
) : Promise < boolean > {
166
166
const compatibility = workflowObj ?. version ?. compatibility ;
167
167
168
168
// Default to true when compatibility cannot be assessed (empty/invalid compatibility array or MDS disabled.)
169
- if ( ! Array . isArray ( compatibility ) || compatibility . length === 0 || dataSourceId === undefined ) {
169
+ if (
170
+ ! Array . isArray ( compatibility ) ||
171
+ compatibility . length === 0 ||
172
+ dataSourceId === undefined
173
+ ) {
170
174
return true ;
171
175
}
172
176
173
- const dataSourceVersion = await getEffectiveVersion ( dataSourceId ) ;
174
- const [ effectiveMajorVersion , effectiveMinorVersion ] = dataSourceVersion . split ( '.' ) . map ( Number ) ;
175
-
177
+ const dataSourceVersion = await getEffectiveVersion ( dataSourceId ) ;
178
+ const [
179
+ effectiveMajorVersion ,
180
+ effectiveMinorVersion ,
181
+ ] = dataSourceVersion . split ( '.' ) . map ( Number ) ;
182
+
176
183
// Checks if any version in compatibility array matches the current dataSourceVersion (major.minor)
177
- return compatibility . some ( compatibleVersion => {
178
- const [ compatibleMajor , compatibleMinor ] = compatibleVersion . split ( '.' ) . map ( Number ) ;
179
- return effectiveMajorVersion === compatibleMajor && effectiveMinorVersion === compatibleMinor ;
184
+ return compatibility . some ( ( compatibleVersion ) => {
185
+ const [ compatibleMajor , compatibleMinor ] = compatibleVersion
186
+ . split ( '.' )
187
+ . map ( Number ) ;
188
+ return (
189
+ effectiveMajorVersion === compatibleMajor &&
190
+ effectiveMinorVersion === compatibleMinor
191
+ ) ;
180
192
} ) ;
181
193
}
182
194
183
-
184
195
export function isValidUiWorkflow ( workflowObj : any ) : boolean {
185
196
return (
186
197
isValidWorkflow ( workflowObj ) &&
@@ -933,13 +944,13 @@ export function getFieldValue(jsonObj: {}, fieldName: string): any | undefined {
933
944
return undefined ;
934
945
}
935
946
936
- // Get the version from the selected data source
947
+ // Get the version from the selected data source, if found
937
948
export const getEffectiveVersion = async (
938
949
dataSourceId : string | undefined
939
- ) : Promise < string > => {
950
+ ) : Promise < string | undefined > => {
940
951
try {
941
952
if ( dataSourceId === undefined ) {
942
- throw new Error ( 'Data source is required' ) ;
953
+ throw new Error ( ) ;
943
954
}
944
955
945
956
if ( dataSourceId === '' ) {
@@ -951,16 +962,26 @@ export const getEffectiveVersion = async (
951
962
'data-source' ,
952
963
dataSourceId
953
964
) ;
954
- const version =
955
- dataSource ?. attributes ?. dataSourceVersion || MIN_SUPPORTED_VERSION ;
956
- return version ;
965
+ return dataSource ?. attributes ?. dataSourceVersion ;
957
966
} catch ( error ) {
958
- console . error ( 'Error getting version:' , error ) ;
959
- return MIN_SUPPORTED_VERSION ;
967
+ console . error ( 'Error getting version: ' , error ) ;
968
+ return undefined ;
960
969
}
961
970
} ;
962
971
963
-
972
+ export function useMissingDataSourceVersion (
973
+ dataSourceId : string | undefined ,
974
+ dataSourceVersion : string | undefined
975
+ ) : boolean {
976
+ const [ missingVersion , setMissingVersion ] = useState < boolean > ( false ) ;
977
+ useEffect ( ( ) => {
978
+ setMissingVersion (
979
+ dataSourceId !== undefined && dataSourceVersion === undefined
980
+ ) ;
981
+ } , [ dataSourceId , dataSourceVersion ] ) ;
982
+ return missingVersion ;
983
+ }
984
+
964
985
/**
965
986
* Formats version string to show only major.minor numbers
966
987
* Example: "3.0.0-alpha1" -> "3.0"
@@ -970,4 +991,3 @@ export function formatDisplayVersion(version: string): string {
970
991
const [ major , minor ] = version . split ( '.' ) ;
971
992
return `${ major } .${ minor } ` ;
972
993
}
973
-
0 commit comments