mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Chore: Fix typescript strict null errors * Added new limit * Fixed ts issue * fixed tests * trying to fix type inference * Fixing more ts errors * Revert tsconfig option * Fix * Fixed code * More fixes * fix tests * Updated snapshot * Chore: More ts strict null fixes * More fixes in some really messed up azure config components * More fixes, current count: 441 * 419 * More fixes * Fixed invalid initial state in explore * Fixing tests * Fixed tests * Explore fix * More fixes * Progress * Sub 300 * Now at 218 * Progress * Update * Progress * Updated tests * at 159 * fixed tests * Progress * YAy blow 100! at 94 * 10,9,8,7,6,5,4,3,2,1... lift off * Fixed tests * Fixed more type errors Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
126 lines
3.0 KiB
TypeScript
126 lines
3.0 KiB
TypeScript
import React from 'react';
|
|
import { Modal, ModalTabsHeader, TabContent } from '@grafana/ui';
|
|
import { DashboardModel, PanelModel } from 'app/features/dashboard/state';
|
|
import { ShareLink } from './ShareLink';
|
|
import { ShareSnapshot } from './ShareSnapshot';
|
|
import { ShareExport } from './ShareExport';
|
|
import { ShareEmbed } from './ShareEmbed';
|
|
import { ShareModalTabModel } from './types';
|
|
|
|
const shareCommonTabs: ShareModalTabModel[] = [
|
|
{ label: 'Link', value: 'link', component: ShareLink },
|
|
{ label: 'Snapshot', value: 'snapshot', component: ShareSnapshot },
|
|
];
|
|
|
|
// prettier-ignore
|
|
const shareDashboardTabs: ShareModalTabModel[] = [
|
|
{ label: 'Export', value: 'export', component: ShareExport },
|
|
];
|
|
|
|
// prettier-ignore
|
|
const sharePanelTabs: ShareModalTabModel[] = [
|
|
{ label: 'Embed', value: 'embed', component: ShareEmbed },
|
|
];
|
|
|
|
const customDashboardTabs: ShareModalTabModel[] = [];
|
|
const customPanelTabs: ShareModalTabModel[] = [];
|
|
|
|
export function addDashboardShareTab(tab: ShareModalTabModel) {
|
|
customDashboardTabs.push(tab);
|
|
}
|
|
|
|
export function addPanelShareTab(tab: ShareModalTabModel) {
|
|
customPanelTabs.push(tab);
|
|
}
|
|
|
|
function getInitialState(props: Props): State {
|
|
const tabs = getTabs(props);
|
|
return {
|
|
tabs,
|
|
activeTab: tabs[0].value,
|
|
};
|
|
}
|
|
|
|
function getTabs(props: Props) {
|
|
const { panel } = props;
|
|
const tabs = [...shareCommonTabs];
|
|
|
|
if (panel) {
|
|
tabs.push(...sharePanelTabs);
|
|
tabs.push(...customPanelTabs);
|
|
} else {
|
|
tabs.push(...shareDashboardTabs);
|
|
tabs.push(...customDashboardTabs);
|
|
}
|
|
|
|
return tabs;
|
|
}
|
|
|
|
interface Props {
|
|
dashboard: DashboardModel;
|
|
panel?: PanelModel;
|
|
|
|
onDismiss(): void;
|
|
}
|
|
|
|
interface State {
|
|
tabs: ShareModalTabModel[];
|
|
activeTab: string;
|
|
}
|
|
|
|
export class ShareModal extends React.Component<Props, State> {
|
|
constructor(props: Props) {
|
|
super(props);
|
|
this.state = getInitialState(props);
|
|
}
|
|
|
|
onDismiss = () => {
|
|
this.setState(getInitialState(this.props));
|
|
this.props.onDismiss();
|
|
};
|
|
|
|
onSelectTab = (t: any) => {
|
|
this.setState({ activeTab: t.value });
|
|
};
|
|
|
|
getTabs() {
|
|
return getTabs(this.props);
|
|
}
|
|
|
|
getActiveTab() {
|
|
const { tabs, activeTab } = this.state;
|
|
return tabs.find(t => t.value === activeTab)!;
|
|
}
|
|
|
|
renderTitle() {
|
|
const { panel } = this.props;
|
|
const { activeTab } = this.state;
|
|
const title = panel ? 'Share Panel' : 'Share';
|
|
const tabs = this.getTabs();
|
|
|
|
return (
|
|
<ModalTabsHeader
|
|
title={title}
|
|
icon="share-alt"
|
|
tabs={tabs}
|
|
activeTab={activeTab}
|
|
onChangeTab={this.onSelectTab}
|
|
/>
|
|
);
|
|
}
|
|
|
|
render() {
|
|
const { dashboard, panel } = this.props;
|
|
const activeTabModel = this.getActiveTab();
|
|
const ActiveTab = activeTabModel.component;
|
|
|
|
return (
|
|
<Modal isOpen={true} title={this.renderTitle()} onDismiss={this.onDismiss}>
|
|
<TabContent>
|
|
<ActiveTab dashboard={dashboard} panel={panel} onDismiss={this.onDismiss} />
|
|
</TabContent>
|
|
</Modal>
|
|
);
|
|
}
|
|
}
|