PublicDashboards: Public dashboard refreshed when access token changes (#87913)

This commit is contained in:
Juan Cabanas 2024-05-15 10:20:00 -03:00 committed by GitHub
parent 90970d5f58
commit a6d64c6ed5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View File

@ -2,7 +2,7 @@ import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { Provider } from 'react-redux';
import { Router } from 'react-router-dom';
import { match, Router } from 'react-router-dom';
import { useEffectOnce } from 'react-use';
import { Props as AutoSizerProps } from 'react-virtualized-auto-sizer';
import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock';
@ -248,6 +248,16 @@ describe('PublicDashboardPage', () => {
});
});
describe('When public dashboard changes', () => {
it('Should init again', async () => {
const { rerender } = setup();
rerender({ match: { params: { accessToken: 'another-new-access-token' } } as unknown as match });
await waitFor(() => {
expect(initDashboard).toHaveBeenCalledTimes(2);
});
});
});
describe('Given a public dashboard with time range enabled', () => {
it('Should render time range and refresh picker buttons', async () => {
setup(undefined, {

View File

@ -69,8 +69,7 @@ const PublicDashboardPage = (props: Props) => {
keybindingSrv: context.keybindings,
})
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [route.routeName, match.params.accessToken, context.keybindings, dispatch]);
useEffect(() => {
if (prevProps?.location.search !== location.search) {
@ -89,7 +88,7 @@ const PublicDashboardPage = (props: Props) => {
getTimeSrv().setAutoRefresh(urlParams.refresh);
}
}
}, [prevProps, location.search, props.queryParams, dashboard?.timepicker.hidden]);
}, [prevProps, location.search, props.queryParams, dashboard?.timepicker.hidden, match.params.accessToken]);
if (!dashboard) {
return <DashboardLoading initPhase={dashboardState.initPhase} />;