add panel && upd logo #2

Merged
rozetko merged 2 commits from datasource into master 2 years ago
  1. 2
      .config/jest.config.js
  2. 10
      src/img/logo.svg
  3. 167
      src/panels/corpglory-dataexporter-panel/components/Panel.tsx
  4. 7
      src/panels/corpglory-dataexporter-panel/module.ts
  5. 18
      src/panels/corpglory-dataexporter-panel/plugin.json
  6. 10
      src/panels/corpglory-dataexporter-panel/types.ts
  7. 8
      src/plugin.json

2
.config/jest.config.js

@ -27,5 +27,5 @@ module.exports = {
}, },
], ],
}, },
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'], setupFilesAfterEnv: ['<rootDir>/.config/jest-setup.js'],
}; };

10
src/img/logo.svg

@ -1,3 +1,11 @@
<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M41.1733 38.7634V42.4019C41.1733 42.7229 41.2816 42.9994 41.4982 43.2313C41.7148 43.4631 41.9856 43.5791 42.3105 43.5791C42.6354 43.5791 42.9152 43.4631 43.1498 43.2313C43.3845 42.9994 43.5018 42.7229 43.5018 42.4019V35.8204C43.5018 35.5351 43.4025 35.3032 43.204 35.1249C43.0054 34.9465 42.7798 34.8573 42.5271 34.8573H35.8123C35.4874 34.8573 35.2166 34.9732 35 35.2051C34.7834 35.437 34.6751 35.6956 34.6751 35.981C34.6751 36.302 34.7834 36.5785 35 36.8103C35.2166 37.0422 35.4874 37.1581 35.8123 37.1581H39.4946L34.4043 42.1879C34.1516 42.4376 34.0253 42.7229 34.0253 43.044C34.0253 43.365 34.1516 43.6326 34.4043 43.8466C34.6209 44.0606 34.8917 44.1677 35.2166 44.1677C35.5415 44.1677 35.8123 44.0606 36.0289 43.8466L41.1733 38.7634ZM39.0614 50C36.0289 50 33.4477 48.9477 31.3177 46.843C29.1877 44.7384 28.1227 42.2057 28.1227 39.2449C28.1227 36.2842 29.1877 33.7337 31.3177 31.5933C33.4477 29.453 36.0289 28.3829 39.0614 28.3829C42.0578 28.3829 44.63 29.453 46.778 31.5933C48.926 33.7337 50 36.2842 50 39.2449C50 42.2057 48.926 44.7384 46.778 46.843C44.63 48.9477 42.0578 50 39.0614 50ZM16.1011 17.7348H34.6751C35.2166 17.7348 35.6769 17.5476 36.056 17.173C36.435 16.7985 36.6245 16.3258 36.6245 15.7551C36.6245 15.22 36.435 14.7652 36.056 14.3906C35.6769 14.0161 35.2166 13.8288 34.6751 13.8288H16.1011C15.5235 13.8288 15.0451 14.0161 14.6661 14.3906C14.287 14.7652 14.0975 15.22 14.0975 15.7551C14.0975 16.3258 14.287 16.7985 14.6661 17.173C15.0451 17.5476 15.5235 17.7348 16.1011 17.7348ZM26.2274 45.1843H8.95307C7.83394 45.1843 6.89531 44.8097 6.13718 44.0606C5.37906 43.3115 5 42.3841 5 41.2782V8.90606C5 7.83591 5.37906 6.91736 6.13718 6.15042C6.89531 5.38347 7.83394 5 8.95307 5H41.769C42.8881 5 43.8267 5.38347 44.5848 6.15042C45.343 6.91736 45.722 7.83591 45.722 8.90606V26.9382C44.7112 26.3674 43.6372 25.9394 42.5 25.654C41.3628 25.3686 40.2166 25.2259 39.0614 25.2259C38.6643 25.2259 38.2581 25.2527 37.843 25.3062C37.4278 25.3597 37.0217 25.4221 36.6245 25.4935V24.9584C36.6245 24.459 36.417 24.0309 36.0018 23.6742C35.5866 23.3175 35.1444 23.1391 34.6751 23.1391H16.1011C15.5235 23.1391 15.0451 23.3353 14.6661 23.7277C14.287 24.1201 14.0975 24.5838 14.0975 25.1189C14.0975 25.654 14.287 26.1088 14.6661 26.4834C15.0451 26.8579 15.5235 27.0452 16.1011 27.0452H32.4007C31.1733 27.6516 30.0722 28.4185 29.0975 29.346C28.1227 30.2735 27.3285 31.3258 26.7148 32.503H16.1011C15.5235 32.503 15.0451 32.6902 14.6661 33.0648C14.287 33.4394 14.0975 33.8942 14.0975 34.4292C14.0975 35 14.287 35.4727 14.6661 35.8472C15.0451 36.2218 15.5235 36.409 16.1011 36.409H25.1986C25.0903 36.8728 25.009 37.3543 24.9549 37.8537C24.9007 38.3531 24.8736 38.8347 24.8736 39.2985C24.8736 40.3329 24.982 41.3496 25.1986 42.3484C25.4152 43.3472 25.7581 44.2925 26.2274 45.1843Z" fill="#7191ED"/> <g clip-path="url(#clip0_2871_2649)">
<path d="M32.2652 22V34.6751C32.2652 35.2166 32.4524 35.6769 32.827 36.056C33.2015 36.435 33.6742 36.6245 34.2449 36.6245C34.78 36.6245 35.2348 36.435 35.6094 36.056C35.9839 35.6769 36.1712 35.2166 36.1712 34.6751V22C36.1712 21.4224 35.9839 20.8791 35.6094 20.5C35.2348 20.1209 34.78 20 34.2449 20C33.6742 20 33.2015 20.1209 32.827 20.5C32.4524 20.8791 32.2652 21.4224 32.2652 22ZM4.8157 26.2274V8.95307C4.8157 7.83394 5.19025 6.89531 5.93936 6.13718C6.68847 5.37906 7.61593 5 8.72176 5L41.0939 5C42.1641 5 43.0826 5.37906 43.8496 6.13718C44.6165 6.89531 45 7.83394 45 8.95307V41.769C45 42.8881 44.6165 43.8267 43.8496 44.5848C43.0826 45.343 42.1641 45.722 41.0939 45.722H23.0618C23.6326 44.7112 24.0606 43.6372 24.346 42.5C24.6314 41.3628 24.7741 40.2166 24.7741 39.0614C24.7741 38.6643 24.7473 38.2581 24.6938 37.843C24.6403 37.4278 24.5779 37.0217 24.5065 36.6245H25.0416C25.541 36.6245 25.9691 36.417 26.3258 36.0018C26.6825 35.5866 26.8609 35.1444 26.8609 34.6751L26.8609 16.1011C26.8609 15.5235 26.6647 15.0451 26.2723 14.6661C25.8799 14.287 25.4162 14.0975 24.8811 14.0975C24.346 14.0975 23.8912 14.287 23.5166 14.6661C23.1421 15.0451 22.9548 15.5235 22.9548 16.1011V32.4007C22.3484 31.1733 21.5815 30.0722 20.654 29.0975C19.7265 28.1227 18.6742 27.3285 17.497 26.7148V22C17.497 21.4224 17.3746 20.8791 17 20.5C16.6254 20.1209 16.0351 20 15.5 20C14.9293 20 14.5541 20.1209 14.1796 20.5C13.805 20.8791 13.591 21.4224 13.591 22V25.1986C13.1272 25.0903 12.6457 25.009 12.1463 24.9549C11.6469 24.9007 11.1653 24.8736 10.7015 24.8736C9.66707 24.8736 8.65041 24.982 7.6516 25.1986C6.65279 25.4152 5.70749 25.7581 4.8157 26.2274Z" fill="#7191ED"/>
<path d="M9.74804 40.9854L7.17521 38.4126C6.9482 38.1856 6.67613 38.0667 6.35901 38.0559C6.04189 38.0451 5.76846 38.1546 5.53871 38.3843C5.30897 38.6141 5.19311 38.8939 5.19114 39.2238C5.18916 39.5536 5.30168 39.8321 5.5287 40.0591L10.1825 44.7129C10.3843 44.9147 10.6184 45.0084 10.8849 44.9942C11.1515 44.9799 11.3741 44.8834 11.5528 44.7047L16.3008 39.9566C16.5306 39.7269 16.6401 39.4534 16.6293 39.1363C16.6185 38.8192 16.5122 38.5597 16.3104 38.358C16.0834 38.1309 15.8113 38.012 15.4942 38.0013C15.1771 37.9905 14.9037 38.0999 14.6739 38.3297L12.0701 40.9335L12.1129 33.7776C12.1151 33.4223 12.0026 33.1312 11.7756 32.9042C11.5486 32.6771 11.2701 32.5773 10.94 32.6047C10.6355 32.6065 10.3684 32.7223 10.1386 32.952C9.9089 33.1818 9.79312 33.4489 9.79129 33.7534L9.74804 40.9854ZM3.29589 31.5466C5.44018 29.4023 8.00949 28.3212 11.0038 28.3033C13.9981 28.2854 16.5421 29.3232 18.6356 31.4168C20.7292 33.5103 21.7797 36.0669 21.787 39.0864C21.7943 42.106 20.7258 44.6879 18.5815 46.8322C16.4627 48.951 13.8872 50.0131 10.8549 50.0185C7.8226 50.024 5.25966 48.9799 3.16609 46.8863C1.07251 44.7928 0.0410613 42.2424 0.0717334 39.2353C0.102405 36.2283 1.17712 33.6653 3.29589 31.5466Z" fill="#7191ED"/>
</g>
<defs>
<clipPath id="clip0_2871_2649">
<rect width="50" height="50" fill="white" transform="translate(50) rotate(90)"/>
</clipPath>
</defs>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

