Skip to content

Commit

Permalink
fix: Fix some linting warnings (#2064)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
Fixes part of #1608 

## Description of the changes
- Added the minimal types needed to fix the linting warnings
- Replaced `{}` with the `object` type

## How was this change tested?
- Ran `yarn lint` locally 

## Checklist
- [X] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [X] I have signed all commits
- [X] I have added unit tests for the new functionality
- [X] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `yarn lint` and `yarn test`

---------

Signed-off-by: Eshaan Aggarwal <96648934+EshaanAgg@users.noreply.github.com>
  • Loading branch information
EshaanAgg committed Dec 24, 2023
1 parent c88b5fc commit 33b22a4
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const CATEGORY_SERVICE = `${FORM_CATEGORY_BASE}/serviceName`;
export function trackFormInput(
resultsLimit: number,
operation: string,
tags: any,
tags: string,
minDuration: number,
maxDuration: number,
lookback: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ type State = {
fromNow: string | boolean;
};

const isErrorTag = ({ key, value }: KeyValuePair) => key === 'error' && (value === true || value === 'true');
const isErrorTag = ({ key, value }: KeyValuePair<boolean | string>) =>
key === 'error' && (value === true || value === 'true');
const trackTraceConversions = () => trackConversions(EAltViewActions.Traces);

export default class ResultItem extends React.PureComponent<Props, State> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class UnconnectedSearchResults extends React.PureComponent<SearchResultsP
}
const cohortIds = new Set(diffCohort.map(datum => datum.id));
const searchUrl = queryOfResults ? getUrl(stripEmbeddedState(queryOfResults)) : getUrl();
const isErrorTag = ({ key, value }: KeyValuePair) =>
const isErrorTag = ({ key, value }: KeyValuePair<string | boolean>) =>
key === 'error' && (value === true || value === 'true');
return (
<div className="SearchResults">
Expand Down
6 changes: 3 additions & 3 deletions packages/jaeger-ui/src/components/TracePage/ScrollManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function isSpanHidden(span: Span, childrenAreHidden: Set<string>, spansMap: Map<
*/
export default class ScrollManager {
_trace: Trace | TNil;
_scroller: IScroller;
_scroller: IScroller | TNil;
_accessors: Accessors | TNil;

constructor(trace: Trace | TNil, scroller: IScroller) {
Expand Down Expand Up @@ -117,7 +117,7 @@ export default class ScrollManager {
y -= vh;
}
y += direction * 0.5 * vh;
this._scroller.scrollTo(y);
this._scroller?.scrollTo(y);
}

_scrollToVisibleSpan(direction: 1 | -1, startRow?: number) {
Expand Down Expand Up @@ -268,7 +268,7 @@ export default class ScrollManager {

destroy() {
this._trace = undefined;
this._scroller = undefined as any;
this._scroller = undefined;
this._accessors = undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function isError(tags: Array<KeyValuePair>) {
return errorTag.value;
}
}

return false;
}

Expand Down Expand Up @@ -82,7 +83,7 @@ export function calculateTraceDag(trace: Trace): TraceDag<TSumSpan & TDenseSpanM

baseDag.nodesMap.forEach(node => {
const ntime = node.members.reduce((p, m) => p + m.span.duration, 0);
const numErrors = node.members.reduce((p, m) => (p + isError(m.span.tags) ? 1 : 0), 0);
const numErrors = node.members.reduce((p, m) => p + (isError(m.span.tags) ? 1 : 0), 0);
const childDurationsDRange = node.members.reduce((p, m) => {
// Using DRange to handle overlapping spans (fork-join)
const cdr = new DRange(m.span.startTime, m.span.startTime + m.span.duration).intersect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ type State = {
visible: boolean;
};

type DataRecord = {
key: string;
kbds: React.JSX.Element;
description: string;
};

const { Column } = Table;

const SYMBOL_CONV: Record<string, string> = {
Expand All @@ -47,15 +53,15 @@ function convertKeys(keyConfig: string | string[]): string[][] {

const padLeft = (text: string) => <span className="ub-pl4">{text}</span>;
const padRight = (text: string) => <span className="ub-pr4">{text}</span>;
const getRowClass = (_: any, index: number) => (index % 2 > 0 ? ODD_ROW_CLASS : '');
const getRowClass = (_: DataRecord, index: number) => (index % 2 > 0 ? ODD_ROW_CLASS : '');

let kbdTable: React.ReactNode | null = null;

function getHelpModal() {
if (kbdTable) {
return kbdTable;
}
const data: { key: string; kbds: any; description: string }[] = [];
const data: DataRecord[] = [];
Object.keys(keyboardMappings).forEach(handle => {
const { binding, label } = keyboardMappings[handle];
const keyConfigs = convertKeys(binding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ export default function AccordianText(props: AccordianTextProps) {
const { className, data, headerClassName, highContrast, interactive, isOpen, label, onToggle } = props;
const isEmpty = !Array.isArray(data) || !data.length;
const iconCls = cx('u-align-icon', { 'AccordianKeyValues--emptyIcon': isEmpty });

let arrow: React.ReactNode | null = null;
let headerProps: Object | null = null;
let headerProps: object | null = null;

if (interactive) {
arrow = isOpen ? <IoChevronDown className={iconCls} /> : <IoChevronForward className={iconCls} />;
headerProps = {
Expand All @@ -45,6 +47,7 @@ export default function AccordianText(props: AccordianTextProps) {
role: 'switch',
};
}

return (
<div className={className || ''}>
<div
Expand Down
2 changes: 1 addition & 1 deletion packages/jaeger-ui/src/model/trace-dag/TraceDag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { TDenseSpan, TDiffCounts, NodeID, TDenseSpanMembers } from './types';
import TDagNode from './types/TDagNode';
import { Trace } from '../../types/trace';

export default class TraceDag<TData extends { [k: string]: unknown } = {}> {
export default class TraceDag<TData extends { [k: string]: unknown }> {
static newFromTrace(trace: Trace, idFactory: TIdFactory = ancestralPathParentOrLeaf) {
const dag: TraceDag<TDenseSpanMembers> = new TraceDag();
const { denseSpansMap, rootIDs } = new DenseTrace(trace);
Expand Down
19 changes: 9 additions & 10 deletions packages/jaeger-ui/src/reducers/metrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,27 @@ function fetchServiceMetricsDone(
}
}
} else {
if (
typeof (promiseResult as PromiseRejectedResult).reason === 'object' &&
(promiseResult as PromiseRejectedResult).reason.httpStatus === 501
) {
const reason = (promiseResult as PromiseRejectedResult).reason;

if (typeof reason === 'object' && reason.httpStatus === 501) {
isATMActivated = false;
}

switch (i) {
case 0:
serviceError.service_latencies_50 = (promiseResult as PromiseRejectedResult).reason;
serviceError.service_latencies_50 = reason;
break;
case 1:
serviceError.service_latencies_75 = (promiseResult as PromiseRejectedResult).reason;
serviceError.service_latencies_75 = reason;
break;
case 2:
serviceError.service_latencies_95 = (promiseResult as PromiseRejectedResult).reason;
serviceError.service_latencies_95 = reason;
break;
case 3:
serviceError.service_call_rate = (promiseResult as PromiseRejectedResult).reason;
serviceError.service_call_rate = reason;
break;
case 4:
serviceError.service_error_rate = (promiseResult as PromiseRejectedResult).reason;
serviceError.service_error_rate = reason;
break;
}
}
Expand Down Expand Up @@ -192,7 +191,7 @@ function fetchOpsMetricsDone(
service_operation_call_rate: 0,
service_operation_error_rate: 0,
};
metricDetails.labels.forEach((label: any) => {
metricDetails.labels.forEach((label: { name: string; value: string }) => {
if (label.name === 'operation') {
opsName = label.value;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jaeger-ui/src/types/api-error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type ApiError = // eslint-disable-line import/prefer-default-export
| string
| {
message: string;
httpStatus?: any;
httpStatus?: number;
httpStatusText?: string;
httpUrl?: string;
httpQuery?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/jaeger-ui/src/types/metrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export type PromiseFulfilledResult<T> = {

export type PromiseRejectedResult = {
status: PromiseStatus.rejected;
reason: any;
reason: ApiError;
};

export type FetchedAllServiceMetricsResponse = [
Expand Down
5 changes: 2 additions & 3 deletions packages/jaeger-ui/src/types/trace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
* All timestamps are in microseconds
*/

// TODO: Everett Tech Debt: Fix KeyValuePair types
export type KeyValuePair = {
export type KeyValuePair<ValueType = string> = {
key: string;
value: any;
value: ValueType;
};

export type Link = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export type DraggableManagerDemoState = {
regionDragging: [number, number] | TNil;
};

export default class DraggableManagerDemo extends React.PureComponent<{}, DraggableManagerDemoState> {
export default class DraggableManagerDemo extends React.PureComponent<object, DraggableManagerDemoState> {
state: DraggableManagerDemoState;

constructor(props: {}) {
constructor(props: object) {
super(props);
this.state = {
dividerPosition: 0.25,
Expand All @@ -38,7 +38,7 @@ export default class DraggableManagerDemo extends React.PureComponent<{}, Dragga
};
}

_udpateState = (nextState: {}) => {
_updateState = (nextState: object) => {
this.setState(nextState);
};

Expand All @@ -52,7 +52,7 @@ export default class DraggableManagerDemo extends React.PureComponent<{}, Dragga
<p>Click and drag the gray divider in the colored area, below.</p>
<p>Value: {dividerPosition.toFixed(3)}</p>
<div className="DraggableManagerDemo--realm">
<DividerDemo position={dividerPosition} updateState={this._udpateState} />
<DividerDemo position={dividerPosition} updateState={this._updateState} />
</div>
</section>
<section className="DraggableManagerDemo--scenario">
Expand All @@ -63,7 +63,7 @@ export default class DraggableManagerDemo extends React.PureComponent<{}, Dragga
<RegionDemo
regionCursor={regionCursor}
regionDragging={regionDragging}
updateState={this._udpateState}
updateState={this._updateState}
/>
</div>
</section>
Expand Down

0 comments on commit 33b22a4

Please sign in to comment.