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

Added the ability to customize the alert message #96

Merged
merged 4 commits into from
Mar 22, 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

## 4.3.0 (IN PROGRESS)

### Features / Enhancements

- Added the ability to customize the alert message (#96)

## 4.2.0 (2024-02-22)

### Features / Enhancements
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ Base64 Image/Video/Audio/PDF Panel is a Grafana plugin that renders PNG, JPG, GI

The Base64 Image/Video/Audio/PDF Panel version requirements for Grafana are as follows:

- Version 4.X requires **Grafana 9** or **Grafana 10**.
- Version 3.X requires **Grafana 8.5** or **Grafana 9**.
- Version 2.X requires **Grafana 8**.
- Version 1.X requires **Grafana 7.1**.
- Base64 Panel 4.X requires **Grafana 9** or **Grafana 10**.
- Base64 Panel 3.X requires **Grafana 8.5** or **Grafana 9**.
- Base64 Panel 2.X requires **Grafana 8**.
- Base64 Panel 1.X requires **Grafana 7.1**.

## Getting Started

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@
"test:ci": "jest --maxWorkers 4 --coverage",
"upgrade": "npm upgrade --save"
},
"version": "4.2.0"
"version": "4.3.0"
}
4 changes: 4 additions & 0 deletions src/components/ImagePanel/ImagePanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@
}),
],
},
options: {
noResultsMessage: 'No results...',
},
})
);

expect(screen.getByTestId(TEST_IDS.panel.root)).toBeInTheDocument();
expect(screen.getByTestId(TEST_IDS.panel.warning)).toBeInTheDocument();
expect(screen.getByTestId(TEST_IDS.panel.warning)).toHaveTextContent('No results...');
});

it('Should render image', async () => {
Expand Down Expand Up @@ -746,7 +750,7 @@

fireEvent.click(screen.getByTestId(TEST_IDS.panel.buttonDownload));

expect(saveAs).toHaveBeenCalledWith(`data:image/jpeg;base64,${image}`);

Check warning on line 753 in src/components/ImagePanel/ImagePanel.test.tsx

View workflow job for this annotation

GitHub Actions / build

'saveAs' is deprecated. use `{ autoBom: false }` as the third argument
});

it('Should not show download button', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ImagePanel/ImagePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
)
.map((field) => field?.values)
.filter((item) => !!item)[0]
?.toArray() || []

Check warning on line 54 in src/components/ImagePanel/ImagePanel.tsx

View workflow job for this annotation

GitHub Actions / tests

'toArray' is deprecated. this is not necessary. This only exists to help migrate Vector to Array

Check warning on line 54 in src/components/ImagePanel/ImagePanel.tsx

View workflow job for this annotation

GitHub Actions / build

'toArray' is deprecated. this is not necessary. This only exists to help migrate Vector to Array

Check warning on line 54 in src/components/ImagePanel/ImagePanel.tsx

View workflow job for this annotation

GitHub Actions / build

'toArray' is deprecated. this is not necessary. This only exists to help migrate Vector to Array
);
}, [data.series, options.name]);

Expand All @@ -68,7 +68,7 @@
.map((series) => series.fields.find((field) => field.name === options.description))
.map((field) => field?.values)
.filter((item) => !!item)[0]
?.toArray() || []

Check warning on line 71 in src/components/ImagePanel/ImagePanel.tsx

View workflow job for this annotation

GitHub Actions / tests

'toArray' is deprecated. this is not necessary. This only exists to help migrate Vector to Array

Check warning on line 71 in src/components/ImagePanel/ImagePanel.tsx

View workflow job for this annotation

GitHub Actions / build

'toArray' is deprecated. this is not necessary. This only exists to help migrate Vector to Array

Check warning on line 71 in src/components/ImagePanel/ImagePanel.tsx

View workflow job for this annotation

GitHub Actions / build

'toArray' is deprecated. this is not necessary. This only exists to help migrate Vector to Array
);
}, [data.series, options.description]);

Expand Down Expand Up @@ -179,7 +179,7 @@
.map((series) =>
series.fields.find((field) => field.type === FieldType.number && field.name === options.heightName)
)
.map((field) => field?.values.get(field.values.length - 1))

Check warning on line 182 in src/components/ImagePanel/ImagePanel.tsx

View workflow job for this annotation

GitHub Actions / tests

'get' is deprecated. Use [idx]. This only exists to help migrate Vector to Array

Check warning on line 182 in src/components/ImagePanel/ImagePanel.tsx

View workflow job for this annotation

GitHub Actions / build

'get' is deprecated. Use [idx]. This only exists to help migrate Vector to Array

Check warning on line 182 in src/components/ImagePanel/ImagePanel.tsx

View workflow job for this annotation

GitHub Actions / build

'get' is deprecated. Use [idx]. This only exists to help migrate Vector to Array
.toString();
imageHeight = Number(heightField) ? Number(heightField) : imageHeight;
}
Expand All @@ -199,7 +199,7 @@
.map((series) =>
series.fields.find((field) => field.type === FieldType.number && field.name === options.widthName)
)
.map((field) => field?.values.get(field.values.length - 1))

Check warning on line 202 in src/components/ImagePanel/ImagePanel.tsx

View workflow job for this annotation

GitHub Actions / tests

'get' is deprecated. Use [idx]. This only exists to help migrate Vector to Array

Check warning on line 202 in src/components/ImagePanel/ImagePanel.tsx

View workflow job for this annotation

GitHub Actions / build

'get' is deprecated. Use [idx]. This only exists to help migrate Vector to Array

Check warning on line 202 in src/components/ImagePanel/ImagePanel.tsx

View workflow job for this annotation

GitHub Actions / build

'get' is deprecated. Use [idx]. This only exists to help migrate Vector to Array
.toString();
imageWidth = Number(widthField) ? Number(widthField) : imageWidth;
}
Expand Down Expand Up @@ -236,7 +236,7 @@
if (!img) {
return renderContainer(
<Alert severity="warning" title="" data-testid={TEST_IDS.panel.warning}>
Nothing to display...
{options.noResultsMessage}
</Alert>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/constants/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ImageScale, ImageSizeMode, PanelOptions, ZoomType } from '../types';
*/
export const DEFAULT_OPTIONS: PanelOptions = {
autoPlay: true,
noResultsMessage: 'Nothing to display...',
infinityPlay: false,
buttons: [],
controls: true,
Expand Down
6 changes: 6 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export const plugin = new PanelPlugin<PanelOptions>(ImagePanel).setNoPadding().s
filter: (f: Field) => f.type === FieldType.string,
noFieldsMessage: 'No strings fields found',
},
})
.addTextInput({
path: 'noResultsMessage',
name: 'No Results Message',
description: 'Specifies no results message text.',
defaultValue: DEFAULT_OPTIONS.noResultsMessage,
});

/**
Expand Down
7 changes: 7 additions & 0 deletions src/types/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,11 @@ export interface PanelOptions {
* @type {ImageScale}
*/
scale: ImageScale;

/**
* No Results Message
*
* @type {string}
*/
noResultsMessage: string;
}