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 { DashboardEmptyExtensionPoint } from './DashboardEmptyExtensionPoint';
|
||||
import { useOnAddVisualization, useOnAddLibraryPanel, useOnImportDashboard } from './DashboardEmptyHooks';
|
||||
import {
|
||||
useIsReadOnlyRepo,
|
||||
useOnAddVisualization,
|
||||
useOnAddLibraryPanel,
|
||||
useOnImportDashboard,
|
||||
} from './DashboardEmptyHooks';
|
||||
|
||||
interface InternalProps {
|
||||
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.
|
||||
// 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 onAddVisualization = useOnAddVisualization(props);
|
||||
const onAddLibraryPanel = useOnAddLibraryPanel(props);
|
||||
const onImportDashboard = useOnImportDashboard(props);
|
||||
const isReadOnlyRepo = useIsReadOnlyRepo(props);
|
||||
const onAddVisualization = useOnAddVisualization({ ...props, isReadOnlyRepo });
|
||||
const onAddLibraryPanel = useOnAddLibraryPanel({ ...props, isReadOnlyRepo });
|
||||
const onImportDashboard = useOnImportDashboard({ ...props, isReadOnlyRepo });
|
||||
|
||||
return (
|
||||
<DashboardEmptyExtensionPoint
|
||||
|
|
|
@ -16,13 +16,22 @@ import {
|
|||
|
||||
import type { Props } from './DashboardEmpty';
|
||||
|
||||
export const useOnAddVisualization = ({ dashboard, canCreate }: Props) => {
|
||||
const dispatch = useDispatch();
|
||||
const initialDatasource = useSelector((state) => state.dashboard.initialDatasource);
|
||||
export const useIsReadOnlyRepo = ({ dashboard }: Props) => {
|
||||
const { isReadOnlyRepo } = useGetResourceRepositoryView({
|
||||
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(() => {
|
||||
if (!canCreate || isReadOnlyRepo) {
|
||||
return undefined;
|
||||
|
@ -44,11 +53,8 @@ export const useOnAddVisualization = ({ dashboard, canCreate }: Props) => {
|
|||
}, [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 { isReadOnlyRepo } = useGetResourceRepositoryView({
|
||||
folderName: dashboard instanceof DashboardScene ? dashboard.state.meta.folderUid : dashboard.meta.folderUid,
|
||||
});
|
||||
|
||||
return useMemo(() => {
|
||||
if (!canCreate || isProvisioned || isReadOnlyRepo) {
|
||||
|
@ -66,11 +72,7 @@ export const useOnAddLibraryPanel = ({ dashboard, canCreate }: Props) => {
|
|||
}, [canCreate, isProvisioned, isReadOnlyRepo, dashboard]);
|
||||
};
|
||||
|
||||
export const useOnImportDashboard = ({ dashboard, canCreate }: Props) => {
|
||||
const { isReadOnlyRepo } = useGetResourceRepositoryView({
|
||||
folderName: dashboard instanceof DashboardScene ? dashboard.state.meta.folderUid : dashboard.meta.folderUid,
|
||||
});
|
||||
|
||||
export const useOnImportDashboard = ({ dashboard, canCreate, isReadOnlyRepo }: HookProps) => {
|
||||
return useMemo(() => {
|
||||
if (!canCreate || isReadOnlyRepo) {
|
||||
return undefined;
|
||||
|
|
Loading…
Reference in New Issue