mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
PublicDashboards: Tag is rerendered when dashboard meta changes in state (#55414)
Can update dashboard meta state using dashboard events.
This commit is contained in:
@@ -119,6 +119,7 @@ describe('SharePublic', () => {
|
||||
await screen.findByText('Welcome to Grafana public dashboards alpha!');
|
||||
expect(screen.getByText('Last 6 hours')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders default absolute time in input 2', async () => {
|
||||
config.featureToggles.publicDashboards = true;
|
||||
const mockDashboard = new DashboardModel({
|
||||
|
||||
@@ -65,10 +65,7 @@ export const SharePublicDashboard = (props: Props) => {
|
||||
usage: false,
|
||||
});
|
||||
|
||||
const timeRange = getTimeRange(
|
||||
{ from: props.dashboard.getDefaultTime().from, to: props.dashboard.getDefaultTime().to },
|
||||
props.dashboard.timezone
|
||||
);
|
||||
const timeRange = getTimeRange(props.dashboard.getDefaultTime(), props.dashboard);
|
||||
|
||||
useEffect(() => {
|
||||
reportInteraction('grafana_dashboards_public_share_viewed');
|
||||
@@ -96,7 +93,7 @@ export const SharePublicDashboard = (props: Props) => {
|
||||
return;
|
||||
}
|
||||
|
||||
savePublicDashboardConfig(props.dashboard.uid, publicDashboard, setPublicDashboardConfig).catch();
|
||||
savePublicDashboardConfig(props.dashboard, publicDashboard, setPublicDashboardConfig).catch();
|
||||
};
|
||||
|
||||
const onAcknowledge = useCallback(
|
||||
|
||||
@@ -6,6 +6,8 @@ import { VariableModel } from 'app/features/variables/types';
|
||||
import { dispatch } from 'app/store/store';
|
||||
import { DashboardDataDTO, DashboardMeta } from 'app/types/dashboard';
|
||||
|
||||
import { DashboardModel } from '../../state';
|
||||
|
||||
export interface PublicDashboard {
|
||||
accessToken?: string;
|
||||
isEnabled: boolean;
|
||||
@@ -28,12 +30,12 @@ export const getPublicDashboardConfig = async (
|
||||
};
|
||||
|
||||
export const savePublicDashboardConfig = async (
|
||||
dashboardUid: string,
|
||||
dashboard: DashboardModel,
|
||||
publicDashboardConfig: PublicDashboard,
|
||||
setPublicDashboard: React.Dispatch<React.SetStateAction<PublicDashboard>>
|
||||
) => {
|
||||
const pdResp: PublicDashboard = await getBackendSrv().post(
|
||||
savePublicDashboardConfigUrl(dashboardUid),
|
||||
savePublicDashboardConfigUrl(dashboard.uid),
|
||||
publicDashboardConfig
|
||||
);
|
||||
|
||||
@@ -43,6 +45,12 @@ export const savePublicDashboardConfig = async (
|
||||
|
||||
dispatch(notifyApp(createSuccessNotification('Dashboard sharing configuration saved')));
|
||||
setPublicDashboard(pdResp);
|
||||
|
||||
// Update runtime emta flag
|
||||
dashboard.updateMeta({
|
||||
publicDashboardUid: pdResp.uid,
|
||||
publicDashboardEnabled: publicDashboardConfig.isEnabled,
|
||||
});
|
||||
};
|
||||
|
||||
export const getPublicDashboardConfigUrl = (dashboardUid: string) => {
|
||||
|
||||
Reference in New Issue
Block a user