167
src/panels/corpglory-dataexporter-panel/components/Panel.tsx

@ -0,0 +1,167 @@
import { PanelOptions, TableRowConfig } from '../types';
import { Table, Button, HorizontalGroup } from '@grafana/ui';
import {
PanelProps,
toDataFrame,
FieldType,
applyFieldOverrides,
createTheme,
DataFrame,
DataLinkClickEvent,
} from '@grafana/data';
import React, { useState } from 'react';
import * as _ from 'lodash';
interface Props extends PanelProps<PanelOptions> {}
export function Panel({ options, data, width, height, timeRange, onChangeTimeRange }: Props) {
console.log('panel', data);
const configs: TableRowConfig[] = [];
const [tasks, setTasks] = useState(configs);
const dataFrame = getDataFrameForTable(tasks, setTasks);
function onAddTaskClick(): void {
const configs = [...tasks, createConfigItem()];
setTasks(configs);
}
return (
<div>
<Table width={width} height={height - 40} data={dataFrame} />
<HorizontalGroup justify="flex-end">
<Button
variant="primary"
aria-label="Rich history button"
icon="plus"
style={{ marginTop: '8px' }}
onClick={onAddTaskClick}
>
Add Task
</Button>
</HorizontalGroup>
</div>
);
}
function getDataFrameForTable(configs: TableRowConfig[], setTasks: any): DataFrame {
const dataFrame = toDataFrame({
name: 'A',
fields: [
{
name: 'Time',
type: FieldType.number,
values: _.map(configs, (config) => convertTimestampToDate(config.timestamp)),
},
{
name: 'User',
type: FieldType.string,
values: _.map(configs, (config) => config.user),
},
{
name: 'Datasource',
type: FieldType.string,
values: _.map(configs, (config) => config.datasource),
},
{
name: 'Exported Rows',
type: FieldType.number,
values: _.map(configs, (config) => config.rowsCount),
},
{
name: 'Progress',
type: FieldType.string,
values: _.map(configs, (config) => `${config.progress}%`),
},
{
name: 'Status',
type: FieldType.string,
values: _.map(configs, (config) => config.status),
},
{
name: 'Download CSV',
type: FieldType.string,
values: _.map(configs, (config) => `data:image/png;base64,${DOWNLOAD_ICON_BASE_64}`),
config: {
custom: {
filterable: false,
displayMode: 'image',
},
links: [
{
targetBlank: false,
title: 'CSV link',
url: 'https://chartwerk.io/',
},
],
},
},
{
name: 'Delete task',
type: FieldType.string,
values: _.map(configs, (config) => `data:image/png;base64,${CLOSE_ICON_BASE_64}`),
config: {
custom: {
filterable: false,
displayMode: 'image',
},
links: [
{
targetBlank: false,
title: 'Delete',
url: '#',
onClick: (event: DataLinkClickEvent) => onDeleteClick(event, configs, setTasks),
},
],
},
},
],
});
const dataFrames = applyFieldOverrides({
data: [dataFrame],
fieldConfig: {
overrides: [],
defaults: {},
},
theme: createTheme(),
replaceVariables: (value: string) => value,
});
return dataFrames[0];
}
function onDeleteClick(e: DataLinkClickEvent, tasks: TableRowConfig[], setTasks: any): void {
const rowIndex = e.origin.rowIndex;
const filteredTasks = _.filter(tasks, (task, idx) => idx !== rowIndex);
setTasks(filteredTasks);
}
function createConfigItem(): TableRowConfig {
return {
timestamp: Date.now(),
user: 'admin',
datasource: 'Prometheus',
rowsCount: 3214,
progress: 100,
status: 'finished',
};
}
function convertTimestampToDate(timestamp: number): string {
const options: Intl.DateTimeFormatOptions = {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
};
return new Date(timestamp).toLocaleString('en-GB', options);
}
const CLOSE_ICON_BASE_64 =
'iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAACJSURBVHgB7ZPRCcAgDESv0lWc0zhC53OIjmAVUpCSamL76YEoyfFIiAGWfldK6SwnKHyhep9xJ3iPcqgH5RyxV1VlBWYJypXVHMEiCaqBbRhAy3W3B76j954wq6ZSVZsOY+WXt6i9l2ymGTlUq0VpOcIqaQC96Zth01DN1zBBefVI4SNp9Za+6wLcH6DKFrfpxgAAAABJRU5ErkJggg==';
const DOWNLOAD_ICON_BASE_64 =
'iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAADlSURBVHgB3ZPNDYJAEIVnN96lBA7A2RIsATuQiiwBSrAD7MAjCZBACXqFwPomMRtEwMVwgZeQhfn5mNnMEG1CaZoeiqKwTWJ3JkFCiEtVVU+8+r9iJRlKSrk3iqOFtWJglmXHf3yDwCRJbBxxnudh34cRYluMMbKGcgWNCIlnjEuIJ1JK2WzDWeKb7YHjONEsYBf6kTABY+mWuYX+3Xiex9UFU7D3FllfwLqueQvi/h8ZCtBprDLY703T6A0yWj2ArmSoxedQV4jSSz5xj4pmCi0/NKfrwNz5bdtaNENciOu6N1qNXhzZXHMb9Q+nAAAAAElFTkSuQmCC';

