Skip to content

Commit

Permalink
[G&M] Added new functions in UI for Custom Calculations (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
smmr-dn authored Dec 5, 2023
1 parent 954a566 commit 3e0beb7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/grouping-mapping-widget",
"comment": "Added new functions for Custom Calculations in FormulaFunctionProvider.ts",
"type": "patch"
}
],
"packageName": "@itwin/grouping-mapping-widget"
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function getNumericalFunction(name: string): FormulaFunction | undefined {
case "tan": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "Number" }], returnType: "Number" };
case "tanh": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "Number" }], returnType: "Number" };
case "trunc": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "Number" }], returnType: "Number" };
case "tonumber": return { argumentCountBounds: [1, 1], expectedArguments: [{ canBeAny: true }], returnType: "Number" };
default: return undefined;
}
}
Expand All @@ -142,6 +143,7 @@ function getStringFunction(name: string): FormulaFunction | undefined {
case "trim": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "String" }], returnType: "String" };
case "trimend": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "String" }], returnType: "String" };
case "trimstart": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "String" }], returnType: "String" };
case "tostring": return { argumentCountBounds: [1, 1], expectedArguments: [{ canBeAny: true }], returnType: "String" };
default: return undefined;
}
}
Expand All @@ -161,9 +163,17 @@ function getConditionalFunction(name: string): FormulaFunction | undefined {
}
}

function getBooleanFunction(name: string): FormulaFunction | undefined {
switch (name) {
case "isin": return { argumentCountBounds: [2, -1], expectedArguments: [{ canBeAny: true }, { canBeAny: true }], typesMatchFromIndex: 0, returnType: "Boolean"};
case "toboolean": return { argumentCountBounds: [1, 1], expectedArguments: [{ canBeAny: true }], returnType: "Boolean"};
default: return undefined;
}
}

export function getFunction(name: string): FormulaFunction | undefined {
const nameLowerCase = name.toLowerCase();
return getNumericalFunction(nameLowerCase) || getStringFunction(nameLowerCase) || getConditionalFunction(nameLowerCase);
return getNumericalFunction(nameLowerCase) || getStringFunction(nameLowerCase) || getConditionalFunction(nameLowerCase) || getBooleanFunction(nameLowerCase);
}

export function isFunction(name: string): boolean {
Expand Down

0 comments on commit 3e0beb7

Please sign in to comment.