-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate OptionSetInfo, prepare way for new ChoiceInfo function (#2235)
OptionSetInfo only returns one value, the logical name of an option set choice. We'd like to redesign this function to accommodate: 1. The logical name is a text wrapped number for number and Boolean backed option sets coming from Dataverse. We recently added the ability to get at these values with the Value and Boolean functions which is a better way, strongly typed. #2230 1. There are other pieces of information that are worth knowing, for example the color of an option set choice, that can't be accommodated with this design. 1. Our preferred design is to return an extensible record of information. We could add an additional second argument with an enum to determine what information to return, with a default value of logical name, but this isn't our first choice. 1. We don't use the term OptionSet any longer in Dataverse, it has been replaced with Choice, which is more consistent with our existing Choices function. As some hosts may still be using this function, it will remain available as a function that can be enabled by calling config.EnableOptionSetInfo. Value/Boolean can be used immediately as a workaround, wrapped with Text if needed. We plan to add a new ChoiceInfo function with a separate PR.
- Loading branch information
1 parent
df482e0
commit 213a272
Showing
9 changed files
with
64 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
src/libraries/Microsoft.PowerFx.Core/Texl/Builtins/OptionSetInfo.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/libraries/Microsoft.PowerFx.Interpreter/Functions/OptionSetInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.PowerFx.Core.Functions; | ||
using Microsoft.PowerFx.Core.IR; | ||
using Microsoft.PowerFx.Core.Localization; | ||
using Microsoft.PowerFx.Core.Types; | ||
using Microsoft.PowerFx.Core.Utils; | ||
using Microsoft.PowerFx.Functions; | ||
using Microsoft.PowerFx.Types; | ||
|
||
namespace Microsoft.PowerFx.Interpreter | ||
{ | ||
internal sealed class OptionSetInfoFunction : TexlFunction, IAsyncTexlFunction | ||
{ | ||
public override bool IsSelfContained => true; | ||
|
||
public override bool SupportsParamCoercion => false; | ||
|
||
public OptionSetInfoFunction() | ||
: base(DPath.Root, "OptionSetInfo", "OptionSetInfo", TexlStrings.AboutOptionSetInfo, FunctionCategories.Text, DType.String, 0, 1, 1, DType.OptionSetValue) | ||
{ | ||
} | ||
|
||
public override IEnumerable<TexlStrings.StringGetter[]> GetSignatures() | ||
{ | ||
yield return new[] { TexlStrings.AboutOptionSetInfoArg1 }; | ||
} | ||
|
||
public async Task<FormulaValue> InvokeAsync(FormulaValue[] args, CancellationToken cancellationToken) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
|
||
switch (args[0]) | ||
{ | ||
case ErrorValue errorValue: | ||
return errorValue; | ||
case BlankValue: | ||
return new StringValue(IRContext.NotInSource(FormulaType.String), string.Empty); | ||
case OptionSetValue osv: | ||
return new StringValue(IRContext.NotInSource(FormulaType.String), osv.Option); | ||
} | ||
|
||
return CommonErrors.GenericInvalidArgument(args[0].IRContext); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters