Files
Alex Khomenko 71cee10cb6 Provisioning: Add dashboard saving functionality (#102269)
* Move dashboard-scene, provisioned dashboard features, and dashboard services/types from grafana-git-ui-sync branch

* Merge

* Update props order

* Fix imports

* Fix imports

* Update dashboard page

* Update imports

* Update test

* Tweaks

* Remove extra mocks

* Split out utils

* Translate

* Revert

* Add translations

* Add comment

* Prettier

* Add comment

* Use AnnoKeyManagerIdentity

* Add manager kind
2025-03-17 16:15:41 +02:00

35 lines
1009 B
TypeScript

/**
* Parameters for generating a dashboard path
*/
export interface GeneratePathParams {
timestamp: string;
pathFromAnnotation?: string;
slug?: string;
folderPath?: string;
}
/**
* Generates a path for a dashboard based on provided parameters
* If pathFromAnnotation is provided, it will be used as the base path
* Otherwise, a path will be generated using the slug or a default name with timestamp
* If folderPath is provided, it will be prepended to the path
*/
export function generatePath({ timestamp, pathFromAnnotation, slug, folderPath = '' }: GeneratePathParams): string {
let path = '';
if (pathFromAnnotation) {
const hashIndex = pathFromAnnotation.indexOf('#');
path = hashIndex > 0 ? pathFromAnnotation.substring(0, hashIndex) : pathFromAnnotation;
} else {
const pathSlug = slug || `new-dashboard-${timestamp}`;
path = `${pathSlug}.json`;
}
// Add folder path if it exists
if (folderPath) {
return `${folderPath}/${path}`;
}
return path;
}