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
Correlations: Add transformation editor #66217
Conversation
This reverts commit 2188a3d.
…or, save values that disappear so they come back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works really great! 🎉
I think there are two main missing bits to make it mergable:
(1) The validation for the expression field should be consistent with other fields:
Screen.Recording.2023-04-12.at.11.57.05.mov
(2) There should also be some test coverage added (at least a smoke test in CorrelationsPage.test.tsx)
Other comments are non-blockers.
}); | ||
const getStyles = (theme: GrafanaTheme2) => { | ||
// show text color at 0.05% to show with alternating background colors of interactive table | ||
const decomposedContrastColor = colorManipulator.decomposeColor(theme.colors.text.primary); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a good idea to make it stand out better, but in long term we may need to rethink the design. Having all forms in the table rows may create more, similar issue. I'll cross-link this comment in #65517
}); | ||
const newValueDetails = getSupportedTransTypeDetails(value.value); | ||
|
||
if (newValueDetails.showExpression) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that I would like to prevent data loss as much as possible for this.
Fair enough. It's quite complex logic and it'd be good to add test coverage for it.
@@ -8,6 +8,11 @@ export type GetCorrelationsResponse = Correlation[]; | |||
|
|||
type CorrelationConfigType = 'query'; | |||
|
|||
export enum TransformationType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use SupportedTransformationType
from @grafana/data
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops - yep! Fixed
rules={{ required: { value: true, message: 'Please select a transformation type' } }} | ||
/> | ||
</Field> | ||
<Field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New fields don't have any aria-label
s, probably worth adding some.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many were added to correspond to the tests but I double checked and made sure all buttons and fields have an aria label
<Select | ||
{...field} | ||
onChange={(value) => { | ||
if (!readOnly) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very confusing in read-only mode. Not a blocker for now but I think we should run it by UX. I'll also mention it in #65517. I think making the description accessible in read-only mode was suggested by @radiorental, but is it the right way of doing it?
…formation delete/add bug
…na/transformations-editor
return ( | ||
<Select | ||
{...field} | ||
value={fieldVal.type} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ifrost this is to fix the bug I talked about.
Replication steps:
- Have a transformation saved already. Refresh to clean slate the state.
- Open the correlation and go to the transformation. Delete it
- Add a new transformation. The select will be pre-filled with the original transformation
To see what the deal is, if you add a console.log for field
in the InputControl
render and fieldVal
in the fields.map
above, you will see the InputControl field still persists this value, as it must grab it from some state that does not get affected by remove
. If there's a more obvious solution here, please let me know :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validation and tests look good 👍 There's still a few comments I left last time that would be good to address.
Found a bug creating a whole new correlation where it gives the "Please select a transformation type" when there is one selected. Will fix and add a test for this. Edit: I only saw this once and was never able to recreate it again. I added creating a transformation in the test for creating a correlation, it should catch this and fail if an error message pops up that prevents saving. |
<Field | ||
label={ | ||
<Stack gap={0.5}> | ||
<Label htmlFor={`config.transformations.${index}.type`}>Type</Label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to use the same id as inputId
prop in the Select
at line 81 otherwise that select is going to be unlabeled.
moreover, we should not use the index here as it causes this label to target all transformations being edited with the same index:
Screen.Recording.2023-04-15.at.09.06.57.mov
we could use htmlFor={`config.transformations.${fieldVal.id}.type`}
here and inputId={`config.transformations.${fieldVal.id}.type`}
in the select. and by doing that you should be able to leverage this label element to describe the input instead of using an explicit aria-label
on the select
<Label htmlFor={`config.transformations.${index}.type`}>Type</Label> | |
<Label htmlFor={`config.transformations.${fieldVal.id}.type`}>Type</Label> |
<Field | ||
label={ | ||
<Stack gap={0.5}> | ||
<Label>Field</Label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should add an htmlFor
here:
<Label>Field</Label> | |
<Label htmlFor={`config.transformations.${fieldVal.id}.field`}>Field</Label> |
readOnly={readOnly} | ||
defaultValue={fieldVal.field} | ||
label="field" | ||
aria-label="field" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to pair with the above comment:
aria-label="field" | |
id={`config.transformations.${fieldVal.id}.field`} |
}} | ||
options={transformOptions} | ||
width={25} | ||
aria-label="Type" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aria-label="Type" | |
inputId={`config.transformations.${fieldVal.id}.type`} |
public/app/features/correlations/Forms/TransformationsEditor.tsx
Outdated
Show resolved
Hide resolved
public/app/features/correlations/Forms/TransformationsEditor.tsx
Outdated
Show resolved
Hide resolved
public/app/features/correlations/Forms/TransformationsEditor.tsx
Outdated
Show resolved
Hide resolved
public/app/features/correlations/Forms/TransformationsEditor.tsx
Outdated
Show resolved
Hide resolved
public/app/features/correlations/Forms/TransformationsEditor.tsx
Outdated
Show resolved
Hide resolved
return Object.keys(SupportedTransformationType).map((key) => { | ||
const transType = getSupportedTransTypeDetails( | ||
SupportedTransformationType[key as keyof typeof SupportedTransformationType] | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you can do this instead so you don't have to do any ugly type assertion:
return Object.keys(SupportedTransformationType).map((key) => { | |
const transType = getSupportedTransTypeDetails( | |
SupportedTransformationType[key as keyof typeof SupportedTransformationType] | |
); | |
return Object.values(SupportedTransformationType).map((key) => { | |
const transType = getSupportedTransTypeDetails(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or probably better:
return Object.keys(SupportedTransformationType).map((key) => { | |
const transType = getSupportedTransTypeDetails( | |
SupportedTransformationType[key as keyof typeof SupportedTransformationType] | |
); | |
return Object.values(SupportedTransformationType).map((transformationType) => { | |
const transType = getSupportedTransTypeDetails(transformationType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Elfo404 good call, this worked great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀
What is this feature?
This feature adds a UI that allows people to create transformations in their correlations.
Why do we need this feature?
Transformations were previously enabled via provisioning, but that does not include an intuitive interface for people to create their own transformations using Grafana's UI. This adds transformations to the existing correlations editor.
Who is this feature for?
For people who want to set up correlations in a ui instead of provisioning.
Which issue(s) does this PR fix?:
Fixes #62095
Special notes for your reviewer:
Please check that: