Skip to content

Commit

Permalink
[7.11] [User Experience] UX use replace history instead of push on fi…
Browse files Browse the repository at this point in the history
…rst load (#88586) (#88819)

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
shahzad31 and kibanamachine authored Jan 20, 2021
1 parent bd39988 commit cf62e47
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ function ServiceNameFilter({ loading, serviceNames }: Props) {
}));

const updateServiceName = useCallback(
(serviceN: string) => {
(serviceN: string, replaceHistory?: boolean) => {
const newLocation = {
...history.location,
search: fromQuery({
...toQuery(history.location.search),
serviceName: serviceN,
}),
};
history.push(newLocation);
if (replaceHistory) {
history.replace(newLocation);
} else {
history.push(newLocation);
}
},
[history]
);
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,26 @@ export function UserPercentile() {
} = useUrlParams();

const updatePercentile = useCallback(
(percentileN?: number) => {
(percentileN?: number, replaceHistory?: boolean) => {
const newLocation = {
...history.location,
search: fromQuery({
...toQuery(history.location.search),
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);
}
});

Expand Down

0 comments on commit cf62e47

Please sign in to comment.