Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v10.3.x] ShareModal: Fixes url sync issue that caused issue with save drawer #81721

Merged
merged 1 commit into from Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,43 +1,21 @@
import React, { useContext, useEffect } from 'react';
import React from 'react';

import { ModalsContext } from '@grafana/ui';
import { useQueryParams } from 'app/core/hooks/useQueryParams';
import { locationService } from '@grafana/runtime';
import { t } from 'app/core/internationalization';
import { DashboardModel } from 'app/features/dashboard/state';
import { DashboardInteractions } from 'app/features/dashboard-scene/utils/interactions';

import { ShareModal } from '../ShareModal';

import { DashNavButton } from './DashNavButton';

export const ShareButton = ({ dashboard }: { dashboard: DashboardModel }) => {
const [queryParams] = useQueryParams();
const { showModal, hideModal } = useContext(ModalsContext);

useEffect(() => {
if (!!queryParams.shareView) {
showModal(ShareModal, {
dashboard,
onDismiss: hideModal,
activeTab: String(queryParams.shareView),
});
}
return () => {
hideModal();
};
}, [showModal, hideModal, dashboard, queryParams.shareView]);

return (
<DashNavButton
tooltip={t('dashboard.toolbar.share', 'Share dashboard')}
icon="share-alt"
iconSize="lg"
onClick={() => {
DashboardInteractions.toolbarShareClick();
showModal(ShareModal, {
dashboard,
onDismiss: hideModal,
});
locationService.partial({ shareView: 'link' });
}}
/>
);
Expand Down
Expand Up @@ -77,7 +77,6 @@ interface Props extends Themeable2 {
dashboard: DashboardModel;
panel?: PanelModel;
activeTab?: string;

onDismiss(): void;
}

Expand Down
6 changes: 6 additions & 0 deletions public/app/features/dashboard/containers/DashboardPage.tsx
Expand Up @@ -31,6 +31,7 @@ import { DashboardPrompt } from '../components/DashboardPrompt/DashboardPrompt';
import { DashboardSettings } from '../components/DashboardSettings';
import { PanelInspector } from '../components/Inspector/PanelInspector';
import { PanelEditor } from '../components/PanelEditor/PanelEditor';
import { ShareModal } from '../components/ShareModal';
import { SubMenu } from '../components/SubMenu/SubMenu';
import { DashboardGrid } from '../dashgrid/DashboardGrid';
import { liveTimer } from '../dashgrid/liveTimer';
Expand Down Expand Up @@ -311,6 +312,10 @@ export class UnthemedDashboardPage extends PureComponent<Props, State> {
return inspectPanel;
}

onCloseShareModal = () => {
locationService.partial({ shareView: null });
};

render() {
const { dashboard, initError, queryParams } = this.props;
const { editPanel, viewPanel, updateScrollTop, pageNav, sectionNav } = this.state;
Expand Down Expand Up @@ -379,6 +384,7 @@ export class UnthemedDashboardPage extends PureComponent<Props, State> {
/>

{inspectPanel && <PanelInspector dashboard={dashboard} panel={inspectPanel} />}
{queryParams.shareView && <ShareModal dashboard={dashboard} onDismiss={this.onCloseShareModal} />}
</Page>
{editPanel && (
<PanelEditor
Expand Down
1 change: 1 addition & 0 deletions public/app/features/dashboard/containers/types.ts
Expand Up @@ -19,4 +19,5 @@ export type DashboardPageRouteSearchParams = {
refresh?: string;
kiosk?: string | true;
scenes?: boolean;
shareView?: string;
};