-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Global Pins] Added a disabling global pins feature #6831
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
Changes from all commits
2cf2b11
dec6a63
6ea22fd
568febf
bbf9050
abb477b
3ff7cd2
bb40a23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -608,6 +608,9 @@ const reducer = createReducer( | |
| if (typeof partialSettings.scalarSmoothing === 'number') { | ||
| metricsSettings.scalarSmoothing = partialSettings.scalarSmoothing; | ||
| } | ||
| if (typeof partialSettings.savingPinsEnabled === 'boolean') { | ||
| metricsSettings.savingPinsEnabled = partialSettings.savingPinsEnabled; | ||
| } | ||
|
|
||
| const isSettingsPaneOpen = | ||
| partialSettings.timeSeriesSettingsPaneOpened ?? state.isSettingsPaneOpen; | ||
|
|
@@ -933,6 +936,19 @@ const reducer = createReducer( | |
| }, | ||
| }; | ||
| }), | ||
| on(actions.metricsEnableSavingPinsToggled, (state) => { | ||
| const nextSavingPinsEnabled = !( | ||
| state.settingOverrides.savingPinsEnabled ?? | ||
| state.settings.savingPinsEnabled | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [optional] I'm curious, did you find out anything about the "legacy reasons" why we need settings as well as settingsOverrides?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may be mistaken, but based on my understanding, the In the code, the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, that makes it clearer! |
||
| ); | ||
| return { | ||
| ...state, | ||
| settingOverrides: { | ||
| ...state.settingOverrides, | ||
| savingPinsEnabled: nextSavingPinsEnabled, | ||
| }, | ||
| }; | ||
| }), | ||
| on( | ||
| actions.multipleTimeSeriesRequested, | ||
| ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1232,6 +1232,25 @@ describe('metrics reducers', () => { | |
| expect(thirdState.settings.hideEmptyCards).toBe(false); | ||
| expect(thirdState.settingOverrides.hideEmptyCards).toBe(false); | ||
| }); | ||
|
|
||
| it('changes savingPinsEnabled on metricsEnableSavingPinsToggled', () => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this tests a "toggle", could we have at least two test cases minimum here? One changing from true -> false, another from false -> true (parameterized tests may help - please see other comment)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added some states to make it true -> false -> true.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: interleaving act and assert steps is explicitly forbidden by our style guide and I think we should follow it unless there's a very strong reason not to. Can we just create separate tests for true->false and false->true?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Applied. Thanks for reminding me! I just followed this interleaving act and assert steps because it was commonly used in this test codebase
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the cleanup! My readability meta-mentor linked me to this when I asked if consistency is important: https://peps.python.org/pep-0008/#a-foolish-consistency-is-the-hobgoblin-of-little-minds My stance now is |
||
| [{value: true}, {value: false}].forEach(({value: initValue}) => { | ||
| const prevState = buildMetricsState({ | ||
| settings: buildMetricsSettingsState({ | ||
| savingPinsEnabled: initValue, | ||
| }), | ||
| settingOverrides: {}, | ||
| }); | ||
|
|
||
| const nextState = reducers( | ||
| prevState, | ||
| actions.metricsEnableSavingPinsToggled() | ||
| ); | ||
|
|
||
| expect(nextState.settings.savingPinsEnabled).toBe(initValue); | ||
| expect(nextState.settingOverrides.savingPinsEnabled).toBe(!initValue); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('loading time series data', () => { | ||
|
|
@@ -3142,6 +3161,7 @@ describe('metrics reducers', () => { | |
| scalarSmoothing: 0.3, | ||
| ignoreOutliers: false, | ||
| tooltipSort: TooltipSort.ASCENDING, | ||
| savingPinsEnabled: true, | ||
| }), | ||
| settingOverrides: { | ||
| scalarSmoothing: 0.5, | ||
|
|
@@ -3155,13 +3175,15 @@ describe('metrics reducers', () => { | |
| partialSettings: { | ||
| ignoreOutliers: true, | ||
| tooltipSort: TooltipSort.DESCENDING, | ||
| savingPinsEnabled: false, | ||
| }, | ||
| }) | ||
| ); | ||
|
|
||
| expect(nextState.settings.scalarSmoothing).toBe(0.3); | ||
| expect(nextState.settings.ignoreOutliers).toBe(true); | ||
| expect(nextState.settings.tooltipSort).toBe(TooltipSort.DESCENDING); | ||
| expect(nextState.settings.savingPinsEnabled).toBe(false); | ||
| expect(nextState.settingOverrides.scalarSmoothing).toBe(0.5); | ||
| expect(nextState.settingOverrides.tooltipSort).toBe( | ||
| TooltipSort.ALPHABETICAL | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1298,6 +1298,20 @@ describe('metrics selectors', () => { | |
| ); | ||
| expect(selectors.getMetricsCardMinWidth(state)).toBe(400); | ||
| }); | ||
|
|
||
| it('returns savingPinsEnabled when called getMetricsSavingPinsEnabled', () => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: the test isn't very robust, as many different expressions could evaluate to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
| [{value: true}, {value: false}].forEach(({value}) => { | ||
| selectors.getMetricsSavingPinsEnabled.release(); | ||
| const state = appStateFromMetricsState( | ||
| buildMetricsState({ | ||
| settings: buildMetricsSettingsState({ | ||
| savingPinsEnabled: value, | ||
| }), | ||
| }) | ||
| ); | ||
| expect(selectors.getMetricsSavingPinsEnabled(state)).toBe(value); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getMetricsTagFilter', () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,28 @@ import {DataTableMode} from '../widgets/data_table/types'; | |
| export function buildMetricsSettingsState( | ||
| overrides?: Partial<MetricsSettings> | ||
| ): MetricsSettings { | ||
| return { | ||
| cardMinWidth: null, | ||
| tooltipSort: TooltipSort.NEAREST, | ||
| ignoreOutliers: false, | ||
| xAxisType: XAxisType.WALL_TIME, | ||
| scalarSmoothing: 0.3, | ||
| hideEmptyCards: true, | ||
| scalarPartitionNonMonotonicX: false, | ||
| imageBrightnessInMilli: 123, | ||
| imageContrastInMilli: 123, | ||
| imageShowActualSize: true, | ||
| histogramMode: HistogramMode.OFFSET, | ||
| savingPinsEnabled: true, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change in |
||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| // Since Settings proto has missing fields, we need to build a partial of | ||
| // Settings to be used in tests. | ||
| export function buildMetricsSettingsOverrides( | ||
| overrides?: Partial<MetricsSettings> | ||
| ): Partial<MetricsSettings> { | ||
| return { | ||
| cardMinWidth: null, | ||
| tooltipSort: TooltipSort.NEAREST, | ||
|
|
||
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 was a bit confused by the naming at first because the effect doesn't actually disable (disabling is done elsewhere), this just removes pins.
WDYT of a naming that describes the actual action, like removeOnDisable?
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 changed to
removeSavedPinsOnDisable👍