Browse Source

fix linter errors

pull/3/head
rozetko 9 months ago
parent
commit
3c7c7428c3
  1. 10
      src/components/Panel.tsx
  2. 6
      src/models/options/gaugeOptions.ts
  3. 2
      src/types.ts
  4. 6
      src/utils.ts

10
src/components/Panel.tsx

@ -24,7 +24,6 @@ export function Panel({ options, data, width, height, timeRange, onChangeTimeRan
const podContainerRef = useRef<HTMLDivElement>(null); const podContainerRef = useRef<HTMLDivElement>(null);
const podContainer = useMemo(() => { const podContainer = useMemo(() => {
const chartClickHandler = (event: React.MouseEvent<HTMLDivElement>) => { const chartClickHandler = (event: React.MouseEvent<HTMLDivElement>) => {
event.preventDefault(); event.preventDefault();
if (options.gauge.link === undefined || options.gauge.link === '') { if (options.gauge.link === undefined || options.gauge.link === '') {
@ -39,10 +38,7 @@ export function Panel({ options, data, width, height, timeRange, onChangeTimeRan
if (options.visualizationType === Pod.BAR) { if (options.visualizationType === Pod.BAR) {
containerHeight = height - 20; containerHeight = height - 20;
} }
if ( if (options.visualizationType === Pod.GAUGE && options.gauge.additionalInfo.display) {
options.visualizationType === Pod.GAUGE &&
options.gauge.additionalInfo.display
) {
containerHeight = height - options.gauge.additionalInfo.size - 8; containerHeight = height - options.gauge.additionalInfo.size - 8;
} }
@ -97,7 +93,8 @@ export function Panel({ options, data, width, height, timeRange, onChangeTimeRan
} }
} }
additionalInfo = <div additionalInfo = (
<div
className={css` className={css`
width: ${width}px; width: ${width}px;
height: ${additionalInfoConfig.size + 8}px; height: ${additionalInfoConfig.size + 8}px;
@ -110,6 +107,7 @@ export function Panel({ options, data, width, height, timeRange, onChangeTimeRan
> >
{additionalInfoConfig.prefix} {value !== undefined ? formatValue(value, additionalInfoConfig) : '-'} {additionalInfoConfig.prefix} {value !== undefined ? formatValue(value, additionalInfoConfig) : '-'}
</div> </div>
);
} }
return ( return (
<div> <div>

6
src/models/options/gaugeOptions.ts

@ -92,7 +92,11 @@ export class GaugeOptions {
// check each condition and return false if something goes wrong // check each condition and return false if something goes wrong
for (let [conditionIdx, metric] of icon.metrics.entries()) { for (let [conditionIdx, metric] of icon.metrics.entries()) {
const value = getLastMetricValue(this.grafanaSeriesList, metric, `Icon ${iconIdx + 1}, Condition ${conditionIdx + 1}`); const value = getLastMetricValue(
this.grafanaSeriesList,
metric,
`Icon ${iconIdx + 1}, Condition ${conditionIdx + 1}`
);
if (value === null || value === undefined) { if (value === null || value === undefined) {
// TODO: may be throw an error // TODO: may be throw an error
return false; return false;

2
src/types.ts

@ -23,7 +23,7 @@ export interface PanelOptions {
prefix: string; prefix: string;
unit: string; unit: string;
decimals: number; decimals: number;
} };
}; };
} }

6
src/utils.ts

@ -7,7 +7,7 @@ import TimeSeries from 'grafana/app/core/time_series2';
import * as _ from 'lodash'; import * as _ from 'lodash';
export function formatValue(value: number, options: { unit?: string, decimals?: number }): string { export function formatValue(value: number, options: { unit?: string; decimals?: number }): string {
const suffix = getValueFormat(options.unit)(0)?.suffix || ''; const suffix = getValueFormat(options.unit)(0)?.suffix || '';
const decimals = _.isNumber(options.decimals) ? options.decimals : 2; const decimals = _.isNumber(options.decimals) ? options.decimals : 2;
return `${value.toFixed(decimals)} ${suffix}`; return `${value.toFixed(decimals)} ${suffix}`;
@ -24,7 +24,7 @@ export function getGrafanaSeriesList(grafanaData: PanelData, timeRange: TimeRang
export function getLastMetricValue( export function getLastMetricValue(
grafanaSeriesList: TimeSeries[], grafanaSeriesList: TimeSeries[],
metricName: string | undefined, metricName: string | undefined,
optionName: string, optionName: string
): number | null { ): number | null {
// optionName -> helper in Error, mb use option path instead // optionName -> helper in Error, mb use option path instead
const filteredSeries = filterMetricListByAlias(grafanaSeriesList, metricName, optionName); const filteredSeries = filterMetricListByAlias(grafanaSeriesList, metricName, optionName);
@ -34,7 +34,7 @@ export function getLastMetricValue(
} }
export function filterMetricListByAlias(list: any[], alias: string | undefined, option: string): any[] { export function filterMetricListByAlias(list: any[], alias: string | undefined, option: string): any[] {
console.log(list) console.log(list);
const filteredSeries = _.filter(list, (serie) => serie.alias === alias); const filteredSeries = _.filter(list, (serie) => serie.alias === alias);
if (filteredSeries.length === 0) { if (filteredSeries.length === 0) {
throw new Error(`${option}: Can't find metric for ${alias} name.`); throw new Error(`${option}: Can't find metric for ${alias} name.`);

Loading…
Cancel
Save