Provisioning: Specify managed by git sync (#111969)
* Provisioning: Specify managed by git sync * linter * Update public/app/features/provisioning/Wizard/hooks/useResourceStats.ts Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com> * Update public/app/features/provisioning/Shared/RepositoryList.tsx Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com> * Update public/app/features/provisioning/Wizard/hooks/useResourceStats.ts Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com> * Update public/app/features/provisioning/Shared/RepositoryList.tsx Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com> * fix frontend lint --------- Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com> Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
co-authored by
Alex Khomenko
Ryan McKinley
parent
0f60e2208e
commit
ed482219c6
@@ -43,13 +43,13 @@ export function RepositoryList({ items }: Props) {
|
||||
i18nKey="provisioning.folder-repository-list.partial-managed"
|
||||
values={{ managedCount, resourceCount }}
|
||||
>
|
||||
{{ managedCount }}/{{ resourceCount }} resources managed.
|
||||
{{ managedCount }}/{{ resourceCount }} resources managed by Git sync.
|
||||
</Trans>
|
||||
{unmanagedCount > 0 && (
|
||||
<>
|
||||
{' '}
|
||||
<Trans i18nKey="provisioning.folder-repository-list.unmanaged-resources" count={unmanagedCount}>
|
||||
{{ count: unmanagedCount }} resources aren't managed as code yet.
|
||||
{{ count: unmanagedCount }} resources aren't managed by Git sync.
|
||||
</Trans>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -11,24 +11,27 @@ import {
|
||||
useGetRepositoryFilesQuery,
|
||||
useGetResourceStatsQuery,
|
||||
} from 'app/api/clients/provisioning/v0alpha1';
|
||||
import { ManagerKind } from 'app/features/apiserver/types';
|
||||
|
||||
function getManagedCount(managed?: ManagerStats[]) {
|
||||
let totalCount = 0;
|
||||
|
||||
// Loop through each managed repository
|
||||
managed?.forEach((manager) => {
|
||||
// Loop through stats inside each manager and sum up the counts
|
||||
manager.stats.forEach((stat) => {
|
||||
if (stat.group === 'folder.grafana.app' || stat.group === 'dashboard.grafana.app') {
|
||||
totalCount += stat.count;
|
||||
}
|
||||
});
|
||||
if (manager.kind === ManagerKind.Repo) {
|
||||
// Loop through stats inside each manager and sum up the counts
|
||||
manager.stats.forEach((stat) => {
|
||||
if (stat.group === 'folder.grafana.app' || stat.group === 'dashboard.grafana.app') {
|
||||
totalCount += stat.count;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
function getResourceCount(stats?: ResourceCount[]) {
|
||||
function getResourceCount(stats?: ResourceCount[], managed?: ManagerStats[]) {
|
||||
let counts: string[] = [];
|
||||
let resourceCount = 0;
|
||||
|
||||
@@ -46,6 +49,26 @@ function getResourceCount(stats?: ResourceCount[]) {
|
||||
}
|
||||
});
|
||||
|
||||
managed?.forEach((manager) => {
|
||||
if (manager.kind !== ManagerKind.Repo) {
|
||||
manager.stats.forEach((stat) => {
|
||||
switch (stat.group) {
|
||||
case 'folders':
|
||||
case 'folder.grafana.app':
|
||||
resourceCount += stat.count;
|
||||
counts.push(t('provisioning.bootstrap-step.folders-count', '{{count}} folder', { count: stat.count }));
|
||||
break;
|
||||
case 'dashboard.grafana.app':
|
||||
resourceCount += stat.count;
|
||||
counts.push(
|
||||
t('provisioning.bootstrap-step.dashboards-count', '{{count}} dashboard', { count: stat.count })
|
||||
);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
counts,
|
||||
resourceCount,
|
||||
@@ -92,7 +115,9 @@ export function useResourceStats(repoName?: string, isLegacyStorage?: boolean, s
|
||||
return {
|
||||
// managed does not exist in response when first time connecting to a repo
|
||||
managedCount: getManagedCount(resourceStatsQuery.data?.managed),
|
||||
unmanagedCount: getResourceCount(resourceStatsQuery.data?.unmanaged).resourceCount,
|
||||
// "unmanaged" means unmanaged by git sync. it may still be managed by other means, like terraform, plugins, file provisioning, etc.
|
||||
unmanagedCount: getResourceCount(resourceStatsQuery.data?.unmanaged, resourceStatsQuery.data?.managed)
|
||||
.resourceCount,
|
||||
};
|
||||
}, [resourceStatsQuery.data]);
|
||||
|
||||
|
||||
@@ -11353,10 +11353,10 @@
|
||||
"all-resources-managed_one": "All {{count}} resource is managed",
|
||||
"all-resources-managed_other": "All {{count}} resources are managed",
|
||||
"no-results-matching-your-query": "No results matching your query",
|
||||
"partial-managed": "{{managedCount}}/{{resourceCount}} resources managed.",
|
||||
"partial-managed": "{{managedCount}}/{{resourceCount}} resources managed by Git sync.",
|
||||
"placeholder-search": "Search",
|
||||
"unmanaged-resources_one": "{{count}} resource isn't managed as code yet.",
|
||||
"unmanaged-resources_other": "{{count}} resources aren't managed as code yet."
|
||||
"unmanaged-resources_one": "{{count}} resource isn't managed by git sync.",
|
||||
"unmanaged-resources_other": "{{count}} resources aren't managed by git sync."
|
||||
},
|
||||
"get-default-values": {
|
||||
"title": {
|
||||
|
||||
Reference in New Issue
Block a user