Skip to content

Commit

Permalink
[8.7] [ML] Date Picker: Fix to not trigger use full data button when …
Browse files Browse the repository at this point in the history
…changing frozen setting. (#151673) (#151731)

# Backport

This will backport the following commits from `main` to `8.7`:
- [[ML] Date Picker: Fix to not trigger use full data button when
changing frozen setting.
(#151673)](#151673)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Walter
Rafelsberger","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-02-21T15:59:23Z","message":"[ML]
Date Picker: Fix to not trigger use full data button when changing
frozen setting. (#151673)\n\nPreviously, when changing the frozen tier
settings in the popover menu\r\nof the date picker, this would also
trigger an action like you were\r\nclicking on the \"Use full data\"
button at the same time. This PR fixes\r\nthe behavior and only updates
the frozen tier settings, to update the\r\ntime range you now have to
click \"Use full data\"
separately.","sha":"07d1adfb14a3d9c4be3b4d2a1a0673a656088944","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix",":ml","v8.7.0","v8.8.0"],"number":151673,"url":"https://github.com/elastic/kibana/pull/151673","mergeCommit":{"message":"[ML]
Date Picker: Fix to not trigger use full data button when changing
frozen setting. (#151673)\n\nPreviously, when changing the frozen tier
settings in the popover menu\r\nof the date picker, this would also
trigger an action like you were\r\nclicking on the \"Use full data\"
button at the same time. This PR fixes\r\nthe behavior and only updates
the frozen tier settings, to update the\r\ntime range you now have to
click \"Use full data\"
separately.","sha":"07d1adfb14a3d9c4be3b4d2a1a0673a656088944"}},"sourceBranch":"main","suggestedTargetBranches":["8.7"],"targetPullRequestStates":[{"branch":"8.7","label":"v8.7.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/151673","number":151673,"mergeCommit":{"message":"[ML]
Date Picker: Fix to not trigger use full data button when changing
frozen setting. (#151673)\n\nPreviously, when changing the frozen tier
settings in the popover menu\r\nof the date picker, this would also
trigger an action like you were\r\nclicking on the \"Use full data\"
button at the same time. This PR fixes\r\nthe behavior and only updates
the frozen tier settings, to update the\r\ntime range you now have to
click \"Use full data\"
separately.","sha":"07d1adfb14a3d9c4be3b4d2a1a0673a656088944"}}]}]
BACKPORT-->

Co-authored-by: Walter Rafelsberger <[email protected]>
  • Loading branch information
kibanamachine and walterra authored Feb 21, 2023
1 parent 50bd9e8 commit 5aa2bdf
Showing 1 changed file with 25 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,43 +90,39 @@ export const FullTimeRangeSelector: FC<FullTimeRangeSelectorProps> = (props) =>
} = useDatePickerContext();

// wrapper around setFullTimeRange to allow for the calling of the optional callBack prop
const setRange = useCallback(
async (i: DataView, q?: QueryDslQueryContainer, excludeFrozenData?: boolean) => {
try {
const fullTimeRange = await setFullTimeRange(
timefilter,
i,
toasts,
http,
q,
excludeFrozenData
);
if (typeof callback === 'function') {
callback(fullTimeRange);
}
} catch (e) {
toasts.addDanger(
i18n.translate(
'xpack.ml.datePicker.fullTimeRangeSelector.errorSettingTimeRangeNotification',
{
defaultMessage: 'An error occurred setting the time range.',
}
)
);
const setRange = useCallback(async () => {
try {
const fullTimeRange = await setFullTimeRange(
timefilter,
dataView,
toasts,
http,
query,
frozenDataPreference === FROZEN_TIER_PREFERENCE.EXCLUDE
);
if (typeof callback === 'function') {
callback(fullTimeRange);
}
},
[callback, http, timefilter, toasts]
);
} catch (e) {
toasts.addDanger(
i18n.translate(
'xpack.ml.datePicker.fullTimeRangeSelector.errorSettingTimeRangeNotification',
{
defaultMessage: 'An error occurred setting the time range.',
}
)
);
}
}, [callback, dataView, frozenDataPreference, http, query, timefilter, toasts]);

const [isPopoverOpen, setPopover] = useState(false);

const setPreference = useCallback(
(id: string) => {
setFrozenDataPreference(id as FrozenTierPreference);
setRange(dataView, query, id === FROZEN_TIER_PREFERENCE.EXCLUDE);
closePopover();
},
[dataView, query, setFrozenDataPreference, setRange]
[setFrozenDataPreference]
);

const onButtonClick = () => {
Expand Down Expand Up @@ -195,7 +191,7 @@ export const FullTimeRangeSelector: FC<FullTimeRangeSelectorProps> = (props) =>
<EuiToolTip content={buttonTooltip}>
<EuiButton
isDisabled={disabled}
onClick={() => setRange(dataView, query, true)}
onClick={() => setRange()}
data-test-subj="mlDatePickerButtonUseFullData"
>
<FormattedMessage
Expand Down

0 comments on commit 5aa2bdf

Please sign in to comment.