mirror of
https://github.com/grafana/grafana.git
synced 2025-09-19 12:01:39 +08:00
Transformations: Add transformation builder tests and refactor (#83285)
* baldm0mma/script_tests/ update jest.config paths * baldm0mma/script_tests/ refactor makefile content * baldm0mma/script_tests/ refactor file write commands * baldm0mma/script_tests/ create test module * baldm0mma/script_tests/ add to codeowners * baldm0mma/script_tests/ recenter content * baldm0mma/script_tests/ create buildMarkdownContent and update whitespace * baldm0mma/script_tests/ run build script * baldm0mma/script_tests/ update tests to remove make dep and node dep * baldm0mma/script_tests/ update cntent * baldm0mma/script_tests/ update makefile * baldm0mma/script_tests/ update buildMarkdownContent * baldm0mma/script_tests/ remove unused imports * baldm0mma/script_tests/ update test annotation * baldm0mma/script_tests/ prettier * baldm0mma/script_tests/ update tests * baldm0mma/script_tests/ update content * baldm0mma/script_tests/ update annos * baldm0mma/script_tests/ remove unused vars * baldm0mma/script_tests/ remove unused imports * baldm0mma/script_tests/ update annos * baldm0mma/script_tests/ update paths * Update scripts/docs/generate-transformations.test.ts Co-authored-by: Jack Baldry <jack.baldry@grafana.com> * baldm0mma/script_tests/ update comment --------- Co-authored-by: Jack Baldry <jack.baldry@grafana.com>
This commit is contained in:
@ -1,13 +1,15 @@
|
||||
import { writeFileSync, readFileSync, read } from 'fs';
|
||||
import { resolve } from 'path';
|
||||
|
||||
import {
|
||||
transformationDocsContent,
|
||||
TransformationDocsContentType,
|
||||
ImageRenderType,
|
||||
} from '../../public/app/features/transformers/docs/content';
|
||||
|
||||
const template = `---
|
||||
comments: |
|
||||
This Markdown file is auto-generated. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
const WRITE_PATH = 'docs/sources/panels-visualizations/query-transform-data/transform-data/index.md';
|
||||
|
||||
export const readMeContent = `
|
||||
To update this Markdown, navigate to the following Typescript files and edit them based on what you need to update:
|
||||
|
||||
scripts/docs/generate-transformations.ts - Includes all content not specific to a transformation.
|
||||
@ -24,6 +26,12 @@ comments: |
|
||||
Browse to http://localhost:3003/docs/grafana/latest/panels-visualizations/query-transform-data/transform-data/
|
||||
|
||||
Refer to ./docs/README.md "Content guidelines" for more information about editing and building these docs.
|
||||
`;
|
||||
|
||||
export const templateMetaContent = `---
|
||||
comments: |
|
||||
This Markdown file is auto-generated. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
${readMeContent}
|
||||
|
||||
aliases:
|
||||
- ../../panels/reference-transformation-functions/
|
||||
@ -47,9 +55,9 @@ labels:
|
||||
title: Transform data
|
||||
description: Use transformations to rename fields, join series data, apply mathematical operations, and more
|
||||
weight: 100
|
||||
---
|
||||
---`;
|
||||
|
||||
# Transform data
|
||||
const templateIntroContent = `# Transform data
|
||||
|
||||
Transformations are a powerful way to manipulate data returned by a query before the system applies a visualization. Using transformations, you can:
|
||||
|
||||
@ -126,13 +134,15 @@ We recommend that you remove transformations that you don't need. When you delet
|
||||
1. Click the trash icon next to the transformation you want to delete.
|
||||
|
||||
{{< figure src="/static/img/docs/transformations/screenshot-example-remove-transformation.png" class="docs-image--no-shadow" max-width= "1100px" alt="A transformation row with the remove transformation icon highlighted" >}}
|
||||
`;
|
||||
|
||||
export const completeTemplate = `${templateMetaContent}
|
||||
|
||||
${templateIntroContent}
|
||||
## Transformation functions
|
||||
|
||||
You can perform the following transformations on your data.
|
||||
|
||||
${buildTransformationDocsContent(transformationDocsContent)}
|
||||
|
||||
{{% docs/reference %}}
|
||||
[Table panel]: "/docs/grafana/ -> /docs/grafana/<GRAFANA VERSION>/panels-visualizations/visualizations/table"
|
||||
[Table panel]: "/docs/grafana-cloud/ -> /docs/grafana/<GRAFANA VERSION>/panels-visualizations/visualizations/table"
|
||||
@ -169,9 +179,8 @@ function buildTransformationDocsContent(transformationDocsContent: Transformatio
|
||||
const content = transformationsList
|
||||
.map((transformationName) => {
|
||||
return `
|
||||
### ${transformationDocsContent[transformationName].name}
|
||||
${transformationDocsContent[transformationName].getHelperDocs(ImageRenderType.ShortcodeFigure)}
|
||||
`;
|
||||
### ${transformationDocsContent[transformationName].name}
|
||||
${transformationDocsContent[transformationName].getHelperDocs(ImageRenderType.ShortcodeFigure)}`;
|
||||
})
|
||||
// Remove the superfluous commas.
|
||||
.join('');
|
||||
@ -179,9 +188,20 @@ function buildTransformationDocsContent(transformationDocsContent: Transformatio
|
||||
return content;
|
||||
}
|
||||
|
||||
/*
|
||||
`process.stdout.write(template + '\n')` was not functioning as expected.
|
||||
Neither the tsc nor ts-node compiler could identify the node `process` object.
|
||||
Fortunately, `console.log` also writes to the standard output.
|
||||
*/
|
||||
console.log(template);
|
||||
export function buildMarkdownContent(): void {
|
||||
// Build the path to the Markdown file.
|
||||
const indexPath = resolve(__dirname, '../../' + WRITE_PATH);
|
||||
|
||||
// Write content to the Markdown file.
|
||||
writeFileSync(indexPath, completeTemplate, 'utf-8');
|
||||
}
|
||||
|
||||
export function getMarkdownContent(): string {
|
||||
const rootDir = resolve(__dirname, '../../');
|
||||
const pathToMarkdown = resolve(rootDir, WRITE_PATH);
|
||||
return readFileSync(pathToMarkdown, 'utf-8');
|
||||
}
|
||||
|
||||
export function getJavaScriptContent(): string {
|
||||
return completeTemplate;
|
||||
}
|
||||
|
Reference in New Issue
Block a user