Snapshots: Add snapshot enable config (#61587)

* Add config to remove Snapshot functionality (frontend is hidden and validation in the backend)
* Add test cases
* Remove unused mock on the test
* Moving Snapshot config from globar variables to settings.Cfg
* Removing warnings on code
This commit is contained in:
lean.dev
2023-01-26 10:28:11 -03:00
committed by GitHub
parent 928e2c9c9e
commit 7d8ec6199d
14 changed files with 191 additions and 99 deletions

View File

@@ -27,22 +27,11 @@ export function addPanelShareTab(tab: ShareModalTabModel) {
customPanelTabs.push(tab);
}
function getInitialState(props: Props): State {
const { tabs, activeTab } = getTabs(props);
return {
tabs,
activeTab,
};
}
function getTabs(props: Props) {
const { panel, activeTab } = props;
function getTabs(panel?: PanelModel, activeTab?: string) {
const linkLabel = t('share-modal.tab-title.link', 'Link');
const tabs: ShareModalTabModel[] = [{ label: linkLabel, value: 'link', component: ShareLink }];
if (contextSrv.isSignedIn) {
if (contextSrv.isSignedIn && config.snapshotEnabled) {
const snapshotLabel = t('share-modal.tab-title.snapshot', 'Snapshot');
tabs.push({ label: snapshotLabel, value: 'snapshot', component: ShareSnapshot });
}
@@ -87,6 +76,15 @@ interface State {
activeTab: string;
}
function getInitialState(props: Props): State {
const { tabs, activeTab } = getTabs(props.panel, props.activeTab);
return {
tabs,
activeTab,
};
}
export class ShareModal extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
@@ -98,13 +96,9 @@ export class ShareModal extends React.Component<Props, State> {
}
onSelectTab = (t: any) => {
this.setState({ activeTab: t.value });
this.setState((prevState) => ({ ...prevState, activeTab: t.value }));
};
getTabs() {
return getTabs(this.props).tabs;
}
getActiveTab() {
const { tabs, activeTab } = this.state;
return tabs.find((t) => t.value === activeTab)!;
@@ -114,12 +108,13 @@ export class ShareModal extends React.Component<Props, State> {
const { panel } = this.props;
const { activeTab } = this.state;
const title = panel ? t('share-modal.panel.title', 'Share Panel') : t('share-modal.dashboard.title', 'Share');
const tabs = getTabs(this.props.panel, this.state.activeTab).tabs;
return (
<ModalTabsHeader
title={title}
icon="share-alt"
tabs={this.getTabs()}
tabs={tabs}
activeTab={activeTab}
onChangeTab={this.onSelectTab}
/>