[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
|
@ -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,
|
||||
}),
|
||||
};
|
||||
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,
|
||||
}),
|
||||
};
|
||||
if (replaceHistory) {
|
||||
history.replace(newLocation);
|
||||
} else {
|
||||
history.push(newLocation);
|
||||
}
|
||||
},
|
||||
[history]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!percentile) {
|
||||
updatePercentile(DEFAULT_P);
|
||||
updatePercentile(DEFAULT_P, true);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue