Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(system, data-frame): change term 'Metadata' to 'Properties' #83

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SystemMetadata } from "../datasources/system/types";
import { SystemProperties } from "../datasources/system/types";

export interface Workspace {
id: string,
Expand All @@ -16,7 +16,7 @@ export interface QuerySystemsRequest {
}

export interface QuerySystemsResponse {
data: SystemMetadata[]
data: SystemProperties[]
count: number
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
CalibrationForecastResponse,
ColumnDescriptorType,
} from "./types";
import { SystemMetadata } from "datasources/system/types";
import { SystemProperties } from "datasources/system/types";
import { dateTime } from "@grafana/data";

let datastore: AssetCalibrationDataSource, backendServer: MockProxy<BackendSrv>
Expand Down Expand Up @@ -208,7 +208,7 @@ const buildCalibrationForecastQuery = getQueryBuilder<AssetCalibrationQuery>()({
groupBy: []
});

const fakeSystems: SystemMetadata[] = [
const fakeSystems: SystemProperties[] = [
{
id: 'Minion1',
alias: 'Minion1-alias',
Expand Down Expand Up @@ -364,7 +364,7 @@ describe('queries', () => {
expect(result.data).toMatchSnapshot()
})

test('handles metadata query error', async () => {
test('handles properties query error', async () => {
backendServer.fetch
.calledWith(requestMatching({ url: '/niapm/v1/assets/calibration-forecast' }))
.mockReturnValue(createFetchError(418))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { ExpressionTransformFunction, transformComputedFieldsQuery } from 'core/
import { AssetCalibrationFieldNames } from './constants';
import { AssetModel, AssetsResponse } from 'datasources/asset-common/types';
import TTLCache from '@isaacs/ttlcache';
import { metadataCacheTTL } from 'datasources/data-frame/constants';
import { SystemMetadata } from 'datasources/system/types';
import { propertiesCacheTTL } from 'datasources/data-frame/constants';
import { SystemProperties } from 'datasources/system/types';
import { defaultOrderBy, defaultProjection } from 'datasources/system/constants';
import { QueryBuilderOperations } from 'core/query-builder.constants';
import { Workspace } from 'core/types';
Expand All @@ -38,8 +38,8 @@ export class AssetCalibrationDataSource extends DataSourceBase<AssetCalibrationQ

public error = '';

public readonly systemAliasCache: TTLCache<string, SystemMetadata> = new TTLCache<string, SystemMetadata>({ ttl: metadataCacheTTL });
public readonly workspacesCache: TTLCache<string, Workspace> = new TTLCache<string, Workspace>({ ttl: metadataCacheTTL });
public readonly systemAliasCache: TTLCache<string, SystemProperties> = new TTLCache<string, SystemProperties>({ ttl: propertiesCacheTTL });
public readonly workspacesCache: TTLCache<string, Workspace> = new TTLCache<string, Workspace>({ ttl: propertiesCacheTTL });

private readonly baseUrl = this.instanceSettings.url + '/niapm/v1';

Expand Down Expand Up @@ -194,7 +194,7 @@ export class AssetCalibrationDataSource extends DataSourceBase<AssetCalibrationQ
}
}

async querySystems(filter = '', projection = defaultProjection): Promise<SystemMetadata[]> {
async querySystems(filter = '', projection = defaultProjection): Promise<SystemProperties[]> {
try {
let response = await this.getSystems({
filter: filter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import React, { ReactNode } from "react";
import { AssetCalibrationQueryBuilder } from "./AssetCalibrationQueryBuilder";
import { render } from "@testing-library/react";
import { Workspace } from "core/types";
import { SystemMetadata } from "datasources/system/types";
import { SystemProperties } from "datasources/system/types";

describe('AssetCalibrationQueryBuilder', () => {
describe('useEffects', () => {
let reactNode: ReactNode;

const containerClass = 'smart-filter-group-condition-container'

function renderElement(workspaces: Workspace[], systems: SystemMetadata[], filter?: string) {
function renderElement(workspaces: Workspace[], systems: SystemProperties[], filter?: string) {
reactNode = React.createElement(AssetCalibrationQueryBuilder, { workspaces, systems, filter, onChange: jest.fn(), areDependenciesLoaded: true });
const renderResult = render(reactNode);
return {
Expand All @@ -27,7 +27,7 @@ describe('AssetCalibrationQueryBuilder', () => {

it('should select workspace in query builder', () => {
const workspace = { id: '1', name: 'Selected workspace' } as Workspace;
const system = { id: '1', alias: 'Selected system' } as SystemMetadata;
const system = { id: '1', alias: 'Selected system' } as SystemProperties;
const { conditionsContainer } = renderElement([workspace], [system], 'Workspace = "1" && ModelName = "SomeRandomModelName"');

expect(conditionsContainer?.length).toBe(2);
Expand All @@ -37,7 +37,7 @@ describe('AssetCalibrationQueryBuilder', () => {

it('should select system in query builder', () => {
const workspace = { id: '1', name: 'Selected workspace' } as Workspace;
const system = { id: '1', alias: 'Selected system' } as SystemMetadata;
const system = { id: '1', alias: 'Selected system' } as SystemProperties;

const { conditionsContainer } = renderElement([workspace], [system], 'Location = "1"');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import { Workspace, QueryBuilderOption } from 'core/types';
import { QBField } from '../types';
import { queryBuilderMessages, QueryBuilderOperations } from 'core/query-builder.constants';
import { expressionBuilderCallback, expressionReaderCallback } from 'core/query-builder.utils';
import { SystemMetadata } from 'datasources/system/types';
import { SystemProperties } from 'datasources/system/types';

type AssetCalibrationQueryBuilderProps = QueryBuilderProps &
React.HTMLAttributes<Element> & {
filter?: string;
workspaces: Workspace[],
systems: SystemMetadata[],
systems: SystemProperties[],
areDependenciesLoaded: boolean;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import _ from 'lodash';
import { AssetCalibrationQueryBuilder } from './AssetCalibrationQueryBuilder';
import { Workspace } from 'core/types';
import { FloatingError } from 'core/errors';
import { SystemMetadata } from 'datasources/system/types';
import { SystemProperties } from 'datasources/system/types';
import './AssetCalibrationQueryEditor.scss';

type Props = QueryEditorProps<AssetCalibrationDataSource, AssetCalibrationQuery>;

export const AssetCalibrationQueryEditor = ({ query, onChange, onRunQuery, datasource }: Props) => {
query = datasource.prepareQuery(query) as AssetCalibrationQuery;
const [workspaces, setWorkspaces] = useState<Workspace[]>([]);
const [systems, setSystems] = useState<SystemMetadata[]>([]);
const [systems, setSystems] = useState<SystemProperties[]>([]);
const [areDependenciesLoaded, setAreDependenciesLoaded] = useState<boolean>(false);

useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/datasources/asset/components/AssetQueryEditor.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { screen, waitForElementToBeRemoved } from '@testing-library/react';
import { SystemMetadata } from '../../system/types';
import { SystemProperties } from '../../system/types';
import { AssetDataSource } from '../AssetDataSource';
import { setupRenderer } from '../../../test/fixtures';
import { ListAssetsDataSource } from './editors/list-assets/ListAssetsDataSource';
Expand All @@ -12,7 +12,7 @@ import { select } from 'react-select-event';
import { AssetSummaryQuery } from '../types/AssetSummaryQuery.types';
import { AssetFeatureTogglesDefaults } from '../types/types';

const fakeSystems: SystemMetadata[] = [
const fakeSystems: SystemProperties[] = [
{
id: '1',
state: 'CONNECTED',
Expand All @@ -30,7 +30,7 @@ let assetDatasourceOptions = {
}

class FakeAssetsSource extends ListAssetsDataSource {
querySystems(filter?: string, projection?: string[]): Promise<SystemMetadata[]> {
querySystems(filter?: string, projection?: string[]): Promise<SystemProperties[]> {
return Promise.resolve(fakeSystems);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DataQueryRequest, DataFrameDTO, DataSourceInstanceSettings } from '@grafana/data';
import { AssetDataSourceOptions, AssetQuery } from '../../../types/types';
import { AssetModel, AssetsResponse } from '../../../../asset-common/types';
import { SystemMetadata } from '../../../../system/types';
import { SystemProperties } from '../../../../system/types';
import { getWorkspaceName, replaceVariables } from '../../../../../core/utils';
import { BackendSrv, getBackendSrv, getTemplateSrv, TemplateSrv } from '@grafana/runtime';
import { defaultOrderBy, defaultProjection } from '../../../../system/constants';
Expand Down Expand Up @@ -74,7 +74,7 @@ export class ListAssetsDataSource extends AssetDataSourceBase {
}
}

async querySystems(filter = '', projection = defaultProjection): Promise<SystemMetadata[]> {
async querySystems(filter = '', projection = defaultProjection): Promise<SystemProperties[]> {
try {
let response = await this.getSystems({
filter: filter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { screen, waitFor, waitForElementToBeRemoved } from '@testing-library/react';
import { SystemMetadata } from '../../../../system/types';
import { SystemProperties } from '../../../../system/types';
import { AssetDataSource } from '../../../AssetDataSource';
import { AssetQueryEditor } from '../../AssetQueryEditor';
import { setupRenderer } from '../../../../../test/fixtures';
Expand All @@ -8,7 +8,7 @@ import { ListAssetsDataSource } from './ListAssetsDataSource';
import { ListAssetsQuery } from '../../../types/ListAssets.types';
import { AssetFeatureTogglesDefaults } from 'datasources/asset/types/types';

const fakeSystems: SystemMetadata[] = [
const fakeSystems: SystemProperties[] = [
{
id: '1',
state: 'CONNECTED',
Expand All @@ -26,7 +26,7 @@ let assetDatasourceOptions = {
}

class FakeAssetsSource extends ListAssetsDataSource {
querySystems(filter?: string, projection?: string[]): Promise<SystemMetadata[]> {
querySystems(filter?: string, projection?: string[]): Promise<SystemProperties[]> {
return Promise.resolve(fakeSystems);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useAsync } from 'react-use';
import { FloatingError, parseErrorMessage } from '../../../../../core/errors';
import { useWorkspaceOptions } from '../../../../../core/utils';
import { isValidId } from '../../../../data-frame/utils';
import { SystemMetadata } from '../../../../system/types';
import { SystemProperties } from '../../../../system/types';
import { AssetFeatureTogglesDefaults, AssetQuery } from '../../../types/types';
import { ListAssetsDataSource } from './ListAssetsDataSource';
import { ListAssetsQuery } from '../../../types/ListAssets.types';
Expand Down Expand Up @@ -56,7 +56,7 @@ export function ListAssetsEditor({ query, handleQueryChange, datasource }: Props
};
const loadMinionIdOptions = (): Array<SelectableValue<string>> => {
let options: SelectableValue[] = (minionIds.value ?? []).map(
(system: SystemMetadata): SelectableValue<string> => ({
(system: SystemProperties): SelectableValue<string> => ({
label: system.alias ?? system.id,
value: system.id,
description: system.state,
Expand Down
28 changes: 14 additions & 14 deletions src/datasources/data-frame/DataFrameDataSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { of, Observable } from 'rxjs';
import { DataQueryRequest, DataSourceInstanceSettings, dateTime, Field, FieldType } from '@grafana/data';
import { BackendSrvRequest, FetchResponse } from '@grafana/runtime';

import { DataFrameQuery, DataFrameQueryType, TableDataRows, TableMetadata } from './types';
import { DataFrameQuery, DataFrameQueryType, TableDataRows, TableProperties } from './types';
import { DataFrameDataSource } from './DataFrameDataSource';

jest.mock('@grafana/runtime', () => ({
Expand Down Expand Up @@ -171,7 +171,7 @@ it('should provide decimation parameters correctly', async () => {
);
});

it('should cache table metadata for subsequent requests', async () => {
it('should cache table properties for subsequent requests', async () => {
const query = buildQuery([{ refId: 'A', type: DataFrameQueryType.Data, tableId: '1', columns: ['int'] }]);

await ds.query(query);
Expand All @@ -184,7 +184,7 @@ it('should cache table metadata for subsequent requests', async () => {
expect(fetchMock).toHaveBeenCalledTimes(3);
});

it('should return error if query columns do not match table metadata', async () => {
it('should return error if query columns do not match table properties', async () => {
const query = buildQuery([{ refId: 'A', type: DataFrameQueryType.Data, tableId: '1', columns: ['nonexistent'] }]);

await expect(ds.query(query)).rejects.toEqual(expect.anything());
Expand All @@ -204,11 +204,11 @@ it('should migrate queries using columns of arrays of objects', async () => {
expect(fetchMock).toHaveBeenCalledWith(expect.objectContaining({ data: expect.objectContaining({ columns: ['float'] }) }));
});

it('attempts to replace variables in metadata query', async () => {
it('attempts to replace variables in properties query', async () => {
const tableId = '$tableId';
replaceMock.mockReturnValueOnce('1');

await ds.getTableMetadata(tableId);
await ds.getTableProperties(tableId);

expect(replaceMock).toHaveBeenCalledTimes(1);
expect(replaceMock).toHaveBeenCalledWith(tableId);
Expand All @@ -228,16 +228,16 @@ it('attempts to replace variables in data query', async () => {

it('metricFindQuery returns table columns', async () => {
const tableId = '1';
const expectedColumns = fakeMetadataResponse.columns.map(col => ({ text: col.name, value: col.name }));
const expectedColumns = fakePropertiesResponse.columns.map(col => ({ text: col.name, value: col.name }));

const columns = await ds.metricFindQuery({ tableId } as DataFrameQuery);

expect(fetchMock).toHaveBeenCalledWith(expect.objectContaining({ url: `_/nidataframe/v1/tables/${tableId}` }));
expect(columns).toEqual(expect.arrayContaining(expectedColumns));
});

it('returns table properties for metadata query', async () => {
const query = buildQuery([{ refId: 'A', type: DataFrameQueryType.Metadata, tableId: '1' }]);
it('returns table properties for properties query', async () => {
const query = buildQuery([{ refId: 'A', type: DataFrameQueryType.Properties, tableId: '1' }]);

const response = await ds.query(query);

Expand All @@ -248,8 +248,8 @@ it('returns table properties for metadata query', async () => {
])
});

it('handles metadata query when table has no properties', async () => {
const query = buildQuery([{ refId: 'A', type: DataFrameQueryType.Metadata, tableId: '2' }]);
it('handles properties query when table has no properties', async () => {
const query = buildQuery([{ refId: 'A', type: DataFrameQueryType.Properties, tableId: '2' }]);

const response = await ds.query(query);

Expand All @@ -267,11 +267,11 @@ const buildQuery = (targets: DataFrameQuery[]): DataQueryRequest<DataFrameQuery>
const setupFetchMock = () => {
fetchMock.mockImplementation((options: BackendSrvRequest) => {
if (/\/tables\/1$/.test(options.url)) {
return of(createFetchResponse(fakeMetadataResponse));
return of(createFetchResponse(fakePropertiesResponse));
}

if (/\/tables\/2$/.test(options.url)) {
return of(createFetchResponse(fakeMetadataResponseNoProperties));
return of(createFetchResponse(fakePropertiesResponseNoProperties));
}

if (/\/tables\/\w+\/query-decimated-data$/.test(options.url)) {
Expand All @@ -296,7 +296,7 @@ const createFetchResponse = <T>(data: T): FetchResponse<T> => {
};
};

const fakeMetadataResponse: TableMetadata = {
const fakePropertiesResponse: TableProperties = {
columns: [
{ name: 'time', dataType: 'TIMESTAMP', columnType: 'INDEX', properties: {} },
{ name: 'int', dataType: 'INT32', columnType: 'NORMAL', properties: {} },
Expand All @@ -311,7 +311,7 @@ const fakeMetadataResponse: TableMetadata = {
workspace: '_',
};

const fakeMetadataResponseNoProperties: TableMetadata = {
const fakePropertiesResponseNoProperties: TableProperties = {
columns: [{ name: 'time', dataType: 'TIMESTAMP', columnType: 'INDEX', properties: {} }],
id: '_',
properties: {},
Expand Down
Loading
Loading