Skip to content

Commit

Permalink
Show only active experiments on create/duplicate schedules page
Browse files Browse the repository at this point in the history
  • Loading branch information
DaoDaoNoCode committed Aug 20, 2024
1 parent 1a34861 commit 3ab3d7f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ describe('Pipeline create runs', () => {

it('creates a schedule', () => {
createScheduleRunCommonTest();
createSchedulePage.findExperimentSelect().should('contain.text', 'Default');
// Default is archived, so it should not pre-select the default
createSchedulePage.findExperimentSelect().should('contain.text', 'Select an experiment');
createSchedulePage.findExperimentSelect().should('not.be.disabled').click();
createSchedulePage.selectExperimentByName('Test experiment 1');
createSchedulePage
Expand Down Expand Up @@ -588,6 +589,8 @@ describe('Pipeline create runs', () => {
it('creates a schedule with trigger type cron without whitespace', () => {
// Fill out the form with a schedule and submit
createScheduleRunCommonTest();
createSchedulePage.findExperimentSelect().should('not.be.disabled').click();
createSchedulePage.selectExperimentByName('Test experiment 1');
createSchedulePage.findScheduledRunTypeSelector().findSelectOption('Cron').click();
createSchedulePage.findScheduledRunCron().fill('@every 5m');
createSchedulePage
Expand All @@ -608,10 +611,10 @@ describe('Pipeline create runs', () => {
},
trigger: { cron_schedule: { cron: '@every 5m' } },
max_concurrency: '10',
mode: 'DISABLE',
mode: 'ENABLE',
no_catchup: false,
service_account: '',
experiment_id: 'default',
experiment_id: 'experiment-1',
});
});

Expand All @@ -623,6 +626,8 @@ describe('Pipeline create runs', () => {

it('creates a schedule with trigger type cron with whitespace', () => {
createScheduleRunCommonTest();
createSchedulePage.findExperimentSelect().should('not.be.disabled').click();
createSchedulePage.selectExperimentByName('Test experiment 1');
createSchedulePage.findScheduledRunTypeSelector().findSelectOption('Cron').click();
createSchedulePage.findScheduledRunCron().fill('@every 5m ');
createSchedulePage
Expand All @@ -643,10 +648,10 @@ describe('Pipeline create runs', () => {
},
trigger: { cron_schedule: { cron: '@every 5m' } },
max_concurrency: '10',
mode: 'DISABLE',
mode: 'ENABLE',
no_catchup: false,
service_account: '',
experiment_id: 'default',
experiment_id: 'experiment-1',
});
});
});
Expand Down Expand Up @@ -730,6 +735,38 @@ describe('Pipeline create runs', () => {
);
});

it('duplicates a schedule with an archived experiment', () => {
const [mockRecurringRun] = initialMockRecurringRuns;
const mockExperiment = { ...mockExperiments[0], storage_state: StorageStateKF.ARCHIVED };

// Mock experiments, pipelines & versions for form select dropdowns
cloneSchedulePage.mockGetExperiments(projectName, mockExperiments);
cloneSchedulePage.mockGetPipelines(projectName, [mockPipeline]);
cloneSchedulePage.mockGetPipelineVersions(
projectName,
[mockPipelineVersion],
mockPipelineVersion.pipeline_id,
);
cloneSchedulePage.mockGetRecurringRun(projectName, mockRecurringRun);
cloneSchedulePage.mockGetPipelineVersion(projectName, mockPipelineVersion);
cloneSchedulePage.mockGetPipeline(projectName, mockPipeline);
cloneSchedulePage.mockGetExperiment(projectName, mockExperiment);

// Navigate to clone run page for a given schedule
cy.visitWithLogin(`/experiments/${projectName}/experiment-1/runs`);
pipelineRunsGlobal.findSchedulesTab().click();
pipelineRecurringRunTable
.getRowByName(mockRecurringRun.display_name)
.findKebabAction('Duplicate')
.click();
verifyRelativeURL(
`/experiments/${projectName}/experiment-1/schedules/clone/${mockRecurringRun.recurring_run_id}`,
);

// Verify pre-populated values & submit
cloneSchedulePage.findExperimentSelect().should('have.text', 'Select an experiment');
});

it('shows cron & periodic fields', () => {
visitLegacyRunsPage();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ const RunForm: React.FC<RunFormProps> = ({ data, onValueChange, isCloned }) => {
projectName={getDisplayNameFromK8sResource(data.project)}
value={data.experiment}
onChange={(experiment) => onValueChange('experiment', experiment)}
isSchedule={isSchedule}
/>

<FormSection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,20 @@ import {
CreateRunPageSections,
runPageSectionTitles,
} from '~/concepts/pipelines/content/createRun/const';
import {
ActiveExperimentSelector,
AllExperimentSelector,
} from '~/concepts/pipelines/content/experiment/ExperimentSelector';
import { ActiveExperimentSelector } from '~/concepts/pipelines/content/experiment/ExperimentSelector';
import CreateExperimentButton from '~/concepts/pipelines/content/experiment/CreateExperimentButton';
import { SupportedArea, useIsAreaAvailable } from '~/concepts/areas';

type ProjectAndExperimentSectionProps = {
projectName: string;
value: ExperimentKFv2 | null;
onChange: (experiment: ExperimentKFv2) => void;
isSchedule: boolean;
};

const ProjectAndExperimentSection: React.FC<ProjectAndExperimentSectionProps> = ({
projectName,
value,
onChange,
isSchedule,
}) => {
const isExperimentsAvailable = useIsAreaAvailable(SupportedArea.PIPELINE_EXPERIMENTS).status;

Expand All @@ -44,11 +39,7 @@ const ProjectAndExperimentSection: React.FC<ProjectAndExperimentSectionProps> =
<FormGroup label="Experiment" aria-label="Experiment" isRequired>
<Stack hasGutter>
<StackItem>
{isSchedule ? (
<AllExperimentSelector selection={value?.display_name} onSelect={onChange} />
) : (
<ActiveExperimentSelector selection={value?.display_name} onSelect={onChange} />
)}
<ActiveExperimentSelector selection={value?.display_name} onSelect={onChange} />
</StackItem>
<StackItem>
<CreateExperimentButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,16 @@ const useUpdateExperimentFormData = (
const [formData, setFormValue] = formState;

React.useEffect(() => {
// on create run page, we always check the experiment archived state
// no matter it's duplicated or carried from the create schedules pages
if (formData.runType.type === RunTypeOption.ONE_TRIGGER) {
if (formData.experiment) {
if (formData.experiment.storage_state === StorageStateKF.ARCHIVED) {
setFormValue('experiment', null);
}
} else if (experiment) {
if (experiment.storage_state === StorageStateKF.ARCHIVED) {
setFormValue('experiment', null);
} else {
setFormValue('experiment', experiment);
}
if (formData.experiment) {
if (formData.experiment.storage_state === StorageStateKF.ARCHIVED) {
setFormValue('experiment', null);
}
} else if (experiment) {
if (experiment.storage_state === StorageStateKF.ARCHIVED) {
setFormValue('experiment', null);
} else {
setFormValue('experiment', experiment);
}
} else if (!formData.experiment && experiment) {
// else, on create schedules page, we do what we did before
setFormValue('experiment', experiment);
}
}, [formData.experiment, setFormValue, experiment, formData.runType.type]);
};
Expand Down

0 comments on commit 3ab3d7f

Please sign in to comment.