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

Add error handling for Plot Wizard plots with x fields #4798

Conversation

julieg18
Copy link
Contributor

@julieg18 julieg18 commented Oct 10, 2023

3/3 main<- #4787 <- #4797 <- this

  • If the user selects more than one x field, we check if there amount of x fields and y fields chosen are the same amount and we check that the user hasn't selected more than one field in a file

Demo

Check for only metric per file

Screen.Recording.2023-10-11.at.5.36.13.PM.mov

Check for x and y having the same amount of metrics

Screen.Recording.2023-10-11.at.5.37.00.PM.mov

Part of #4654

@julieg18 julieg18 added the bug Something isn't working label Oct 10, 2023
@julieg18 julieg18 self-assigned this Oct 10, 2023
@codeclimate
Copy link

codeclimate bot commented Oct 10, 2023

Code Climate has analyzed commit 135582a and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 63.3% (85% is the threshold).

This pull request will bring the total coverage in the repository to 94.9%.

View more on Code Climate.

@julieg18 julieg18 changed the title Add error handling for Plot Wizard plots with an x dict Add error handling for Plot Wizard plots with x fields Oct 10, 2023
@julieg18 julieg18 changed the base branch from main to allow-plot-wizard-multi-x-selection October 11, 2023 12:57
@@ -588,17 +617,109 @@ describe('pickPlotConfiguration', () => {
mockedQuickPickOne.mockResolvedValue('simple')
mockedGetInput.mockResolvedValue('simple_plot')
mockedQuickPickUserOrderedValues
.mockResolvedValueOnce([
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -580,6 +580,35 @@ describe('pickPlotConfiguration', () => {
expect(mockedQuickPickUserOrderedValues).toHaveBeenCalledTimes(2)
expect(noFieldsResult).toStrictEqual(undefined)
})

it('should show a toast if user selects more than one key in a file for an x field', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, we've got around 20 different tests in this describe block. I'd like to break group these tests to make things more readable but I'll do it in a separate pr since that would involve touching the whole file. Updated #4654.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Q] What is the problem with having 20 tests in a block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily a problem but I find it easier to navigate/update a test file when tests are grouped. Looking at this file, we could group file picking and field picking into its own blocks. Though, of course, no strong preference, I'm happy to leave it as is if preferred.

@julieg18 julieg18 marked this pull request as ready for review October 11, 2023 23:24
extension/src/pipeline/quickPick.ts Outdated Show resolved Hide resolved
extension/src/pipeline/quickPick.ts Outdated Show resolved Hide resolved
extension/src/pipeline/quickPick.ts Outdated Show resolved Hide resolved
extension/src/pipeline/quickPick.ts Outdated Show resolved Hide resolved

if (yValues.length !== xFieldsLength) {
void Toast.showError(
'The amount of y metrics needs to match the amount of x metrics. See [an example](https://dvc.org/doc/user-guide/project-structure/dvcyaml-files#available-configuration-fields) of a plot with multiple x metrics.'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[C] When there are multiple x metrics selected there must be an equal number of y metrics.

[Q] Also, did you consider using a version of quickPickLimitedValues when there are multiple xs? That would avoid the need for this validation. Thinking out loud => maybe we could have a quick pick that validates the number of items selected in the onDidAccept callback?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[F] The CLI error is WARNING: In 'workspace', cannot have different number of x and y data sources. found 2 x and 4 y data sources.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, did you consider using a version of quickPickLimitedValues when there are multiple xs? That would avoid the need for this validation. Thinking out loud => maybe we could have a quick pick that validates the number of items selected in the onDidAccept callback?

That might work! I didn't think we could control that in the onDidAccept but I'll try it out! Even if it doesn't work, we could still use quickPickLimitedValues to at least help with making sure the user doesn't select too many items 🤔

extension/src/pipeline/quickPick.ts Outdated Show resolved Hide resolved
extension/src/pipeline/quickPick.ts Outdated Show resolved Hide resolved
@julieg18
Copy link
Contributor Author

Going to merge and improve validation for the y metrics quick pick (#4798 (comment)) in a followup pr!

@julieg18 julieg18 merged commit 7033ec6 into allow-plot-wizard-multi-x-selection Oct 13, 2023
3 checks passed
@julieg18 julieg18 deleted the add-error-handling-for-plot-wizard-field-dict branch October 13, 2023 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants