From a50e44c27a4a36593b71989a0b3ea1228d0d4487 Mon Sep 17 00:00:00 2001 From: Yunwen Zheng Date: Thu, 14 Aug 2025 15:32:57 -0400 Subject: [PATCH] RepositoryResources: hide history button when repo type is pure git (#109628) * RepositoryResources: hide history button when repo type is pure git * hide history button from file page * hide history button from file page and file history detail page --- .../provisioning/File/FileHistoryPage.tsx | 28 ++++++++++++++----- .../features/provisioning/File/FilesView.tsx | 11 ++++++-- .../app/features/provisioning/File/utils.ts | 4 +++ .../Repository/RepositoryResources.tsx | 16 ++++++++--- public/locales/en-US/grafana.json | 4 ++- 5 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 public/app/features/provisioning/File/utils.ts diff --git a/public/app/features/provisioning/File/FileHistoryPage.tsx b/public/app/features/provisioning/File/FileHistoryPage.tsx index 78385deac55..f1a4274ada7 100644 --- a/public/app/features/provisioning/File/FileHistoryPage.tsx +++ b/public/app/features/provisioning/File/FileHistoryPage.tsx @@ -1,25 +1,36 @@ +import { skipToken } from '@reduxjs/toolkit/query'; import { useParams } from 'react-router-dom-v5-compat'; -import { Trans } from '@grafana/i18n'; +import { Trans, t } from '@grafana/i18n'; import { Card, EmptyState, Spinner, Stack, Text, TextLink, UserIcon } from '@grafana/ui'; import { useGetRepositoryHistoryWithPathQuery, useGetRepositoryStatusQuery, } from 'app/api/clients/provisioning/v0alpha1'; import { Page } from 'app/core/components/Page/Page'; +import { useUrlParams } from 'app/core/navigation/hooks'; import { isNotFoundError } from 'app/features/alerting/unified/api/util'; import { PROVISIONING_URL } from '../constants'; import { HistoryListResponse } from '../types'; import { formatTimestamp } from '../utils/time'; +import { isFileHistorySupported } from './utils'; + export default function FileHistoryPage() { const params = useParams(); const name = params['name'] ?? ''; const path = params['*'] ?? ''; + const [urlParams] = useUrlParams(); + const repoType = urlParams.get('repo_type'); + const historyNotSupported = !isFileHistorySupported(repoType); const query = useGetRepositoryStatusQuery({ name }); - const history = useGetRepositoryHistoryWithPathQuery({ name, path }); - const notFound = query.isError && isNotFoundError(query.error); + const history = useGetRepositoryHistoryWithPathQuery(historyNotSupported ? skipToken : { name, path }); + const notFound = (query.isError && isNotFoundError(query.error)) || historyNotSupported; + + const notFoundErrorMsg = historyNotSupported + ? t('provisioning.file-history-page.history-not-supported', 'File history is not supported for this repository') + : t('provisioning.file-history-page.repository-not-found', 'Repository not found'); return ( {notFound ? ( - + - - Make sure the repository config exists in the configuration file. - + {/* only show detail message if repoType is not git */} + {repoType !== 'git' && ( + + Make sure the repository config exists in the configuration file. + + )} Back to repositories diff --git a/public/app/features/provisioning/File/FilesView.tsx b/public/app/features/provisioning/File/FilesView.tsx index 0df6f7340a4..37a55b9bca5 100644 --- a/public/app/features/provisioning/File/FilesView.tsx +++ b/public/app/features/provisioning/File/FilesView.tsx @@ -7,6 +7,8 @@ import { Repository, useGetRepositoryFilesQuery } from 'app/api/clients/provisio import { PROVISIONING_URL } from '../constants'; import { FileDetails } from '../types'; +import { isFileHistorySupported } from './utils'; + interface FilesViewProps { repo: Repository; } @@ -20,6 +22,7 @@ export function FilesView({ repo }: FilesViewProps) { const data = [...(query.data?.items ?? [])].filter((file) => file.path.toLowerCase().includes(searchQuery.toLowerCase()) ); + const showHistoryBtn = isFileHistorySupported(repo.spec?.type); const columns: Array> = [ { @@ -57,9 +60,11 @@ export function FilesView({ repo }: FilesViewProps) { View )} - - History - + {showHistoryBtn && ( + + History + + )} ); }, diff --git a/public/app/features/provisioning/File/utils.ts b/public/app/features/provisioning/File/utils.ts new file mode 100644 index 00000000000..4856787eadf --- /dev/null +++ b/public/app/features/provisioning/File/utils.ts @@ -0,0 +1,4 @@ +export function isFileHistorySupported(repoType?: string | null): boolean { + const supportedRepoTypes = new Set(['github', 'gitlab', 'bitbucket']); + return !!repoType && supportedRepoTypes.has(repoType); +} diff --git a/public/app/features/provisioning/Repository/RepositoryResources.tsx b/public/app/features/provisioning/Repository/RepositoryResources.tsx index e7c0554152f..fdffe1cea74 100644 --- a/public/app/features/provisioning/Repository/RepositoryResources.tsx +++ b/public/app/features/provisioning/Repository/RepositoryResources.tsx @@ -4,6 +4,7 @@ import { Trans, t } from '@grafana/i18n'; import { CellProps, Column, FilterInput, InteractiveTable, Link, LinkButton, Spinner, Stack } from '@grafana/ui'; import { Repository, ResourceListItem, useGetRepositoryResourcesQuery } from 'app/api/clients/provisioning/v0alpha1'; +import { isFileHistorySupported } from '../File/utils'; import { PROVISIONING_URL } from '../constants'; interface RepoProps { @@ -23,6 +24,9 @@ export function RepositoryResources({ repo }: RepoProps) { Resource.path.toLowerCase().includes(searchQuery.toLowerCase()) ); + // hide history button when repo type is pure git as it won't be implemented. + const historySupported = isFileHistorySupported(repo.spec?.type); + const columns: Array> = useMemo( () => [ { @@ -98,15 +102,19 @@ export function RepositoryResources({ repo }: RepoProps) { View )} - - History - + {historySupported && ( + + History + + )} ); }, }, ], - [repo.metadata?.name] + [repo.metadata?.name, historySupported, repo.spec?.type] ); if (query.isLoading) { diff --git a/public/locales/en-US/grafana.json b/public/locales/en-US/grafana.json index 2cf0531c0d8..9eecf0099ab 100644 --- a/public/locales/en-US/grafana.json +++ b/public/locales/en-US/grafana.json @@ -11272,7 +11272,9 @@ }, "file-history-page": { "back-to-repositories": "Back to repositories", - "repository-config-exists-configuration": "Make sure the repository config exists in the configuration file." + "history-not-supported": "File history is not supported for this repository", + "repository-config-exists-configuration": "Make sure the repository config exists in the configuration file.", + "repository-not-found": "Repository not found" }, "file-status-page": { "save": "Save",