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 before render code async and pass markdown instance #322

Merged
merged 4 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 5.1.0 (IN PROGRESS)

### Features / Enhancements

- Update before render code async and pass markdown instance (#322)

## 5.0.0 (2024-06-06)

### Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@
"test:e2e": "npx playwright test",
"upgrade": "npm upgrade --save"
},
"version": "5.0.0"
"version": "5.1.0"
}
116 changes: 116 additions & 0 deletions provisioning/dashboards/plugins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 7,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": {
"type": "marcusolsson-static-datasource",
"uid": "U0HP2Rv4z"
},
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
},
"id": 1,
"options": {
"afterRender": "",
"content": "- [x] task 1\n- [ ] task 2\n- [x] task 3",
"defaultContent": "The query didn't return any results.",
"editor": {
"format": "auto",
"language": "markdown"
},
"editors": [
"helpers",
"styles"
],
"externalStyles": [],
"helpers": "return import('https://cdn.jsdelivr.net/npm/@mdit/plugin-tasklist').then(({ tasklist }) => {\n context.markdown.use(tasklist, {\n containerClass: 'tasklist',\n itemClass: 'tasklist-item'\n });\n\n return () => {\n console.log('unsubscribe');\n }\n})",
"renderMode": "everyRow",
"styles": ".tasklist {\n list-style: none;\n padding: 0;\n}\n\n.tasklist-item {\n margin: 0;\n display: flex;\n gap: 4px;\n}",
"wrap": true
},
"pluginVersion": "5.0.0",
"targets": [
{
"datasource": {
"type": "marcusolsson-static-datasource",
"uid": "U0HP2Rv4z"
},
"frame": {
"fields": [
{
"config": {},
"name": "Field 1",
"type": "string",
"values": [
""
]
}
],
"meta": {}
},
"refId": "A"
}
],
"title": "Tasklist",
"type": "marcusolsson-dynamictext-panel"
}
],
"refresh": "",
"schemaVersion": 39,
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "Plugins",
"uid": "b7b805e3-5d83-486d-9a58-e10f7dfe2b09",
"version": 12,
"weekStart": ""
}
2 changes: 1 addition & 1 deletion src/components/Row/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import React, { useCallback, useEffect, useRef } from 'react';
import { RowItem } from 'types';

import { TEST_IDS } from '../../constants';
import { afterRenderCodeParameters, createExecutionCode } from '../../helpers';
import { afterRenderCodeParameters, createExecutionCode } from '../../utils';

/**
* Properties
Expand Down
32 changes: 16 additions & 16 deletions src/components/Text/Text.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppEvents, FieldType, toDataFrame } from '@grafana/data';
import { render, screen } from '@testing-library/react';
import { act, render, screen } from '@testing-library/react';
import React from 'react';

import { DEFAULT_OPTIONS, TEST_IDS } from '../../constants';
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('Text', () => {
eventBus: {} as any,
};

render(<Text {...props} />);
await act(async () => render(<Text {...props} />));

expect(screen.getByTestId(TEST_IDS.text.content)).toBeInTheDocument();
expect(screen.getByTestId(TEST_IDS.text.content)).toHaveTextContent('Test default content');
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('Text', () => {
eventBus: eventBus as any,
};

render(<Text {...props} />);
await act(async () => render(<Text {...props} />));

expect(eventBus.publish).toHaveBeenCalledWith('ready', expect.any(HTMLDivElement));
});
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('Text', () => {
eventBus: eventBus as any,
};

render(<Text {...props} />);
await act(async () => render(<Text {...props} />));

expect(publish).toHaveBeenCalledTimes(2);
expect(publish).toHaveBeenCalledWith({
Expand Down Expand Up @@ -148,12 +148,12 @@ describe('Text', () => {
eventBus: eventBus as any,
};

const { rerender } = render(<Text {...props} />);
const { rerender } = await act(async () => render(<Text {...props} />));

/**
* Re-render with updated props
*/
rerender(<Text {...props} timeZone="123" />);
await act(async () => rerender(<Text {...props} timeZone="123" />));

expect(eventBus.publish).toHaveBeenCalledWith('destroy');
});
Expand Down Expand Up @@ -189,7 +189,7 @@ describe('Text', () => {
eventBus: eventBus as any,
};

render(<Text {...props} />);
await act(async () => render(<Text {...props} />));

expect(publish).toHaveBeenCalledTimes(2);
expect(publish).toHaveBeenCalledWith({
Expand Down Expand Up @@ -232,7 +232,7 @@ describe('Text', () => {
eventBus: {} as any,
};

render(<Text {...props} />);
await act(async () => render(<Text {...props} />));

const statuses = screen.getAllByTestId('status');
expect(statuses[0]).toHaveStyle({ backgroundColor: 'green' });
Expand Down Expand Up @@ -280,7 +280,7 @@ describe('Text', () => {
eventBus: {} as any,
};

render(<Text {...props} />);
await act(async () => render(<Text {...props} />));

const statuses = screen.getAllByTestId('status');

Expand Down Expand Up @@ -339,7 +339,7 @@ describe('Text', () => {
eventBus: {} as any,
};

render(<Text {...props} />);
await act(async () => render(<Text {...props} />));
expect(screen.getAllByTestId(TEST_IDS.text.content)[0]).toBeInTheDocument();
expect(screen.getAllByTestId(TEST_IDS.text.content)[0]).toHaveTextContent('Value 1 1.05 MB');
});
Expand Down Expand Up @@ -377,7 +377,7 @@ describe('Text', () => {
eventBus: {} as any,
};

render(<Text {...props} />);
await act(async () => render(<Text {...props} />));
expect(screen.getAllByTestId(TEST_IDS.text.content)[0]).toBeInTheDocument();
expect(screen.getAllByTestId(TEST_IDS.text.content)[0]).toHaveTextContent('Value 1 1048576');
});
Expand Down Expand Up @@ -418,7 +418,7 @@ describe('Text', () => {
eventBus: {} as any,
};

render(<Text {...props} />);
await act(async () => render(<Text {...props} />));

expect(screen.getAllByTestId(TEST_IDS.text.content)[0]).toBeInTheDocument();
expect(screen.getAllByTestId(TEST_IDS.text.content)[0]).toHaveTextContent('Test content');
Expand Down Expand Up @@ -448,7 +448,7 @@ describe('Text', () => {
eventBus: {} as any,
};

render(<Text {...props} />);
await act(async () => render(<Text {...props} />));

expect(screen.getAllByText('Test content')).toHaveLength(1);
});
Expand Down Expand Up @@ -487,7 +487,7 @@ describe('Text', () => {
eventBus: {} as any,
};

render(<Text {...props} />);
await act(async () => render(<Text {...props} />));

expect(screen.getAllByText('Test content')).toHaveLength(1);
});
Expand Down Expand Up @@ -537,7 +537,7 @@ describe('Text', () => {
eventBus: {} as any,
};

render(<Text {...props} />);
await act(async () => render(<Text {...props} />));

expect(screen.getAllByRole('row')[1]).toHaveTextContent('Erik');
expect(screen.getAllByRole('row')[2]).toHaveTextContent('Natasha');
Expand Down Expand Up @@ -599,7 +599,7 @@ describe('Text', () => {
eventBus: {} as any,
};

render(<Text {...props} />);
await act(async () => render(<Text {...props} />));

expect(screen.getAllByRole('row')[1]).toHaveTextContent('Erik');
expect(screen.getAllByRole('row')[2]).toHaveTextContent('Natasha');
Expand Down
Loading
Loading