Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ac68af4

Browse files
committedFeb 26, 2025··
Fixed local cluster bug and added datasource version compatibility check before importing workflows
Signed-off-by: saimedhi <saimedhi@amazon.com>
1 parent 227a4e8 commit ac68af4

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed
 

‎public/pages/workflows/import_workflow/import_workflow_modal.tsx

+16-10
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import {
4444
WORKFLOW_NAME_RESTRICTIONS,
4545
} from '../../../../common';
4646
import { WORKFLOWS_TAB } from '../workflows';
47-
import { getDataSourceId } from '../../../utils/utils';
47+
import { getDataSourceId, getEffectiveVersion, formatDisplayVersion } from '../../../utils/utils';
4848

4949
interface ImportWorkflowModalProps {
5050
isImportModalOpen: boolean;
@@ -62,6 +62,17 @@ interface ImportWorkflowModalProps {
6262
export function ImportWorkflowModal(props: ImportWorkflowModalProps) {
6363
const dispatch = useAppDispatch();
6464
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]);
6576
const { workflows } = useSelector((state: AppState) => state.workflows);
6677

6778
// workflow name state
@@ -87,10 +98,8 @@ export function ImportWorkflowModal(props: ImportWorkflowModalProps) {
8798
return description.length > MAX_DESCRIPTION_LENGTH;
8899
}
89100

90-
// States for tracking workflow template compatibility with current data source version
101+
// State for tracking workflow template compatibility with current data source version
91102
const [isCompatible, setIsCompatible] = useState<boolean>(true);
92-
const [inCompatibleDataSourceVersion, setInCompatibleDataSourceVersion] = useState<string | undefined>();
93-
94103

95104
// transient importing state for button state
96105
const [isImporting, setIsImporting] = useState<boolean>(false);
@@ -124,11 +133,8 @@ export function ImportWorkflowModal(props: ImportWorkflowModalProps) {
124133
useEffect(() => {
125134
async function checkCompatibility() {
126135
if (isValidWorkflow(fileObj)) {
127-
const [isCompatible, dataSourceVersion] = await isCompatibleWorkflow(fileObj, dataSourceId);
136+
const isCompatible = await isCompatibleWorkflow(fileObj, dataSourceId);
128137
setIsCompatible(isCompatible);
129-
if (dataSourceVersion) {
130-
setInCompatibleDataSourceVersion(dataSourceVersion);
131-
}
132138
}
133139
}
134140
checkCompatibility();
@@ -161,11 +167,11 @@ export function ImportWorkflowModal(props: ImportWorkflowModalProps) {
161167
<EuiSpacer size="m" />
162168
</>
163169
)}
164-
{isValidWorkflow(fileObj) && !isCompatible && inCompatibleDataSourceVersion && (
170+
{isValidWorkflow(fileObj) && !isCompatible && dataSourceVersion && (
165171
<>
166172
<EuiFlexItem>
167173
<EuiCallOut
168-
title={`The uploaded file is not compatible with the current data source version ${inCompatibleDataSourceVersion}. Upload a compatible file or switch to another data source.`}
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.`}
169175
iconType={'alert'}
170176
color="danger"
171177
/>

‎public/utils/utils.tsx

+16-5
Original file line numberDiff line numberDiff line change
@@ -157,27 +157,26 @@ export function isValidWorkflow(workflowObj: any): boolean {
157157
return workflowObj?.name !== undefined;
158158
}
159159

160+
// Determines if a file used for import workflow is compatible with the current data source version.
160161
export async function isCompatibleWorkflow(
161162
workflowObj: any,
162163
dataSourceId?: string | undefined
163-
): Promise<[boolean, string | undefined]> {
164+
): Promise<boolean> {
164165
const compatibility = workflowObj?.version?.compatibility;
165166

166167
// Default to true when compatibility cannot be assessed (empty/invalid compatibility array or MDS disabled.)
167168
if (!Array.isArray(compatibility) || compatibility.length === 0 || dataSourceId === undefined) {
168-
return [true, undefined];
169+
return true;
169170
}
170171

171172
const dataSourceVersion = await getEffectiveVersion(dataSourceId);
172173
const [effectiveMajorVersion, effectiveMinorVersion] = dataSourceVersion.split('.').map(Number);
173174

174175
// Checks if any version in compatibility array matches the current dataSourceVersion (major.minor)
175-
const isCompatible = compatibility.some(compatibleVersion => {
176+
return compatibility.some(compatibleVersion => {
176177
const [compatibleMajor, compatibleMinor] = compatibleVersion.split('.').map(Number);
177178
return effectiveMajorVersion === compatibleMajor && effectiveMinorVersion === compatibleMinor;
178179
});
179-
180-
return [isCompatible, `${effectiveMajorVersion}.${effectiveMinorVersion}`];
181180
}
182181

183182

@@ -936,3 +935,15 @@ export const getEffectiveVersion = async (
936935
return MIN_SUPPORTED_VERSION;
937936
}
938937
};
938+
939+
940+
/**
941+
* Formats version string to show only major.minor numbers
942+
* Example: "3.0.0-alpha1" -> "3.0"
943+
*/
944+
export function formatDisplayVersion(version: string): string {
945+
// Take first two parts of version number (major.minor)
946+
const [major, minor] = version.split('.');
947+
return `${major}.${minor}`;
948+
}
949+

0 commit comments

Comments
 (0)
Please sign in to comment.