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

feat(asset): compute "Now" in a way that can be saved #107

Merged
merged 1 commit into from
Oct 29, 2024
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
2 changes: 1 addition & 1 deletion src/core/query-builder.utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('QueryBuilderUtils', () => {
});

it('should handle unsupported operations correctly', () => {
const query = 'Object1 > "value1" AND Object2 < "value2"';
const query = 'Object1 % "value1" AND Object2 % "value2"';
const result = transformComputedFieldsQuery(query, computedDataFields);
expect(result).toBe(query);
});
Expand Down
2 changes: 1 addition & 1 deletion src/core/query-builder.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type ExpressionTransformFunction = (value: string, operation: string, opt
/**
* Supported operations for computed fields
*/
export const computedFieldsupportedOperations = ['=', '!='];
export const computedFieldsupportedOperations = ['=', '!=', '>', '>=', '<', '<='];

/**
* The function will replace the computed fields with their transformation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,18 @@ describe('AssetQueryBuilder', () => {
expect(conditionsContainer.item(0)?.textContent).toContain(globalVariableOption.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;
[['${__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 { conditionsContainer } = renderElement([workspace], [system], 'ExternalCalibration.NextRecommendedDate > \"${__from:date}\"');
const { conditionsContainer } = renderElement([workspace], [system], `ExternalCalibration.NextRecommendedDate > \"${value}\"` );

expect(conditionsContainer?.length).toBe(1);
expect(conditionsContainer.item(0)?.textContent).toContain("From");
expect(conditionsContainer?.length).toBe(1);
expect(conditionsContainer.item(0)?.textContent).toContain(label);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const AssetQueryBuilder: React.FC<AssetCalibrationQueryBuilderProps> = ({
...(calibrationField.lookup?.dataSource || []),
{ label: 'From', value: '${__from:date}' },
{ label: 'To', value: '${__to:date}' },
{ label: 'Now', value: new Date().toISOString() },
{ label: 'Now', value: '${__now:date}' },
],
},
};
Expand Down
1 change: 1 addition & 0 deletions src/datasources/asset/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum AllFieldNames {
VENDOR_NAME = 'VendorName',
BUS_TYPE = 'BusType',
ASSET_TYPE = 'AssetType',
CALIBRATION_DUE_DATE = 'ExternalCalibration.NextRecommendedDate',
}

export const QUERY_LIMIT = 1000;
14 changes: 13 additions & 1 deletion src/datasources/asset/data-sources/AssetDataSourceBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export abstract class AssetDataSourceBase extends DataSourceBase<AssetQuery, Ass
}

public readonly queryTransformationOptions = new Map<string, Map<string, unknown>>([
[AllFieldNames.LOCATION, this.systemAliasCache]
[AllFieldNames.LOCATION, this.systemAliasCache],
[AllFieldNames.CALIBRATION_DUE_DATE, new Map<string, unknown>()]
]);

public readonly assetComputedDataFields = new Map<string, ExpressionTransformFunction>([
Expand All @@ -116,6 +117,17 @@ export abstract class AssetDataSourceBase extends DataSourceBase<AssetQuery, Ass
}

return `Locations.Any(l => l.MinionId ${operation} "${value}" ${this.getLocicalOperator(operation)} l.PhysicalLocation ${operation} "${value}")`;
}],
[
AllFieldNames.CALIBRATION_DUE_DATE,
(value: string, operation: string, options?: Map<string, unknown>) =>
{
if (value === '${__now:date}' )
{
return `${AllFieldNames.CALIBRATION_DUE_DATE} ${operation} "${new Date().toISOString()}"`;
}

return `${AllFieldNames.CALIBRATION_DUE_DATE} ${operation} "${value}"`;
}]]);

protected multipleValuesQuery(field: string): ExpressionTransformFunction {
Expand Down
Loading