7
src/panels/corpglory-dataexporter-panel/module.ts

@ -0,0 +1,7 @@
import { PanelOptions } from './types';
import { Panel } from './components/Panel';
import { PanelPlugin } from '@grafana/data';
export const plugin = new PanelPlugin<PanelOptions>(Panel);

18
src/panels/corpglory-dataexporter-panel/plugin.json

@ -0,0 +1,18 @@
{
"$schema": "https://raw.githubusercontent.com/grafana/grafana/master/docs/sources/developers/plugins/plugin.schema.json",
"type": "panel",
"name": "Data Exporter Panel",
"id": "corpglory-dataexporter-panel",
"skipDataQuery": true,
"info": {
"description": "Panel for exporting metrics from Grafana dashboards",
"author": {
"name": "CorpGlory Inc.",
"url": "https://corpglory.com"
},
"logos": {
"small": "../corpglory-dataexporter-app/img/logo.svg",
"large": "../corpglory-dataexporter-app/img/logo.svg"
}
}
}

10
src/panels/corpglory-dataexporter-panel/types.ts

@ -0,0 +1,10 @@
export interface PanelOptions {}
export type TableRowConfig = {
timestamp: number;
user: string;
datasource: string;
rowsCount: number;
progress: number;
status: string;
};

8
src/plugin.json

@ -1,7 +1,7 @@
{ {
"$schema": "https://raw.githubusercontent.com/grafana/grafana/master/docs/sources/developers/plugins/plugin.schema.json", "$schema": "https://raw.githubusercontent.com/grafana/grafana/master/docs/sources/developers/plugins/plugin.schema.json",
"type": "app", "type": "app",
"name": "Data Exporter", "name": "Data Exporter App",
"id": "corpglory-dataexporter-app", "id": "corpglory-dataexporter-app",
"info": { "info": {
"description": "", "description": "",
@ -24,6 +24,12 @@
"url": "{{ .JsonData.dataExporterApiUrl }}/api/" "url": "{{ .JsonData.dataExporterApiUrl }}/api/"
} }
], ],
"includes": [
{
"name": "Data Exporter Panel",
"type": "panel"
}
],
"dependencies": { "dependencies": {
"grafanaDependency": ">=7.0.0", "grafanaDependency": ">=7.0.0",
"plugins": [] "plugins": []

Loading…
Cancel
Save