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

fix(ui): displaying variable list default values #17097

Merged
merged 7 commits into from
Mar 9, 2020
Merged

Conversation

asalem1
Copy link
Contributor

@asalem1 asalem1 commented Mar 5, 2020

Closes #16058

Problem

Variable list was showing only created variables and not showing default variables

Solution

Default variables are populated whenever the query runs, so the solution involved calculating the default variables whenever the variable list was rendered & whenever the variable tooltip was being toggled. Here's how it looks like in action:

defaultVariables

  • CHANGELOG.md updated with a link to the PR (not the Issue)

@asalem1 asalem1 requested a review from a team March 5, 2020 00:04
@ghost ghost requested review from hoorayimhelping and removed request for a team March 5, 2020 00:04
Copy link
Contributor Author

@asalem1 asalem1 left a comment

Choose a reason for hiding this comment

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

Going to add some tests here to ensure that this is stable

@desa desa requested review from a team and removed request for a team March 5, 2020 17:42
@hoorayimhelping
Copy link
Contributor

@asalem1 is this ready for review or should i wait for you to fix the e2e tests?

@asalem1
Copy link
Contributor Author

asalem1 commented Mar 5, 2020

@hoorayimhelping not quite yet unfortunately. I managed to update and add some tests, but I'm currently trying to add some individual tests for the utility functions I created and bumping into some uncaught existing issues that I'm looking to smooth over. I'll DM you when the PR is ready to go :D

Copy link
Contributor

@121watts 121watts left a comment

Choose a reason for hiding this comment

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

Unit tests and selectors please 😄

const values = getTimeMachineValues(state, ownProps.variableID)
const {variableID} = ownProps
let values: VariableValues
if (variableID.includes('timeRange') || variableID.includes('windowPeriod')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This code is a perfect example of something that should live inside a selector and unit tested. Shoot, it could even go inside the getTimeMachineValues selector. Generally, anytime I'm doing a whole bunch of logic inside of mstp I like to ask myself "should this go into a selector?"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me

@asalem1 asalem1 requested a review from 121watts March 5, 2020 22:32
Copy link
Contributor

@121watts 121watts left a comment

Choose a reason for hiding this comment

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

Nice work man. Some suggestions below. Nothing blocking.

ui/src/shared/utils/getMinDurationFromAST.ts Show resolved Hide resolved
@@ -48,7 +48,7 @@ const VariableToolbar: FunctionComponent<OwnProps & StateProps> = ({
}

const mstp = (state: AppState): StateProps => {
const variables = extractVariablesList(state)
const variables = extractVariablesListWithDefaults(state)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const variables = extractVariablesListWithDefaults(state)
const variables = getVariables(state)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd rather keep this as is since:

  1. We already have an oats generated API call by that name
  2. Default variables (like windowPeriod, timeRangeStart, timeRangeStop) are never returned when we currently deal with anything getVariable related.

@@ -53,3 +56,24 @@ describe('getTimeRangeVars', () => {
})
})
})

describe('getTimeRangeAsVariable', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

💃

Comment on lines 102 to 109
{dropdownItems.length === 1 && (
<Dropdown
button={button}
style={{width: '200px'}}
menu={menu}
testID="variable--tooltip-dropdown"
/>
)}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this piece of logic after speaking to a user and them mentioning that dropdowns with only 1 option are confusing since they'd expect them to have more than 1 option

@asalem1 asalem1 merged commit a017f0c into master Mar 9, 2020
@asalem1 asalem1 deleted the fix/display-variables branch March 9, 2020 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display all available variables in UI
3 participants