mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: removing some type assertions (#85839)
* fix some type assertions in loops * some more cleanup * some alerting fixes * put comments in correct place to ignore rule * couple more * undo SilencesFilter changes
This commit is contained in:
parent
96f49bfaee
commit
3c69de6be5
@ -1,5 +1,5 @@
|
||||
// BETTERER RESULTS V2.
|
||||
//
|
||||
//
|
||||
// If this file contains merge conflicts, use `betterer merge` to automatically resolve them:
|
||||
// https://phenomnomnominal.github.io/betterer/docs/results-file/#merge
|
||||
//
|
||||
@ -14,10 +14,6 @@ exports[`better eslint`] = {
|
||||
"packages/grafana-data/src/dataframe/CircularDataFrame.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||
],
|
||||
"packages/grafana-data/src/dataframe/DataFrameJSON.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"]
|
||||
],
|
||||
"packages/grafana-data/src/dataframe/DataFrameView.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
@ -43,8 +39,7 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "2"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "3"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "4"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "5"]
|
||||
[0, 0, 0, "Do not use any type assertions.", "4"]
|
||||
],
|
||||
"packages/grafana-data/src/dataframe/dimensions.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||
@ -194,10 +189,8 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||
],
|
||||
"packages/grafana-data/src/transformations/transformers/nulls/nullInsertThreshold.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
|
||||
],
|
||||
"packages/grafana-data/src/transformations/transformers/reduce.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
@ -323,8 +316,7 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "7"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "8"]
|
||||
[0, 0, 0, "Do not use any type assertions.", "7"]
|
||||
],
|
||||
"packages/grafana-data/src/types/options.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
@ -681,9 +673,6 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Styles should be written using objects.", "17"],
|
||||
[0, 0, 0, "Styles should be written using objects.", "18"]
|
||||
],
|
||||
"packages/grafana-prometheus/src/querybuilder/operationUtils.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
],
|
||||
"packages/grafana-prometheus/src/querybuilder/shared/OperationEditor.tsx:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||
],
|
||||
@ -892,10 +881,8 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "6"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "7"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "8"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "9"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "11"]
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "9"]
|
||||
],
|
||||
"packages/grafana-ui/src/components/Select/SelectOptionGroup.tsx:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
@ -1097,12 +1084,6 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"]
|
||||
],
|
||||
"packages/grafana-ui/src/options/builder/axis.tsx:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "2"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
|
||||
],
|
||||
"packages/grafana-ui/src/options/builder/hideSeries.tsx:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
],
|
||||
@ -1560,11 +1541,10 @@ exports[`better eslint`] = {
|
||||
],
|
||||
"public/app/features/alerting/unified/RuleList.tsx:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
[0, 0, 0, "Styles should be written using objects.", "1"],
|
||||
[0, 0, 0, "Styles should be written using objects.", "2"],
|
||||
[0, 0, 0, "Styles should be written using objects.", "3"],
|
||||
[0, 0, 0, "Styles should be written using objects.", "4"],
|
||||
[0, 0, 0, "Styles should be written using objects.", "5"]
|
||||
[0, 0, 0, "Styles should be written using objects.", "4"]
|
||||
],
|
||||
"public/app/features/alerting/unified/components/AlertLabel.tsx:5381": [
|
||||
[0, 0, 0, "Styles should be written using objects.", "0"]
|
||||
@ -1580,8 +1560,7 @@ exports[`better eslint`] = {
|
||||
],
|
||||
"public/app/features/alerting/unified/components/AnnotationDetailsField.tsx:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
[0, 0, 0, "Styles should be written using objects.", "2"]
|
||||
[0, 0, 0, "Styles should be written using objects.", "1"]
|
||||
],
|
||||
"public/app/features/alerting/unified/components/Authorize.tsx:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
@ -1702,9 +1681,6 @@ exports[`better eslint`] = {
|
||||
"public/app/features/alerting/unified/components/alert-groups/GroupBy.tsx:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
],
|
||||
"public/app/features/alerting/unified/components/alert-groups/MatcherFilter.tsx:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
],
|
||||
"public/app/features/alerting/unified/components/contact-points/ContactPoints.tsx:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
],
|
||||
@ -2332,9 +2308,6 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"]
|
||||
],
|
||||
"public/app/features/alerting/unified/utils/misc.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
],
|
||||
"public/app/features/alerting/unified/utils/receiver-form.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
@ -2349,8 +2322,7 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Do not use any type assertions.", "4"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "5"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "6"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "7"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "8"]
|
||||
[0, 0, 0, "Do not use any type assertions.", "7"]
|
||||
],
|
||||
"public/app/features/alerting/unified/utils/rulerClient.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
@ -2541,11 +2513,6 @@ exports[`better eslint`] = {
|
||||
"public/app/features/dashboard-scene/utils/PanelModelCompatibilityWrapper.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
],
|
||||
"public/app/features/dashboard-scene/utils/test-utils.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "2"]
|
||||
],
|
||||
"public/app/features/dashboard/components/AddWidgetModal/AddWidgetModal.tsx:5381": [
|
||||
[0, 0, 0, "Styles should be written using objects.", "0"],
|
||||
[0, 0, 0, "Styles should be written using objects.", "1"],
|
||||
@ -3014,8 +2981,7 @@ exports[`better eslint`] = {
|
||||
],
|
||||
"public/app/features/datasources/components/DataSourceTestingStatus.tsx:5381": [
|
||||
[0, 0, 0, "Styles should be written using objects.", "0"],
|
||||
[0, 0, 0, "Styles should be written using objects.", "1"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "2"]
|
||||
[0, 0, 0, "Styles should be written using objects.", "1"]
|
||||
],
|
||||
"public/app/features/datasources/components/DataSourceTypeCard.tsx:5381": [
|
||||
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"]
|
||||
@ -3431,9 +3397,6 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Styles should be written using objects.", "4"],
|
||||
[0, 0, 0, "Styles should be written using objects.", "5"]
|
||||
],
|
||||
"public/app/features/explore/TraceView/components/TraceTimelineViewer/SpanDetail/SpanFlameGraph.tsx:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
],
|
||||
"public/app/features/explore/TraceView/components/TraceTimelineViewer/SpanDetail/TextList.tsx:5381": [
|
||||
[0, 0, 0, "Styles should be written using objects.", "0"],
|
||||
[0, 0, 0, "Styles should be written using objects.", "1"],
|
||||
@ -5554,9 +5517,6 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Styles should be written using objects.", "17"],
|
||||
[0, 0, 0, "Styles should be written using objects.", "18"]
|
||||
],
|
||||
"public/app/plugins/datasource/prometheus/querybuilder/operationUtils.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
],
|
||||
"public/app/plugins/datasource/prometheus/querybuilder/shared/LabelFilterItem.tsx:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
|
@ -128,9 +128,10 @@ const ENTITY_MAP: Record<keyof FieldValueEntityLookup, number | undefined> = {
|
||||
* @internal use locally
|
||||
*/
|
||||
export function decodeFieldValueEntities(lookup: FieldValueEntityLookup, values: FieldValues) {
|
||||
for (const key in lookup) {
|
||||
const repl = ENTITY_MAP[key as keyof FieldValueEntityLookup];
|
||||
for (const idx of lookup[key as keyof FieldValueEntityLookup]!) {
|
||||
let key: keyof typeof lookup;
|
||||
for (key in lookup) {
|
||||
const repl = ENTITY_MAP[key];
|
||||
for (const idx of lookup[key]!) {
|
||||
if (idx < values.length) {
|
||||
values[idx] = repl;
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ export class StreamingDataFrame implements DataFrame {
|
||||
const dataFrameDTO = toFilteredDataFrameDTO(this, fieldPredicate);
|
||||
|
||||
const numberOfItemsToRemove = getNumberOfItemsToRemove(
|
||||
dataFrameDTO.fields.map((f) => f.values) as unknown[][],
|
||||
dataFrameDTO.fields.map((f) => f.values ?? []),
|
||||
typeof trimValues?.maxLength === 'number' ? Math.min(trimValues.maxLength, options.maxLength) : options.maxLength,
|
||||
this.timeFieldIndex,
|
||||
options.maxDelta
|
||||
|
@ -46,18 +46,12 @@ export function compareDataFrameStructures(a: DataFrame, b: DataFrame, skipConfi
|
||||
const cfgA = fA.config;
|
||||
const cfgB = fB.config;
|
||||
|
||||
// need to type assert on the object keys here
|
||||
// see e.g. https://github.com/Microsoft/TypeScript/issues/12870
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
let aKeys = Object.keys(cfgA) as Array<keyof typeof cfgA>;
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
let bKeys = Object.keys(cfgB) as Array<keyof typeof cfgB>;
|
||||
|
||||
if (aKeys.length !== bKeys.length) {
|
||||
if (Object.keys(cfgA).length !== Object.keys(cfgB).length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const key of aKeys) {
|
||||
let key: keyof typeof cfgA;
|
||||
for (key in cfgA) {
|
||||
if (!(key in cfgB)) {
|
||||
return false;
|
||||
}
|
||||
@ -110,15 +104,12 @@ export function shallowCompare<T extends {}>(a: T, b: T, cmp: Cmp = defaultCmp)
|
||||
return true;
|
||||
}
|
||||
|
||||
const aKeys = Object.keys(a);
|
||||
const bKeys = Object.keys(b);
|
||||
|
||||
if (aKeys.length !== bKeys.length) {
|
||||
if (Object.keys(a).length !== Object.keys(b).length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let key of aKeys) {
|
||||
//@ts-ignore
|
||||
let key: keyof typeof a;
|
||||
for (key in a) {
|
||||
if (!cmp(a[key], b[key])) {
|
||||
return false;
|
||||
}
|
||||
|
@ -19,11 +19,9 @@ function getDisplayProcessorFromConfig(config: FieldConfig, fieldType: FieldType
|
||||
function assertSame(input: unknown, processors: DisplayProcessor[], match: DisplayValue) {
|
||||
processors.forEach((processor) => {
|
||||
const value = processor(input);
|
||||
for (const key of Object.keys(match)) {
|
||||
// need to type assert on the object keys here
|
||||
// see e.g. https://github.com/Microsoft/TypeScript/issues/12870
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
expect(value[key as keyof typeof match]).toEqual(match[key as keyof typeof match]);
|
||||
let key: keyof typeof match;
|
||||
for (key in match) {
|
||||
expect(value[key]).toEqual(match[key]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ describe('calculateField transformer w/ timeseries', () => {
|
||||
text: '10000',
|
||||
},
|
||||
};
|
||||
for (const key of Object.keys(variables)) {
|
||||
for (const key in variables) {
|
||||
if (target === `$${key}`) {
|
||||
return variables[key]!.value + '';
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ describe('filterByName transformer', () => {
|
||||
text: 'Test',
|
||||
},
|
||||
};
|
||||
for (const key of Object.keys(variables)) {
|
||||
for (const key in variables) {
|
||||
return target.replace(`$${key}`, variables[key]!.value);
|
||||
}
|
||||
return target;
|
||||
@ -256,7 +256,7 @@ describe('filterByName transformer', () => {
|
||||
text: 'Test',
|
||||
},
|
||||
};
|
||||
for (const key of Object.keys(variables)) {
|
||||
for (const key in variables) {
|
||||
return target.replace(`$${key}`, variables[key]!.value);
|
||||
}
|
||||
return target;
|
||||
@ -293,7 +293,7 @@ describe('filterByName transformer', () => {
|
||||
text: 'Test',
|
||||
},
|
||||
};
|
||||
for (const key of Object.keys(variables)) {
|
||||
for (const key in variables) {
|
||||
return target.replace(`$${key}`, variables[key]!.value);
|
||||
}
|
||||
return target;
|
||||
|
@ -50,9 +50,9 @@ export function applyNullInsertThreshold(opts: NullInsertOptions): DataFrame {
|
||||
|
||||
const thresholds = frame.fields.map((field) => field.config.custom?.insertNulls || refField.config.interval || null);
|
||||
|
||||
const uniqueThresholds = new Set<number>(thresholds);
|
||||
const uniqueThresholds = new Set<number | null>(thresholds);
|
||||
|
||||
uniqueThresholds.delete(null as any);
|
||||
uniqueThresholds.delete(null);
|
||||
|
||||
if (uniqueThresholds.size === 0) {
|
||||
return frame;
|
||||
|
@ -122,7 +122,7 @@ function reduceSeriesToRows(
|
||||
if (labelsToFields) {
|
||||
names[i] = field.name;
|
||||
if (field.labels) {
|
||||
for (const key of Object.keys(field.labels)) {
|
||||
for (const key in field.labels) {
|
||||
labels[key][i] = field.labels[key];
|
||||
}
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ export function toLiveChannelId(addr: LiveChannelAddress): LiveChannelId {
|
||||
if (!addr.scope) {
|
||||
return '';
|
||||
}
|
||||
let id = addr.scope as string;
|
||||
let id: string = addr.scope;
|
||||
if (!addr.namespace) {
|
||||
return id;
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ const getUrlForPartial = (location: Location, searchParamsToUpdate: UrlQueryMap)
|
||||
const searchParams = urlUtil.parseKeyValue(
|
||||
location.search.startsWith('?') ? location.search.substring(1) : location.search
|
||||
);
|
||||
for (const key of Object.keys(searchParamsToUpdate)) {
|
||||
for (const key in searchParamsToUpdate) {
|
||||
// removing params with null | undefined
|
||||
if (searchParamsToUpdate[key] === null || searchParamsToUpdate[key] === undefined) {
|
||||
delete searchParams[key];
|
||||
|
@ -124,31 +124,33 @@ export function getOperationParamId(operationId: string, paramIndex: number) {
|
||||
}
|
||||
|
||||
export function getRangeVectorParamDef(withRateInterval = false): QueryBuilderOperationParamDef {
|
||||
const param: QueryBuilderOperationParamDef = {
|
||||
name: 'Range',
|
||||
type: 'string',
|
||||
options: [
|
||||
{
|
||||
label: '$__interval',
|
||||
value: '$__interval',
|
||||
// tooltip: 'Dynamic interval based on max data points, scrape and min interval',
|
||||
},
|
||||
{ label: '1m', value: '1m' },
|
||||
{ label: '5m', value: '5m' },
|
||||
{ label: '10m', value: '10m' },
|
||||
{ label: '1h', value: '1h' },
|
||||
{ label: '24h', value: '24h' },
|
||||
],
|
||||
};
|
||||
const options: Array<SelectableValue<string>> = [
|
||||
{
|
||||
label: '$__interval',
|
||||
value: '$__interval',
|
||||
// tooltip: 'Dynamic interval based on max data points, scrape and min interval',
|
||||
},
|
||||
{ label: '1m', value: '1m' },
|
||||
{ label: '5m', value: '5m' },
|
||||
{ label: '10m', value: '10m' },
|
||||
{ label: '1h', value: '1h' },
|
||||
{ label: '24h', value: '24h' },
|
||||
];
|
||||
|
||||
if (withRateInterval) {
|
||||
(param.options as Array<SelectableValue<string>>).unshift({
|
||||
options.unshift({
|
||||
label: '$__rate_interval',
|
||||
value: '$__rate_interval',
|
||||
// tooltip: 'Always above 4x scrape interval',
|
||||
});
|
||||
}
|
||||
|
||||
const param: QueryBuilderOperationParamDef = {
|
||||
name: 'Range',
|
||||
type: 'string',
|
||||
options,
|
||||
};
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ export class HistoryWrapper implements LocationService {
|
||||
const currentLocation = this.history.location;
|
||||
const newQuery = this.getSearchObject();
|
||||
|
||||
for (const key of Object.keys(query)) {
|
||||
for (const key in query) {
|
||||
// removing params with null | undefined
|
||||
if (query[key] === null || query[key] === undefined) {
|
||||
delete newQuery[key];
|
||||
|
@ -272,7 +272,7 @@ export function SelectBase<T, Rest = {}>({
|
||||
|
||||
// Instead of having AsyncSelect, as a separate component we render ReactAsyncSelect
|
||||
if (loadOptions) {
|
||||
ReactSelectComponent = (allowCustomValue ? AsyncCreatable : ReactAsyncSelect) as any;
|
||||
ReactSelectComponent = allowCustomValue ? AsyncCreatable : ReactAsyncSelect;
|
||||
asyncSelectProps = {
|
||||
loadOptions,
|
||||
cacheOptions,
|
||||
|
@ -100,8 +100,8 @@ export function addAxisConfig(
|
||||
path: 'scaleDistribution',
|
||||
name: 'Scale',
|
||||
category,
|
||||
editor: ScaleDistributionEditor as any,
|
||||
override: ScaleDistributionEditor as any,
|
||||
editor: ScaleDistributionEditor,
|
||||
override: ScaleDistributionEditor,
|
||||
defaultValue: { type: ScaleDistribution.Linear },
|
||||
shouldApply: (f) => f.type === FieldType.number,
|
||||
process: identityOverrideProcessor,
|
||||
|
@ -107,7 +107,7 @@ export class AngularLocationWrapper {
|
||||
newQuery = locationSearchToObject(search);
|
||||
}
|
||||
|
||||
for (const key of Object.keys(newQuery)) {
|
||||
for (const key in newQuery) {
|
||||
// removing params with null | undefined
|
||||
if (newQuery[key] === null || newQuery[key] === undefined) {
|
||||
delete newQuery[key];
|
||||
|
@ -47,9 +47,8 @@ const RuleList = withErrorBoundary(
|
||||
const [queryParams] = useQueryParams();
|
||||
const { filterState, hasActiveFilters } = useRulesFilter();
|
||||
|
||||
const view = VIEWS[queryParams['view'] as keyof typeof VIEWS]
|
||||
? (queryParams['view'] as keyof typeof VIEWS)
|
||||
: 'groups';
|
||||
const queryParamView = queryParams['view'] as keyof typeof VIEWS;
|
||||
const view = VIEWS[queryParamView] ? queryParamView : 'groups';
|
||||
|
||||
const ViewComponent = VIEWS[view];
|
||||
|
||||
|
@ -19,9 +19,10 @@ interface Props {
|
||||
}
|
||||
|
||||
export const AnnotationDetailsField = ({ annotationKey, value, valueLink }: Props) => {
|
||||
const label = annotationLabels[annotationKey as Annotation] ? (
|
||||
const annotation = annotationKey as Annotation;
|
||||
const label = annotationLabels[annotation] ? (
|
||||
<Tooltip content={annotationKey} placement="top" theme="info">
|
||||
<span>{annotationLabels[annotationKey as Annotation]}</span>
|
||||
<span>{annotationLabels[annotation]}</span>
|
||||
</Tooltip>
|
||||
) : (
|
||||
annotationKey
|
||||
|
@ -20,7 +20,7 @@ export const MatcherFilter = ({ onFilterChange, defaultQueryString }: Props) =>
|
||||
() =>
|
||||
debounce((e: FormEvent<HTMLInputElement>) => {
|
||||
logInfo(LogMessages.filterByLabel);
|
||||
const target = e.target as HTMLInputElement;
|
||||
const target = e.currentTarget;
|
||||
onFilterChange(target.value);
|
||||
}, 600),
|
||||
[onFilterChange]
|
||||
|
@ -226,7 +226,7 @@ export function isLocalDevEnv() {
|
||||
}
|
||||
|
||||
export function isErrorLike(error: unknown): error is Error {
|
||||
return 'message' in (error as Error);
|
||||
return Boolean(error && typeof error === 'object' && 'message' in error);
|
||||
}
|
||||
|
||||
export function stringifyErrorLike(error: unknown): string {
|
||||
|
@ -6,6 +6,8 @@ import { appEvents } from 'app/core/core';
|
||||
|
||||
import { logInfo, LogMessages } from '../Analytics';
|
||||
|
||||
import { isErrorLike } from './misc';
|
||||
|
||||
export interface AsyncRequestState<T> {
|
||||
result?: T;
|
||||
loading: boolean;
|
||||
@ -158,9 +160,8 @@ export function messageFromError(e: Error | FetchError | SerializedError): strin
|
||||
}
|
||||
}
|
||||
// message in e object, return message
|
||||
const errorMessage = (e as Error)?.message;
|
||||
if (errorMessage) {
|
||||
return errorMessage;
|
||||
if (isErrorLike(e)) {
|
||||
return e.message;
|
||||
}
|
||||
// for some reason (upstream this code), sometimes we get an object without the message field neither in the e.data and nor in e.message
|
||||
// in this case we want to avoid String(e) printing [object][object]
|
||||
|
@ -21,10 +21,10 @@ import { RowRepeaterBehavior } from '../scene/RowRepeaterBehavior';
|
||||
|
||||
export function setupLoadDashboardMock(rsp: DeepPartial<DashboardDTO>, spy?: jest.Mock) {
|
||||
const loadDashboardMock = (spy || jest.fn()).mockResolvedValue(rsp);
|
||||
// disabling type checks since this is a test util
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
setDashboardLoaderSrv({
|
||||
loadDashboard: loadDashboardMock,
|
||||
// disabling type checks since this is a test util
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
} as unknown as DashboardLoaderSrv);
|
||||
return loadDashboardMock;
|
||||
}
|
||||
@ -35,6 +35,8 @@ export function mockResizeObserver() {
|
||||
setTimeout(() => {
|
||||
callback(
|
||||
[
|
||||
// disabling type checks since this is a test util
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
{
|
||||
contentRect: {
|
||||
x: 1,
|
||||
@ -46,8 +48,6 @@ export function mockResizeObserver() {
|
||||
left: 100,
|
||||
right: 0,
|
||||
},
|
||||
// disabling type checks since this is a test util
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
} as ResizeObserverEntry,
|
||||
],
|
||||
this
|
||||
|
@ -57,7 +57,7 @@ export function getDashboardUrl(options: DashboardUrlOptions) {
|
||||
const params = options.currentQueryParams ? locationSearchToObject(options.currentQueryParams) : {};
|
||||
|
||||
if (options.updateQuery) {
|
||||
for (const key of Object.keys(options.updateQuery)) {
|
||||
for (const key in options.updateQuery) {
|
||||
// removing params with null | undefined
|
||||
if (options.updateQuery[key] === null || options.updateQuery[key] === undefined) {
|
||||
delete params[key];
|
||||
|
@ -74,8 +74,8 @@ const AlertSuccessMessage = ({ title, exploreUrl, dataSourceId, onDashboardLinkC
|
||||
|
||||
AlertSuccessMessage.displayName = 'AlertSuccessMessage';
|
||||
|
||||
const alertVariants = new Set<AlertVariant>(['success', 'info', 'warning', 'error']);
|
||||
const isAlertVariant = (str: string): str is AlertVariant => alertVariants.has(str as AlertVariant);
|
||||
const alertVariants = new Set(['success', 'info', 'warning', 'error']);
|
||||
const isAlertVariant = (str: string): str is AlertVariant => alertVariants.has(str);
|
||||
const getAlertVariant = (status: string): AlertVariant => {
|
||||
if (status.toLowerCase() === 'ok') {
|
||||
return 'success';
|
||||
|
@ -264,7 +264,7 @@ export function buildEditRowModels(value: ValueMapping[]) {
|
||||
for (const mapping of value) {
|
||||
switch (mapping.type) {
|
||||
case MappingType.ValueToText:
|
||||
for (const key of Object.keys(mapping.options)) {
|
||||
for (const key in mapping.options) {
|
||||
editRows.push(
|
||||
createRow({
|
||||
type: mapping.type,
|
||||
|
@ -17,7 +17,6 @@ import { TraceToProfilesOptions } from '@grafana/o11y-ds-frontend';
|
||||
import { config, DataSourceWithBackend, getTemplateSrv } from '@grafana/runtime';
|
||||
import { useStyles2 } from '@grafana/ui';
|
||||
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
||||
import { PyroscopeQueryType } from 'app/plugins/datasource/grafana-pyroscope-datasource/dataquery.gen';
|
||||
import { Query } from 'app/plugins/datasource/grafana-pyroscope-datasource/types';
|
||||
|
||||
import {
|
||||
@ -125,7 +124,7 @@ export default function SpanFlameGraph(props: SpanFlameGraphProps) {
|
||||
labelSelector,
|
||||
groupBy: [],
|
||||
profileTypeId: traceToProfilesOptions.profileTypeId ?? '',
|
||||
queryType: 'profile' as PyroscopeQueryType,
|
||||
queryType: 'profile' as const,
|
||||
spanSelector: [profileTagValue],
|
||||
refId: 'span-flamegraph-refId',
|
||||
datasource: {
|
||||
|
@ -47,11 +47,12 @@ let props = {
|
||||
describe('<VirtualizedTraceViewImpl>', () => {
|
||||
beforeEach(() => {
|
||||
jest.mocked(SpanTreeOffset).mockReturnValue(<div />);
|
||||
Object.keys(props).forEach((key) => {
|
||||
if (typeof props[key as keyof VirtualizedTraceViewProps] === 'function') {
|
||||
(props[key as keyof VirtualizedTraceViewProps] as jest.Mock).mockReset();
|
||||
let key: keyof VirtualizedTraceViewProps;
|
||||
for (key in props) {
|
||||
if (typeof props[key] === 'function') {
|
||||
(props[key] as jest.Mock).mockReset();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('renders service name, operation name and duration for each span', () => {
|
||||
|
@ -903,7 +903,7 @@ export class ElasticDatasource
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const key of Object.keys(obj)) {
|
||||
for (const key in obj) {
|
||||
if (Array.isArray(obj[key])) {
|
||||
for (const item of obj[key]) {
|
||||
if (this.objectContainsTemplate(item)) {
|
||||
|
@ -124,31 +124,33 @@ export function getOperationParamId(operationId: string, paramIndex: number) {
|
||||
}
|
||||
|
||||
export function getRangeVectorParamDef(withRateInterval = false): QueryBuilderOperationParamDef {
|
||||
const param: QueryBuilderOperationParamDef = {
|
||||
name: 'Range',
|
||||
type: 'string',
|
||||
options: [
|
||||
{
|
||||
label: '$__interval',
|
||||
value: '$__interval',
|
||||
// tooltip: 'Dynamic interval based on max data points, scrape and min interval',
|
||||
},
|
||||
{ label: '1m', value: '1m' },
|
||||
{ label: '5m', value: '5m' },
|
||||
{ label: '10m', value: '10m' },
|
||||
{ label: '1h', value: '1h' },
|
||||
{ label: '24h', value: '24h' },
|
||||
],
|
||||
};
|
||||
const options: Array<SelectableValue<string>> = [
|
||||
{
|
||||
label: '$__interval',
|
||||
value: '$__interval',
|
||||
// tooltip: 'Dynamic interval based on max data points, scrape and min interval',
|
||||
},
|
||||
{ label: '1m', value: '1m' },
|
||||
{ label: '5m', value: '5m' },
|
||||
{ label: '10m', value: '10m' },
|
||||
{ label: '1h', value: '1h' },
|
||||
{ label: '24h', value: '24h' },
|
||||
];
|
||||
|
||||
if (withRateInterval) {
|
||||
(param.options as Array<SelectableValue<string>>).unshift({
|
||||
options.unshift({
|
||||
label: '$__rate_interval',
|
||||
value: '$__rate_interval',
|
||||
// tooltip: 'Always above 4x scrape interval',
|
||||
});
|
||||
}
|
||||
|
||||
const param: QueryBuilderOperationParamDef = {
|
||||
name: 'Range',
|
||||
type: 'string',
|
||||
options,
|
||||
};
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ export function getLayerPropertyInfo(features: FeatureLike[]): LayerContentInfo
|
||||
const types = new Set<string>();
|
||||
const props = new Set<string>();
|
||||
features.some((feature, idx) => {
|
||||
for (const key of Object.keys(feature.getProperties())) {
|
||||
for (const key in feature.getProperties()) {
|
||||
if (key === 'geometry') {
|
||||
continue;
|
||||
}
|
||||
|
@ -685,7 +685,7 @@ function validNumber(val: unknown): number | undefined {
|
||||
|
||||
function getReducersFromLegend(obj: Record<string, unknown>): string[] {
|
||||
const ids: string[] = [];
|
||||
for (const key of Object.keys(obj)) {
|
||||
for (const key in obj) {
|
||||
const r = fieldReducers.getIfExists(key);
|
||||
if (r) {
|
||||
ids.push(r.id);
|
||||
|
Loading…
Reference in New Issue
Block a user