mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[User Experience] UX use replace history instead of push on first load (#88586)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
f718e90a81
commit
37cc7af49d
2 changed files with 15 additions and 7 deletions
|
@ -28,7 +28,7 @@ function ServiceNameFilter({ loading, serviceNames }: Props) {
|
|||
}));
|
||||
|
||||
const updateServiceName = useCallback(
|
||||
(serviceN: string) => {
|
||||
(serviceN: string, replaceHistory?: boolean) => {
|
||||
const newLocation = {
|
||||
...history.location,
|
||||
search: fromQuery({
|
||||
|
@ -36,7 +36,11 @@ function ServiceNameFilter({ loading, serviceNames }: Props) {
|
|||
serviceName: serviceN,
|
||||
}),
|
||||
};
|
||||
history.push(newLocation);
|
||||
if (replaceHistory) {
|
||||
history.replace(newLocation);
|
||||
} else {
|
||||
history.push(newLocation);
|
||||
}
|
||||
},
|
||||
[history]
|
||||
);
|
||||
|
@ -45,12 +49,12 @@ function ServiceNameFilter({ loading, serviceNames }: Props) {
|
|||
if (serviceNames?.length > 0) {
|
||||
// select first from the list
|
||||
if (!selectedServiceName) {
|
||||
updateServiceName(serviceNames[0]);
|
||||
updateServiceName(serviceNames[0], true);
|
||||
}
|
||||
|
||||
// in case serviceName is cached from url and isn't present in current list
|
||||
if (selectedServiceName && !serviceNames.includes(selectedServiceName)) {
|
||||
updateServiceName(serviceNames[0]);
|
||||
updateServiceName(serviceNames[0], true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ export function UserPercentile() {
|
|||
} = useUrlParams();
|
||||
|
||||
const updatePercentile = useCallback(
|
||||
(percentileN?: number) => {
|
||||
(percentileN?: number, replaceHistory?: boolean) => {
|
||||
const newLocation = {
|
||||
...history.location,
|
||||
search: fromQuery({
|
||||
|
@ -30,14 +30,18 @@ export function UserPercentile() {
|
|||
percentile: percentileN,
|
||||
}),
|
||||
};
|
||||
history.push(newLocation);
|
||||
if (replaceHistory) {
|
||||
history.replace(newLocation);
|
||||
} else {
|
||||
history.push(newLocation);
|
||||
}
|
||||
},
|
||||
[history]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!percentile) {
|
||||
updatePercentile(DEFAULT_P);
|
||||
updatePercentile(DEFAULT_P, true);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue