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
This commit is contained in:
Yunwen Zheng
2025-08-14 19:32:57 +00:00
committed by GitHub
parent 6305d6daed
commit a50e44c27a
5 changed files with 48 additions and 15 deletions
@@ -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 (
<Page
@@ -31,11 +42,14 @@ export default function FileHistoryPage() {
>
<Page.Contents isLoading={false}>
{notFound ? (
<EmptyState message={`Repository not found`} variant="not-found">
<EmptyState message={notFoundErrorMsg} variant="not-found">
<Text element={'p'}>
<Trans i18nKey="provisioning.file-history-page.repository-config-exists-configuration">
Make sure the repository config exists in the configuration file.
</Trans>
{/* only show detail message if repoType is not git */}
{repoType !== 'git' && (
<Trans i18nKey="provisioning.file-history-page.repository-config-exists-configuration">
Make sure the repository config exists in the configuration file.
</Trans>
)}
</Text>
<TextLink href={PROVISIONING_URL}>
<Trans i18nKey="provisioning.file-history-page.back-to-repositories">Back to repositories</Trans>
@@ -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<Column<FileDetails>> = [
{
@@ -57,9 +60,11 @@ export function FilesView({ repo }: FilesViewProps) {
<Trans i18nKey="provisioning.files-view.columns.view">View</Trans>
</LinkButton>
)}
<LinkButton href={`${PROVISIONING_URL}/${name}/history/${path}`}>
<Trans i18nKey="provisioning.files-view.columns.history">History</Trans>
</LinkButton>
{showHistoryBtn && (
<LinkButton href={`${PROVISIONING_URL}/${name}/history/${path}?repo_type=${repo.spec?.type}`}>
<Trans i18nKey="provisioning.files-view.columns.history">History</Trans>
</LinkButton>
)}
</Stack>
);
},
@@ -0,0 +1,4 @@
export function isFileHistorySupported(repoType?: string | null): boolean {
const supportedRepoTypes = new Set(['github', 'gitlab', 'bitbucket']);
return !!repoType && supportedRepoTypes.has(repoType);
}
@@ -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<Column<ResourceListItem>> = useMemo(
() => [
{
@@ -98,15 +102,19 @@ export function RepositoryResources({ repo }: RepoProps) {
<Trans i18nKey="provisioning.repository-resources.columns.view-folder">View</Trans>
</LinkButton>
)}
<LinkButton href={`${PROVISIONING_URL}/${repo.metadata?.name}/history/${path}`}>
<Trans i18nKey="provisioning.repository-resources.columns.history">History</Trans>
</LinkButton>
{historySupported && (
<LinkButton
href={`${PROVISIONING_URL}/${repo.metadata?.name}/history/${path}?repo_type=${repo.spec?.type}`}
>
<Trans i18nKey="provisioning.repository-resources.columns.history">History</Trans>
</LinkButton>
)}
</Stack>
);
},
},
],
[repo.metadata?.name]
[repo.metadata?.name, historySupported, repo.spec?.type]
);
if (query.isLoading) {
+3 -1
View File
@@ -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",