Provisioning: Disable imports for new dashboard (#114419)

* Provisioning: Disable imports for new dashboard

* Refactor
This commit is contained in:
Alex Khomenko
2025-11-26 15:45:36 +02:00
committed by GitHub
parent f0a394e67b
commit d49993ddab
2 changed files with 17 additions and 13 deletions
@@ -15,7 +15,7 @@ import { SuggestedDashboards } from '../DashboardLibrary/SuggestedDashboards';
import { DashboardEmptyExtensionPoint } from './DashboardEmptyExtensionPoint';
import {
useIsReadOnlyRepo,
useRepositoryStatus,
useOnAddVisualization,
useOnAddLibraryPanel,
useOnImportDashboard,
@@ -149,10 +149,10 @@ export interface Props {
// We pass the default empty UI through to the extension point so that the extension can conditionally render it if needed.
// For example, an extension might want to render custom UI for a specific experiment cohort, and the default UI for everyone else.
const DashboardEmpty = (props: Props) => {
const isReadOnlyRepo = useIsReadOnlyRepo(props);
const onAddVisualization = useOnAddVisualization({ ...props, isReadOnlyRepo });
const onAddLibraryPanel = useOnAddLibraryPanel({ ...props, isReadOnlyRepo });
const onImportDashboard = useOnImportDashboard({ ...props, isReadOnlyRepo });
const { isReadOnlyRepo, isProvisioned } = useRepositoryStatus(props);
const onAddVisualization = useOnAddVisualization({ ...props, isReadOnlyRepo, isProvisioned });
const onAddLibraryPanel = useOnAddLibraryPanel({ ...props, isReadOnlyRepo, isProvisioned });
const onImportDashboard = useOnImportDashboard({ ...props, isReadOnlyRepo, isProvisioned });
return (
<DashboardEmptyExtensionPoint
@@ -16,16 +16,23 @@ import {
import type { Props } from './DashboardEmpty';
export const useIsReadOnlyRepo = ({ dashboard }: Props) => {
const { isReadOnlyRepo } = useGetResourceRepositoryView({
export const useRepositoryStatus = ({ dashboard }: Props) => {
const { isReadOnlyRepo, repository } = useGetResourceRepositoryView({
folderName: dashboard instanceof DashboardScene ? dashboard.state.meta.folderUid : dashboard.meta.folderUid,
});
return isReadOnlyRepo;
const isFolderProvisioned = Boolean(repository);
const isProvisioned = isFolderProvisioned || (dashboard instanceof DashboardScene && dashboard.isManagedRepository());
return {
isReadOnlyRepo,
isProvisioned,
};
};
interface HookProps extends Props {
isReadOnlyRepo: boolean;
isProvisioned: boolean;
}
export const useOnAddVisualization = ({ dashboard, canCreate, isReadOnlyRepo }: HookProps) => {
@@ -53,9 +60,7 @@ export const useOnAddVisualization = ({ dashboard, canCreate, isReadOnlyRepo }:
}, [canCreate, isReadOnlyRepo, dashboard, dispatch, initialDatasource]);
};
export const useOnAddLibraryPanel = ({ dashboard, canCreate, isReadOnlyRepo }: HookProps) => {
const isProvisioned = dashboard instanceof DashboardScene && dashboard.isManagedRepository();
export const useOnAddLibraryPanel = ({ dashboard, canCreate, isReadOnlyRepo, isProvisioned }: HookProps) => {
return useMemo(() => {
if (!canCreate || isProvisioned || isReadOnlyRepo) {
return undefined;
@@ -72,8 +77,7 @@ export const useOnAddLibraryPanel = ({ dashboard, canCreate, isReadOnlyRepo }: H
}, [canCreate, isProvisioned, isReadOnlyRepo, dashboard]);
};
export const useOnImportDashboard = ({ dashboard, canCreate, isReadOnlyRepo }: HookProps) => {
const isProvisioned = dashboard instanceof DashboardScene && dashboard.isManagedRepository();
export const useOnImportDashboard = ({ canCreate, isReadOnlyRepo, isProvisioned }: HookProps) => {
return useMemo(() => {
if (!canCreate || isProvisioned || isReadOnlyRepo) {
return undefined;