Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest run name based on the pipeline version used to create run #2731

Merged
merged 13 commits into from
Dec 17, 2019
28 changes: 27 additions & 1 deletion frontend/src/pages/NewRun.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ describe('NewRun', () => {
const updateSnackbarSpy = jest.fn();
const updateToolbarSpy = jest.fn();

const mockMath = Object.create(global.Math);
mockMath.random = () => 0.5;
global.Math = mockMath;
Bobgy marked this conversation as resolved.
Show resolved Hide resolved

let MOCK_EXPERIMENT = newMockExperiment();
let MOCK_PIPELINE = newMockPipeline();
let MOCK_PIPELINE_VERSION = newMockPipelineVersion();
Expand Down Expand Up @@ -218,6 +222,20 @@ describe('NewRun', () => {
expect(tree.state()).toHaveProperty('runName', 'run name');
});

it('reports validation error when missing the run name', async () => {
const props = generateProps();
props.location.search = `?${QUERY_PARAMS.pipelineId}=${MOCK_PIPELINE.id}&${
QUERY_PARAMS.pipelineVersionId
}=${MOCK_PIPELINE.default_version!.id}`;

tree = shallow(<TestNewRun {...props} />);
await TestUtils.flushPromises();

(tree.instance() as TestNewRun).handleChange('runName')({ target: { value: null } });

expect(tree.state()).toHaveProperty('errorMessage', 'Run name is required');
});

it('allows updating the run description', async () => {
tree = shallow(<TestNewRun {...(generateProps() as any)} />);
await TestUtils.flushPromises();
Expand Down Expand Up @@ -364,7 +382,9 @@ describe('NewRun', () => {
expect(tree.state()).toHaveProperty('pipeline', MOCK_PIPELINE);
expect(tree.state()).toHaveProperty('pipelineName', MOCK_PIPELINE.name);
expect(tree.state()).toHaveProperty('pipelineVersion', MOCK_PIPELINE_VERSION);
expect(tree.state()).toHaveProperty('errorMessage', 'Run name is required');
expect((tree.state() as any).runName).toMatch(
/Run_of_\(original mock pipeline version name\)_.*/,
Bobgy marked this conversation as resolved.
Show resolved Hide resolved
);
expect(tree).toMatchSnapshot();
});

Expand Down Expand Up @@ -1052,6 +1072,8 @@ describe('NewRun', () => {
`&${QUERY_PARAMS.pipelineVersionId}=${MOCK_PIPELINE_VERSION.id}`;

tree = shallow(<TestNewRun {...props} />);
await TestUtils.flushPromises();

(tree.instance() as TestNewRun).handleChange('runName')({
target: { value: 'test run name' },
});
Expand Down Expand Up @@ -1386,6 +1408,8 @@ describe('NewRun', () => {
`&${QUERY_PARAMS.pipelineVersionId}=${MOCK_PIPELINE_VERSION.id}`;

tree = shallow(<TestNewRun {...props} />);
await TestUtils.flushPromises();

(tree.instance() as TestNewRun).handleChange('runName')({
target: { value: 'test run name' },
});
Expand Down Expand Up @@ -1435,6 +1459,8 @@ describe('NewRun', () => {

tree = TestUtils.mountWithRouter(<TestNewRun {...props} />);
const instance = tree.instance() as TestNewRun;
await TestUtils.flushPromises();

instance.handleChange('runName')({ target: { value: 'test run name' } });
instance.handleChange('description')({ target: { value: 'test run description' } });
await TestUtils.flushPromises();
Expand Down
56 changes: 36 additions & 20 deletions frontend/src/pages/NewRun.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,38 @@ class NewRun extends Page<{}, NewRunState> {
pipeline,
pipelineName: (pipeline && pipeline.name) || '',
});
const possiblePipelineVersionId =
urlParser.get(QUERY_PARAMS.pipelineVersionId) ||
(pipeline.default_version && pipeline.default_version.id);
if (possiblePipelineVersionId) {
try {
const pipelineVersion = await Apis.pipelineServiceApi.getPipelineVersion(
possiblePipelineVersionId,
);
this.setStateSafe({
parameters: pipelineVersion.parameters || [],
pipelineVersion,
pipelineVersionName: (pipelineVersion && pipelineVersion.name) || '',
runName: this._getRunNameFromPipelineVersion(
(pipelineVersion && pipelineVersion.name) || '',
),
});
} catch (err) {
urlParser.clear(QUERY_PARAMS.pipelineVersionId);
await this.showPageError(
`Error: failed to retrieve pipeline version: ${possiblePipelineVersionId}.`,
err,
);
logger.error(
`Failed to retrieve pipeline version: ${possiblePipelineVersionId}`,
err,
);
}
} else {
this.setStateSafe({
runName: this._getRunNameFromPipelineVersion((pipeline && pipeline.name) || ''),
});
}
} catch (err) {
urlParser.clear(QUERY_PARAMS.pipelineId);
await this.showPageError(
Expand All @@ -626,26 +658,6 @@ class NewRun extends Page<{}, NewRunState> {
logger.error(`Failed to retrieve pipeline: ${possiblePipelineId}`, err);
}
}
const possiblePipelineVersionId = urlParser.get(QUERY_PARAMS.pipelineVersionId);
if (possiblePipelineVersionId) {
try {
const pipelineVersion = await Apis.pipelineServiceApi.getPipelineVersion(
possiblePipelineVersionId,
);
this.setStateSafe({
parameters: pipelineVersion.parameters || [],
pipelineVersion,
pipelineVersionName: (pipelineVersion && pipelineVersion.name) || '',
});
} catch (err) {
urlParser.clear(QUERY_PARAMS.pipelineVersionId);
await this.showPageError(
`Error: failed to retrieve pipeline version: ${possiblePipelineVersionId}.`,
err,
);
logger.error(`Failed to retrieve pipeline version: ${possiblePipelineVersionId}`, err);
}
}
}

let experiment: ApiExperiment | undefined;
Expand Down Expand Up @@ -1045,6 +1057,10 @@ class NewRun extends Page<{}, NewRunState> {
}
}

private _getRunNameFromPipelineVersion(pipelineVersionName: string): string {
return 'Run_of_(' + pipelineVersionName + ')_' + Math.floor(Math.random() * 1000) + 1;
}

private _validate(): void {
// Validate state
const { pipelineVersion, workflowFromRun, maxConcurrentRuns, runName, trigger } = this.state;
Expand Down
8 changes: 3 additions & 5 deletions frontend/src/pages/__snapshots__/NewRun.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2923,7 +2923,7 @@ exports[`NewRun fetches the associated pipeline if one is present in the query p
label="Run name"
onChange={[Function]}
required={true}
value=""
value="Run_of_(original mock pipeline version name)_5001"
variant="outlined"
/>
<Component
Expand Down Expand Up @@ -3006,7 +3006,7 @@ exports[`NewRun fetches the associated pipeline if one is present in the query p
<BusyButton
busy={false}
className="buttonAction"
disabled={true}
disabled={false}
id="startNewRunBtn"
onClick={[Function]}
title="Start"
Expand All @@ -3024,9 +3024,7 @@ exports[`NewRun fetches the associated pipeline if one is present in the query p
"color": "red",
}
}
>
Run name is required
</div>
/>
</div>
</div>
</div>
Expand Down