Skip to content

Commit

Permalink
we forget to update relative date when loading the page by a refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierM committed Feb 5, 2020
1 parent b6aa68c commit 49659d0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ export const getParamFromQueryString = (queryString: string, key: string): strin
return Array.isArray(queryParam) ? queryParam[0] : queryParam;
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const replaceStateKeyInQueryString = <UrlState extends any>(
stateKey: string,
urlState: UrlState | undefined
) => (queryString: string) => {
export const replaceStateKeyInQueryString = <T>(stateKey: string, urlState: T) => (
queryString: string
): string => {
const previousQueryValues = QueryString.decode(queryString);
if (urlState == null || (typeof urlState === 'string' && urlState === '')) {
delete previousQueryValues[stateKey];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ describe('UrlStateContainer', () => {
mount(<HookWrapper hookProps={mockProps} hook={args => useUrlStateHooks(args)} />);

expect(mockSetRelativeRangeDatePicker.mock.calls[1][0]).toEqual({
from: 1558591200000,
from: 11223344556677,
fromStr: 'now-1d/d',
kind: 'relative',
to: 1558677599999,
to: 11223344556677,
toStr: 'now-1d/d',
id: 'global',
});

expect(mockSetRelativeRangeDatePicker.mock.calls[0][0]).toEqual({
from: 1558732849370,
from: 11223344556677,
fromStr: 'now-15m',
kind: 'relative',
to: 1558733749370,
to: 11223344556677,
toStr: 'now',
id: 'timeline',
});
Expand Down Expand Up @@ -189,7 +189,7 @@ describe('UrlStateContainer', () => {
wrapper.update();
await wait();
if (CONSTANTS.hostsPage === page) {
// There is no change in url state, so that's expected
// There is no change in url state, so that's expected we only have two actions
expect(mockSetRelativeRangeDatePicker.mock.calls.length).toEqual(2);
} else {
expect(mockSetRelativeRangeDatePicker.mock.calls[3][0]).toEqual({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,11 @@ export const useUrlStateHooks = ({
search: mySearch,
urlKey,
});
if (isInitializing) {
urlStateToUpdate = [
...urlStateToUpdate,
{
urlKey,
newUrlStateString,
},
];
} else if (needUpdate) {
if (isInitializing || needUpdate) {
const updatedUrlStateString =
getParamFromQueryString(getQueryStringFromLocation(mySearch), urlKey) ??
newUrlStateString;
if (!isEqual(updatedUrlStateString, newUrlStateString)) {
if (isInitializing || !isEqual(updatedUrlStateString, newUrlStateString)) {
urlStateToUpdate = [
...urlStateToUpdate,
{
Expand Down Expand Up @@ -206,7 +198,7 @@ export const useUrlStateHooks = ({
} else if (pathName !== prevProps.pathName) {
handleInitialize(type, true);
}
}, [isInitializing, pathName, pageName, prevProps, urlState]);
}, [isInitializing, history, pathName, pageName, prevProps, urlState]);

useEffect(() => {
document.title = `${getTitle(pageName, detailName, navTabs)} - Kibana`;
Expand Down

0 comments on commit 49659d0

Please sign in to comment.