mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 06:51:49 +08:00

* centralise iam api * centralise folder api client * rename to baseAPI * centralise provisioning api * remove iam feature folder from CODEOWNERS * fix type name * Update public/app/features/provisioning/utils/selectors.ts Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com> --------- Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
26 lines
921 B
TypeScript
26 lines
921 B
TypeScript
import { skipToken } from '@reduxjs/toolkit/query/react';
|
|
|
|
import { useGetFolderQuery } from '../../../api/clients/folder';
|
|
import { AnnoKeyManagerKind } from '../../apiserver/types';
|
|
|
|
import { useRepositoryList } from './useRepositoryList';
|
|
|
|
interface GetResourceRepositoryArgs {
|
|
name?: string;
|
|
folderUid?: string;
|
|
}
|
|
|
|
export const useGetResourceRepository = ({ name, folderUid }: GetResourceRepositoryArgs) => {
|
|
const [items, isLoading] = useRepositoryList(name || !folderUid ? skipToken : undefined);
|
|
// Get the folder data from API to get the repository data for nested folders
|
|
const folderQuery = useGetFolderQuery(name || !folderUid ? skipToken : { name: folderUid });
|
|
|
|
const repoName = name || folderQuery.data?.metadata?.annotations?.[AnnoKeyManagerKind];
|
|
|
|
if (!items?.length || isLoading || !repoName) {
|
|
return undefined;
|
|
}
|
|
|
|
return items.find((repo) => repo.metadata?.name === repoName);
|
|
};
|