Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update packages for Code Editor #380

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@grafana/ui": "^11.4.0",
"@types/highlight.js": "^10.1.0",
"@types/markdown-it": "^14.1.2",
"@volkovlabs/components": "^3.7.0",
"@volkovlabs/components": "^3.8.0",
"dayjs": "^1.11.13",
"handlebars": "^4.7.8",
"helper-date": "^1.0.1",
Expand Down
93 changes: 93 additions & 0 deletions src/migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,97 @@ describe('Migration', () => {
});
});
});

describe('5.6.0', () => {
describe('Execution code', () => {
it.each([
{
name: 'content',
initial: `<br>\\n<p class=\"panel-title\">Test</p>\\n<span>next line</span>;`,
expected: `<br>\n<p class=\"panel-title\">Test</p>\n<span>next line</span>;`,
},
{
name: 'afterRender',
initial: `console.log('after render')\\nconsole.log('after render')\\nconsole.log('after render')`,
expected: `console.log('after render')\nconsole.log('after render')\nconsole.log('after render')`,
},
{
name: 'helpers',
initial: `console.log('before render')\\nconsole.log('before render')\\nconsole.log('before render')`,
expected: `console.log('before render')\nconsole.log('before render')\nconsole.log('before render')`,
},
{
name: 'defaultContent',
initial: `<br>\\n<p class=\"panel-title\">Test default content</p>\\n<span>next line</span>;`,
expected: `<br>\n<p class=\"panel-title\">Test default content</p>\n<span>next line</span>;`,
},
{
name: 'styles',
initial: `.test{ \\n color:red;\\n}`,
expected: `.test{ \n color:red;\n}`,
},
])('Should migrate $name', ({ initial, expected }) => {
expect(
getMigratedOptions({
pluginVersion: '5.5.0',
options: {
helpers: initial,
afterRender: initial,
content: initial,
defaultContent: initial,
styles: initial,
},
} as any).helpers
).toEqual(expected);
expect(
getMigratedOptions({
pluginVersion: '5.5.0',
options: {
helpers: initial,
afterRender: initial,
content: initial,
defaultContent: initial,
styles: initial,
},
} as any).afterRender
).toEqual(expected);
expect(
getMigratedOptions({
pluginVersion: '5.5.0',
options: {
helpers: initial,
afterRender: initial,
content: initial,
defaultContent: initial,
styles: initial,
},
} as any).content
).toEqual(expected);
expect(
getMigratedOptions({
pluginVersion: '5.5.0',
options: {
helpers: initial,
afterRender: initial,
content: initial,
defaultContent: initial,
styles: initial,
},
} as any).defaultContent
).toEqual(expected);
expect(
getMigratedOptions({
pluginVersion: '5.5.0',
options: {
helpers: initial,
afterRender: initial,
content: initial,
defaultContent: initial,
styles: initial,
},
} as any).styles
).toEqual(expected);
});
});
});
});
22 changes: 21 additions & 1 deletion src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,34 @@ const normalizeHelpersOption = (code: string): string => {
*/
export const getMigratedOptions = (panel: PanelModel<OutdatedPanelOptions & PanelOptions>): PanelOptions => {
const { everyRow, ...actualOptions } = panel.options;

/**
* Normalize non context code parameters before 5.0.0
*/
if (panel.pluginVersion && semver.lt(panel.pluginVersion, '5.0.0')) {
actualOptions.helpers = normalizeHelpersOption(actualOptions.helpers);
}

/**
* Normalize \\n characters to \n for versions lt 5.6.0
*/
if (panel.pluginVersion && semver.lt(panel.pluginVersion, '5.6.0')) {
if (actualOptions.helpers) {
actualOptions.helpers = actualOptions.helpers.replaceAll('\\n', '\n');
}
if (actualOptions.afterRender) {
actualOptions.afterRender = actualOptions.afterRender.replaceAll('\\n', '\n');
}
if (actualOptions.defaultContent) {
actualOptions.defaultContent = actualOptions.defaultContent.replaceAll('\\n', '\n');
}
if (actualOptions.content) {
actualOptions.content = actualOptions.content.replaceAll('\\n', '\n');
}
if (actualOptions.styles) {
actualOptions.styles = actualOptions.styles.replaceAll('\\n', '\n');
}
}

/**
* Normalize every row
*/
Expand Down
Loading