mirror of
https://github.com/grafana/grafana.git
synced 2025-01-11 00:22:06 -06:00
Chore: Update to typescript 5 (#76511)
* Update dependency typescript to v5 * Update yarn.lock * Fix typescript errors * Update typescript version sdk * Revert useDescription.ts * Fix ts errors * Fix Typescript errors after Symbol.unscopables type change * Fix colormanipulator errors * Update packages/grafana-data/src/vector/FunctionalVector.ts * Fix ts errors in dashboardmigrator * Fix sandbox component typescript error * Update yarn * Update to typescript 5.2 * Fix typescript error * update typescript/vscode patch/sdk/whatever * fix ts errors in elasticsearch * Fix two errors in alerting * Fix error in dashboard-scene * Fix errors in dashboard tests * Fix errors in explore tests * Fix error in plugins sandbox * fix error in DashboardQueryRunner * fix errors in grafana-data * fix errors in PanelChrome story * update betterer * better fix for cloud monitoring * fix error in reducer tester --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com> Co-authored-by: Josh Hunt <joshhunt@users.noreply.github.com> Co-authored-by: joshhunt <josh@trtr.co>
This commit is contained in:
parent
895c1374e5
commit
0b03344baa
@ -4669,9 +4669,6 @@ exports[`better eslint`] = {
|
||||
"public/app/features/plugins/sandbox/distortion_map.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
],
|
||||
"public/app/features/plugins/sandbox/sandbox_components.tsx:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||
],
|
||||
"public/app/features/plugins/sandbox/sandbox_plugin_loader.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
@ -5542,12 +5539,11 @@ exports[`better eslint`] = {
|
||||
],
|
||||
"public/app/plugins/datasource/cloud-monitoring/datasource.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "2"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "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.", "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.", "4"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "5"]
|
||||
],
|
||||
"public/app/plugins/datasource/cloud-monitoring/functions.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
|
2
.yarn/sdks/typescript/package.json
vendored
2
.yarn/sdks/typescript/package.json
vendored
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "typescript",
|
||||
"version": "4.8.4-sdk",
|
||||
"version": "5.2.2-sdk",
|
||||
"main": "./lib/typescript.js",
|
||||
"type": "commonjs",
|
||||
"bin": {
|
||||
|
@ -7,7 +7,7 @@ enableTelemetry: false
|
||||
nodeLinker: pnp
|
||||
|
||||
packageExtensions:
|
||||
'@storybook/core-common@7.4.5':
|
||||
"@storybook/core-common@7.4.5":
|
||||
dependencies:
|
||||
'@storybook/react-webpack5': 7.4.5
|
||||
doctrine@3.0.0:
|
||||
@ -26,14 +26,14 @@ packageExtensions:
|
||||
react-simple-compat: 1.2.2
|
||||
react-icons@2.2.7:
|
||||
peerDependencies:
|
||||
prop-types: '*'
|
||||
prop-types: "*"
|
||||
react-resizable@3.0.4:
|
||||
peerDependencies:
|
||||
react-dom: 17.0.1
|
||||
|
||||
plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-outdated.cjs
|
||||
spec: 'https://mskelton.dev/yarn-outdated/v2'
|
||||
spec: "https://mskelton.dev/yarn-outdated/v2"
|
||||
|
||||
yarnPath: .yarn/releases/yarn-4.0.0.cjs
|
||||
# Uncomment the following lines if you want to use Verdaccio local npm registry. Read more at packages/README.md
|
||||
|
@ -226,7 +226,7 @@
|
||||
"tracelib": "1.0.1",
|
||||
"ts-jest": "29.1.1",
|
||||
"ts-node": "10.9.1",
|
||||
"typescript": "4.8.4",
|
||||
"typescript": "5.2.2",
|
||||
"webpack": "5.89.0",
|
||||
"webpack-bundle-analyzer": "4.9.0",
|
||||
"webpack-cli": "5.1.4",
|
||||
|
@ -91,7 +91,7 @@
|
||||
"rollup-plugin-dts": "^5.0.0",
|
||||
"rollup-plugin-esbuild": "5.0.0",
|
||||
"rollup-plugin-node-externals": "^5.0.0",
|
||||
"typescript": "4.8.4"
|
||||
"typescript": "5.2.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^17.0.0 || ^18.0.0",
|
||||
|
@ -32,9 +32,15 @@ export function hexToRgb(color: string) {
|
||||
color = color.slice(1);
|
||||
|
||||
const re = new RegExp(`.{1,${color.length >= 6 ? 2 : 1}}`, 'g');
|
||||
let colors = color.match(re);
|
||||
let result = color.match(re);
|
||||
|
||||
if (colors && colors[0].length === 1) {
|
||||
if (!result) {
|
||||
return '';
|
||||
}
|
||||
|
||||
let colors = Array.from(result);
|
||||
|
||||
if (colors[0].length === 1) {
|
||||
colors = colors.map((n) => n + n);
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ export interface DataSourceWithLogsContextSupport<TQuery extends DataQuery = Dat
|
||||
}
|
||||
|
||||
export const hasLogsContextSupport = (datasource: unknown): datasource is DataSourceWithLogsContextSupport => {
|
||||
if (!datasource) {
|
||||
if (!datasource || typeof datasource !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -253,7 +253,7 @@ export const hasSupplementaryQuerySupport = <TQuery extends DataQuery>(
|
||||
};
|
||||
|
||||
export const hasLogsContextUiSupport = (datasource: unknown): datasource is DataSourceWithLogsContextSupport => {
|
||||
if (!datasource) {
|
||||
if (!datasource || typeof datasource !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -66,9 +66,10 @@ export interface DataSourceWithQueryExportSupport<TQuery extends SchemaDataQuery
|
||||
export const hasQueryImportSupport = <TQuery extends SchemaDataQuery>(
|
||||
datasource: unknown
|
||||
): datasource is DataSourceWithQueryImportSupport<TQuery> => {
|
||||
if (!datasource) {
|
||||
if (!datasource || typeof datasource !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return 'importFromAbstractQueries' in datasource;
|
||||
};
|
||||
|
||||
@ -78,7 +79,7 @@ export const hasQueryImportSupport = <TQuery extends SchemaDataQuery>(
|
||||
export const hasQueryExportSupport = <TQuery extends SchemaDataQuery>(
|
||||
datasource: unknown
|
||||
): datasource is DataSourceWithQueryExportSupport<TQuery> => {
|
||||
if (!datasource) {
|
||||
if (!datasource || typeof datasource !== 'object') {
|
||||
return false;
|
||||
}
|
||||
return 'exportToAbstractQueries' in datasource;
|
||||
|
@ -101,18 +101,8 @@ export abstract class FunctionalVector<T = any> implements Vector<T> {
|
||||
copyWithin(target: number, start: number, end?: number | undefined): this {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
[Symbol.unscopables](): {
|
||||
copyWithin: boolean;
|
||||
entries: boolean;
|
||||
fill: boolean;
|
||||
find: boolean;
|
||||
findIndex: boolean;
|
||||
keys: boolean;
|
||||
values: boolean;
|
||||
} {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
// Object not implemented
|
||||
[Symbol.unscopables] = {};
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// Delegated Array function -- these will not be efficient :grimmice:
|
||||
|
@ -52,6 +52,6 @@
|
||||
"dependencies": {
|
||||
"@grafana/tsconfig": "^1.2.0-rc1",
|
||||
"tslib": "2.6.0",
|
||||
"typescript": "4.8.4"
|
||||
"typescript": "5.2.2"
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@
|
||||
"tracelib": "1.0.1",
|
||||
"ts-loader": "8.4.0",
|
||||
"tslib": "2.6.0",
|
||||
"typescript": "4.8.4",
|
||||
"typescript": "5.2.2",
|
||||
"uuid": "9.0.0",
|
||||
"yaml": "^2.0.0"
|
||||
}
|
||||
|
@ -79,7 +79,7 @@
|
||||
"rollup-plugin-node-externals": "^5.0.0",
|
||||
"ts-jest": "29.1.1",
|
||||
"ts-node": "10.9.1",
|
||||
"typescript": "4.8.4"
|
||||
"typescript": "5.2.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^17.0.0 || ^18.0.0",
|
||||
|
@ -73,7 +73,7 @@
|
||||
"rollup-plugin-node-externals": "^5.0.0",
|
||||
"rollup-plugin-sourcemaps": "0.6.3",
|
||||
"rollup-plugin-terser": "7.0.2",
|
||||
"typescript": "4.8.4"
|
||||
"typescript": "5.2.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^17.0.0 || ^18.0.0",
|
||||
|
@ -47,7 +47,7 @@
|
||||
"rollup-plugin-dts": "^5.0.0",
|
||||
"rollup-plugin-esbuild": "5.0.0",
|
||||
"rollup-plugin-node-externals": "^5.0.0",
|
||||
"typescript": "4.8.4"
|
||||
"typescript": "5.2.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"tslib": "2.6.0"
|
||||
|
@ -185,7 +185,7 @@
|
||||
"storybook-addon-turbo-build": "2.0.1",
|
||||
"storybook-dark-mode": "3.0.1",
|
||||
"style-loader": "3.3.3",
|
||||
"typescript": "4.8.4",
|
||||
"typescript": "5.2.2",
|
||||
"webpack": "5.89.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
@ -51,7 +51,7 @@ function renderPanel(name: string, overrides?: Partial<PanelChromeProps>) {
|
||||
|
||||
return (
|
||||
<PanelChrome {...props}>
|
||||
{(innerWidth, innerHeight) => {
|
||||
{(innerWidth: number, innerHeight: number) => {
|
||||
return <div style={{ width: innerWidth, height: innerHeight, ...contentStyle }}>{name}</div>;
|
||||
}}
|
||||
</PanelChrome>
|
||||
@ -75,7 +75,7 @@ function renderCollapsiblePanel(name: string, overrides?: Partial<PanelChromePro
|
||||
|
||||
return (
|
||||
<PanelChrome {...props} collapsed={collapsed} onToggleCollapse={toggleCollapsed}>
|
||||
{(innerWidth, innerHeight) => {
|
||||
{(innerWidth: number, innerHeight: number) => {
|
||||
return <div style={{ width: innerWidth, height: innerHeight, ...contentStyle }}>{name}</div>;
|
||||
}}
|
||||
</PanelChrome>
|
||||
|
@ -381,7 +381,7 @@ function hasNegSample(data: unknown[], samples = 100) {
|
||||
for (let i = firstIdx; i <= lastIdx; i += stride) {
|
||||
const v = data[i];
|
||||
|
||||
if (v != null) {
|
||||
if (v != null && typeof v === 'number') {
|
||||
if (v < 0 || Object.is(v, -0)) {
|
||||
negCount++;
|
||||
} else if (v > 0) {
|
||||
|
@ -215,7 +215,6 @@ describe('CloneRuleEditor', function () {
|
||||
render(
|
||||
<CloneRuleEditor
|
||||
sourceRuleId={{
|
||||
uid: 'prom-rule-1',
|
||||
ruleSourceName: 'my-prom-ds',
|
||||
namespace: 'namespace-one',
|
||||
groupName: 'group1',
|
||||
|
@ -161,7 +161,8 @@ const alertStateToStateMap: Record<PromAlertingRuleState | GrafanaAlertState | A
|
||||
[AlertState.Paused]: 'warning',
|
||||
[AlertState.Alerting]: 'bad',
|
||||
[AlertState.OK]: 'good',
|
||||
[AlertState.Pending]: 'warning',
|
||||
// AlertState.Pending is not included because the 'pending' value is already covered by `PromAlertingRuleState.Pending`
|
||||
// [AlertState.Pending]: 'warning',
|
||||
[AlertState.Unknown]: 'info',
|
||||
};
|
||||
|
||||
|
@ -120,5 +120,5 @@ export function toggleVizPanelLegend(vizPanel: VizPanel) {
|
||||
}
|
||||
|
||||
function hasLegendOptions(optionsWithLegend: unknown): optionsWithLegend is OptionsWithLegend {
|
||||
return optionsWithLegend != null && 'legend' in optionsWithLegend;
|
||||
return optionsWithLegend != null && typeof optionsWithLegend === 'object' && 'legend' in optionsWithLegend;
|
||||
}
|
||||
|
@ -1079,12 +1079,14 @@ describe('DashboardModel', () => {
|
||||
type: 'query',
|
||||
name: 'variable_with_unknown_refresh_with_options',
|
||||
options: [{ text: 'A', value: 'A' }],
|
||||
// @ts-expect-error
|
||||
refresh: 2001,
|
||||
},
|
||||
{
|
||||
type: 'query',
|
||||
name: 'variable_with_unknown_refresh_without_options',
|
||||
options: [],
|
||||
// @ts-expect-error
|
||||
refresh: 2001,
|
||||
},
|
||||
{
|
||||
@ -1904,13 +1906,13 @@ describe('DashboardModel', () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
// @ts-expect-error
|
||||
{
|
||||
type: 'row',
|
||||
id: 5,
|
||||
panels: [
|
||||
{
|
||||
id: 6,
|
||||
// @ts-expect-error
|
||||
datasource: 'prom',
|
||||
},
|
||||
],
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { keys as _keys } from 'lodash';
|
||||
|
||||
import { dateTime, TimeRange, VariableHide } from '@grafana/data';
|
||||
import { Dashboard, defaultVariableModel } from '@grafana/schema';
|
||||
import { Dashboard, defaultVariableModel, RowPanel } from '@grafana/schema';
|
||||
|
||||
import { getDashboardModel } from '../../../../test/helpers/getDashboardModel';
|
||||
import { variableAdapters } from '../../variables/adapters';
|
||||
@ -538,6 +538,14 @@ describe('DashboardModel', () => {
|
||||
let dashboard: DashboardModel;
|
||||
|
||||
beforeEach(() => {
|
||||
const panels: RowPanel['panels'] = [
|
||||
// this whole test is about dealing with out-of-spec (or at least ambigious) data...
|
||||
// @ts-expect-error
|
||||
{ id: 3, type: 'graph', gridPos: { w: 12, h: 2 } },
|
||||
// @ts-expect-error
|
||||
{ id: 4, type: 'graph', gridPos: { w: 12, h: 2 } },
|
||||
];
|
||||
|
||||
dashboard = createDashboardModelFixture({
|
||||
panels: [
|
||||
{ id: 1, type: 'graph', gridPos: { x: 0, y: 0, w: 24, h: 6 } },
|
||||
@ -546,13 +554,7 @@ describe('DashboardModel', () => {
|
||||
type: 'row',
|
||||
gridPos: { x: 0, y: 6, w: 24, h: 1 },
|
||||
collapsed: true,
|
||||
panels: [
|
||||
// this whole test is about dealing with out-of-spec (or at least ambigious) data...
|
||||
//@ts-expect-error
|
||||
{ id: 3, type: 'graph', gridPos: { w: 12, h: 2 } },
|
||||
//@ts-expect-error
|
||||
{ id: 4, type: 'graph', gridPos: { w: 12, h: 2 } },
|
||||
],
|
||||
panels: panels,
|
||||
},
|
||||
{ id: 5, type: 'row', collapsed: false, panels: [], gridPos: { x: 0, y: 7, w: 1, h: 1 } },
|
||||
],
|
||||
|
@ -35,7 +35,7 @@ function mapStateToProps(state: StoreState, { exploreId }: RawPrometheusContaine
|
||||
const { tableResult, rawPrometheusResult, range } = item;
|
||||
const loadingInState = selectIsWaitingForData(exploreId)(state);
|
||||
const rawPrometheusFrame: DataFrame[] = rawPrometheusResult ? [rawPrometheusResult] : [];
|
||||
const result = (tableResult?.length ?? false) > 0 && rawPrometheusResult ? tableResult : rawPrometheusFrame;
|
||||
const result = (tableResult?.length ?? 0) > 0 && rawPrometheusResult ? tableResult : rawPrometheusFrame;
|
||||
const loading = result && result.length > 0 ? false : loadingInState;
|
||||
|
||||
return { loading, tableResult: result, range };
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { flattenDeep } from 'lodash';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
|
||||
import {
|
||||
@ -409,9 +408,11 @@ describe('decorateWithCorrelations', () => {
|
||||
correlations: [],
|
||||
defaultTargetDatasource: undefined,
|
||||
})(panelData);
|
||||
expect(
|
||||
flattenDeep(postDecoratedPanel.series.map((frame) => frame.fields.map((field) => field.config.links)))
|
||||
).toEqual([]);
|
||||
|
||||
const flattenedLinks = postDecoratedPanel.series
|
||||
.flatMap((frame) => frame.fields)
|
||||
.flatMap((field) => field.config.links);
|
||||
expect(flattenedLinks).toEqual([]);
|
||||
});
|
||||
|
||||
it('returns one field link per field if there are no correlations, but there are editor links', () => {
|
||||
@ -430,9 +431,11 @@ describe('decorateWithCorrelations', () => {
|
||||
correlations: [],
|
||||
defaultTargetDatasource: datasource,
|
||||
})(panelData);
|
||||
const flattenedLinks = flattenDeep(
|
||||
postDecoratedPanel.series.map((frame) => frame.fields.map((field) => field.config.links))
|
||||
);
|
||||
|
||||
const flattenedLinks = postDecoratedPanel.series
|
||||
.flatMap((frame) => frame.fields)
|
||||
.flatMap((field) => field.config.links);
|
||||
|
||||
expect(flattenedLinks.length).toEqual(table.fields.length);
|
||||
expect(flattenedLinks[0]).not.toBeUndefined();
|
||||
});
|
||||
@ -454,9 +457,11 @@ describe('decorateWithCorrelations', () => {
|
||||
correlations: correlations,
|
||||
defaultTargetDatasource: datasource,
|
||||
})(panelData);
|
||||
const flattenedLinks = flattenDeep(
|
||||
postDecoratedPanel.series.map((frame) => frame.fields.map((field) => field.config.links))
|
||||
);
|
||||
|
||||
const flattenedLinks = postDecoratedPanel.series
|
||||
.flatMap((frame) => frame.fields)
|
||||
.flatMap((field) => field.config.links);
|
||||
|
||||
expect(flattenedLinks.length).toEqual(table.fields.length);
|
||||
expect(flattenedLinks[0]).not.toBeUndefined();
|
||||
});
|
||||
@ -487,8 +492,11 @@ describe('decorateWithCorrelations', () => {
|
||||
correlations: correlations,
|
||||
defaultTargetDatasource: undefined,
|
||||
})(panelData);
|
||||
expect(
|
||||
flattenDeep(postDecoratedPanel.series.map((frame) => frame.fields.map((field) => field.config.links))).length
|
||||
).toEqual(correlations.length);
|
||||
|
||||
const flattenedLinks = postDecoratedPanel.series
|
||||
.flatMap((frame) => frame.fields)
|
||||
.flatMap((field) => field.config.links);
|
||||
|
||||
expect(flattenedLinks.length).toEqual(correlations.length);
|
||||
});
|
||||
});
|
||||
|
@ -146,7 +146,7 @@ export function InspectJSONTab({ panel, dashboard, data, onClose }: Props) {
|
||||
height={height}
|
||||
language="json"
|
||||
showLineNumbers={true}
|
||||
showMiniMap={(text && text.length) > 100}
|
||||
showMiniMap={text.length > 100}
|
||||
value={text || ''}
|
||||
readOnly={!isPanelJSON}
|
||||
onBlur={setText}
|
||||
|
@ -535,7 +535,7 @@ function adjustMetaInfo(logsModel: LogsModel, visibleRangeMs?: number, requested
|
||||
const limitIndex = logsModelMeta.findIndex((meta) => meta.label === LIMIT_LABEL);
|
||||
const limit = limitIndex >= 0 && logsModelMeta[limitIndex]?.value;
|
||||
|
||||
if (limit && limit > 0) {
|
||||
if (limit && typeof limit === 'number' && limit > 0) {
|
||||
let metaLimitValue;
|
||||
|
||||
if (limit === logsModel.rows.length && visibleRangeMs && requestedRangeMs) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { isFunction } from 'lodash';
|
||||
import React, { ComponentType, FC } from 'react';
|
||||
|
||||
import { PluginConfigPage, PluginExtensionConfig, PluginMeta, PluginType } from '@grafana/data';
|
||||
import { GrafanaPlugin, PluginExtensionConfig, PluginMeta, PluginType } from '@grafana/data';
|
||||
|
||||
import { SandboxedPluginObject } from './types';
|
||||
import { isSandboxedPluginObject } from './utils';
|
||||
@ -70,7 +70,8 @@ export async function sandboxPluginComponents(
|
||||
|
||||
// config pages
|
||||
if (Reflect.has(pluginObject, 'configPages')) {
|
||||
const configPages: Record<string, PluginConfigPage<any>> = Reflect.get(pluginObject, 'configPages');
|
||||
const configPages: NonNullable<GrafanaPlugin['configPages']> = Reflect.get(pluginObject, 'configPages') ?? [];
|
||||
|
||||
for (const [key, value] of Object.entries(configPages)) {
|
||||
if (!value.body || !isFunction(value.body)) {
|
||||
continue;
|
||||
|
@ -59,7 +59,7 @@ export class AnnotationsWorker implements DashboardQueryRunnerWorker {
|
||||
}
|
||||
|
||||
return datasourceObservable.pipe(
|
||||
mergeMap((datasource?: DataSourceApi) => {
|
||||
mergeMap((datasource: DataSourceApi | undefined) => {
|
||||
const runner = this.runners.find((r) => r.canRun(datasource));
|
||||
if (!runner) {
|
||||
return of([]);
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
import React, { ComponentProps } from 'react';
|
||||
import { selectOptionInTest } from 'test/helpers/selectOptionInTest';
|
||||
|
||||
import { selectors } from '@grafana/e2e-selectors';
|
||||
@ -43,7 +43,7 @@ const props = {
|
||||
{ text: 'Prometheus', value: null }, // default datasource
|
||||
{ text: 'Loki', value: { type: 'loki-ds', uid: 'abc' } },
|
||||
],
|
||||
},
|
||||
} as ComponentProps<typeof AdHocVariableEditor>['extended'],
|
||||
variable: adHocBuilder().withId('adhoc').withRootStateKey('key').withName('adhoc').build(),
|
||||
onPropChange: jest.fn(),
|
||||
|
||||
|
@ -89,7 +89,7 @@ export default class CloudMonitoringDatasource extends DataSourceWithBackend<
|
||||
projectName: string,
|
||||
aggregation?: Aggregation,
|
||||
timeRange?: TimeRange
|
||||
) {
|
||||
): Promise<{ [k: string]: string[] }> {
|
||||
const options = {
|
||||
targets: [
|
||||
{
|
||||
@ -130,11 +130,13 @@ export default class CloudMonitoringDatasource extends DataSourceWithBackend<
|
||||
},
|
||||
});
|
||||
}),
|
||||
|
||||
map(({ data }) => {
|
||||
const dataQueryResponse = toDataQueryResponse({
|
||||
data: data,
|
||||
});
|
||||
const labels = dataQueryResponse?.data
|
||||
|
||||
const labels: Record<string, Set<string>> = dataQueryResponse?.data
|
||||
.map((f) => f.meta?.custom?.labels)
|
||||
.filter((p) => !!p)
|
||||
.reduce((acc, labels) => {
|
||||
@ -148,10 +150,11 @@ export default class CloudMonitoringDatasource extends DataSourceWithBackend<
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
return Object.fromEntries(
|
||||
Object.entries(labels).map((l: any) => {
|
||||
l[1] = Array.from(l[1]);
|
||||
return l;
|
||||
Object.entries(labels).map(([key, value]) => {
|
||||
const fromArr = Array.from(value);
|
||||
return [key, fromArr];
|
||||
})
|
||||
);
|
||||
})
|
||||
|
@ -198,19 +198,22 @@ function normalizeQuery(query: string) {
|
||||
}
|
||||
|
||||
function isLeftOnlyAST(ast: unknown): ast is LeftOnlyAST {
|
||||
if (!ast) {
|
||||
if (!ast || typeof ast !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ('left' in ast && !('right' in ast)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isBinaryAST(ast: unknown): ast is BinaryAST {
|
||||
if (!ast) {
|
||||
if (!ast || typeof ast !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ('left' in ast && 'right' in ast) {
|
||||
return true;
|
||||
}
|
||||
@ -222,12 +225,10 @@ function isAST(ast: unknown): ast is AST {
|
||||
}
|
||||
|
||||
function isNodeTerm(ast: unknown): ast is NodeTerm {
|
||||
if (!ast) {
|
||||
return false;
|
||||
}
|
||||
if ('term' in ast) {
|
||||
if (ast && typeof ast === 'object' && 'term' in ast) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -182,7 +182,7 @@ export function runFetchStream(
|
||||
data.refId = target.refId;
|
||||
data.name = target.alias || 'Fetch ' + target.refId;
|
||||
|
||||
let reader: ReadableStreamReader<Uint8Array>;
|
||||
let reader: ReadableStreamDefaultReader<Uint8Array>;
|
||||
const csv = new CSVReader({
|
||||
callback: {
|
||||
onHeader: (fields: Field[]) => {
|
||||
|
@ -25,32 +25,29 @@ export interface Then<State> {
|
||||
whenActionIsDispatched: (action: AnyAction) => Then<State>;
|
||||
}
|
||||
|
||||
const isNotException = (object: unknown, propertyName: string) =>
|
||||
typeof object === 'function'
|
||||
? propertyName !== 'caller' && propertyName !== 'callee' && propertyName !== 'arguments'
|
||||
: true;
|
||||
|
||||
export const deepFreeze = <T>(obj: T): T => {
|
||||
Object.freeze(obj);
|
||||
if (typeof obj === 'object') {
|
||||
for (const key in obj) {
|
||||
const prop = obj[key];
|
||||
|
||||
const isNotException = (object: unknown, propertyName: string) =>
|
||||
typeof object === 'function'
|
||||
? propertyName !== 'caller' && propertyName !== 'callee' && propertyName !== 'arguments'
|
||||
: true;
|
||||
const hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
|
||||
if (obj && obj instanceof Object) {
|
||||
const object: Record<string, unknown> = obj;
|
||||
Object.getOwnPropertyNames(object).forEach((propertyName) => {
|
||||
const objectProperty = object[propertyName];
|
||||
if (
|
||||
hasOwnProp.call(object, propertyName) &&
|
||||
isNotException(object, propertyName) &&
|
||||
objectProperty &&
|
||||
(typeof objectProperty === 'object' || typeof objectProperty === 'function') &&
|
||||
Object.isFrozen(objectProperty) === false
|
||||
prop &&
|
||||
Object.hasOwn(obj, key) &&
|
||||
isNotException(obj, key) &&
|
||||
(typeof prop === 'object' || typeof prop === 'function') &&
|
||||
!Object.isFrozen(prop)
|
||||
) {
|
||||
deepFreeze(objectProperty);
|
||||
deepFreeze(prop);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
return Object.freeze(obj);
|
||||
};
|
||||
|
||||
interface ReducerTester<State> extends Given<State>, When<State>, Then<State> {}
|
||||
|
Loading…
Reference in New Issue
Block a user