PublicDashboards: Tag is rerendered when dashboard meta changes in state (#55414)

Can update dashboard meta state using dashboard events.
This commit is contained in:
owensmallwood
2022-09-20 10:42:57 -06:00
committed by GitHub
parent 862a6a2fa6
commit aae2c3c4f4
8 changed files with 99 additions and 8 deletions

View File

@@ -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({

View File

@@ -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(

View File

@@ -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) => {