mirror of https://github.com/grafana/grafana.git
Dashboards: De-duplicate read-only repo check in empty state
CodeQL checks / Detect whether code changed (push) Waiting to run
Details
CodeQL checks / Analyze (actions) (push) Blocked by required conditions
Details
CodeQL checks / Analyze (go) (push) Blocked by required conditions
Details
CodeQL checks / Analyze (javascript) (push) Blocked by required conditions
Details
CodeQL checks / Detect whether code changed (push) Waiting to run
Details
CodeQL checks / Analyze (actions) (push) Blocked by required conditions
Details
CodeQL checks / Analyze (go) (push) Blocked by required conditions
Details
CodeQL checks / Analyze (javascript) (push) Blocked by required conditions
Details
This commit is contained in:
parent
888e245fc2
commit
2d7104bbca
|
@ -9,7 +9,12 @@ import { DashboardModel } from 'app/features/dashboard/state/DashboardModel';
|
||||||
import { DashboardScene } from 'app/features/dashboard-scene/scene/DashboardScene';
|
import { DashboardScene } from 'app/features/dashboard-scene/scene/DashboardScene';
|
||||||
|
|
||||||
import { DashboardEmptyExtensionPoint } from './DashboardEmptyExtensionPoint';
|
import { DashboardEmptyExtensionPoint } from './DashboardEmptyExtensionPoint';
|
||||||
import { useOnAddVisualization, useOnAddLibraryPanel, useOnImportDashboard } from './DashboardEmptyHooks';
|
import {
|
||||||
|
useIsReadOnlyRepo,
|
||||||
|
useOnAddVisualization,
|
||||||
|
useOnAddLibraryPanel,
|
||||||
|
useOnImportDashboard,
|
||||||
|
} from './DashboardEmptyHooks';
|
||||||
|
|
||||||
interface InternalProps {
|
interface InternalProps {
|
||||||
onAddVisualization?: () => void;
|
onAddVisualization?: () => void;
|
||||||
|
@ -116,9 +121,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.
|
// 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.
|
// 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 DashboardEmpty = (props: Props) => {
|
||||||
const onAddVisualization = useOnAddVisualization(props);
|
const isReadOnlyRepo = useIsReadOnlyRepo(props);
|
||||||
const onAddLibraryPanel = useOnAddLibraryPanel(props);
|
const onAddVisualization = useOnAddVisualization({ ...props, isReadOnlyRepo });
|
||||||
const onImportDashboard = useOnImportDashboard(props);
|
const onAddLibraryPanel = useOnAddLibraryPanel({ ...props, isReadOnlyRepo });
|
||||||
|
const onImportDashboard = useOnImportDashboard({ ...props, isReadOnlyRepo });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardEmptyExtensionPoint
|
<DashboardEmptyExtensionPoint
|
||||||
|
|
|
@ -16,13 +16,22 @@ import {
|
||||||
|
|
||||||
import type { Props } from './DashboardEmpty';
|
import type { Props } from './DashboardEmpty';
|
||||||
|
|
||||||
export const useOnAddVisualization = ({ dashboard, canCreate }: Props) => {
|
export const useIsReadOnlyRepo = ({ dashboard }: Props) => {
|
||||||
const dispatch = useDispatch();
|
|
||||||
const initialDatasource = useSelector((state) => state.dashboard.initialDatasource);
|
|
||||||
const { isReadOnlyRepo } = useGetResourceRepositoryView({
|
const { isReadOnlyRepo } = useGetResourceRepositoryView({
|
||||||
folderName: dashboard instanceof DashboardScene ? dashboard.state.meta.folderUid : dashboard.meta.folderUid,
|
folderName: dashboard instanceof DashboardScene ? dashboard.state.meta.folderUid : dashboard.meta.folderUid,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return isReadOnlyRepo;
|
||||||
|
};
|
||||||
|
|
||||||
|
interface HookProps extends Props {
|
||||||
|
isReadOnlyRepo: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useOnAddVisualization = ({ dashboard, canCreate, isReadOnlyRepo }: HookProps) => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const initialDatasource = useSelector((state) => state.dashboard.initialDatasource);
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
if (!canCreate || isReadOnlyRepo) {
|
if (!canCreate || isReadOnlyRepo) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -44,11 +53,8 @@ export const useOnAddVisualization = ({ dashboard, canCreate }: Props) => {
|
||||||
}, [canCreate, isReadOnlyRepo, dashboard, dispatch, initialDatasource]);
|
}, [canCreate, isReadOnlyRepo, dashboard, dispatch, initialDatasource]);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useOnAddLibraryPanel = ({ dashboard, canCreate }: Props) => {
|
export const useOnAddLibraryPanel = ({ dashboard, canCreate, isReadOnlyRepo }: HookProps) => {
|
||||||
const isProvisioned = dashboard instanceof DashboardScene && dashboard.isManagedRepository();
|
const isProvisioned = dashboard instanceof DashboardScene && dashboard.isManagedRepository();
|
||||||
const { isReadOnlyRepo } = useGetResourceRepositoryView({
|
|
||||||
folderName: dashboard instanceof DashboardScene ? dashboard.state.meta.folderUid : dashboard.meta.folderUid,
|
|
||||||
});
|
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
if (!canCreate || isProvisioned || isReadOnlyRepo) {
|
if (!canCreate || isProvisioned || isReadOnlyRepo) {
|
||||||
|
@ -66,11 +72,7 @@ export const useOnAddLibraryPanel = ({ dashboard, canCreate }: Props) => {
|
||||||
}, [canCreate, isProvisioned, isReadOnlyRepo, dashboard]);
|
}, [canCreate, isProvisioned, isReadOnlyRepo, dashboard]);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useOnImportDashboard = ({ dashboard, canCreate }: Props) => {
|
export const useOnImportDashboard = ({ dashboard, canCreate, isReadOnlyRepo }: HookProps) => {
|
||||||
const { isReadOnlyRepo } = useGetResourceRepositoryView({
|
|
||||||
folderName: dashboard instanceof DashboardScene ? dashboard.state.meta.folderUid : dashboard.meta.folderUid,
|
|
||||||
});
|
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
if (!canCreate || isReadOnlyRepo) {
|
if (!canCreate || isReadOnlyRepo) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
Loading…
Reference in New Issue