Skip to content

Commit 0d330da

Browse files
committed
Block simulate on ingest if version not foundg
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
1 parent 4bfd70c commit 0d330da

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
lines changed

public/pages/workflow_detail/workflow_inputs/workflow_inputs.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import {
6060
sleep,
6161
useDataSourceVersion,
6262
getIsPreV219,
63+
useMissingDataSourceVersion,
6364
} from '../../../utils';
6465
import { BooleanField } from './input_fields';
6566
import '../workspace/workspace-styles.scss';
@@ -104,6 +105,10 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
104105
const dataSourceId = getDataSourceId();
105106
const dataSourceVersion = useDataSourceVersion(dataSourceId);
106107
const isPreV219 = getIsPreV219(dataSourceVersion);
108+
const missingDataSourceVersion = useMissingDataSourceVersion(
109+
dataSourceId,
110+
dataSourceVersion
111+
);
107112

108113
// transient running states
109114
const [isUpdatingSearchPipeline, setIsUpdatingSearchPipeline] = useState<
@@ -610,7 +615,10 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
610615
if (
611616
!isEmpty(values?.ingest?.enrich) &&
612617
values?.ingest?.pipelineName !== undefined &&
613-
values?.ingest?.pipelineName !== ''
618+
values?.ingest?.pipelineName !== '' &&
619+
// if the data source version is missing/undefined, we cannot
620+
// guarantee that the simulate API will be available
621+
!missingDataSourceVersion
614622
) {
615623
const curDocs = prepareDocsForSimulate(
616624
values?.ingest?.docs,

public/utils/utils.tsx

+39-19
Original file line numberDiff line numberDiff line change
@@ -160,27 +160,38 @@ export function isValidWorkflow(workflowObj: any): boolean {
160160

161161
// Determines if a file used for import workflow is compatible with the current data source version.
162162
export async function isCompatibleWorkflow(
163-
workflowObj: any,
163+
workflowObj: any,
164164
dataSourceId?: string | undefined
165165
): Promise<boolean> {
166166
const compatibility = workflowObj?.version?.compatibility;
167167

168168
// 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+
) {
170174
return true;
171175
}
172176

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+
176183
// 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+
);
180192
});
181193
}
182194

183-
184195
export function isValidUiWorkflow(workflowObj: any): boolean {
185196
return (
186197
isValidWorkflow(workflowObj) &&
@@ -933,13 +944,13 @@ export function getFieldValue(jsonObj: {}, fieldName: string): any | undefined {
933944
return undefined;
934945
}
935946

936-
// Get the version from the selected data source
947+
// Get the version from the selected data source, if found
937948
export const getEffectiveVersion = async (
938949
dataSourceId: string | undefined
939-
): Promise<string> => {
950+
): Promise<string | undefined> => {
940951
try {
941952
if (dataSourceId === undefined) {
942-
throw new Error('Data source is required');
953+
throw new Error();
943954
}
944955

945956
if (dataSourceId === '') {
@@ -951,16 +962,26 @@ export const getEffectiveVersion = async (
951962
'data-source',
952963
dataSourceId
953964
);
954-
const version =
955-
dataSource?.attributes?.dataSourceVersion || MIN_SUPPORTED_VERSION;
956-
return version;
965+
return dataSource?.attributes?.dataSourceVersion;
957966
} catch (error) {
958-
console.error('Error getting version:', error);
959-
return MIN_SUPPORTED_VERSION;
967+
console.error('Error getting version: ', error);
968+
return undefined;
960969
}
961970
};
962971

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+
964985
/**
965986
* Formats version string to show only major.minor numbers
966987
* Example: "3.0.0-alpha1" -> "3.0"
@@ -970,4 +991,3 @@ export function formatDisplayVersion(version: string): string {
970991
const [major, minor] = version.split('.');
971992
return `${major}.${minor}`;
972993
}
973-

0 commit comments

Comments
 (0)