Skip to content

Commit

Permalink
Merge pull request #895 from MiaofeiWang/CfMetadataCellValueSubtype
Browse files Browse the repository at this point in the history
[patch] Re-submit #867: Custom function - new field "cellValueType" for input cell value type information
  • Loading branch information
millerds authored Oct 9, 2024
2 parents ccd3179 + 996e83b commit c2087a0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 16 deletions.
21 changes: 21 additions & 0 deletions packages/custom-functions-metadata/src/parseTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface IFunctionParameter {
name: string;
description?: string;
type: string;
cellValueType?: string;
dimensionality?: string;
optional?: boolean;
repeating?: boolean;
Expand Down Expand Up @@ -161,6 +162,19 @@ const CELLVALUETYPE_MAPPINGS = {
"Excel.ValueTypeNotAvailableCellValue": "unsupported",
};

const CELLVALUETYPE_TO_BASICTYPE_MAPPINGS = {
"cellvalue": "any",
"booleancellvalue": "boolean",
"doublecellvalue": "number",
"entitycellvalue": "any",
"errorcellvalue": "any",
"formattednumbercellvalue": "number",
"linkedentitycellvalue": "any",
"localimagecellvalue": "any",
"stringcellvalue": "string",
"webimagecellvalue": "any",
};

type CustomFunctionsSchemaDimensionality = "invalid" | "scalar" | "matrix";

/**
Expand Down Expand Up @@ -708,6 +722,13 @@ function getParameters(parameterItem: IGetParametersArguments): IFunctionParamet
type: ptype,
};

// for backward compatibility, we put cell value type in cellValueType instead of type.
if (Object.values(CELLVALUETYPE_MAPPINGS).includes(ptype)) {
// @ts-ignore
pMetadataItem.type = CELLVALUETYPE_TO_BASICTYPE_MAPPINGS[ptype];
pMetadataItem.cellValueType = ptype
}

// Only return dimensionality = matrix. Default assumed scalar
if (pMetadataItem.dimensionality === "scalar") {
delete pMetadataItem.dimensionality;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"parameters": [
{
"name": "x",
"type": "cellvalue"
"type": "any",
"cellValueType": "cellvalue"
}
],
"result": {}
Expand All @@ -20,7 +21,8 @@
"parameters": [
{
"name": "x",
"type": "booleancellvalue"
"type": "boolean",
"cellValueType": "booleancellvalue"
}
],
"result": {}
Expand All @@ -32,7 +34,8 @@
"parameters": [
{
"name": "x",
"type": "doublecellvalue"
"type": "number",
"cellValueType": "doublecellvalue"
}
],
"result": {}
Expand All @@ -44,7 +47,8 @@
"parameters": [
{
"name": "x",
"type": "entitycellvalue"
"type": "any",
"cellValueType": "entitycellvalue"
}
],
"result": {}
Expand All @@ -56,7 +60,8 @@
"parameters": [
{
"name": "x",
"type": "errorcellvalue"
"type": "any",
"cellValueType": "errorcellvalue"
}
],
"result": {}
Expand All @@ -68,7 +73,8 @@
"parameters": [
{
"name": "x",
"type": "formattednumbercellvalue"
"type": "number",
"cellValueType": "formattednumbercellvalue"
}
],
"result": {}
Expand All @@ -80,7 +86,8 @@
"parameters": [
{
"name": "x",
"type": "linkedentitycellvalue"
"type": "any",
"cellValueType": "linkedentitycellvalue"
}
],
"result": {}
Expand All @@ -92,7 +99,8 @@
"parameters": [
{
"name": "x",
"type": "localimagecellvalue"
"type": "any",
"cellValueType": "localimagecellvalue"
}
],
"result": {}
Expand All @@ -104,7 +112,8 @@
"parameters": [
{
"name": "x",
"type": "stringcellvalue"
"type": "string",
"cellValueType": "stringcellvalue"
}
],
"result": {}
Expand All @@ -116,7 +125,8 @@
"parameters": [
{
"name": "x",
"type": "webimagecellvalue"
"type": "any",
"cellValueType": "webimagecellvalue"
}
],
"result": {}
Expand All @@ -129,7 +139,8 @@
{
"name": "x",
"repeating": true,
"type": "booleancellvalue"
"type": "boolean",
"cellValueType": "booleancellvalue"
}
],
"result": {}
Expand All @@ -142,7 +153,8 @@
{
"dimensionality": "matrix",
"name": "x",
"type": "booleancellvalue"
"type": "boolean",
"cellValueType": "booleancellvalue"
}
],
"result": {}
Expand All @@ -156,7 +168,8 @@
"dimensionality": "matrix",
"name": "x",
"repeating": true,
"type": "booleancellvalue"
"type": "boolean",
"cellValueType": "booleancellvalue"
}
],
"result": {}
Expand All @@ -169,7 +182,8 @@
{
"name": "x",
"repeating": true,
"type": "booleancellvalue"
"type": "boolean",
"cellValueType": "booleancellvalue"
}
],
"result": {}
Expand All @@ -182,7 +196,8 @@
{
"dimensionality": "matrix",
"name": "x",
"type": "booleancellvalue"
"type": "boolean",
"cellValueType": "booleancellvalue"
}
],
"result": {}
Expand All @@ -196,7 +211,8 @@
"dimensionality": "matrix",
"name": "x",
"repeating": true,
"type": "booleancellvalue"
"type": "boolean",
"cellValueType": "booleancellvalue"
}
],
"result": {}
Expand Down

0 comments on commit c2087a0

Please sign in to comment.