[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:
Shahzad 2021-01-20 11:29:44 +01:00 committed by GitHub
parent f718e90a81
commit 37cc7af49d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

View file

@ -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);
}
}

View file

@ -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);
}
});