Skip to content

Commit

Permalink
Merge pull request #944 from kubeshop/razvantopliceanu/feat/optional-…
Browse files Browse the repository at this point in the history
…test-source

feat: optional test source for container executors
  • Loading branch information
topliceanurazvan authored Nov 17, 2023
2 parents 2ff32aa + 1f1e886 commit cb82e68
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ const TestCreationForm: React.FC<TestCreationFormProps> = props => {
return executors.find((executor: Executor) => executor.executor?.types?.includes(form.getFieldValue('testType')));
}, [form.getFieldValue('testType')]);

const isContainerExecutor = useMemo(
() => selectedExecutor?.executor.executorType === 'container',
[selectedExecutor]
);

return (
<Form form={form} layout="vertical" name="test-creation" onFinish={onSave} style={{flex: 1}} labelAlign="right">
<div ref={topRef} />
Expand All @@ -114,7 +119,14 @@ const TestCreationForm: React.FC<TestCreationFormProps> = props => {
<Input placeholder="e.g.: my-test" autoComplete="off" />
</FormItem>
<FormItem name="testType" label="Type" rules={[required]} required>
<Select placeholder="Select from available executors..." showSearch options={remappedExecutors} />
<Select
onChange={() => {
form.validateFields(['testSource']);
}}
placeholder="Select from available executors..."
showSearch
options={remappedExecutors}
/>
</FormItem>
<FormItem
noStyle
Expand All @@ -135,7 +147,12 @@ const TestCreationForm: React.FC<TestCreationFormProps> = props => {
];

return (
<FormItem rules={[required]} label="Source" name="testSource" required>
<FormItem
rules={isContainerExecutor ? [] : [required]}
label="Source"
name="testSource"
required={!isContainerExecutor}
>
<Select placeholder="Select a source..." options={options} showSearch />
</FormItem>
);
Expand Down
7 changes: 6 additions & 1 deletion packages/web/src/utils/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ export const getTestSourceSpecificFields = (values: any, isCustomGit?: boolean)

export const getSourcePayload = (values: any, testSources: SourceWithRepository[]) => {
const {testSource} = values;

if (!testSource) {
return {};
}

const isCustomGit = testSource.includes(customGitSourceString);

const testSourceSpecificFields = getTestSourceSpecificFields(values, isCustomGit);
Expand All @@ -107,7 +112,7 @@ export const getSourcePayload = (values: any, testSources: SourceWithRepository[
};

export const getCustomSourceField = (testSource: string) => {
const isCustomTestSource = testSource.includes(customGitSourceString);
const isCustomTestSource = testSource?.includes(customGitSourceString);

return isCustomTestSource ? {source: testSource.replace(customGitSourceString, '')} : {source: ''};
};
Expand Down

0 comments on commit cb82e68

Please sign in to comment.