Browse Source

fix linter errors

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

34
src/components/Panel.tsx

@ -24,7 +24,6 @@ export function Panel({ options, data, width, height, timeRange, onChangeTimeRan
const podContainerRef = useRef<HTMLDivElement>(null);
const podContainer = useMemo(() => {
const chartClickHandler = (event: React.MouseEvent<HTMLDivElement>) => {
event.preventDefault();
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) {
containerHeight = height - 20;
}
if (
options.visualizationType === Pod.GAUGE &&
options.gauge.additionalInfo.display
) {
if (options.visualizationType === Pod.GAUGE && options.gauge.additionalInfo.display) {
containerHeight = height - options.gauge.additionalInfo.size - 8;
}
@ -97,19 +93,21 @@ export function Panel({ options, data, width, height, timeRange, onChangeTimeRan
}
}
additionalInfo = <div
className={css`
width: ${width}px;
height: ${additionalInfoConfig.size + 8}px;
font-size: ${additionalInfoConfig.size}px;
color: ${additionalInfoConfig.color};
display: flex;
justify-content: center;
align-items: center;
`}
>
{additionalInfoConfig.prefix} {value !== undefined ? formatValue(value, additionalInfoConfig) : '-'}
</div>
additionalInfo = (
<div
className={css`
width: ${width}px;
height: ${additionalInfoConfig.size + 8}px;
font-size: ${additionalInfoConfig.size}px;
color: ${additionalInfoConfig.color};
display: flex;
justify-content: center;
align-items: center;
`}
>
{additionalInfoConfig.prefix} {value !== undefined ? formatValue(value, additionalInfoConfig) : '-'}
</div>
);
}
return (
<div>

6
src/models/options/gaugeOptions.ts

@ -92,7 +92,11 @@ export class GaugeOptions {
// check each condition and return false if something goes wrong
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) {
// TODO: may be throw an error
return false;

2
src/types.ts

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

6
src/utils.ts

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

Loading…
Cancel
Save