From 384fb7f6c3a5beac88a06ed1cdf31246fb0d4cd6 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Wed, 5 Mar 2025 10:58:55 +0300 Subject: [PATCH] rename sync with main --- public/app/features/apiserver/types.ts | 19 ++++++++++--------- .../saving/SaveDashboardAsForm.tsx | 4 ++-- .../provisioned/SaveProvisionedDashboard.tsx | 4 ++-- .../saving/provisioned/hooks.ts | 16 +++++++++------- .../dashboard-scene/scene/DashboardScene.tsx | 8 ++++---- public/app/features/provisioning/dashboard.ts | 9 +++++---- 6 files changed, 32 insertions(+), 28 deletions(-) diff --git a/public/app/features/apiserver/types.ts b/public/app/features/apiserver/types.ts index 89f15d33a80..3c04564f8dd 100644 --- a/public/app/features/apiserver/types.ts +++ b/public/app/features/apiserver/types.ts @@ -43,11 +43,11 @@ export const AnnoKeyFolderUrl = 'grafana.app/folderUrl'; export const AnnoKeyMessage = 'grafana.app/message'; export const AnnoKeySlug = 'grafana.app/slug'; -// Identify where values came from -export const AnnoKeyRepoName = 'grafana.app/repoName'; -export const AnnoKeyRepoPath = 'grafana.app/repoPath'; -export const AnnoKeyRepoHash = 'grafana.app/repoHash'; -export const AnnoKeyRepoTimestamp = 'grafana.app/repoTimestamp'; +export const AnnoKeyManagerKind = 'grafana.app/managedBy'; +export const AnnoKeyManagerIdentity = 'grafana.app/managerId'; +export const AnnoKeySourcePath = 'grafana.app/sourcePath'; +export const AnnoKeySourceChecksum = 'grafana.app/sourceChecksum'; +export const AnnoKeySourceTimestamp = 'grafana.app/sourceTimestamp'; export const AnnoKeySavedFromUI = 'grafana.app/saved-from-ui'; export const AnnoKeyDashboardNotFound = 'grafana.app/dashboard-not-found'; @@ -66,10 +66,11 @@ type GrafanaAnnotations = { [AnnoKeyFolder]?: string; [AnnoKeySlug]?: string; - [AnnoKeyRepoName]?: string; - [AnnoKeyRepoPath]?: string; - [AnnoKeyRepoHash]?: string; - [AnnoKeyRepoTimestamp]?: string; + [AnnoKeyManagerKind]?: string; + [AnnoKeyManagerIdentity]?: string; + [AnnoKeySourcePath]?: string; + [AnnoKeySourceChecksum]?: string; + [AnnoKeySourceTimestamp]?: string; }; // Annotations provided by the front-end client diff --git a/public/app/features/dashboard-scene/saving/SaveDashboardAsForm.tsx b/public/app/features/dashboard-scene/saving/SaveDashboardAsForm.tsx index 5e6a74fcec6..eb762724d46 100644 --- a/public/app/features/dashboard-scene/saving/SaveDashboardAsForm.tsx +++ b/public/app/features/dashboard-scene/saving/SaveDashboardAsForm.tsx @@ -7,7 +7,7 @@ import { Button, Input, Switch, Field, Label, TextArea, Stack, Alert, Box } from import { FolderPicker } from 'app/core/components/Select/FolderPicker'; import { validationSrv } from 'app/features/manage-dashboards/services/ValidationSrv'; -import { AnnoKeyRepoName } from '../../apiserver/types'; +import { AnnoKeyManagerIdentity } from '../../apiserver/types'; import { RepositoryView } from '../../provisioning/api'; import { DashboardScene } from '../scene/DashboardScene'; @@ -140,7 +140,7 @@ export function SaveDashboardAsForm({ dashboard, changeInfo }: Props) { setHasFolderChanged(uid !== folderUid); dashboard.setState({ meta: { - k8s: name ? { annotations: { [AnnoKeyRepoName]: name } } : undefined, + k8s: name ? { annotations: { [AnnoKeyManagerIdentity]: name } } : undefined, folderUid: uid, }, }); diff --git a/public/app/features/dashboard-scene/saving/provisioned/SaveProvisionedDashboard.tsx b/public/app/features/dashboard-scene/saving/provisioned/SaveProvisionedDashboard.tsx index bcf8df93ce6..66327fdc54d 100644 --- a/public/app/features/dashboard-scene/saving/provisioned/SaveProvisionedDashboard.tsx +++ b/public/app/features/dashboard-scene/saving/provisioned/SaveProvisionedDashboard.tsx @@ -7,7 +7,7 @@ import { getAppEvents, locationService } from '@grafana/runtime'; import { Alert, Button, Field, Input, RadioButtonGroup, Stack, TextArea } from '@grafana/ui'; import { FolderPicker } from 'app/core/components/Select/FolderPicker'; import { useUrlParams } from 'app/core/navigation/hooks'; -import { AnnoKeyRepoName } from 'app/features/apiserver/types'; +import { AnnoKeyManagerIdentity } from 'app/features/apiserver/types'; import { validationSrv } from 'app/features/manage-dashboards/services/ValidationSrv'; import { RepositoryView } from 'app/features/provisioning/api'; import { PROVISIONING_URL } from 'app/features/provisioning/constants'; @@ -167,7 +167,7 @@ export function SaveProvisionedDashboard({ drawer, changeInfo, dashboard }: Prop } dashboard.setState({ meta: { - k8s: name ? { annotations: { [AnnoKeyRepoName]: name } } : undefined, + k8s: name ? { annotations: { [AnnoKeyManagerIdentity]: name } } : undefined, folderUid: uid, }, }); diff --git a/public/app/features/dashboard-scene/saving/provisioned/hooks.ts b/public/app/features/dashboard-scene/saving/provisioned/hooks.ts index f9991c18e4d..448a8681bbd 100644 --- a/public/app/features/dashboard-scene/saving/provisioned/hooks.ts +++ b/public/app/features/dashboard-scene/saving/provisioned/hooks.ts @@ -1,7 +1,7 @@ import { Chance } from 'chance'; import { dateTime } from '@grafana/data'; -import { AnnoKeyRepoName, AnnoKeyRepoPath } from 'app/features/apiserver/types'; +import { AnnoKeyManagerIdentity, AnnoKeyManagerKind, AnnoKeySourcePath } from 'app/features/apiserver/types'; import { useGetResourceRepository } from 'app/features/provisioning/hooks'; import { DashboardMeta } from 'app/types'; @@ -25,10 +25,12 @@ function generatePath(timestamp: string, pathFromAnnotation?: string, slug?: str export function useDefaultValues({ meta, defaultTitle, defaultDescription }: UseDefaultValuesParams) { const annotations = meta.k8s?.annotations; - const annoName = annotations?.[AnnoKeyRepoName]; - const annoPath = annotations?.[AnnoKeyRepoPath]; + const managerKind = annotations?.[AnnoKeyManagerKind]; + const managerIdentity = annotations?.[AnnoKeyManagerIdentity]; + const sourcePath = annotations?.[AnnoKeySourcePath]; // Get config by resource name or folder UID for new resources - const repositoryConfig = useGetResourceRepository({ name: annoName, folderUid: meta.folderUid }); + const repositoryConfig = + managerKind === 'repo' ? useGetResourceRepository({ name: managerIdentity, folderUid: meta.folderUid }) : undefined; const repository = repositoryConfig?.spec; const random = Chance(1); @@ -37,8 +39,8 @@ export function useDefaultValues({ meta, defaultTitle, defaultDescription }: Use return { values: { ref: `dashboard/${timestamp}`, - path: generatePath(timestamp, annoPath, meta.slug), - repo: annoName || repositoryConfig?.metadata?.name || '', + path: generatePath(timestamp, sourcePath, meta.slug), + repo: managerIdentity || repositoryConfig?.metadata?.name || '', comment: '', folder: { uid: meta.folderUid, @@ -48,7 +50,7 @@ export function useDefaultValues({ meta, defaultTitle, defaultDescription }: Use description: defaultDescription ?? '', workflow: getDefaultWorkflow(repository), }, - isNew: !annoName, + isNew: !managerIdentity, repositoryConfig: repository, isGitHub: repository?.type === 'github', }; diff --git a/public/app/features/dashboard-scene/scene/DashboardScene.tsx b/public/app/features/dashboard-scene/scene/DashboardScene.tsx index eca6cc0de84..463d0027b70 100644 --- a/public/app/features/dashboard-scene/scene/DashboardScene.tsx +++ b/public/app/features/dashboard-scene/scene/DashboardScene.tsx @@ -42,7 +42,7 @@ import { VariablesChanged } from 'app/features/variables/types'; import { DashboardDTO, DashboardMeta, KioskMode, SaveDashboardResponseDTO } from 'app/types'; import { ShowConfirmModalEvent } from 'app/types/events'; -import { AnnoKeyRepoName, AnnoKeyRepoPath } from '../../apiserver/types'; +import { AnnoKeyManagerIdentity, AnnoKeySourcePath } from '../../apiserver/types'; import { DashboardEditPane } from '../edit-pane/DashboardEditPane'; import { PanelEditor } from '../panel-edit/PanelEditor'; import { DashboardSceneChangeTracker } from '../saving/DashboardSceneChangeTracker'; @@ -747,7 +747,7 @@ export class DashboardScene extends SceneObjectBase impleme * Provisioned dashboards helpers */ getRepoName() { - return this.state.meta.k8s?.annotations?.[AnnoKeyRepoName]; + return this.state.meta.k8s?.annotations?.[AnnoKeyManagerIdentity]; } isProvisioned() { @@ -755,13 +755,13 @@ export class DashboardScene extends SceneObjectBase impleme } getPath() { - return this.state.meta.k8s?.annotations?.[AnnoKeyRepoPath]; + return this.state.meta.k8s?.annotations?.[AnnoKeySourcePath]; } setRepoName(name: string) { this.setState({ meta: { - k8s: { annotations: { [AnnoKeyRepoName]: name } }, + k8s: { annotations: { [AnnoKeyManagerIdentity]: name } }, }, }); } diff --git a/public/app/features/provisioning/dashboard.ts b/public/app/features/provisioning/dashboard.ts index 532ee35dbec..7927e91f005 100644 --- a/public/app/features/provisioning/dashboard.ts +++ b/public/app/features/provisioning/dashboard.ts @@ -1,7 +1,7 @@ import { getBackendSrv } from '@grafana/runtime'; import { DashboardDTO } from 'app/types'; -import { AnnoKeyRepoName, AnnoKeyRepoPath } from '../apiserver/types'; +import { AnnoKeyManagerIdentity, AnnoKeyManagerKind, AnnoKeySourcePath } from '../apiserver/types'; import { BASE_URL } from './api/baseAPI'; @@ -32,10 +32,11 @@ export async function loadDashboardFromProvisioning(repo: string, path: string): if (!anno) { dryRun.metadata.annotations = anno = {}; } - anno[AnnoKeyRepoName] = repo; - anno[AnnoKeyRepoPath] = path; + anno[AnnoKeyManagerKind] = 'repo'; + anno[AnnoKeyManagerIdentity] = repo; + anno[AnnoKeySourcePath] = path; if (ref) { - anno[AnnoKeyRepoPath] = path + '#' + ref; + anno[AnnoKeySourcePath] = path + '#' + ref; } return {