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

Merged
merged 13 commits into from
Jan 16, 2025
Merged
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
6 changes: 4 additions & 2 deletions src/core/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { SystemMetadata } from "../datasources/system/types";
import { SystemProperties } from "../datasources/system/types";

export const LEGACY_METADATA_TYPE = 'Metadata';

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

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

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, waitFor } from '@testing-library/react';
import { SystemMetadata } from '../../system/types';
import { SystemProperties } from '../../system/types';
import { AssetDataSource } from '../AssetDataSource';
import { setupRenderer } from '../../../test/fixtures';
import { CalibrationForecastDataSource } from '../data-sources/calibration-forecast/CalibrationForecastDataSource';
Expand All @@ -12,7 +12,7 @@ import { AssetFeatureTogglesDefaults, AssetQueryType } from '../types/types';
import { ListAssetsDataSource } from '../data-sources/list-assets/ListAssetsDataSource';
import { AssetSummaryDataSource } from '../data-sources/asset-summary/AssetSummaryDataSource';

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
Expand Up @@ -9,7 +9,7 @@ import {
import _ from 'lodash';
import { SelectableValue, toOption } from '@grafana/data';
import { Workspace } from '../../../../../core/types';
import { SystemMetadata } from '../../../../system/types';
import { SystemProperties } from '../../../../system/types';
import { InlineField, MultiSelect } from '@grafana/ui';
import { FloatingError } from '../../../../../core/errors';
import { enumToOptions } from '../../../../../core/utils';
Expand All @@ -25,7 +25,7 @@ type Props = {
export function CalibrationForecastEditor({ query, handleQueryChange, datasource }: Props) {
query = datasource.prepareQuery(query) as CalibrationForecastQuery;
const [workspaces, setWorkspaces] = useState<Workspace[]>([]);
const [systems, setSystems] = useState<SystemMetadata[]>([]);
const [systems, setSystems] = useState<SystemProperties[]>([]);
const [areDependenciesLoaded, setAreDependenciesLoaded] = useState<boolean>(false);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import React, { ReactNode } from "react";
import { CalibrationForecastQueryBuilder } from "./CalibrationForecastQueryBuilder";
import { render } from "@testing-library/react";
import { QueryBuilderOption, Workspace } from "core/types";
import { SystemMetadata } from "datasources/system/types";
import { SystemProperties } from "datasources/system/types";

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

const containerClass = 'smart-filter-group-condition-container';
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;

function renderElement(workspaces: Workspace[], systems: SystemMetadata[], filter?: string, globalVariableOptions: QueryBuilderOption[] = []) {
function renderElement(workspaces: Workspace[], systems: SystemProperties[], filter?: string, globalVariableOptions: QueryBuilderOption[] = []) {
reactNode = React.createElement(CalibrationForecastQueryBuilder, { workspaces, systems, filter, globalVariableOptions, onChange: jest.fn(), areDependenciesLoaded: true });
const renderResult = render(reactNode);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'smart-webcomponents-react/source/styles/components/smart.querybuilder.cs
import { Workspace, QueryBuilderOption } from 'core/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';
import { QBField } from '../../../../types/CalibrationForecastQuery.types';
import { AssetCalibrationFields, AssetCalibrationStaticFields } from '../../../../constants/CalibrationForecastQuery.constants';
import { filterXSSField, filterXSSLINQExpression } from 'core/utils';
Expand All @@ -20,7 +20,7 @@ type CalibrationForecastQueryBuilderProps = QueryBuilderProps &
React.HTMLAttributes<Element> & {
filter?: string;
workspaces: Workspace[];
systems: SystemMetadata[];
systems: SystemProperties[];
globalVariableOptions: QueryBuilderOption[];
areDependenciesLoaded: boolean;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { screen, waitFor } 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';
import { ListAssetsQuery } from '../../../types/ListAssets.types';
import { AssetFeatureTogglesDefaults } from 'datasources/asset/types/types';
import { ListAssetsDataSource } from '../../../data-sources/list-assets/ListAssetsDataSource';

const fakeSystems: SystemMetadata[] = [
const fakeSystems: SystemProperties[] = [
{
id: '1',
state: 'CONNECTED',
Expand All @@ -25,7 +25,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 @@ -3,7 +3,7 @@ import React, { useEffect, useState } from 'react';
import { InlineField } from '@grafana/ui';
import _ from 'lodash';
import { FloatingError } from '../../../../../core/errors';
import { SystemMetadata } from '../../../../system/types';
import { SystemProperties } from '../../../../system/types';
import { AssetQuery } from '../../../types/types';
import { ListAssetsQuery } from '../../../types/ListAssets.types';
import { AssetQueryBuilder } from './query-builder/AssetQueryBuilder';
Expand All @@ -18,7 +18,7 @@ type Props = {

export function ListAssetsEditor({ query, handleQueryChange, datasource }: Props) {
const [workspaces, setWorkspaces] = useState<Workspace[]>([]);
const [systems, setSystems] = useState<SystemMetadata[]>([]);
const [systems, setSystems] = useState<SystemProperties[]>([]);
const [areDependenciesLoaded, setAreDependenciesLoaded] = useState<boolean>(false);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import React, { ReactNode } from 'react';
import { AssetQueryBuilder } from './AssetQueryBuilder';
import { render } from '@testing-library/react';
import { QueryBuilderOption, Workspace } from 'core/types';
import { SystemMetadata } from 'datasources/system/types';
import { SystemProperties } from 'datasources/system/types';

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

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

function renderElement(workspaces: Workspace[], systems: SystemMetadata[], filter?: string, globalVariableOptions: QueryBuilderOption[] = []) {
function renderElement(workspaces: Workspace[], systems: SystemProperties[], filter?: string, globalVariableOptions: QueryBuilderOption[] = []) {
reactNode = React.createElement(AssetQueryBuilder, {
workspaces,
systems,
Expand All @@ -34,7 +34,7 @@ describe('AssetQueryBuilder', () => {

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"');

expect(conditionsContainer?.length).toBe(1);
Expand All @@ -43,7 +43,7 @@ describe('AssetQueryBuilder', () => {

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 All @@ -53,7 +53,7 @@ describe('AssetQueryBuilder', () => {

it('should select global variable option', () => {
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 globalVariableOption = { label: 'Global variable', value: 'global_variable' };

const { conditionsContainer } = renderElement([workspace], [system], 'AssetType = \"global_variable\"', [globalVariableOption]);
Expand All @@ -65,7 +65,7 @@ describe('AssetQueryBuilder', () => {
[['${__from:date}', 'From'], ['${__to:date}', 'To'], ['${__now:date}', 'Now']].forEach(([value, label]) => {
it(`should select user friendly value for calibration due date`, () => {
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], `ExternalCalibration.NextRecommendedDate > \"${value}\"`);

Expand All @@ -76,7 +76,7 @@ describe('AssetQueryBuilder', () => {

it('should select a sanitized 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 = "<script>alert(\'Workspace\')</script>"');

expect(conditionsContainer?.length).toBe(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'smart-webcomponents-react/source/styles/components/smart.querybuilder.cs
import { Workspace, QueryBuilderOption } from 'core/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';
import { QBField } from '../../../../types/CalibrationForecastQuery.types';
import { ListAssetsFields, ListAssetsStaticFields } from '../../../../constants/ListAssets.constants';
import { filterXSSField, filterXSSLINQExpression } from 'core/utils';
Expand All @@ -20,7 +20,7 @@ type AssetCalibrationQueryBuilderProps = QueryBuilderProps &
React.HTMLAttributes<Element> & {
filter?: string;
workspaces: Workspace[];
systems: SystemMetadata[];
systems: SystemProperties[];
globalVariableOptions: QueryBuilderOption[];
areDependenciesLoaded: boolean;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { screen, waitFor } from '@testing-library/react';
import { AssetQuery, AssetQueryType } from '../../types/types';
import { SystemMetadata } from '../../../system/types'
import { SystemProperties } from '../../../system/types'
import { AssetVariableQueryEditor } from './AssetVariableQueryEditor';
import { Workspace } from 'core/types';
import { setupRenderer } from 'test/fixtures';
import { ListAssetsDataSource } from '../../data-sources/list-assets/ListAssetsDataSource';
import { AssetDataSource } from 'datasources/asset/AssetDataSource';

const fakeSystems: SystemMetadata[] = [
const fakeSystems: SystemProperties[] = [
{
id: '1',
state: 'CONNECTED',
Expand Down Expand Up @@ -39,7 +39,7 @@ class FakeAssetsSource extends ListAssetsDataSource {
getWorkspaces(): Promise<Workspace[]> {
return Promise.resolve(fakeWorkspaces);
}
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 @@ -5,14 +5,14 @@ import { AssetDataSource } from '../../AssetDataSource'
import { FloatingError } from '../../../../core/errors';
import { AssetQueryBuilder } from '../editors/list-assets/query-builder/AssetQueryBuilder';
import { Workspace } from '../../../../core/types';
import { SystemMetadata } from '../../../system/types';
import { SystemProperties } from '../../../system/types';
import { AssetVariableQuery } from '../../../asset/types/AssetVariableQuery.types';

type Props = QueryEditorProps<AssetDataSource, AssetQuery, AssetDataSourceOptions>;

export function AssetVariableQueryEditor({ datasource, query, onChange }: Props) {
const [workspaces, setWorkspaces] = useState<Workspace[]>([]);
const [systems, setSystems] = useState<SystemMetadata[]>([]);
const [systems, setSystems] = useState<SystemProperties[]>([]);
const [areDependenciesLoaded, setAreDependenciesLoaded] = useState<boolean>(false);
const assetVariableQuery = query as AssetVariableQuery;
const assetListDatasource = useRef(datasource.getListAssetsSource());
Expand Down
8 changes: 4 additions & 4 deletions src/datasources/asset/data-sources/AssetDataSourceBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DataFrameDTO, DataQueryRequest, TestDataSourceResponse } from "@grafana
import { AssetDataSourceOptions, AssetQuery } from "../types/types";
import { DataSourceBase } from "../../../core/DataSourceBase";
import { defaultOrderBy, defaultProjection } from "../../system/constants";
import { SystemMetadata } from "../../system/types";
import { SystemProperties } from "../../system/types";
import { parseErrorMessage } from "../../../core/errors";
import { QueryBuilderOption, Workspace } from "../../../core/types";
import { ExpressionTransformFunction } from "../../../core/query-builder.utils";
Expand All @@ -19,7 +19,7 @@ export abstract class AssetDataSourceBase extends DataSourceBase<AssetQuery, Ass

public error = '';

public readonly systemAliasCache = new Map<string, SystemMetadata>([]);
public readonly systemAliasCache = new Map<string, SystemProperties>([]);
public readonly workspacesCache = new Map<string, Workspace>([]);


Expand All @@ -31,7 +31,7 @@ export abstract class AssetDataSourceBase extends DataSourceBase<AssetQuery, Ass
throw new Error("Method not implemented.");
}

public async querySystems(filter = '', projection = defaultProjection): Promise<SystemMetadata[]> {
public async querySystems(filter = '', projection = defaultProjection): Promise<SystemProperties[]> {
try {
let response = await this.getSystems({
filter: filter,
Expand All @@ -45,7 +45,7 @@ export abstract class AssetDataSourceBase extends DataSourceBase<AssetQuery, Ass
}
}

public getCachedSystems(): SystemMetadata[] {
public getCachedSystems(): SystemProperties[] {
return Array.from(this.systemAliasCache.values());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
requestMatching,
setupDataSource,
} from "test/fixtures";
import { SystemMetadata } from "datasources/system/types";
import { SystemProperties } from "datasources/system/types";
import { dateTime } from "@grafana/data";
import { AssetCalibrationForecastKey, AssetCalibrationPropertyGroupByType, AssetCalibrationTimeBasedGroupByType, CalibrationForecastQuery, CalibrationForecastResponse, ColumnDescriptorType } from "../../types/CalibrationForecastQuery.types";
import { CalibrationForecastDataSource } from "./CalibrationForecastDataSource";
Expand Down Expand Up @@ -311,7 +311,7 @@ const buildCalibrationForecastQuery = getQueryBuilder<CalibrationForecastQuery>(
groupBy: []
});

const fakeSystems: SystemMetadata[] = [
const fakeSystems: SystemProperties[] = [
{
id: 'Minion1',
alias: 'Minion1-alias',
Expand Down
Loading
Loading